当我从C++生成LLVM IR代码时,我可以使用console命令clang++ -emit-llvm –S test.cpp获取test.ll文件,这是我想要的LLVM IR.
要获得可执行文件,请遵循以下步骤:
llvm-as test.ll - >给我test.bc文件.
llc test.bc --o test.s - >给我test.s文件.
clang++ test.s -o test.native - >给我一个我可以执行的本机文件.
对于C++,这很好用.
从理论上讲,当我编写Rust或Python代码时,是否应该采用相同的步骤?
我通过输入我的Rust代码并获得LLVM IR rustc test.rs --emit llvm-ir.这再次给了我test.ll文件.
对于Python,我使用"Numba"并通过键入获得LLVM IR,numba --dump-llvm test.py> test.ll这也给了我test.ll文件.
从这些.ll文件生成可执行文件的步骤应该相同.
它们一直工作到创建本机可执行文件的最后一步:
Python错误
/tmp/test-9aa440.o: In function 'main':
test.bc:(.text+0x67): undefined reference to 'numba_gil_ensure'
test.bc:(.text+0x79): undefined reference to 'numba_unpickle'
test.bc:(.text+0x84): undefined reference to 'PyObject_Str'
test.bc:(.text+0x8f): undefined reference to 'PyString_AsString'
test.bc:(.text+0xa1): undefined reference to 'PySys_WriteStdout'
test.bc:(.text+0xa9): undefined reference to 'Py_DecRef'
test.bc:(.text+0xb1): undefined …Run Code Online (Sandbox Code Playgroud)