<div dir="ltr">Frankly, the MC assembler infrastructure is pretty weak. I've spoken personally to some of the developers who wrote it, and they said they know it's bad and suggested that it be rewritten. My experience from attempting to make MC parse Intel x86 asm confirms this.<div><div class="gmail_extra"><br></div><div class="gmail_extra">Here's some questions for you:</div><div class="gmail_extra">Do you need a high-level macro assembler designed for human consumption?<br>Do you need Clang to understand inline assembly that uses these high-level assembly constructs?</div><div class="gmail_extra">Do you need the assembler to parse the output of `clang -S`?</div><div class="gmail_extra"><br></div><div class="gmail_extra">It might be best to have your own small frontend for the macro assembler language that produces MCInsts which can be printed using a more traditional gas-like mneumonic. Running llvm-mc on a hexagon assembly file and re-emitting assembly would parse the high-level assembly and produce the low-level assembly.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Alternatively, you can do as you say and try to make MC into more of a real language frontend. The major problem is that lexing rules are not the same across all targets, even when they all use a gas-like syntax.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 14, 2015 at 10:58 AM, Colin LeMahieu <span dir="ltr"><<a href="mailto:colinl@codeaurora.org" target="_blank">colinl@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal">Hi everyone.  We’re interested in contributing a Hexagon assembler to MC and we’re looking for comments on a good way to integrate the grammar in to the infrastructure.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">We rely on having a robust assembler because we have a large base of developers that write in assembly due to low power requirements for mobile devices.  We put in some C-like concepts to make the syntax easier and this design is fairly well received by users.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">The following is a list of grammar snippets we’ve had trouble integrating in to the asm parser framework.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Instruction packets are optionally enclosed in braces.<u></u><u></u></p><p class="MsoNormal">    { r0 = add(r1, r2) r1 = add(r2, r0) }<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Register can be the beginning of a statement.  Register transfers have no mnemonic.<u></u><u></u></p><p class="MsoNormal">    r0 = r1<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Double registers have a colon in the middle which can look like a label<u></u><u></u></p><p class="MsoNormal">    r1:0 = add(r3:2, r5:4)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Predicated variants for many instructions<u></u><u></u></p><p class="MsoNormal">    if(p1) r0 = add(r1, r2)<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Dense semantics for DSP applications.  Complex multiply optionally shifting result left by 1 with optional rounding and optional saturation<u></u><u></u></p><p class="MsoNormal">    r0 = cmpy(r1, r2):<<1:rnd:sat<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Hardware loops ended by optional packet suffix<u></u><u></u></p><p class="MsoNormal">    { r0 = r1 }:endloop0:endloop1<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">We found the Hexagon grammar to be straight forward to implement using plain lex / parse but harder within the MCTargetAsmParser. <u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">We were thinking a way to get the grammar to work would involve modifying tablegen and the main asm parser loop.  We’d have to make tablegen break down each instructions in to a sequence of tokens and build a sorted matching table based on the set of these sequences.  The matching loop would bisect this sorted list looking for a match.  We think existing grammars would be unaffected; all existing instructions start with a mnemonic so their first token would be an identifier followed by the same sequence of tokens they currently have.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Let us know if we’re likely to run in to any issues making these changes or if there are other recommendations on what we could do.  Thanks!<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="color:black">Qualcomm Innovation Center, Inc.</span><span style="font-size:10.0pt;font-family:"Tahoma",sans-serif;color:black"><br></span><span style="color:black">The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, </span><span style="font-size:10.0pt;font-family:"Tahoma",sans-serif;color:black"><br></span><span style="color:black">a Linux Foundation Collaborative Project</span><u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p></div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div></div>