Verify bitcode before write, minor fixes. (#21)
This commit is contained in:
+8
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user