Update gitignore, add support for arrays and pointers
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
parent
327f2bdd86
commit
5dc73ab5f2
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@ speedcat.exe
|
|||||||
speedcat.pdb
|
speedcat.pdb
|
||||||
test.exe
|
test.exe
|
||||||
hello.ll
|
hello.ll
|
||||||
|
*.ll
|
||||||
|
*.exe
|
@ -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)
|
fmt.panicf("LLVM-IR: Unsupported float type bit size: {}", type.bit_size)
|
||||||
}
|
}
|
||||||
case .Array:
|
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:
|
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")
|
panic("LLVM-IR: Invalid type")
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,7 @@ foreign llvmc {
|
|||||||
|
|
||||||
LLVMVoidTypeInContext :: proc(C: LLVMContextRef) -> LLVMTypeRef ---
|
LLVMVoidTypeInContext :: proc(C: LLVMContextRef) -> LLVMTypeRef ---
|
||||||
|
|
||||||
|
LLVMArrayType2 :: proc(ElementType: LLVMTypeRef, ElementCount: u64) -> LLVMTypeRef ---
|
||||||
LLVMPointerType :: proc(ElementType: LLVMTypeRef, AddressSpace: uint) -> LLVMTypeRef ---
|
LLVMPointerType :: proc(ElementType: LLVMTypeRef, AddressSpace: uint) -> LLVMTypeRef ---
|
||||||
|
|
||||||
LLVMConstInt :: proc(IntTy: LLVMTypeRef, N: u64, SignExtend: LLVMBool) -> LLVMValueRef ---
|
LLVMConstInt :: proc(IntTy: LLVMTypeRef, N: u64, SignExtend: LLVMBool) -> LLVMValueRef ---
|
||||||
|
@ -49,14 +49,43 @@ main :: proc() {
|
|||||||
|
|
||||||
node_print(ast)
|
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()
|
ctx := LLVMContextCreate()
|
||||||
defer LLVMContextDispose(ctx)
|
defer LLVMContextDispose(ctx)
|
||||||
module := LLVMModuleCreateWithNameInContext("hello", ctx)
|
module := LLVMModuleCreateWithNameInContext(cstring(raw_data(module_name[:])), ctx)
|
||||||
defer LLVMDisposeModule(module)
|
defer LLVMDisposeModule(module)
|
||||||
builder := LLVMCreateBuilderInContext(ctx)
|
builder := LLVMCreateBuilderInContext(ctx)
|
||||||
|
|
||||||
generate_llvm(ctx, module, builder, ast)
|
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
|
||||||
|
}
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
\name 123.0 456.0
|
\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
|
fn put_i32(val: i32) i32
|
||||||
|
|
||||||
let amogus := 500 + (put_i32 80085)
|
let amogus := 500 + (put_i32 8008135)
|
||||||
|
|
||||||
put_i32 69 * amogus + 420
|
put_i32 69 * amogus + 420
|
||||||
|
Loading…
x
Reference in New Issue
Block a user