Verify bitcode before write, minor fixes. (#21)

This commit is contained in:
Nikolay Igotti
2016-10-27 18:54:38 +03:00
committed by GitHub
parent f448358ec2
commit cbb5499313
5 changed files with 11 additions and 10 deletions
@@ -24,6 +24,14 @@ fun emitLLVM(module: IrModuleFragment, runtimeFile: String, outFile: String) {
module.acceptVoid(RTTIGeneratorVisitor(context))
context.runtime.importRuntime(llvmModule)
module.acceptVoid(CodeGeneratorVisitor(context))
memScoped {
val errorRef = alloc(Int8Box.ref)
// TODO: use LLVMDisposeMessage() on errorRef, once possible in interop.
if (LLVMVerifyModule(
llvmModule, LLVMVerifierFailureAction.LLVMPrintMessageAction, errorRef) == 1) {
throw Error("Invalid module");
}
}
LLVMWriteBitcodeToFile(llvmModule, outFile)
}
@@ -85,7 +85,7 @@ internal fun getLlvmFunctionType(function: FunctionDescriptor): LLVMOpaqueType?
if (extraParam.size == 0) return LLVMFunctionType(returnType, null, 0, 0)
memScoped {
val paramTypesPtr = mallocNativeArrayOf(LLVMOpaqueType, *extraParam.toTypedArray())[0] // TODO: dispose
val paramTypesPtr = allocNativeArrayOf(LLVMOpaqueType, *extraParam.toTypedArray())[0] // TODO: dispose
return LLVMFunctionType(returnType, paramTypesPtr, extraParam.size, 0)
}
}
+2 -1
View File
@@ -13,7 +13,8 @@ ArenaContainer::ArenaContainer(uint32_t size) {
calloc(size + sizeof(ArenaContainerHeader), 1));
header_ = header;
header->ref_count_ = CONTAINER_TAG_INCREMENT;
header->current_ = reinterpret_cast<uint8_t*>(header_) + sizeof(ArenaContainerHeader);
header->current_ =
reinterpret_cast<uint8_t*>(header_) + sizeof(ArenaContainerHeader);
header->end_ = header->current_ + size;
}
-5
View File
@@ -1,5 +0,0 @@
int foo(int a, int b){
int c;
c = a + b;
return c;
}
-3
View File
@@ -1,3 +0,0 @@
int foo() { return 1; }
int bar() {return 2;}
int sum() {return foo() + bar();}