Update gitignore, add support for arrays and pointers

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
Slendi 2024-03-01 12:21:44 +02:00
parent 327f2bdd86
commit 5dc73ab5f2
5 changed files with 41 additions and 7 deletions

4
.gitignore vendored
View File

@ -2,4 +2,6 @@ speedcat
speedcat.exe
speedcat.pdb
test.exe
hello.ll
hello.ll
*.ll
*.exe

View File

@ -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")
}

View File

@ -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 ---

View File

@ -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
}

View File

@ -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