[LLVMdev] Problem with labels

Tim Lenertz timlenertz at gmail.com
Wed Nov 20 23:19:41 PST 2013


Hi,
I'm trying to assemble the following LLVM assembly source code, but
llvm-as reports an error (expected opcode instruction) at the label
"Until2:" (in function @find). If i remove both the load and store
instructions before it it works, but then there is the same problem with
Until1 (in @main).
I wanted to ask how to solve this / where labels can be placed?

@.intFormat = internal constant [3 x i8] c"%d\00"

declare i32 @scanf(i8*, ...);
declare i32 @printf(i8*, ...);
declare i32 @puts(i8*)

define void @readInteger(i32* %ptr) {
%format = getelementptr [3 x i8]* @.intFormat, i32 0, i32 0
call i32 (i8*, ...)* @scanf(i8* %format, i32* %ptr)
ret void
}

define void @writeInteger(i32 %integer) {
%format = getelementptr [3 x i8]* @.intFormat, i32 0, i32 0
call i32 (i8*, ...)* @printf(i8* %format, i32 %integer)
ret void
}

@b = private global i32 0
@c = private global i32 0
@a = private global i32 0

@.string1 = internal unnamed_addr constant [8 x i8] c"valeur:\00"

define void @find() {
%tmp1 = load i32* @c
store i32 %tmp1, i32* @b
Until2:
%a6 = load i32* @a
%b7 = load i32* @b
%conditionVar5 = icmp slt i32 %a6, %b7
br i1 %conditionVar5, label %EndUntil4, label %Call3
Call3:
call void @diff()
br label %Until2
EndUntil4:
%tmp8 = load i32* @a
store i32 %tmp8, i32* @b
%tmp9 = load i32* @c
store i32 %tmp9, i32* @a
ret void
}

define void @main() {
call void @readInteger(i32* @a)
call void @readInteger(i32* @b)
Until1:
%a5 = load i32* @b
%b6 = or i32 0, 0
%conditionVar4 = icmp eq i32 %a5, %b6
br i1 %conditionVar4, label %EndUntil3, label %Call2
Call2:
call void @find()
br label %Until1
EndUntil3:
%ptr7 = getelementptr [8 x i8]* @.string1, i32 0, i32 0
call i32 (i8*)* @puts(i8* %ptr7)
%output8 = load i32* @a
call void @writeInteger(i32 %output8)
ret void
}

define void @diff() {
%a2 = load i32* @a
%b3 = load i32* @b
%tmp1 = sub i32 i32 %a2, %b3
store i32 %tmp1, i32* @a
ret void
}






More information about the llvm-dev mailing list