error: expected value token when calling the GEP instruction
error: expected value token when calling the GEP instruction
我正在玩 LLVM 并从简单的 Hello World 开始。这是我正在尝试的代码 运行:
test.s:
; Declare the string constant as a global constant.
@.str = private unnamed_addr constant [13 x i8] c"Hello world![=10=]"
; 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![=12=]"
; 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
这应该是您的 lli
和官方 LLVM 文档之间版本不匹配的问题。官方 LLVM 文档适用于 LLVM 的最新开发版本,3.7
.
您问题中的 LLVM IR 代码已于 Mar 4 2015
更新。根据 this link,getelementptr
指令格式更新后。
但是,您的 lli 版本是 3.3
,它是在 Jun 18 2013
上发布的。
请将您的 llvm 工具链更新到最新版本,然后重试。
我正在玩 LLVM 并从简单的 Hello World 开始。这是我正在尝试的代码 运行:
test.s:
; Declare the string constant as a global constant.
@.str = private unnamed_addr constant [13 x i8] c"Hello world![=10=]"
; 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![=12=]"
; 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
这应该是您的 lli
和官方 LLVM 文档之间版本不匹配的问题。官方 LLVM 文档适用于 LLVM 的最新开发版本,3.7
.
您问题中的 LLVM IR 代码已于 Mar 4 2015
更新。根据 this link,getelementptr
指令格式更新后。
但是,您的 lli 版本是 3.3
,它是在 Jun 18 2013
上发布的。
请将您的 llvm 工具链更新到最新版本,然后重试。