Sparc assembly syntax

Any code that I generate for the Sparc fails at assembly time using a gas assembler built for the Sparc.

I get code like the following from the code generator:
         .text
         .align 16
         .globl main
         .type main, #function
main:
         save -96, %o6, %o6

and get a syntax error on the save instruction.

I think sparc syntax should be:

         .text
         .align 16
         .globl main
         .type main, #function
main:
         save %o6, -96, %o6

Is that correct? Should I file a bug report?

-Rich

save %o6, -96, %o6

is the usual syntax for Sparc assemblers. But this instruction is so fundamental nothing could ever have worked if it's broken, so there may be something deeper going on.

This is probably a difference between the sun and GNU assemblers. There is no current sparc maintainer, so feel free to change it if one way works better for you.

-Chris

Chris Lattner wrote:

This is probably a difference between the sun and GNU assemblers. There is no current sparc maintainer, so feel free to change it if one way works better for you.

Hi Chris,

Here's the fix:

Index: SparcRegisterInfo.cpp

OK, so the next thing I found in Sparc world is that sparc-elf-as doesn't understand .bss as a directive for some reason.

I modified the Sparc code generator to output .section ".bss" and that works just fine. My (temporary) solution is a hack, however:

Hi Richard,

My question is: What is the "right" way to do this? I looked at the Mips
code generator a little bit and it feels a little more modern. Is that
correct?

Yes. There's new work on ELF asm output going on, and AFAIK only
Mips and X86 are using it.

Which code generator(s) are the best to look at for a template to do
asm/ELF output?

x86 is the most complete one, but as a start I'd suggest Mips.

I've started work on a Nios2 code generator, which I originally based on
Mips because its architecture is similar. Is there a better starting point?

Cool, send patches when you get something working :slight_smile:

Pretty much yes, Sun as will accept either form (with the same meaning), but GNU gas will only accept 'save %o6, -96, %o6'.

Cheers,
Nathan

After refreshing my memory on how the sparc backend works, it turns out that this was a serious bug and that your patch is absolutely the right fix. The .td description was expecting the operands in the order the assembler was expecting, and we happened to get lucky that nothing downstream looked at the .td operand info.

Thanks Richard, I applied your patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20080728/065608.html

-Chris

As others mentioned, Anton is working on a significant cleanup to help unify the asm printers. If you need to do this in the short term, I'd add an "isTargetELF()" method to the SparcSubtarget class, and have it autodetect it from the target triple as the x86 backend does. With that, you can predicate the output based on whether the target is elf or not.

-Chris