Change all previous weird logs to log:: logs
This commit is contained in:
		
							parent
							
								
									3a5766186a
								
							
						
					
					
						commit
						1d0fd9dd0a
					
				| @ -11,8 +11,6 @@ default = ["color", "cli"] | ||||
| 
 | ||||
| color = ["colored"] | ||||
| cli = ["argh", "stderrlog"] | ||||
| log_output = [] | ||||
| context_debug = [] | ||||
| 
 | ||||
| [dependencies] | ||||
| ## Make it easier to generate errors | ||||
|  | ||||
| @ -37,16 +37,13 @@ fn main() -> Result<(), std::io::Error> { | ||||
|                 }, | ||||
|                 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); | ||||
|                 } | ||||
|                 log::trace!("{}", _llvm_ir); | ||||
|                 log::debug!("Compiled with triple: {}\n", &_triple); | ||||
|                 log::debug!("Output LLVM IR to {:?}", llvm_ir_path); | ||||
|                 log::debug!("Output Assembly to {:?}", asm_path); | ||||
|                 log::debug!("Output Object-file to {:?}\n", object_path); | ||||
|                 log::debug!("Output LLIR-file to {:?}\n", llir_path); | ||||
|                 log::debug!("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!"); | ||||
| @ -71,8 +68,7 @@ fn main() -> Result<(), std::io::Error> { | ||||
|             Err(e) => panic!("{}", e), | ||||
|         }; | ||||
|     } else { | ||||
|         #[cfg(feature = "log_output")] | ||||
|         println!("Please input compiled file path!") | ||||
|         log::error!("Please input compiled file path!") | ||||
|     } | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
| @ -1,9 +1,4 @@ | ||||
| use std::{ | ||||
|     path::PathBuf, | ||||
|     process::{Command, Stdio}, | ||||
|     thread, | ||||
|     time::Duration, | ||||
| }; | ||||
| use std::{path::PathBuf, process::Command, thread, time::Duration}; | ||||
| 
 | ||||
| pub struct LDRunner { | ||||
|     command: String, | ||||
| @ -49,8 +44,6 @@ impl LDRunner { | ||||
|             input_path, | ||||
|             out_path | ||||
|         ); | ||||
|         #[cfg(feature = "log_output")] | ||||
|         dbg!(&ld); | ||||
| 
 | ||||
|         let ld_output = ld.output().expect("Unable to execute ld!"); | ||||
|         if !ld_output.status.success() { | ||||
|  | ||||
| @ -98,8 +98,7 @@ pub fn parse_module<'map, T: Into<String>>( | ||||
|     map.set_tokens(id, tokens.clone()); | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:#?}", &tokens); | ||||
|     log::trace!("{:#?}", &tokens); | ||||
| 
 | ||||
|     Ok((id, tokens)) | ||||
| } | ||||
| @ -158,8 +157,7 @@ pub fn compile_module<'map>( | ||||
|     } | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     dbg!(&ast_module); | ||||
|     log::trace!("{:#?}", &ast_module); | ||||
| 
 | ||||
|     Ok(Ok(ast_module.process(module_id))) | ||||
| } | ||||
| @ -169,12 +167,10 @@ pub fn perform_all_passes<'map>( | ||||
|     module_map: &'map mut ErrorModules, | ||||
| ) -> Result<(), ReidError> { | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     dbg!(&context); | ||||
|     log::trace!("{:#?}", &context); | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:#}", &context); | ||||
|     log::trace!("{:#}", &context); | ||||
| 
 | ||||
|     let state = context.pass(&mut LinkerPass { | ||||
|         module_map, | ||||
| @ -188,14 +184,11 @@ pub fn perform_all_passes<'map>( | ||||
|     } | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:-^100}", "LINKER OUTPUT"); | ||||
|     log::trace!("{:-^100}", "LINKER OUTPUT"); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:#}", &context); | ||||
|     log::trace!("{:#}", &context); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     dbg!(&state); | ||||
|     log::trace!("{:#?}", &state); | ||||
| 
 | ||||
|     if !state.errors.is_empty() { | ||||
|         return Err(ReidError::from_kind( | ||||
| @ -216,14 +209,11 @@ pub fn perform_all_passes<'map>( | ||||
|     let state = context.pass(&mut macro_pass)?; | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:-^100}", "MACRO OUTPUT"); | ||||
|     log::trace!("{:-^100}", "MACRO OUTPUT"); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:#}", &context); | ||||
|     log::trace!("{:#}", &context); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     dbg!(&state); | ||||
|     log::trace!("{:#?}", &state); | ||||
| 
 | ||||
|     if !state.errors.is_empty() { | ||||
|         return Err(ReidError::from_kind( | ||||
| @ -257,17 +247,13 @@ pub fn perform_all_passes<'map>( | ||||
|     let state = context.pass(&mut TypeInference { refs: &mut refs })?; | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:-^100}", "TYPE INFERRER OUTPUT"); | ||||
|     log::trace!("{:-^70}", "TYPE INFERRER OUTPUT"); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{}", &refs); | ||||
|     log::trace!("{}", &refs); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:#}", &context); | ||||
|     log::trace!("{:#}", &context); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     dbg!(&state); | ||||
|     log::trace!("{:#?}", &state); | ||||
| 
 | ||||
|     if !state.errors.is_empty() { | ||||
|         return Err(ReidError::from_kind( | ||||
| @ -283,14 +269,11 @@ pub fn perform_all_passes<'map>( | ||||
|     let state = context.pass(&mut TypeCheck { refs: &refs })?; | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:-^100}", "TYPECHECKER OUTPUT"); | ||||
|     log::trace!("{:-^100}", "TYPECHECKER OUTPUT"); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:#}", &context); | ||||
|     log::trace!("{:#}", &context); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     dbg!(&state); | ||||
|     log::trace!("{:#?}", &state); | ||||
| 
 | ||||
|     if !state.errors.is_empty() { | ||||
|         return Err(ReidError::from_kind( | ||||
| @ -303,9 +286,6 @@ pub fn perform_all_passes<'map>( | ||||
|         )); | ||||
|     } | ||||
| 
 | ||||
|     #[cfg(feature = "context_debug")] | ||||
|     dbg!(&context); | ||||
| 
 | ||||
|     Ok(()) | ||||
| } | ||||
| 
 | ||||
| @ -330,11 +310,9 @@ pub fn compile_and_pass<'map>( | ||||
|     perform_all_passes(&mut mir_context, module_map)?; | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:-^100}", "FINAL OUTPUT"); | ||||
|     log::trace!("{:-^100}", "FINAL OUTPUT"); | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{:#}", &mir_context); | ||||
|     log::trace!("{:#}", &mir_context); | ||||
| 
 | ||||
|     let mut context = Context::new(format!("Reid ({})", env!("CARGO_PKG_VERSION"))); | ||||
|     let codegen_modules = match mir_context.codegen(&mut context) { | ||||
| @ -343,8 +321,7 @@ pub fn compile_and_pass<'map>( | ||||
|     }; | ||||
| 
 | ||||
|     #[cfg(debug_assertions)] | ||||
|     #[cfg(feature = "log_output")] | ||||
|     println!("{}", &codegen_modules.context); | ||||
|     log::trace!("{}", &codegen_modules.context); | ||||
| 
 | ||||
|     let compiled = codegen_modules.compile(cpu, features); | ||||
|     Ok(( | ||||
|  | ||||
							
								
								
									
										103
									
								
								reid/src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										103
									
								
								reid/src/main.rs
									
									
									
									
									
								
							| @ -1,4 +1,4 @@ | ||||
| use std::{env, fs, path::PathBuf}; | ||||
| use std::{fs, path::PathBuf}; | ||||
| 
 | ||||
| use argh::FromArgs; | ||||
| use log::*; | ||||
| @ -12,6 +12,9 @@ struct Options { | ||||
|     #[argh(option, short = 'l', default = "log::Level::Info")] | ||||
|     /// log level
 | ||||
|     log_level: log::Level, | ||||
|     #[argh(switch, short = 't')] | ||||
|     /// should logs be timestamped
 | ||||
|     timestamps: bool, | ||||
|     #[argh(subcommand)] | ||||
|     command: Command, | ||||
| } | ||||
| @ -27,7 +30,7 @@ enum Command { | ||||
| #[argh(subcommand, name = "build")] | ||||
| struct BuildOpts { | ||||
|     #[argh(option, long = "lib", short = 'l')] | ||||
|     /// asd
 | ||||
|     /// additional libraries to link against (with ld)
 | ||||
|     libraries: Vec<String>, | ||||
|     #[argh(positional)] | ||||
|     path: PathBuf, | ||||
| @ -37,7 +40,7 @@ fn main() { | ||||
|     let options: Options = argh::from_env(); | ||||
|     let mut errlog = stderrlog::new(); | ||||
|     errlog.module(module_path!()).verbosity(options.log_level); | ||||
|     if options.log_level as u8 > 3 { | ||||
|     if options.timestamps { | ||||
|         errlog.timestamp(stderrlog::Timestamp::Second); | ||||
|     } | ||||
|     errlog.init().unwrap(); | ||||
| @ -82,16 +85,13 @@ fn main() { | ||||
|                     }, | ||||
|                     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); | ||||
|                     } | ||||
|                     log::trace!("{}", _llvm_ir); | ||||
|                     log::debug!("Compiled with triple: {}\n", &_triple); | ||||
|                     log::debug!("Output LLVM IR to {:?}", llvm_ir_path); | ||||
|                     log::debug!("Output Assembly to {:?}", asm_path); | ||||
|                     log::debug!("Output Object-file to {:?}\n", object_path); | ||||
|                     log::debug!("Output LLIR-file to {:?}\n", llir_path); | ||||
|                     log::debug!("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!"); | ||||
| @ -99,12 +99,12 @@ fn main() { | ||||
|                     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!( | ||||
|                     log::info!( | ||||
|                         "Compilation took: {:.2}ms\n", | ||||
|                         (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 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(())
 | ||||
| // }
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user