我llvmlite
用来翻译try ... except ...
,当我使用函数时landingpad
,它可以生成 IR,但是在验证它时会抛出错误,我已经搜索过关于这个的文档,我发现它被移动了(https://github.com/numba/llvmlite/pull/ 156),我解决不了,求助……
演示代码:
try:
e = a * b
f = 2 / 3
print(e)
except Exception as e:
# pass
print(e)
源代码:
def translate_except(self, builder_except):
tp_pers = ir.FunctionType(ir.IntType(8), (), var_arg=True)
pers = ir.Function(self.module, tp_pers, '__gxx_personality_v0')
landingpad = builder_except.landingpad(ir.LiteralStructType([ir.IntType(32), ir.IntType(8).as_pointer()]),
'lp')
int_typeinfo = ir.GlobalVariable(builder_except.function.module, ir.IntType(8).as_pointer(),
"_ZTIi")
int_typeinfo.global_constant = True
int_typeinfo.linkage = 'internal'
int_typeinfo.unnamed_addr = True
landingpad.add_clause(ir.CatchClause(int_typeinfo))
landingpad.add_clause(ir.FilterClause(ir.Constant(ir.ArrayType(int_typeinfo.type, 1),
[int_typeinfo])))
return landingpad
...
...
...
# vevify
mod = llvm.parse_assembly(str(handle_bc.module))
mod.verify()
print('verify Done.')
红外线:
...
...
except.11233:
%"lp" = landingpad {i32, i8*}
catch i8** @"_ZTIi"
filter [1 x i8**] [i8** @"_ZTIi"]
%"11244" = load i32, i32* %"e.4", align 8
call void (...) @"print"(i32 %"11244")
resume {i32, i8*} %"lp"
...
...
验证它仍然抛出这个,:
Traceback (most recent call last):
File "D:/python/bc2ir/BC_TO_IR.py", line 317, in main
mod.verify()
File "C:\Python\lib\site-packages\llvmlite\binding\module.py", line 115, in verify
raise RuntimeError(str(outmsg))
RuntimeError: LandingPadInst needs to be in a function with a personality.
%lp = landingpad { i32, i8* }
catch i8** @_ZTIi
filter [1 x i8**] [i8** @_ZTIi]
Instruction does not dominate all uses!
%e.4 = alloca i32, i32 8
%"11244" = load i32, i32* %e.4, align 8
ResumeInst needs to be in a function with a personality.
resume { i32, i8* } %lp