2013-02-07 78 views
13

Online LLVM demo頁面可以選擇從源代碼生成LLVM C++ API代碼作爲後端。但是,該演示頁面現在已禁用。我想知道如何使用可用的LLVM工具自己做到這一點。生成LLVM C++ API代碼作爲後端

我嘗試以下

clang++ -c -emit-llvm input.cpp -o input.ll 
llc -march=cpp -o input.ll.cpp input.ll 

它提供了以下錯誤

llc: error: invalid target 'cpp'. 

我使用LLVM/Clang的3.2版本。

+3

是否將'llc -version' list'cpp'列爲有效的後端目標? – Necrolis

+0

llc -version不會在列表中顯示cpp。它需要任何註冊或包含cpp的東西,或者什麼? – MetallicPriest

+0

@MetallicPriest我想他們只是不啓用它的在線演示(這不是真的是人們感興趣的,我猜)爲什麼你不在本地系統上安裝LLVM? – us2012

回答

6

構建LLVM時,必須在配置期間啓用LLVM C++後端。它在默認情況下在 configure(autotools)構建中啓用,但在Windows上構建時不在CMake構建中。您可以通過在使用CMake進行配置時設置適當的標誌來啓用它。有關更多信息,請參閱 this page

報價:

LLVM_TARGETS_TO_BUILD:目標STRING 分號分隔的列表來構建,或者全部建築物的所有目標。區分大小寫。對於Visual C++,默認爲X86。在 其他情況下默認爲全部。示例: -DLLVM_TARGETS_TO_BUILD =「X86; PowerPC」。

UPDATE

由於version 3.9的CppBackend不再是一個有效的目標。由於生成的代碼呈現幾個問題,他們已從代碼中刪除。

Check this commit

Remove bit-rotten CppBackend. 

This backend was supposed to generate C++ code which will re-construct 
the LLVM IR passed as input. This seems to me to have very marginal 
usefulness in the first place. 

However, the code has never been updated to use IRBuilder, which makes 
its current value negative -- people who look at the output may be 
steered to use the *wrong* C++ APIs to construct IR. 

Furthermore, it's generated code that doesn't compile since at least 
2013. 

Differential Revision: http://reviews.llvm.org/D19942 

git-svn-id: https://llvm.org/svn/llvm-project/llvm/[email protected] 91177308-0d34-0410-b5e6-96231b3b80d8 
1

可悲的是,這似乎不再可能在較新版本的LLVM的。相關的提交消息很好地解釋了它。

正如您在以下提交中看到的, Remove bit-rotten CppBackend,生成的代碼會顯示問題。

commit 257fabb18605265a79397d35dd79a3973760ffaf 
Author: --- 
Date: Thu May 5 14:35:40 2016 +0000 

Remove bit-rotten CppBackend. 

This backend was supposed to generate C++ code which will re-construct 
the LLVM IR passed as input. This seems to me to have very marginal 
usefulness in the first place. 

However, the code has never been updated to use IRBuilder, which makes 
its current value negative -- people who look at the output may be 
steered to use the *wrong* C++ APIs to construct IR. 

Furthermore, it's generated code that doesn't compile since at least 
2013. 

Differential Revision: http://reviews.llvm.org/D19942 

git-svn-id: https://llvm.org/svn/llvm-project/llvm/[email protected] 91177308-0d34-0410-b5e6-96231b3b80d8