2015-05-22 32 views
1

我在玩LLVM,並已開始使用簡單的Hello World。下面是我試圖運行代碼:錯誤:調用GEP指令時的期望值令牌

test.s

; Declare the string constant as a global constant.     
@.str = private unnamed_addr constant [13 x i8] c"Hello world!\00" 

; External declaration of the puts function       
declare i32 @puts(i8* nocapture) nounwind        

; Definition of main function           
define i32 @main() { ; i32()*          
    ; Convert [13 x i8]* to i8 *...          
    %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0 

    ; Call putr function to write out the string to stdout. 
    call i32 @puts(i8* %cast210) 
    ret i32 0 
} 

我把它從這裏:http://llvm.org/docs/LangRef.html#id610。當我運行它時,出現以下錯誤:

$lli test.s 
lli: test.s:10:37: error: expected value token 
%cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0 
           ^

當官方LLVM網站的代碼失敗時,有點令人困惑。

test_fixed.s

; Declare the string constant as a global constant.     
@.str = private unnamed_addr constant [13 x i8] c"Hello world!\00" 

; External declaration of the puts function       
declare i32 @puts(i8* nocapture) nounwind        

; Definition of main function           
define i32 @main() { ; i32()*          
    ; Convert [13 x i8]* to i8 *...          
    %cast210 = getelementptr [13 x i8]* @.str, i64 0, i64 0 

    ; Call putr function to write out the string to stdout. 
    call i32 @puts(i8* %cast210) 
    ret i32 0 
} 

我的問題是:什麼是怎麼回事但是,可以通過修改有問題的線路如下固定的嗎?當我檢查getelementptr文檔:http://llvm.org/docs/LangRef.html#id937時,我得到的印象是test.s的確是正確的。但它不起作用。請幫忙。

一些背景信息:

$ lli -version 
    LLVM (http://llvm.org/): 
     LLVM version 3.3 
     Optimized build. 
     Built Jun 18 2013 (05:58:10). 
     Default target: x86_64-pld-linux-gnu 
     Host CPU: bdver1 

回答

3

這應該是一個關於你的lli和官方LLVM文檔之間的版本不匹配的問題。官方的LLVM文檔是LLVM的最新開發版本,3.7

您問題中的LLVM IR代碼更新於Mar 4 2015。根據this link,指令格式更新後getelementptr

但是,您的lli版本是3.3,它在Jun 18 2013上發佈。

請將您的llvm工具鏈更新到最新版本,然後重試。

+0

完全有道理,謝謝!我是LLVM的新手,並不總是在哪裏尋找答案。這非常有幫助! –

+0

@ banach-space:嘿,我也遇到了同樣的錯誤。我正在使用llvm3.8.1來生成.ll文件,並且我正在使用該.ll文件傳遞給我的程序,該程序早先在llvm3.6上。我的程序從這個.ll文件獲取輸入,並且與llvm3.8.1成功編譯。所以我認爲沒有問題。如何解決這個問題?提前致謝。 – user413201

相關問題