Skip to content

Commit

Permalink
misc: added macro for IsIrType of fundamental types
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Mar 21, 2020
1 parent af00353 commit e66cbbc
Showing 1 changed file with 25 additions and 80 deletions.
105 changes: 25 additions & 80 deletions crates/mun_codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,69 +134,38 @@ impl AsFunctionReturnType for () {
}
}

impl IsIrType for u8 {
type Type = IntType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i8_type()
}
}

impl IsIrType for u16 {
type Type = IntType;
macro_rules! impl_fundamental_ir_types {
($(
$ty:ty => $context_fun:ident():$inkwell_ty:ty
),+) => {
$(
impl IsIrType for $ty {
type Type = $inkwell_ty;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i16_type()
fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.$context_fun()
}
}
)+
}
}

impl IsIrType for u32 {
type Type = IntType;
impl_fundamental_ir_types!(
i8 => i8_type():IntType,
i16 => i16_type():IntType,
i32 => i32_type():IntType,
i64 => i64_type():IntType,

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i32_type()
}
}
u8 => i8_type():IntType,
u16 => i16_type():IntType,
u32 => i32_type():IntType,
u64 => i64_type():IntType,

impl IsIrType for u64 {
type Type = IntType;
bool => bool_type():IntType,

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i64_type()
}
}

impl IsIrType for i8 {
type Type = IntType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i8_type()
}
}

impl IsIrType for i16 {
type Type = IntType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i16_type()
}
}

impl IsIrType for i32 {
type Type = IntType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i32_type()
}
}

impl IsIrType for i64 {
type Type = IntType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.i64_type()
}
}
f32 => f32_type():FloatType,
f64 => f64_type():FloatType
);

impl IsIrType for usize {
type Type = IntType;
Expand All @@ -222,30 +191,6 @@ impl IsIrType for isize {
}
}

impl IsIrType for f32 {
type Type = FloatType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.f32_type()
}
}

impl IsIrType for f64 {
type Type = FloatType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.f64_type()
}
}

impl IsIrType for bool {
type Type = IntType;

fn ir_type(context: &Context, _target: &TargetData) -> Self::Type {
context.bool_type()
}
}

pub trait IsPointerType {
fn ir_type(context: &Context, target: &TargetData) -> PointerType;
}
Expand Down

0 comments on commit e66cbbc

Please sign in to comment.