Compare commits
No commits in common. "38b7030e98cd49921e869110a901f9ee0a29410e" and "2f56f148cb377eb1d63c6b48481ea715c76ec6ce" have entirely different histories.
38b7030e98
...
2f56f148cb
@ -385,10 +385,12 @@ impl Builder {
|
|||||||
}
|
}
|
||||||
Instr::FunctionCall(fun, params) => {
|
Instr::FunctionCall(fun, params) => {
|
||||||
let param_types = self.function_data(&fun).params;
|
let param_types = self.function_data(&fun).params;
|
||||||
|
dbg!(¶ms, ¶m_types);
|
||||||
if param_types.len() != params.len() {
|
if param_types.len() != params.len() {
|
||||||
return Err(()); // TODO error: invalid amount of params
|
return Err(()); // TODO error: invalid amount of params
|
||||||
}
|
}
|
||||||
for (a, b) in param_types.iter().zip(params) {
|
for (a, b) in param_types.iter().zip(params) {
|
||||||
|
dbg!(b.get_type(&self)?);
|
||||||
if *a != b.get_type(&self)? {
|
if *a != b.get_type(&self)? {
|
||||||
return Err(()); // TODO error: params do not match
|
return Err(()); // TODO error: params do not match
|
||||||
}
|
}
|
||||||
|
@ -672,7 +672,7 @@ impl mir::Expression {
|
|||||||
};
|
};
|
||||||
Some(StackValue(
|
Some(StackValue(
|
||||||
StackValueKind::Immutable(scope.block.build(instr).unwrap()),
|
StackValueKind::Immutable(scope.block.build(instr).unwrap()),
|
||||||
lhs_type,
|
TypeKind::U32,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
mir::ExprKind::FunctionCall(call) => {
|
mir::ExprKind::FunctionCall(call) => {
|
||||||
|
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(())
|
||||||
|
}
|
@ -1,7 +1,12 @@
|
|||||||
fn foo() -> f32 { return 1.0; }
|
fn vec_sub(l: [f32; 3], r: [f32; 3]) -> [f32; 3] {
|
||||||
|
return [l[0]-r[0], l[1]-r[1], l[2]-r[2]];
|
||||||
fn main() -> u8 {
|
|
||||||
let mut a = 0;
|
|
||||||
a = (foo() * 1.0) as u8;
|
|
||||||
return a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn foo(x: f32) {
|
||||||
|
let a = [x, x, 0.0];
|
||||||
|
let b = [x, x, x]; // works
|
||||||
|
// let b = [x * 0.5, x * 0.5, x]; // does not work
|
||||||
|
vec_sub(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user