Skip to content

Commit 810ba8f

Browse files
committed
feat(hir): copy intrinsics for i8
1 parent fe7b626 commit 810ba8f

3 files changed

Lines changed: 15 additions & 21 deletions

File tree

src/passes/codegen.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,20 @@ impl<'ctx, 'mir, 'ink> Codegen<'ctx, 'mir, 'ink> {
404404
.as_basic_value_enum(),
405405
lhs_ty_id,
406406
),
407-
(Type::U8, BinaryOperation::PlusWithOverflow, Type::U8) => {
407+
(
408+
lhs_ty @ (Type::U8 | Type::I8),
409+
BinaryOperation::PlusWithOverflow,
410+
rhs_ty @ (Type::U8 | Type::I8),
411+
) if lhs_ty == rhs_ty => {
408412
let intrinsic = Intrinsic::find("llvm.uadd.with.overflow").unwrap();
409413
let intrinsic_function = intrinsic
410-
.get_declaration(&self.module, &[self.ink.i8_type().into()])
414+
.get_declaration(&self.module, &[self.basic_ty(lhs_ty_id)])
411415
.unwrap();
412416
let call_result = builder
413417
.build_call(
414418
intrinsic_function,
415419
&[lhs.into(), rhs.into()],
416-
"u8_add_overflow",
420+
"add_overflow",
417421
)
418422
.unwrap();
419423

src/passes/hir_gen/annotations/intrinsic.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ pub fn intrinsic_handler(ctx: &mut Ctx, hir: &mut hir::Hir, hir_node: HirId) {
3333
.parameters
3434
.iter()
3535
.zip(hir_signature.parameters.iter().map(|(_, ty)| *ty))
36-
.all(|(intrinsic, signature)| intrinsic.into_type(&mut ctx.types) == signature)
36+
.all(|(intrinsic, signature)| intrinsic.as_type(&mut ctx.types) == signature)
3737
// Return type must match.
3838
&& intrinsic
3939
.signature
4040
.return_ty
4141
.as_ref()
42-
.map(|ty| ty.into_type(&mut ctx.types))
42+
.map(|ty| ty.as_type(&mut ctx.types))
4343
.unwrap_or(ctx.types.unit())
4444
== hir_signature.return_ty;
4545
if !signature_valid {
@@ -113,15 +113,15 @@ enum PrimitiveType {
113113
}
114114

115115
impl PrimitiveType {
116-
fn into_type(&self, types: &mut Types) -> TypeId {
116+
fn as_type(&self, types: &mut Types) -> TypeId {
117117
match self {
118118
PrimitiveType::U8 => types.u8(),
119119
PrimitiveType::I8 => types.i8(),
120120
PrimitiveType::Boolean => types.boolean(),
121121
PrimitiveType::Tuple(primitive_types) => {
122122
let inner = primitive_types
123123
.iter()
124-
.map(|ty| ty.into_type(types))
124+
.map(|ty| ty.as_type(types))
125125
.collect::<Vec<_>>();
126126
types.tuple(inner)
127127
}
@@ -214,4 +214,8 @@ intrinsics! {
214214
u8_add_wrapping(lhs: u8, rhs: u8) -> u8 { BinaryOperation(Plus) };
215215
u8_add_overflow(lhs: u8, rhs: u8) -> (u8, bool) { BinaryOperation(PlusWithOverflow) };
216216
u8_not(n: u8) -> u8 { UnaryOperation(Not) };
217+
218+
i8_add_wrapping(lhs: i8, rhs: i8) -> i8 { BinaryOperation(Plus) };
219+
i8_add_overflow(lhs: i8, rhs: i8) -> (i8, bool) { BinaryOperation(PlusWithOverflow) };
220+
i8_not(n: i8) -> i8 { UnaryOperation(Not) };
217221
}

src/passes/hir_gen/annotations/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ pub struct Annotation {
1616
pub value: Option<StringId>,
1717
}
1818

19-
impl Annotation {
20-
pub fn new(key: StringId, value: Option<StringId>) -> Self {
21-
Self { key, value }
22-
}
23-
24-
pub fn key(key: StringId) -> Self {
25-
Self::new(key, None)
26-
}
27-
28-
pub fn key_value(key: StringId, value: StringId) -> Self {
29-
Self::new(key, Some(value))
30-
}
31-
}
32-
3319
pub fn run_annotation_handlers(ctx: &mut Ctx, hir: &mut hir::Hir) {
3420
// HACK: Don't clone all annotations.
3521
for (node, annotations) in hir.annotations.clone() {

0 commit comments

Comments
 (0)