Put all debug prints behind debug-assertions

This commit is contained in:
Sofia 2025-07-14 23:43:03 +03:00
parent 0e5f12e0e2
commit 5b5ec48b8d
5 changed files with 22 additions and 20 deletions

View File

@ -6,7 +6,7 @@
# Do note this file is extremely simply for my own personal convenience # Do note this file is extremely simply for my own personal convenience
export .env export .env
cargo run --example cli $1 && \ cargo run --release --example cli $1 && \
# clang hello.o -o main && \ # clang hello.o -o main && \
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 \ ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
-o main /usr/lib/crt1.o hello.o -lc && \ -o main /usr/lib/crt1.o hello.o -lc && \

View File

@ -246,7 +246,7 @@ impl FunctionHolder {
if self.data.flags.is_extern { if self.data.flags.is_extern {
LLVMSetLinkage(own_function.value_ref, LLVMLinkage::LLVMExternalLinkage); LLVMSetLinkage(own_function.value_ref, LLVMLinkage::LLVMExternalLinkage);
// Use "available internally" if the other kind of extern // TODO Use "available internally" if the other kind of extern
return; return;
} }

View File

@ -38,6 +38,7 @@
//! - ~~Extern functions~~ (DONE) //! - ~~Extern functions~~ (DONE)
//! - ~~Strings~~ (DONE) //! - ~~Strings~~ (DONE)
//! - Loops //! - Loops
//! - Debug Symbols
//! ``` //! ```
use std::path::PathBuf; use std::path::PathBuf;
@ -79,6 +80,7 @@ pub fn compile_module(
) -> Result<mir::Module, ReidError> { ) -> Result<mir::Module, ReidError> {
let tokens = lexer::tokenize(source)?; let tokens = lexer::tokenize(source)?;
#[cfg(debug_assertions)]
dbg!(&tokens); dbg!(&tokens);
let mut token_stream = TokenStream::from(&tokens); let mut token_stream = TokenStream::from(&tokens);
@ -101,12 +103,13 @@ pub fn compile_module(
} }
pub fn perform_all_passes(context: &mut mir::Context) -> Result<(), ReidError> { pub fn perform_all_passes(context: &mut mir::Context) -> Result<(), ReidError> {
let state = context.pass(&mut LinkerPass);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ println!("{}", &context);
dbg!(&context);
println!("{}", &context); let state = context.pass(&mut LinkerPass);
}
#[cfg(debug_assertions)]
println!("{:?}\n{}", &context, &context);
if !state.errors.is_empty() { if !state.errors.is_empty() {
return Err(ReidError::LinkerErrors(state.errors)); return Err(ReidError::LinkerErrors(state.errors));
@ -115,23 +118,22 @@ pub fn perform_all_passes(context: &mut mir::Context) -> Result<(), ReidError> {
let refs = TypeRefs::default(); let refs = TypeRefs::default();
let state = context.pass(&mut TypeInference { refs: &refs }); let state = context.pass(&mut TypeInference { refs: &refs });
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ dbg!(&state, &refs);
dbg!(&state, &refs); #[cfg(debug_assertions)]
dbg!(&context); println!("{}", &context);
println!("{}", &context);
}
if !state.errors.is_empty() { if !state.errors.is_empty() {
return Err(ReidError::TypeInferenceErrors(state.errors)); return Err(ReidError::TypeInferenceErrors(state.errors));
} }
let state = context.pass(&mut TypeCheck { refs: &refs }); let state = context.pass(&mut TypeCheck { refs: &refs });
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ dbg!(&state);
dbg!(&state); #[cfg(debug_assertions)]
println!("{}", &context); println!("{}", &context);
}
if !state.errors.is_empty() { if !state.errors.is_empty() {
return Err(ReidError::TypeCheckErrors(state.errors)); return Err(ReidError::TypeCheckErrors(state.errors));
@ -156,14 +158,14 @@ pub fn compile(source: &str, path: PathBuf) -> Result<String, ReidError> {
path.parent().unwrap().to_owned(), path.parent().unwrap().to_owned(),
); );
println!("{}", &mir_context);
perform_all_passes(&mut mir_context)?; perform_all_passes(&mut mir_context)?;
let mut context = Context::new(); let mut context = Context::new();
let codegen_modules = mir_context.codegen(&mut context); let codegen_modules = mir_context.codegen(&mut context);
#[cfg(debug_assertions)]
dbg!(&codegen_modules); dbg!(&codegen_modules);
let compiled = codegen_modules.compile(); let compiled = codegen_modules.compile();
compiled.output(); compiled.output();

View File

@ -130,6 +130,7 @@ impl<'a, 'b> TokenStream<'a, 'b> {
match T::parse(clone) { match T::parse(clone) {
Ok(res) => { Ok(res) => {
#[cfg(debug_assertions)]
dbg!(&res); dbg!(&res);
let new_pos = ref_pos.max(self.position); let new_pos = ref_pos.max(self.position);
Ok((res, new_pos)) Ok((res, new_pos))

View File

@ -1,10 +1,9 @@
import std::print; import std::print;
fn main() -> u16 { fn main() {
let hello = "hello world"; let hello = "hello world";
print(hello); print(hello);
return 0;
} }