<div dir="ltr"><div style>Man would it be nice to have testcases that didn't need to go through clang :)</div><div style><br></div><div>-eric</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 12, 2013 at 1:33 PM, Chad Rosier <span dir="ltr"><<a href="mailto:mcrosier@apple.com" target="_blank">mcrosier@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mcrosier<br>
Date: Tue Feb 12 15:33:51 2013<br>
New Revision: 175008<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=175008&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=175008&view=rev</a><br>
Log:<br>
[ms-inline-asm] Implement align directive (which is roughly equivalent to .align).<br>
<br>
Also, allow _EMIT and __EMIT for the emit directive.  We already do the same<br>
for TYPE, SIZE, and LENGTH.<br>
rdar://13200215<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/MC/MCTargetAsmParser.h<br>
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCTargetAsmParser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCTargetAsmParser.h?rev=175008&r1=175007&r2=175008&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCTargetAsmParser.h?rev=175008&r1=175007&r2=175008&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCTargetAsmParser.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCTargetAsmParser.h Tue Feb 12 15:33:51 2013<br>
@@ -22,6 +22,7 @@ class MCInst;<br>
 template <typename T> class SmallVectorImpl;<br>
<br>
 enum AsmRewriteKind {<br>
+  AOK_Align,          // Rewrite align as .align.<br>
   AOK_DotOperator,    // Rewrite a dot operator expression as an immediate.<br>
                       // E.g., [eax].foo.bar -> [eax].8<br>
   AOK_Emit,           // Rewrite _emit as .byte.<br>
<br>
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=175008&r1=175007&r2=175008&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=175008&r1=175007&r2=175008&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Feb 12 15:33:51 2013<br>
@@ -443,9 +443,12 @@ private:<br>
   bool ParseDirectiveIrpc(SMLoc DirectiveLoc); // ".irpc"<br>
   bool ParseDirectiveEndr(SMLoc DirectiveLoc); // ".endr"<br>
<br>
-  // "_emit"<br>
-  bool ParseDirectiveEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,<br>
-                          size_t len);<br>
+  // "_emit" or "__emit"<br>
+  bool ParseDirectiveMSEmit(SMLoc DirectiveLoc, ParseStatementInfo &Info,<br>
+                            size_t Len);<br>
+<br>
+  // "align"<br>
+  bool ParseDirectiveMSAlign(SMLoc DirectiveLoc, ParseStatementInfo &Info);<br>
<br>
   void initializeDirectiveKindMap();<br>
 };<br>
@@ -1447,9 +1450,14 @@ bool AsmParser::ParseStatement(ParseStat<br>
     return Error(IDLoc, "unknown directive");<br>
   }<br>
<br>
-  // _emit or __emit<br>
-  if (ParsingInlineAsm && (IDVal == "_emit" || IDVal == "__emit"))<br>
-    return ParseDirectiveEmit(IDLoc, Info, IDVal.size());<br>
+  // __asm _emit or __asm __emit<br>
+  if (ParsingInlineAsm && (IDVal == "_emit" || IDVal == "__emit" ||<br>
+                           IDVal == "_EMIT" || IDVal == "__EMIT"))<br>
+    return ParseDirectiveMSEmit(IDLoc, Info, IDVal.size());<br>
+<br>
+  // __asm align<br>
+  if (ParsingInlineAsm && (IDVal == "align" || IDVal == "ALIGN"))<br>
+    return ParseDirectiveMSAlign(IDLoc, Info);<br>
<br>
   CheckForValidSection();<br>
<br>
@@ -3989,7 +3997,7 @@ bool AsmParser::ParseDirectiveEndr(SMLoc<br>
   return false;<br>
 }<br>
<br>
-bool AsmParser::ParseDirectiveEmit(SMLoc IDLoc, ParseStatementInfo &Info, size_t len) {<br>
+bool AsmParser::ParseDirectiveMSEmit(SMLoc IDLoc, ParseStatementInfo &Info, size_t Len) {<br>
   const MCExpr *Value;<br>
   SMLoc ExprLoc = getLexer().getLoc();<br>
   if (ParseExpression(Value))<br>
@@ -4001,7 +4009,23 @@ bool AsmParser::ParseDirectiveEmit(SMLoc<br>
   if (!isUIntN(8, IntValue) && !isIntN(8, IntValue))<br>
     return Error(ExprLoc, "literal value out of range for directive");<br>
<br>
-  Info.AsmRewrites->push_back(AsmRewrite(AOK_Emit, IDLoc, len));<br>
+  Info.AsmRewrites->push_back(AsmRewrite(AOK_Emit, IDLoc, Len));<br>
+  return false;<br>
+}<br>
+<br>
+bool AsmParser::ParseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {<br>
+  const MCExpr *Value;<br>
+  SMLoc ExprLoc = getLexer().getLoc();<br>
+  if (ParseExpression(Value))<br>
+    return true;<br>
+  const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(Value);<br>
+  if (!MCE)<br>
+    return Error(ExprLoc, "unexpected expression in align");<br>
+  uint64_t IntValue = MCE->getValue();<br>
+  if (!isPowerOf2_64(IntValue))<br>
+    return Error(ExprLoc, "literal value not a power of two greater then zero");<br>
+<br>
+  Info.AsmRewrites->push_back(AsmRewrite(AOK_Align, IDLoc, 5, Log2_64(IntValue)));<br>
   return false;<br>
 }<br>
<br>
@@ -4133,6 +4157,7 @@ bool AsmParser::ParseMSInlineAsm(void *A<br>
          I = AsmStrRewrites.begin(), E = AsmStrRewrites.end(); I != E; ++I) {<br>
     const char *Loc = (*I).Loc.getPointer();<br>
<br>
+    unsigned AdditionalSkip = 0;<br>
     AsmRewriteKind Kind = (*I).Kind;<br>
<br>
     // Emit everything up to the immediate/expression.  If the previous rewrite<br>
@@ -4180,6 +4205,15 @@ bool AsmParser::ParseMSInlineAsm(void *A<br>
     case AOK_Emit:<br>
       OS << ".byte";<br>
       break;<br>
+    case AOK_Align: {<br>
+      unsigned Val = (*I).Val;<br>
+      OS << ".align " << Val;<br>
+<br>
+      // Skip the original immediate.<br>
+      assert (Val < 10 && "Expected alignment less then 2^10.");<br>
+      AdditionalSkip = (Val < 4) ? 2 : Val < 7 ? 3 : 4;<br>
+      break;<br>
+    }<br>
     case AOK_DotOperator:<br>
       OS << (*I).Val;<br>
       break;<br>
@@ -4187,7 +4221,7 @@ bool AsmParser::ParseMSInlineAsm(void *A<br>
<br>
     // Skip the original expression.<br>
     if (Kind != AOK_SizeDirective)<br>
-      Start = Loc + (*I).Len;<br>
+      Start = Loc + (*I).Len + AdditionalSkip;<br>
   }<br>
<br>
   // Emit the remainder of the asm string.<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>