[LLVMdev] Trouble with inline asm
Chris Lattner
sabre at nondot.org
Sat Jun 7 11:40:58 PDT 2008
On Jun 7, 2008, at 11:16 AM, Tomas Lindquist Olsen wrote:
>>
>> Good luck doing this; I imagine this is going to be tricky to
>> implement, especially converting from Intel to AT&T syntax.
>
> Thanx, we'll need it ;) Fortunately much of the code is already in
> place (taken from the GDC D compiler), so it "only" had to be adapted
> from GCC to LLVM.
Incidentally, llvm-gcc has partial support for this with the -fasm-
blocks command line option. This code is accepted by apple gcc:
int printf(char*,...);
int main()
{
int i = 12;
printf("%d\n", i);
asm
{
mov EAX, i;
add EAX, EAX;
mul EAX, 2;
mov i, EAX; // ***
}
printf("%d\n", i);
return 0;
}
But it looks like it is currently rejected by llvm-gcc (invalid or
unsupported asm). This is a bug that we will fix in time. I think
that the GCC front-end makes the same mistake as the D front-end,
where it lowers each statement into a separate inline asm node.
Here's an example that does work with llvm-gcc, though it produces
ugly code like Apple GCC (pinning 'i' to the stack):
int printf(char*,...);
int main()
{
int i = 12;
printf("%d\n", i);
asm
{
shl i, 1
}
printf("%d\n", i);
return 0;
}
-Chris
More information about the llvm-dev
mailing list