我正在尝试转换这个原始 LLVM 代码:
%UnwEx = type { i64, i8*, i64, i64 }
@UnwEx.size = constant i64 ptrtoint (%UnwEx* getelementptr (%UnwEx* null, i32 1) to i64)
到 llvmlite:
unw_ex = context.get_identified_type("UnwEx")
unw_ex.elements = [int_, i8_ptr, int_, int_]
i32 = ir.IntType(32)
gep = builder.gep(ir.PointerType(unw_ex), [i32(1)], name="gep")
... # some extra code to cast gep to integer
这个想法是UnwEx
在运行时获取结构化类型的大小。然而,命令的最后一行get
提出了这个问题:
Traceback (most recent call last):
File "C:/Users/DavidRagazzi/Desktop/mamba/mamba/core/runtime.py", line 495, in <module>
generate(None, 64, 8)
File "C:/Users/DavidRagazzi/Desktop/mamba/mamba/core/runtime.py", line 280, in generate
gep = builder.gep(unw_ex_ptr, [i32(1)], name="gep")
File "C:\Program Files\Python37\lib\site-packages\llvmlite\ir\builder.py", line 925, in gep
inbounds=inbounds, name=name)
File "C:\Program Files\Python37\lib\site-packages\llvmlite\ir\instructions.py", line 494, in __init__
typ = ptr.type
AttributeError: 'PointerType' object has no attribute 'type'
这有什么问题?有没有更好的方法来获取类型的大小?