C++에서 LLVM IR 코드를 생성 할 때 콘솔 명령 clang++ -emit-llvm –S test.cpp
을 사용하여 내가 원하는 LLVM IR 인 test.ll 파일을 얻을 수 있습니다. Rust/Python 소스 코드에서 생성 된 LLVM IR 코드
llvm-as test.ll
가 -> 나에게 test.bc 파일을 제공합니다.llc test.bc --o test.s
-> 내게 test.s 파일을 제공합니다.clang++ test.s -o test.native
-> 내가 실행할 수있는 기본 파일을 제공합니다.
C++의 경우에는 정상적으로 작동합니다.
이론상 녹 또는 파이썬 코드를 쓸 때 동일한 단계를 적용해야합니까?
내 녹 코드를 받아서 rustc test.rs --emit llvm-ir
을 입력하여 LLVM IR을 얻습니다. 이것은 나에게 test.ll 파일을 다시 준다.
파이썬의 경우 "Numba"를 사용하고 numba --dump-llvm test.py> test.ll
을 입력하여 LLVM IR을 얻습니다.이 또한 test.ll 파일을 제공합니다.
이러한 .ll 파일에서 실행 파일을 생성하는 단계는 동일해야합니다.
파이썬 오류
이/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 reference to 'Py_DecRef'
test.bc:(.text+0xbd): undefined reference to 'PySys_WriteStdout'
test.bc:(.text+0xc5): undefined reference to 'numba_gil_release'
test.bc:(.text+0xff): undefined reference to 'numba_gil_ensure'
test.bc:(.text+0x10b): undefined reference to 'PySys_WriteStdout'
test.bc:(.text+0x113): undefined reference to 'numba_gil_release'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
녹 오류
/tmp/main-5e59bd.o: In function ‘main::sum::h514304ffa40dd7c3’:
main.bc:(.text+0xf): undefined reference to ‘core::panicking::panic::h2596388ccef1871c’
/tmp/main-5e59bd.o: In function ‘main’: main.bc:(.text+0x53): undefined reference to ‘std::rt::lang_start::h65647f6e36cffdae’
clang: error: linker command failed with exit code 1 (use -v to see invocation)
내가이에서 얻을 것이 있다는 것입니다 :
그들은 기본 실행 파일을 생성하는 마지막 단계까지 작업 clang은 LLVM IR 파일의 Rust/Python 특정 부분을 이해하지 못합니다 (예 : "PyO 파이썬에서 "bject"또는 Rust에서 "panic") .bc, .s 및 .native 파일을 생성하는 데 사용되었습니다.
하지만 처음에는 정보 검색 (IR)에있는 이유가 무엇입니까? LLVM IR이 균일해야하며 해당 부분이 변형되어 LLVM 툴체인이 함께 작업 할 수 있습니까? LLVM의 모듈성은 LLVM IR을 사용하여 이러한 단계를 허용해야합니다. 이 일을하는 또 다른 방법이 있을지 모르겠습니다.
clang이 이해할 수있는 "순수한"LLVM IR을 제공하는 다른 방법으로 해당 언어의 IR을 생성 할 수 있습니까? 아니면 그 파일에서 실행 파일을 생성 할 수 있습니까?
Possible Linked to : http://stackoverflow.com/questions/15169015/call-python-code-from-llvm-jit?rq=1 – MKesper
.ll 소스를 검사 할 경우 외부에서 정의 된 함수에 대한 참조를 찾아야합니다. 파이썬과 녹이 모두. C++ 소스에서 생성 된 IR에 대해서도 마찬가지 일 수 있지만'clang ++'에는 C++ 표준 lib가 기본적으로 포함되어 있습니다. – SPAT