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