Merge branch 'main' into if-expr-lhs-rhs
This commit is contained in:
		
						commit
						f944387847
					
				| @ -629,14 +629,17 @@ impl Type { | |||||||
|             } |             } | ||||||
|             (I32 | U32, I16 | U16 | I8 | U8) => Some(Instr::Trunc(value, other.clone())), |             (I32 | U32, I16 | U16 | I8 | U8) => Some(Instr::Trunc(value, other.clone())), | ||||||
|             (I16 | U16, I8 | U8) => Some(Instr::Trunc(value, other.clone())), |             (I16 | U16, I8 | U8) => Some(Instr::Trunc(value, other.clone())), | ||||||
|             (U8 | I8, U16 | I16 | U32 | I32 | U64 | I64 | U128 | I128) => { |             (U8 | I8, U8 | I8 | U16 | I16 | U32 | I32 | U64 | I64 | U128 | I128) => { | ||||||
|                 Some(Instr::ZExt(value, other.clone())) |                 Some(Instr::ZExt(value, other.clone())) | ||||||
|             } |             } | ||||||
|             (U16 | I16, U32 | I32 | U64 | I64 | U128 | I128) => { |             (U16 | I16, U16 | I16 | U32 | I32 | U64 | I64 | U128 | I128) => { | ||||||
|                 Some(Instr::ZExt(value, other.clone())) |                 Some(Instr::ZExt(value, other.clone())) | ||||||
|             } |             } | ||||||
|             (U32 | I32, U64 | I64 | U128 | I128) => Some(Instr::ZExt(value, other.clone())), |             (U32 | I32, U32 | I32 | U64 | I64 | U128 | I128) => { | ||||||
|             (U64 | I64, U128 | I128) => Some(Instr::ZExt(value, other.clone())), |                 Some(Instr::ZExt(value, other.clone())) | ||||||
|  |             } | ||||||
|  |             (U64 | I64, U64 | I64 | U128 | I128) => Some(Instr::ZExt(value, other.clone())), | ||||||
|  |             (U128 | I128, U128 | I128) => Some(Instr::ZExt(value, other.clone())), | ||||||
|             (U8 | U16 | U32 | U64 | U128, F16 | F32 | F32B | F64 | F80 | F128 | F128PPC) => { |             (U8 | U16 | U32 | U64 | U128, F16 | F32 | F32B | F64 | F80 | F128 | F128PPC) => { | ||||||
|                 Some(Instr::UIToFP(value, other.clone())) |                 Some(Instr::UIToFP(value, other.clone())) | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -14,6 +14,6 @@ color = ["colored"] | |||||||
| [dependencies] | [dependencies] | ||||||
| ## Make it easier to generate errors | ## Make it easier to generate errors | ||||||
| thiserror = "1.0.44" | thiserror = "1.0.44" | ||||||
| reid-lib = { path = "../reid-llvm-lib" } | reid-lib = { path = "../reid-llvm-lib", version = "0.1.0"} | ||||||
| 
 | 
 | ||||||
| colored = {version = "3.0.0", optional = true} | colored = {version = "3.0.0", optional = true} | ||||||
| @ -94,5 +94,13 @@ fn str_length(string: *char, position: u32) -> u32 { | |||||||
| 
 | 
 | ||||||
| pub fn add_num_to_str(string: &mut String, num: u64) { | pub fn add_num_to_str(string: &mut String, num: u64) { | ||||||
|     if num == 0 { add_char(string, '0'); }  |     if num == 0 { add_char(string, '0'); }  | ||||||
|     else if num == 1 { add_char(string, '1'); } |     else { if num == 1 { add_char(string, '1'); }  | ||||||
|  |     else { if num == 2 { add_char(string, '2'); }  | ||||||
|  |     else { if num == 3 { add_char(string, '3'); }  | ||||||
|  |     else { if num == 4 { add_char(string, '4'); }  | ||||||
|  |     else { if num == 5 { add_char(string, '5'); }  | ||||||
|  |     else { if num == 6 { add_char(string, '6'); }  | ||||||
|  |     else { if num == 7 { add_char(string, '7'); }  | ||||||
|  |     else { if num == 8 { add_char(string, '8'); }  | ||||||
|  |     else { if num == 9 { add_char(string, '9'); } } } } } } } } } } | ||||||
| } | } | ||||||
| @ -1085,7 +1085,8 @@ impl mir::Expression { | |||||||
|                         }, |                         }, | ||||||
|                         (TypeKind::UserPtr(_), TypeKind::UserPtr(_)) |                         (TypeKind::UserPtr(_), TypeKind::UserPtr(_)) | ||||||
|                         | (TypeKind::Char, TypeKind::U8) |                         | (TypeKind::Char, TypeKind::U8) | ||||||
|                         | (TypeKind::U8, TypeKind::Char) => Some(StackValue( |                         | (TypeKind::U8, TypeKind::Char) | ||||||
|  |                         | (TypeKind::U8, TypeKind::I8) => Some(StackValue( | ||||||
|                             val.0.derive( |                             val.0.derive( | ||||||
|                                 scope |                                 scope | ||||||
|                                     .block |                                     .block | ||||||
|  | |||||||
							
								
								
									
										46
									
								
								reid/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								reid/src/main.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | |||||||
|  | use std::{env, fs, path::PathBuf}; | ||||||
|  | 
 | ||||||
|  | use reid::compile_simple; | ||||||
|  | use reid_lib::compile::CompileOutput; | ||||||
|  | 
 | ||||||
|  | fn main() -> Result<(), std::io::Error> { | ||||||
|  |     let args: Vec<String> = env::args().collect(); | ||||||
|  |     if let Some(filename) = args.get(1) { | ||||||
|  |         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 asm_path = parent.with_extension("asm"); | ||||||
|  | 
 | ||||||
|  |         let before = std::time::SystemTime::now(); | ||||||
|  | 
 | ||||||
|  |         let text = fs::read_to_string(&path)?; | ||||||
|  |         match compile_simple(&text, PathBuf::from(&path)) { | ||||||
|  |             Ok(CompileOutput { | ||||||
|  |                 triple, | ||||||
|  |                 assembly, | ||||||
|  |                 obj_buffer, | ||||||
|  |                 llvm_ir, | ||||||
|  |             }) => { | ||||||
|  |                 println!("{}", llvm_ir); | ||||||
|  | 
 | ||||||
|  |                 let after = std::time::SystemTime::now(); | ||||||
|  |                 println!("Compiled with triple: {}\n", &triple); | ||||||
|  |                 fs::write(&llvm_ir_path, &llvm_ir).expect("Could not write LLVM IR -file!"); | ||||||
|  |                 println!("Output LLVM IR to {:?}", llvm_ir_path); | ||||||
|  |                 fs::write(&asm_path, &assembly).expect("Could not write Assembly-file!"); | ||||||
|  |                 println!("Output Assembly to {:?}", asm_path); | ||||||
|  |                 fs::write(&object_path, &obj_buffer).expect("Could not write Object-file!"); | ||||||
|  |                 println!("Output Object-file to {:?}\n", object_path); | ||||||
|  |                 println!( | ||||||
|  |                     "Compilation took: {:.2}ms\n", | ||||||
|  |                     (after.duration_since(before).unwrap().as_micros() as f32) / 1000. | ||||||
|  |                 ); | ||||||
|  |             } | ||||||
|  |             Err(e) => panic!("{}", e), | ||||||
|  |         }; | ||||||
|  |     } else { | ||||||
|  |         println!("Please input compiled file path!") | ||||||
|  |     } | ||||||
|  |     Ok(()) | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user