Skip to content

Commit

Permalink
misc: removed float, int, uint
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed May 2, 2020
1 parent 29e3b79 commit 7298dfa
Show file tree
Hide file tree
Showing 70 changed files with 1,061 additions and 1,137 deletions.
1 change: 0 additions & 1 deletion crates/mun_codegen/src/ir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ impl<'a, 'b, D: IrDatabase> BodyIrGenerator<'a, 'b, D> {
let ir_ty = match ty.bitness.resolve(&self.db.target_data_layout()) {
hir::FloatBitness::X32 => context.f32_type().const_float(v.value),
hir::FloatBitness::X64 => context.f64_type().const_float(v.value),
_ => unreachable!("unresolved bitness in code generation"),
};

ir_ty.into()
Expand Down
1 change: 0 additions & 1 deletion crates/mun_codegen/src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ fn float_ty_query(db: &impl IrDatabase, fty: FloatTy) -> FloatType {
match fty.bitness.resolve(&db.target_data_layout()) {
FloatBitness::X64 => context.f64_type(),
FloatBitness::X32 => context.f32_type(),
_ => unreachable!(),
}
}

Expand Down
32 changes: 16 additions & 16 deletions crates/mun_codegen/src/snapshots/test__assignment_op_struct.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
source: crates/mun_codegen/src/test.rs
expression: "struct(value) Value(int, int);\nstruct(gc) Heap(float, float);\n\npub fn assign_value(a: Value, b: Value) -> Value {\n a = b;\n a\n}\n\npub fn assign_heap(a: Heap, b: Heap) -> Heap {\n a = b;\n a\n}\n// TODO: Add errors\n// a += b;\n// a *= b;\n// a -= b;\n// a /= b;\n// a %= b;"
expression: "struct(value) Value(i32, i32);\nstruct(gc) Heap(f64, f64);\n\npub fn assign_value(a: Value, b: Value) -> Value {\n a = b;\n a\n}\n\npub fn assign_heap(a: Heap, b: Heap) -> Heap {\n a = b;\n a\n}\n// TODO: Add errors\n// a += b;\n// a *= b;\n// a -= b;\n// a /= b;\n// a %= b;"
---
; == FILE IR =====================================
; ModuleID = 'main.mun'
source_filename = "main.mun"

%DispatchTable = type { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* }
%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 }
%Value = type { i64, i64 }
%Value = type { i32, i32 }
%Heap = type { double, double }

@allocatorHandle = external global i8*
Expand All @@ -30,7 +30,7 @@ body:
%deref2 = load %Value, %Value* %mem_ptr1
%assign_value = call %Value @assign_value(%Value %deref, %Value %deref2)
%new_ptr = load i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i8* addrspace(4)* (i8 addrspace(4)*, i8*)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%Value_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([7 x %struct.MunTypeInfo addrspace(4)*], [7 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 3)
%Value_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([7 x %struct.MunTypeInfo addrspace(4)*], [7 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 1)
%type_info_ptr_to_i8_ptr = bitcast %struct.MunTypeInfo addrspace(4)* %Value_ptr to i8 addrspace(4)*
%allocator_handle = load i8*, i8** @allocatorHandle
%new = call i8* addrspace(4)* %new_ptr(i8 addrspace(4)* %type_info_ptr_to_i8_ptr, i8* %allocator_handle)
Expand All @@ -55,30 +55,30 @@ source_filename = "group_name"
%struct.MunStructInfo = type { i8 addrspace(4)* addrspace(4)*, %struct.MunTypeInfo addrspace(4)* addrspace(4)*, i16 addrspace(4)*, i16, i8 }

@dispatchTable = global %DispatchTable zeroinitializer
@"type_info::<*const TypeInfo>::name" = private unnamed_addr constant [16 x i8] c"*const TypeInfo\00"
@"type_info::<*const TypeInfo>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"=\A1-\1F\C2\A7\88`d\90\F4\B5\BEE}x", [16 x i8]* @"type_info::<*const TypeInfo>::name", i32 64, i8 8, i8 0 }
@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00"
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 }
@"type_info::<core::f64>::name" = private unnamed_addr constant [10 x i8] c"core::f64\00"
@"type_info::<core::f64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"`\DBF\9C?YJ%G\AD4\9F\D5\92%A", [10 x i8]* @"type_info::<core::f64>::name", i32 64, i8 8, i8 0 }
@"type_info::<core::i32>::name" = private unnamed_addr constant [10 x i8] c"core::i32\00"
@"type_info::<core::i32>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\17yzt\19\D62\17\D25\95C\17\88[\FA", [10 x i8]* @"type_info::<core::i32>::name", i32 32, i8 4, i8 0 }
@"type_info::<Value>::name" = private unnamed_addr constant [6 x i8] c"Value\00"
@"struct_info::<Value>::field_names" = private unnamed_addr constant [2 x i8] c"0\00"
@"struct_info::<Value>::field_names.1" = private unnamed_addr constant [2 x i8] c"1\00"
@0 = private unnamed_addr constant [2 x i8 addrspace(4)*] [i8 addrspace(4)* @"struct_info::<Value>::field_names", i8 addrspace(4)* @"struct_info::<Value>::field_names.1"]
@"struct_info::<Value>::field_types" = private unnamed_addr constant [2 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>"]
@"struct_info::<Value>::field_offsets" = private unnamed_addr constant [2 x i16] [i16 0, i16 8]
@"type_info::<Value>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"ub,\CA\DB\C8\15\93'Q\F0\ECY\E6\E8v", [6 x i8]* @"type_info::<Value>::name", i32 128, i8 8, i8 1 }, %struct.MunStructInfo { [2 x i8 addrspace(4)*]* @0, [2 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Value>::field_types", [2 x i16]* @"struct_info::<Value>::field_offsets", i16 2, i8 1 } }
@"type_info::<*const *mut core::void>::name" = private unnamed_addr constant [23 x i8] c"*const *mut core::void\00"
@"type_info::<*const *mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\C5fO\BD\84\DF\06\BFd+\B1\9Abv\CE\00", [23 x i8]* @"type_info::<*const *mut core::void>::name", i32 64, i8 8, i8 0 }
@"struct_info::<Value>::field_types" = private unnamed_addr constant [2 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i32>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::i32>"]
@"struct_info::<Value>::field_offsets" = private unnamed_addr constant [2 x i16] [i16 0, i16 4]
@"type_info::<Value>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"(3\1C%q\83\13+L\A6Q\F7\1DX\A6\9B", [6 x i8]* @"type_info::<Value>::name", i32 64, i8 4, i8 1 }, %struct.MunStructInfo { [2 x i8 addrspace(4)*]* @0, [2 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Value>::field_types", [2 x i16]* @"struct_info::<Value>::field_offsets", i16 2, i8 1 } }
@"type_info::<Heap>::name" = private unnamed_addr constant [5 x i8] c"Heap\00"
@"struct_info::<Heap>::field_names" = private unnamed_addr constant [2 x i8] c"0\00"
@"struct_info::<Heap>::field_names.2" = private unnamed_addr constant [2 x i8] c"1\00"
@1 = private unnamed_addr constant [2 x i8 addrspace(4)*] [i8 addrspace(4)* @"struct_info::<Heap>::field_names", i8 addrspace(4)* @"struct_info::<Heap>::field_names.2"]
@"type_info::<core::f64>::name" = private unnamed_addr constant [10 x i8] c"core::f64\00"
@"type_info::<core::f64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"`\DBF\9C?YJ%G\AD4\9F\D5\92%A", [10 x i8]* @"type_info::<core::f64>::name", i32 64, i8 8, i8 0 }
@"struct_info::<Heap>::field_types" = private unnamed_addr constant [2 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>"]
@"struct_info::<Heap>::field_offsets" = private unnamed_addr constant [2 x i16] [i16 0, i16 8]
@"type_info::<Heap>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"\C9\B1\99\D7\18\A3Z\B8\1EL7a1\03\F7L", [5 x i8]* @"type_info::<Heap>::name", i32 128, i8 8, i8 1 }, %struct.MunStructInfo { [2 x i8 addrspace(4)*]* @1, [2 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Heap>::field_types", [2 x i16]* @"struct_info::<Heap>::field_offsets", i16 2, i8 0 } }
@"type_info::<Heap>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"1\1CC\F80{\17\AFq\94\89\FB4\AC\A8\F3", [5 x i8]* @"type_info::<Heap>::name", i32 128, i8 8, i8 1 }, %struct.MunStructInfo { [2 x i8 addrspace(4)*]* @1, [2 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Heap>::field_types", [2 x i16]* @"struct_info::<Heap>::field_offsets", i16 2, i8 0 } }
@"type_info::<*const TypeInfo>::name" = private unnamed_addr constant [16 x i8] c"*const TypeInfo\00"
@"type_info::<*const TypeInfo>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"=\A1-\1F\C2\A7\88`d\90\F4\B5\BEE}x", [16 x i8]* @"type_info::<*const TypeInfo>::name", i32 64, i8 8, i8 0 }
@"type_info::<*const *mut core::void>::name" = private unnamed_addr constant [23 x i8] c"*const *mut core::void\00"
@"type_info::<*const *mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\C5fO\BD\84\DF\06\BFd+\B1\9Abv\CE\00", [23 x i8]* @"type_info::<*const *mut core::void>::name", i32 64, i8 8, i8 0 }
@"type_info::<*mut core::void>::name" = private unnamed_addr constant [16 x i8] c"*mut core::void\00"
@"type_info::<*mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\F0Y\22\FC\95\9E\7F\CE\08T\B1\A2\CD\A7\FAz", [16 x i8]* @"type_info::<*mut core::void>::name", i32 64, i8 8, i8 0 }
@global_type_table = global [7 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<*const TypeInfo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Value>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const *mut core::void>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Heap>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*mut core::void>"]
@global_type_table = global [7 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i32>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Value>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Heap>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const TypeInfo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const *mut core::void>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*mut core::void>"]
@allocatorHandle = unnamed_addr global i8* null

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/mun_codegen/src/test.rs
expression: "pub fn main(a:int) -> int {\n if a > 4 {\n return a;\n }\n a - 1\n}"
expression: "pub fn main(a:i32) -> i32 {\n if a > 4 {\n return a;\n }\n a - 1\n}"
---
; == FILE IR =====================================
; ModuleID = 'main.mun'
Expand All @@ -10,17 +10,17 @@ source_filename = "main.mun"

@global_type_table = external global [1 x %struct.MunTypeInfo addrspace(4)*]

define i64 @main(i64) {
define i32 @main(i32) {
body:
%greater = icmp sgt i64 %0, 4
%greater = icmp sgt i32 %0, 4
br i1 %greater, label %then, label %if_merge

then: ; preds = %body
ret i64 %0
ret i32 %0

if_merge: ; preds = %body
%sub = sub i64 %0, 1
ret i64 %sub
%sub = sub i32 %0, 1
ret i32 %sub
}


Expand All @@ -30,7 +30,7 @@ source_filename = "group_name"

%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 }

@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00"
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 }
@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>"]
@"type_info::<core::i32>::name" = private unnamed_addr constant [10 x i8] c"core::i32\00"
@"type_info::<core::i32>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\17yzt\19\D62\17\D25\95C\17\88[\FA", [10 x i8]* @"type_info::<core::i32>::name", i32 32, i8 4, i8 0 }
@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i32>"]

16 changes: 8 additions & 8 deletions crates/mun_codegen/src/snapshots/test__extern_fn.snap
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
source: crates/mun_codegen/src/test.rs
expression: "extern fn add(a:int, b:int) -> int;\npub fn main() {\n add(3,4);\n}"
expression: "extern fn add(a:i32, b:i32) -> i32;\npub fn main() {\n add(3,4);\n}"
---
; == FILE IR =====================================
; ModuleID = 'main.mun'
source_filename = "main.mun"

%DispatchTable = type { i64 (i64, i64)* }
%DispatchTable = type { i32 (i32, i32)* }
%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 }

@dispatchTable = external global %DispatchTable
@global_type_table = external global [1 x %struct.MunTypeInfo addrspace(4)*]

define void @main() {
body:
%add_ptr = load i64 (i64, i64)*, i64 (i64, i64)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%add = call i64 %add_ptr(i64 3, i64 4)
%add_ptr = load i32 (i32, i32)*, i32 (i32, i32)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%add = call i32 %add_ptr(i32 3, i32 4)
ret void
}

Expand All @@ -24,11 +24,11 @@ body:
; ModuleID = 'group_name'
source_filename = "group_name"

%DispatchTable = type { i64 (i64, i64)* }
%DispatchTable = type { i32 (i32, i32)* }
%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 }

@dispatchTable = global %DispatchTable zeroinitializer
@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00"
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 }
@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>"]
@"type_info::<core::i32>::name" = private unnamed_addr constant [10 x i8] c"core::i32\00"
@"type_info::<core::i32>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\17yzt\19\D62\17\D25\95C\17\88[\FA", [10 x i8]* @"type_info::<core::i32>::name", i32 32, i8 4, i8 0 }
@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i32>"]

38 changes: 19 additions & 19 deletions crates/mun_codegen/src/snapshots/test__fibonacci.snap
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
---
source: crates/mun_codegen/src/test.rs
expression: "pub fn fibonacci(n:int) -> int {\n if n <= 1 {\n n\n } else {\n fibonacci(n-1) + fibonacci(n-2)\n }\n}"
expression: "pub fn fibonacci(n:i32) -> i32 {\n if n <= 1 {\n n\n } else {\n fibonacci(n-1) + fibonacci(n-2)\n }\n}"
---
; == FILE IR =====================================
; ModuleID = 'main.mun'
source_filename = "main.mun"

%DispatchTable = type { i64 (i64)* }
%DispatchTable = type { i32 (i32)* }
%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 }

@dispatchTable = external global %DispatchTable
@global_type_table = external global [1 x %struct.MunTypeInfo addrspace(4)*]

define i64 @fibonacci(i64) {
define i32 @fibonacci(i32) {
body:
%lesseq = icmp sle i64 %0, 1
%lesseq = icmp sle i32 %0, 1
br i1 %lesseq, label %if_merge, label %else

else: ; preds = %body
%sub = sub i64 %0, 1
%fibonacci_ptr = load i64 (i64)*, i64 (i64)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%fibonacci = call i64 %fibonacci_ptr(i64 %sub)
%sub5 = sub i64 %0, 2
%fibonacci_ptr6 = load i64 (i64)*, i64 (i64)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%fibonacci7 = call i64 %fibonacci_ptr6(i64 %sub5)
%add = add i64 %fibonacci, %fibonacci7
%sub = sub i32 %0, 1
%fibonacci_ptr = load i32 (i32)*, i32 (i32)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%fibonacci = call i32 %fibonacci_ptr(i32 %sub)
%sub5 = sub i32 %0, 2
%fibonacci_ptr6 = load i32 (i32)*, i32 (i32)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%fibonacci7 = call i32 %fibonacci_ptr6(i32 %sub5)
%add = add i32 %fibonacci, %fibonacci7
br label %if_merge

if_merge: ; preds = %body, %else
%iftmp = phi i64 [ %add, %else ], [ %0, %body ]
ret i64 %iftmp
%iftmp = phi i32 [ %add, %else ], [ %0, %body ]
ret i32 %iftmp
}


; == GROUP IR ====================================
; ModuleID = 'group_name'
source_filename = "group_name"

%DispatchTable = type { i64 (i64)* }
%DispatchTable = type { i32 (i32)* }
%struct.MunTypeInfo = type { [16 x i8], i8 addrspace(4)*, i32, i8, i8 }

@dispatchTable = global %DispatchTable { i64 (i64)* @fibonacci }
@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00"
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 }
@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>"]
@dispatchTable = global %DispatchTable { i32 (i32)* @fibonacci }
@"type_info::<core::i32>::name" = private unnamed_addr constant [10 x i8] c"core::i32\00"
@"type_info::<core::i32>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\17yzt\19\D62\17\D25\95C\17\88[\FA", [10 x i8]* @"type_info::<core::i32>::name", i32 32, i8 4, i8 0 }
@global_type_table = global [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i32>"]

declare i64 @fibonacci(i64)
declare i32 @fibonacci(i32)

Loading

0 comments on commit 7298dfa

Please sign in to comment.