aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-03-30 23:24:54 +0100
committerMichael Williamson <mike@zwobble.org>2026-03-30 23:24:54 +0100
commit92873be6588b5eb41f6c4cfd6401ccd7fd83d76e (patch)
treeb080c705f4f765f3afe6cbd18da0d0c4931eddd7
parent02b2620b5f5961cd8ffcd761e58e4bff61d29f32 (diff)
Extract types for int and int32
-rw-r--r--patio-to-cranelift/src/lib.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/patio-to-cranelift/src/lib.rs b/patio-to-cranelift/src/lib.rs
index 302faa2d..1221cdd3 100644
--- a/patio-to-cranelift/src/lib.rs
+++ b/patio-to-cranelift/src/lib.rs
@@ -275,16 +275,13 @@ fn compile_operand(
match operand.value_operand_value_type() {
PatioOperandValue::PatioIntConst => {
let int_const = operand.value_operand_value_as_patio_int_const().unwrap();
- // TODO: de-duplicate with patio_type_to_cranelift_type (and in so doing remove assumption about int size)
- let cranelift_int_type = cranelift::prelude::Type::int(64).unwrap();
+ let cranelift_int_type = cranelift_int_type(&context.target_triple);
compile_int_value(int_const.value(), cranelift_int_type, context)
}
PatioOperandValue::PatioInt32Const => {
let int_32_const = operand.value_operand_value_as_patio_int_32_const().unwrap();
- // TODO: de-duplicate with patio_type_to_cranelift_type
- let cranelift_int_type = cranelift::prelude::Type::int(32).unwrap();
- compile_int_value(int_32_const.value(), cranelift_int_type, context)
+ compile_int_value(int_32_const.value(), CRANELIFT_INT_32_TYPE, context)
}
PatioOperandValue::PatioLocalRef => {
@@ -372,7 +369,7 @@ fn patio_type_to_cranelift_type(
match patio_type.value_patio_type_type() {
PatioTypeValue::PatioBoolType => cranelift::prelude::Type::int(1).unwrap(),
- PatioTypeValue::PatioByteType => cranelift::prelude::Type::int(8).unwrap(),
+ PatioTypeValue::PatioByteType => cranelift_codegen::ir::types::I8,
PatioTypeValue::PatioDataPtrType => {
cranelift::prelude::Type::triple_pointer_type(&target_triple)
@@ -382,18 +379,21 @@ fn patio_type_to_cranelift_type(
cranelift::prelude::Type::triple_pointer_type(&target_triple)
}
- PatioTypeValue::PatioIntType =>
- // TODO: this assumes that pointers are at least as wide as i32s:
- // probably safe, but we should check.
- // TODO: this relies on cranelift pointer types just being integers.
- {
- cranelift::prelude::Type::triple_pointer_type(&target_triple)
- }
+ PatioTypeValue::PatioIntType => cranelift_int_type(target_triple),
- PatioTypeValue::PatioInt32Type => cranelift::prelude::Type::int(32).unwrap(),
+ PatioTypeValue::PatioInt32Type => CRANELIFT_INT_32_TYPE,
PatioTypeValue::PatioVoidType => todo!(),
_ => todo!(),
}
}
+
+fn cranelift_int_type(target_triple: &target_lexicon::Triple) -> cranelift_codegen::ir::Type {
+ // TODO: this assumes that pointers are at least as wide as i32s:
+ // probably safe, but we should check.
+ // TODO: this relies on cranelift pointer types just being integers.
+ cranelift::prelude::Type::triple_pointer_type(&target_triple)
+}
+
+const CRANELIFT_INT_32_TYPE: cranelift_codegen::ir::Type = cranelift_codegen::ir::types::I32;