Skip to content

Commit c894d2a

Browse files
committed
Addes support for all ints and unints and the boolean type.
1 parent d064308 commit c894d2a

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

src/lib.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenResults};
1212
use rustc_metadata::EncodedMetadata;
1313
use rustc_middle::{
1414
dep_graph::{WorkProduct, WorkProductId},
15-
ty::{Ty,TyCtxt,TyKind,IntTy},
15+
ty::{Ty,TyCtxt,TyKind,IntTy,UintTy},
1616
};
1717
use rustc_span::ErrorGuaranteed;
1818
use std::any::Any;
@@ -31,7 +31,9 @@ pub type IString = Box<str>;
3131
struct MyBackend;
3232
#[derive(Clone,Debug)]
3333
enum VariableType{
34-
I32,
34+
I8,I16,I32,I64,I128,ISize,
35+
U8,U16,U32,U64,U128,USize,
36+
Bool,
3537
}
3638
#[derive(Debug)]
3739
struct FunctionSignature{
@@ -54,13 +56,37 @@ impl FunctionSignature{
5456
impl VariableType{
5557
fn from_ty(ty:Ty)->Self{
5658
match ty.kind() {
59+
TyKind::Int(IntTy::I8) => VariableType::I8,
60+
TyKind::Int(IntTy::I16) => VariableType::I16,
5761
TyKind::Int(IntTy::I32) => VariableType::I32,
62+
TyKind::Int(IntTy::I64) => VariableType::I64,
63+
TyKind::Int(IntTy::I128) => VariableType::I128,
64+
TyKind::Int(IntTy::Isize) => VariableType::ISize,
65+
TyKind::Uint(UintTy::U8) => VariableType::U8,
66+
TyKind::Uint(UintTy::U16) => VariableType::U16,
67+
TyKind::Uint(UintTy::U32) => VariableType::U32,
68+
TyKind::Uint(UintTy::U64) => VariableType::U64,
69+
TyKind::Uint(UintTy::U128) => VariableType::U128,
70+
TyKind::Uint(UintTy::Usize) => VariableType::USize,
71+
TyKind::Bool=>VariableType::Bool,
5872
_ => todo!("Unhandled type kind {:?}", ty.kind()),
5973
}
6074
}
6175
pub(crate) fn il_name(&self)->IString{
6276
match self{
63-
Self::I32=>"int32"
77+
Self::I8=>"int8",
78+
Self::I16=>"int16",
79+
Self::I32=>"int32",
80+
Self::I64=>"int64",
81+
Self::I128=>"[System.Runtime]System.Int128",
82+
Self::ISize => "native int",
83+
Self::U8=>"uint8",
84+
Self::U16=>"uint16",
85+
Self::U32=>"uint32",
86+
Self::U64=>"uint64",
87+
Self::U128=>"[System.Runtime]System.UInt128",
88+
Self::USize =>"native uint",
89+
Self::Bool=>"bool",
6490
}.into()
6591
}
6692
}

test/identity.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1+
#[no_mangle]
12
pub extern fn identity(a:i32)->i32{a}
2-
pub extern fn add(a:i32)->i32{a+a}
3-
pub extern fn add2(a:i32,b:i32)->i32{a + b}
3+
4+
#[no_mangle]
45
pub extern fn sqr_mag(ax:i32,ay:i32)->i32{ax*ax + ay*ay}
6+
#[no_mangle]
57
pub extern fn pow2(power:i32)->i32{1<<power}
8+
9+
#[no_mangle]
10+
pub extern fn addisize(a:isize,b:isize)->isize{a+b}
11+
#[no_mangle]
12+
pub extern fn addi128(a:i128,b:i128)->i128{a+b}
13+
#[no_mangle]
14+
pub extern fn addi64(a:i64,b:i64)->i64{a+b}
15+
#[no_mangle]
16+
pub extern fn addi32(a:i32,b:i32)->i32{a+b}
17+
#[no_mangle]
18+
pub extern fn addi16(a:i16,b:i16)->i16{a+b}
19+
#[no_mangle]
20+
pub extern fn addi8(a:i8,b:i8)->i8{a+b}
21+
22+
#[no_mangle]
23+
pub extern fn addusize(a:usize,b:usize)->usize{a+b}
24+
#[no_mangle]
25+
pub extern fn addu128(a:u128,b:u128)->u128{a+b}
26+
#[no_mangle]
27+
pub extern fn addu64(a:u64,b:u64)->u64{a+b}
28+
#[no_mangle]
29+
pub extern fn addu32(a:u32,b:u32)->u32{a+b}
30+
#[no_mangle]
31+
pub extern fn addu16(a:u16,b:u16)->u16{a+b}
32+
#[no_mangle]
33+
pub extern fn addu8(a:u8,b:u8)->u8{a+b}
34+
35+
#[no_mangle]
36+
pub extern fn boolident(a:bool)->bool{a}
637
/*
738
pub extern fn factorial(mut n:i32)->i32{
839
let mut factorial = 1;

0 commit comments

Comments
 (0)