Labels

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Labels

Michael Ness
I'm attempting to modify a parser generator to emit LLVM code instead of C.  
So far the experience has been trivial, but I am now running into an error
regarding labels that I can't seem to solve.

Situation 1:  A label is used immediately after a void function call (l6 in
this case):

<snip>
        %tmp26 = load i32* @yybegin, align 4
        %tmp27 = load i32* @yyend, align 4
        call void @yyDo(void (i8*, i32)* @yy_7_body, i32 %tmp26, i32 %tmp27)
l6:
        br label %l2
<snip>

I get the following error:

llvm-as: test.ll:578,0: test.ll:578: error: syntax error, unexpected LABELSTR,
expecting LOAD or STORE while reading token: 'l6:'

Why is this label unexpected?



Situation 2:  More than 1 label is used to refer to the same location (l11 in
this case):

<snip>
PredicateEqualZero3:
        br label %l1
PredicateNotEqualZero3:


l11:


l2:

        ret i32 1
<snip>

I get the same error:

llvm-as: test.ll:706,0: test.ll:706: error: syntax error, unexpected LABELSTR,
expecting LOAD or STORE while reading token: 'l11:'

If this code were hand written I'd just use one label here, but the parser
generator automatically creates several labels.  When these overlap there are
sometimes multiple labels for the same location in the code.  Why is this an
error and is there any way to allow it?

Also, is there a NO-OP instruction in LLVM?

I've attached the complete LLVM code as well.

Thanks,
Mike

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

test.l (23K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Labels

Jaap Suter
> Why is this label unexpected?

Because a label starts a new basic block, but a call instruction is not a proper
closing instruction for the previous basic block.

The solution that I use is to insert a "br l6" instruction just after the call
instruction (effectively a no-op, but it closes the basic-block properly).

See the LLVM documentation on terminators for more information on what closes a
basic block:
 
    http://llvm.org/docs/LangRef.html#terminators

Hope that helps,

Jaap Suter - http://jaapsuter.com

> %tmp26 = load i32* @yybegin, align 4
> %tmp27 = load i32* @yyend, align 4
> call void @yyDo(void (i8*, i32)* @yy_7_body, i32 %tmp26, i32 %tmp27)
> l6:
> br label %l2
> <snip>
>
> I get the following error:
>
> llvm-as: test.ll:578,0: test.ll:578: error: syntax error, unexpected
> LABELSTR,
> expecting LOAD or STORE while reading token: 'l6:'



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev