diff --git a/.gitignore b/.gitignore index 97616a4..ff1fd37 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ speedcat speedcat.exe speedcat.pdb test.exe -hello.ll \ No newline at end of file +hello.ll +*.ll +*.exe \ No newline at end of file diff --git a/src/llvm_emitter.odin b/src/llvm_emitter.odin index 5ba316e..bf62040 100644 --- a/src/llvm_emitter.odin +++ b/src/llvm_emitter.odin @@ -107,9 +107,11 @@ generate_llvm :: proc(ctx: LLVMContextRef, mod: LLVMModuleRef, builder: LLVMBuil fmt.panicf("LLVM-IR: Unsupported float type bit size: {}", type.bit_size) } case .Array: - panic("FIXME: Implement array LLVM IR generation") + array_of := generate_llvm_type_from_node(ctx, mod, builder, type.array_of) + return LLVMArrayType2(array_of, type.array_size) case .Pointer: - panic("FIXME: Implement pointer LLVM IR generation") + pointer_of := generate_llvm_type_from_node(ctx, mod, builder, type.pointer_to) + return LLVMPointerType(pointer_of, 0) } panic("LLVM-IR: Invalid type") } diff --git a/src/llvmc.odin b/src/llvmc.odin index 6368baa..6fb6afe 100644 --- a/src/llvmc.odin +++ b/src/llvmc.odin @@ -76,6 +76,7 @@ foreign llvmc { LLVMVoidTypeInContext :: proc(C: LLVMContextRef) -> LLVMTypeRef --- + LLVMArrayType2 :: proc(ElementType: LLVMTypeRef, ElementCount: u64) -> LLVMTypeRef --- LLVMPointerType :: proc(ElementType: LLVMTypeRef, AddressSpace: uint) -> LLVMTypeRef --- LLVMConstInt :: proc(IntTy: LLVMTypeRef, N: u64, SignExtend: LLVMBool) -> LLVMValueRef --- diff --git a/src/main.odin b/src/main.odin index 13eadd4..7bb1326 100644 --- a/src/main.odin +++ b/src/main.odin @@ -49,14 +49,43 @@ main :: proc() { node_print(ast) + name : string + if handle == os.stdin { + name = "stdin" + } else { + name = os.args[1] + } + module_name := main_module_name_from_filename(name) ctx := LLVMContextCreate() defer LLVMContextDispose(ctx) - module := LLVMModuleCreateWithNameInContext("hello", ctx) + module := LLVMModuleCreateWithNameInContext(cstring(raw_data(module_name[:])), ctx) defer LLVMDisposeModule(module) builder := LLVMCreateBuilderInContext(ctx) generate_llvm(ctx, module, builder, ast) - LLVMPrintModuleToFile(module, "hello.ll", nil) + append(&module_name, '.') + append(&module_name, 'l') + append(&module_name, 'l') + LLVMPrintModuleToFile(module, cstring(raw_data(module_name[:])), nil) } +main_module_name_from_filename :: proc(fname: string) -> (module_name: [dynamic]u8) { + temp_name := [dynamic]u8{} + for ch in transmute([]u8)fname { + if ch == '/' || ch == '\\' { + clear(&temp_name) + } else { + append(&temp_name, ch) + } + } + + for ch in temp_name { + if ch == '.' { + break + } + append(&module_name, ch) + } + + return +} diff --git a/test_type_checker.cat b/test_type_checker.cat index e65c5f1..ce23301 100644 --- a/test_type_checker.cat +++ b/test_type_checker.cat @@ -7,10 +7,10 @@ \name 123.0 456.0 -\let arr: []i32, arr2: [69]u8, ptr: ^i32 +let arr: []i32, arr2: [69]u8, ptr: ^i32 fn put_i32(val: i32) i32 -let amogus := 500 + (put_i32 80085) +let amogus := 500 + (put_i32 8008135) put_i32 69 * amogus + 420