Change all previous weird logs to log:: logs

This commit is contained in:
Sofia 2025-08-17 17:15:27 +03:00
parent 3a5766186a
commit 1d0fd9dd0a
5 changed files with 44 additions and 153 deletions

View File

@ -11,8 +11,6 @@ default = ["color", "cli"]
color = ["colored"] color = ["colored"]
cli = ["argh", "stderrlog"] cli = ["argh", "stderrlog"]
log_output = []
context_debug = []
[dependencies] [dependencies]
## Make it easier to generate errors ## Make it easier to generate errors

View File

@ -37,16 +37,13 @@ fn main() -> Result<(), std::io::Error> {
}, },
CustomIRs { llir, mir }, CustomIRs { llir, mir },
)) => { )) => {
#[cfg(feature = "log_output")] log::trace!("{}", _llvm_ir);
{ log::debug!("Compiled with triple: {}\n", &_triple);
println!("{}", _llvm_ir); log::debug!("Output LLVM IR to {:?}", llvm_ir_path);
println!("Compiled with triple: {}\n", &_triple); log::debug!("Output Assembly to {:?}", asm_path);
println!("Output LLVM IR to {:?}", llvm_ir_path); log::debug!("Output Object-file to {:?}\n", object_path);
println!("Output Assembly to {:?}", asm_path); log::debug!("Output LLIR-file to {:?}\n", llir_path);
println!("Output Object-file to {:?}\n", object_path); log::debug!("Output MIR-file to {:?}\n", mir_path);
println!("Output LLIR-file to {:?}\n", llir_path);
println!("Output MIR-file to {:?}\n", mir_path);
}
fs::write(&llvm_ir_path, &_llvm_ir).expect("Could not write LLVM IR -file!"); fs::write(&llvm_ir_path, &_llvm_ir).expect("Could not write LLVM IR -file!");
fs::write(&asm_path, &assembly).expect("Could not write Assembly-file!"); fs::write(&asm_path, &assembly).expect("Could not write Assembly-file!");
@ -71,8 +68,7 @@ fn main() -> Result<(), std::io::Error> {
Err(e) => panic!("{}", e), Err(e) => panic!("{}", e),
}; };
} else { } else {
#[cfg(feature = "log_output")] log::error!("Please input compiled file path!")
println!("Please input compiled file path!")
} }
Ok(()) Ok(())
} }

View File

@ -1,9 +1,4 @@
use std::{ use std::{path::PathBuf, process::Command, thread, time::Duration};
path::PathBuf,
process::{Command, Stdio},
thread,
time::Duration,
};
pub struct LDRunner { pub struct LDRunner {
command: String, command: String,
@ -49,8 +44,6 @@ impl LDRunner {
input_path, input_path,
out_path out_path
); );
#[cfg(feature = "log_output")]
dbg!(&ld);
let ld_output = ld.output().expect("Unable to execute ld!"); let ld_output = ld.output().expect("Unable to execute ld!");
if !ld_output.status.success() { if !ld_output.status.success() {

View File

@ -98,8 +98,7 @@ pub fn parse_module<'map, T: Into<String>>(
map.set_tokens(id, tokens.clone()); map.set_tokens(id, tokens.clone());
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#?}", &tokens);
println!("{:#?}", &tokens);
Ok((id, tokens)) Ok((id, tokens))
} }
@ -158,8 +157,7 @@ pub fn compile_module<'map>(
} }
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#?}", &ast_module);
dbg!(&ast_module);
Ok(Ok(ast_module.process(module_id))) Ok(Ok(ast_module.process(module_id)))
} }
@ -169,12 +167,10 @@ pub fn perform_all_passes<'map>(
module_map: &'map mut ErrorModules, module_map: &'map mut ErrorModules,
) -> Result<(), ReidError> { ) -> Result<(), ReidError> {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#?}", &context);
dbg!(&context);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#}", &context);
println!("{:#}", &context);
let state = context.pass(&mut LinkerPass { let state = context.pass(&mut LinkerPass {
module_map, module_map,
@ -188,14 +184,11 @@ pub fn perform_all_passes<'map>(
} }
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:-^100}", "LINKER OUTPUT");
println!("{:-^100}", "LINKER OUTPUT");
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#}", &context);
println!("{:#}", &context);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#?}", &state);
dbg!(&state);
if !state.errors.is_empty() { if !state.errors.is_empty() {
return Err(ReidError::from_kind( return Err(ReidError::from_kind(
@ -216,14 +209,11 @@ pub fn perform_all_passes<'map>(
let state = context.pass(&mut macro_pass)?; let state = context.pass(&mut macro_pass)?;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:-^100}", "MACRO OUTPUT");
println!("{:-^100}", "MACRO OUTPUT");
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#}", &context);
println!("{:#}", &context);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#?}", &state);
dbg!(&state);
if !state.errors.is_empty() { if !state.errors.is_empty() {
return Err(ReidError::from_kind( return Err(ReidError::from_kind(
@ -257,17 +247,13 @@ pub fn perform_all_passes<'map>(
let state = context.pass(&mut TypeInference { refs: &mut refs })?; let state = context.pass(&mut TypeInference { refs: &mut refs })?;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:-^70}", "TYPE INFERRER OUTPUT");
println!("{:-^100}", "TYPE INFERRER OUTPUT");
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{}", &refs);
println!("{}", &refs);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#}", &context);
println!("{:#}", &context);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#?}", &state);
dbg!(&state);
if !state.errors.is_empty() { if !state.errors.is_empty() {
return Err(ReidError::from_kind( return Err(ReidError::from_kind(
@ -283,14 +269,11 @@ pub fn perform_all_passes<'map>(
let state = context.pass(&mut TypeCheck { refs: &refs })?; let state = context.pass(&mut TypeCheck { refs: &refs })?;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:-^100}", "TYPECHECKER OUTPUT");
println!("{:-^100}", "TYPECHECKER OUTPUT");
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#}", &context);
println!("{:#}", &context);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#?}", &state);
dbg!(&state);
if !state.errors.is_empty() { if !state.errors.is_empty() {
return Err(ReidError::from_kind( return Err(ReidError::from_kind(
@ -303,9 +286,6 @@ pub fn perform_all_passes<'map>(
)); ));
} }
#[cfg(feature = "context_debug")]
dbg!(&context);
Ok(()) Ok(())
} }
@ -330,11 +310,9 @@ pub fn compile_and_pass<'map>(
perform_all_passes(&mut mir_context, module_map)?; perform_all_passes(&mut mir_context, module_map)?;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:-^100}", "FINAL OUTPUT");
println!("{:-^100}", "FINAL OUTPUT");
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{:#}", &mir_context);
println!("{:#}", &mir_context);
let mut context = Context::new(format!("Reid ({})", env!("CARGO_PKG_VERSION"))); let mut context = Context::new(format!("Reid ({})", env!("CARGO_PKG_VERSION")));
let codegen_modules = match mir_context.codegen(&mut context) { let codegen_modules = match mir_context.codegen(&mut context) {
@ -343,8 +321,7 @@ pub fn compile_and_pass<'map>(
}; };
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[cfg(feature = "log_output")] log::trace!("{}", &codegen_modules.context);
println!("{}", &codegen_modules.context);
let compiled = codegen_modules.compile(cpu, features); let compiled = codegen_modules.compile(cpu, features);
Ok(( Ok((

View File

@ -1,4 +1,4 @@
use std::{env, fs, path::PathBuf}; use std::{fs, path::PathBuf};
use argh::FromArgs; use argh::FromArgs;
use log::*; use log::*;
@ -12,6 +12,9 @@ struct Options {
#[argh(option, short = 'l', default = "log::Level::Info")] #[argh(option, short = 'l', default = "log::Level::Info")]
/// log level /// log level
log_level: log::Level, log_level: log::Level,
#[argh(switch, short = 't')]
/// should logs be timestamped
timestamps: bool,
#[argh(subcommand)] #[argh(subcommand)]
command: Command, command: Command,
} }
@ -27,7 +30,7 @@ enum Command {
#[argh(subcommand, name = "build")] #[argh(subcommand, name = "build")]
struct BuildOpts { struct BuildOpts {
#[argh(option, long = "lib", short = 'l')] #[argh(option, long = "lib", short = 'l')]
/// asd /// additional libraries to link against (with ld)
libraries: Vec<String>, libraries: Vec<String>,
#[argh(positional)] #[argh(positional)]
path: PathBuf, path: PathBuf,
@ -37,7 +40,7 @@ fn main() {
let options: Options = argh::from_env(); let options: Options = argh::from_env();
let mut errlog = stderrlog::new(); let mut errlog = stderrlog::new();
errlog.module(module_path!()).verbosity(options.log_level); errlog.module(module_path!()).verbosity(options.log_level);
if options.log_level as u8 > 3 { if options.timestamps {
errlog.timestamp(stderrlog::Timestamp::Second); errlog.timestamp(stderrlog::Timestamp::Second);
} }
errlog.init().unwrap(); errlog.init().unwrap();
@ -82,16 +85,13 @@ fn main() {
}, },
CustomIRs { llir, mir }, CustomIRs { llir, mir },
)) => { )) => {
#[cfg(feature = "log_output")] log::trace!("{}", _llvm_ir);
{ log::debug!("Compiled with triple: {}\n", &_triple);
println!("{}", _llvm_ir); log::debug!("Output LLVM IR to {:?}", llvm_ir_path);
println!("Compiled with triple: {}\n", &_triple); log::debug!("Output Assembly to {:?}", asm_path);
println!("Output LLVM IR to {:?}", llvm_ir_path); log::debug!("Output Object-file to {:?}\n", object_path);
println!("Output Assembly to {:?}", asm_path); log::debug!("Output LLIR-file to {:?}\n", llir_path);
println!("Output Object-file to {:?}\n", object_path); log::debug!("Output MIR-file to {:?}\n", mir_path);
println!("Output LLIR-file to {:?}\n", llir_path);
println!("Output MIR-file to {:?}\n", mir_path);
}
fs::write(&llvm_ir_path, &_llvm_ir).expect("Could not write LLVM IR -file!"); fs::write(&llvm_ir_path, &_llvm_ir).expect("Could not write LLVM IR -file!");
fs::write(&asm_path, &assembly).expect("Could not write Assembly-file!"); fs::write(&asm_path, &assembly).expect("Could not write Assembly-file!");
@ -99,12 +99,12 @@ fn main() {
fs::write(&llir_path, &llir).expect("Could not write LLIR-file!"); fs::write(&llir_path, &llir).expect("Could not write LLIR-file!");
fs::write(&mir_path, &mir).expect("Could not write MIR-file!"); fs::write(&mir_path, &mir).expect("Could not write MIR-file!");
let after = std::time::SystemTime::now(); let after = std::time::SystemTime::now();
println!( log::info!(
"Compilation took: {:.2}ms\n", "Compilation took: {:.2}ms\n",
(after.duration_since(before).unwrap().as_micros() as f32) / 1000. (after.duration_since(before).unwrap().as_micros() as f32) / 1000.
); );
println!("Linking {:?}", &object_path); log::info!("Linking {:?}", &object_path);
let linker = std::env::var("LD").unwrap_or("ld".to_owned()); let linker = std::env::var("LD").unwrap_or("ld".to_owned());
let mut linker = LDRunner::from_command(&linker).with_library("c").with_library("m"); let mut linker = LDRunner::from_command(&linker).with_library("c").with_library("m");
@ -118,76 +118,3 @@ fn main() {
} }
} }
} }
// fn main() -> Result<(), std::io::Error> {
// let args: Vec<String> = env::args().collect();
// let mut iter = args.into_iter().skip(1);
// if let Some(filename) = iter.next() {
// let mut libraries = Vec::new();
// while let Some(libname) = iter.next() {
// libraries.push(libname);
// }
// let path = PathBuf::from(filename).canonicalize().unwrap();
// let parent = path.with_extension("");
// let llvm_ir_path = parent.with_extension("ll");
// let object_path = parent.with_extension("o");
// let llir_path = parent.with_extension("llir");
// let mir_path = parent.with_extension("mir");
// let asm_path = parent.with_extension("asm");
// let before = std::time::SystemTime::now();
// let text = fs::read_to_string(&path)?;
// let cpu = std::env::var("CPU").unwrap_or("generic".to_owned());
// let features = std::env::var("REIDFLAGS").unwrap_or("".to_owned());
// match compile_simple(&text, PathBuf::from(&path), Some(cpu), vec![features]) {
// Ok((
// CompileOutput {
// triple: _triple,
// assembly,
// obj_buffer,
// llvm_ir: _llvm_ir,
// },
// CustomIRs { llir, mir },
// )) => {
// #[cfg(feature = "log_output")]
// {
// println!("{}", _llvm_ir);
// println!("Compiled with triple: {}\n", &_triple);
// println!("Output LLVM IR to {:?}", llvm_ir_path);
// println!("Output Assembly to {:?}", asm_path);
// println!("Output Object-file to {:?}\n", object_path);
// println!("Output LLIR-file to {:?}\n", llir_path);
// println!("Output MIR-file to {:?}\n", mir_path);
// }
// fs::write(&llvm_ir_path, &_llvm_ir).expect("Could not write LLVM IR -file!");
// fs::write(&asm_path, &assembly).expect("Could not write Assembly-file!");
// fs::write(&object_path, &obj_buffer).expect("Could not write Object-file!");
// fs::write(&llir_path, &llir).expect("Could not write LLIR-file!");
// fs::write(&mir_path, &mir).expect("Could not write MIR-file!");
// let after = std::time::SystemTime::now();
// println!(
// "Compilation took: {:.2}ms\n",
// (after.duration_since(before).unwrap().as_micros() as f32) / 1000.
// );
// println!("Linking {:?}", &object_path);
// let linker = std::env::var("LD").unwrap_or("ld".to_owned());
// let mut linker = LDRunner::from_command(&linker).with_library("c").with_library("m");
// for library in libraries {
// linker = linker.with_library(&library);
// }
// linker.invoke(&object_path, &object_path.with_extension("out"));
// }
// Err(e) => panic!("{}", e),
// };
// } else {
// println!("Please input compiled file path!")
// }
// Ok(())
// }