Code cleanup
This commit is contained in:
+13
-13
@@ -42,16 +42,17 @@ impl<'l> CompilationContext<'l> {
|
||||
modules: HashMap::default(),
|
||||
functions: HashMap::default(),
|
||||
native_int_ty: match target.get_target_data().get_pointer_byte_size(None) {
|
||||
8 => ctx.i8_type().into(),
|
||||
16 => ctx.i16_type().into(),
|
||||
32 => ctx.i32_type().into(),
|
||||
64 => ctx.i64_type().into(),
|
||||
128 => ctx.i128_type().into(),
|
||||
8 => ctx.i8_type(),
|
||||
16 => ctx.i16_type(),
|
||||
32 => ctx.i32_type(),
|
||||
64 => ctx.i64_type(),
|
||||
128 => ctx.i128_type(),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::mutable_key_type)]
|
||||
pub fn compile(&self, assembly: &'l Assembly<'l>) -> LlvmModule<'l> {
|
||||
let mut exists = true;
|
||||
let module = self
|
||||
@@ -79,8 +80,8 @@ impl<'l> CompilationContext<'l> {
|
||||
.or_insert_with(|| module.add_function(name, ty, None));
|
||||
}
|
||||
|
||||
for (i, func) in assembly.functions() {
|
||||
let llvm_func = self.functions.get_sync(&(assembly, *func)).unwrap().clone();
|
||||
for (_, func) in assembly.functions() {
|
||||
let llvm_func = *self.functions.get_sync(&(assembly, *func)).unwrap();
|
||||
|
||||
let Some(body) = func.body() else {
|
||||
continue;
|
||||
@@ -128,7 +129,7 @@ impl<'l> CompilationContext<'l> {
|
||||
break 'val None;
|
||||
};
|
||||
let ptr = value.into_pointer_value();
|
||||
Some(builder.build_load(ty, ptr, "").unwrap().into())
|
||||
Some(builder.build_load(ty, ptr, "").unwrap())
|
||||
}
|
||||
InstructionVariant::Store(target, value) => 'val: {
|
||||
let Some(t_val) = self.get_value(&values, target) else {
|
||||
@@ -220,7 +221,7 @@ impl<'l> CompilationContext<'l> {
|
||||
|
||||
InstructionVariant::Call(func, args) => {
|
||||
// TODO This will fail with external assemblies. Fix this.
|
||||
let func = self.functions.get_sync(&(assembly, *func)).unwrap().clone();
|
||||
let func = *self.functions.get_sync(&(assembly, *func)).unwrap();
|
||||
let args: Vec<_> = args
|
||||
.iter()
|
||||
.filter_map(|a| self.get_value(&values, a).map(|a| a.into()))
|
||||
@@ -334,13 +335,14 @@ impl<'l> CompilationContext<'l> {
|
||||
llvm_ty
|
||||
}
|
||||
|
||||
#[allow(clippy::mutable_key_type)]
|
||||
fn get_value(
|
||||
&self,
|
||||
map: &FxHashMap<Value<'l>, Option<BasicValueEnum<'l>>>,
|
||||
val: &Value<'l>,
|
||||
) -> Option<BasicValueEnum<'l>> {
|
||||
if let Some(value) = map.get(val) {
|
||||
return value.clone();
|
||||
return *value;
|
||||
}
|
||||
match val {
|
||||
Value::Constant(val) => match val {
|
||||
@@ -353,9 +355,7 @@ impl<'l> CompilationContext<'l> {
|
||||
AnyConst::Int(Int::U32(v)) => {
|
||||
Some(self.ctx.i32_type().const_int(*v as u64, false).into())
|
||||
}
|
||||
AnyConst::Int(Int::U64(v)) => {
|
||||
Some(self.ctx.i64_type().const_int(*v as u64, false).into())
|
||||
}
|
||||
AnyConst::Int(Int::U64(v)) => Some(self.ctx.i64_type().const_int(*v, false).into()),
|
||||
AnyConst::Int(Int::USize(v)) => {
|
||||
Some(self.native_int_ty.const_int(*v as u64, false).into())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user