[llvm-commits] [llvm] r78716 - in /llvm/trunk: include/llvm/Target/Target.td lib/Target/X86/X86.td utils/TableGen/AsmMatcherEmitter.cpp

Daniel Dunbar daniel at zuster.org
Tue Aug 11 13:59:48 PDT 2009


Author: ddunbar
Date: Tue Aug 11 15:59:47 2009
New Revision: 78716

URL: http://llvm.org/viewvc/llvm-project?rev=78716&view=rev
Log:
llvm-mc/AsmParser: Allow target to specific a comment delimiter, which will be
used to strip hard coded comments out of .td assembly strings.

Modified:
    llvm/trunk/include/llvm/Target/Target.td
    llvm/trunk/lib/Target/X86/X86.td
    llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp

Modified: llvm/trunk/include/llvm/Target/Target.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Target.td?rev=78716&r1=78715&r2=78716&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/Target.td (original)
+++ llvm/trunk/include/llvm/Target/Target.td Tue Aug 11 15:59:47 2009
@@ -484,6 +484,17 @@
   // used to support targets that need to parser multiple formats for the 
   // assembly language.
   int Variant = 0;
+
+  // CommentDelimiter - If given, the delimiter string used to recognize
+  // comments which are hard coded in the .td assembler strings for individual
+  // instructions.
+  string CommentDelimiter = "";
+
+  // RegisterPrefix - If given, the token prefix which indicates a register
+  // token. This is used by the matcher to automatically recognize hard coded
+  // register tokens as constrained registers, instead of tokens, for the
+  // purposes of matching.
+  string RegisterPrefix = "";
 }
 def DefaultAsmParser : AsmParser;
 

Modified: llvm/trunk/lib/Target/X86/X86.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86.td?rev=78716&r1=78715&r2=78716&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86.td (original)
+++ llvm/trunk/lib/Target/X86/X86.td Tue Aug 11 15:59:47 2009
@@ -182,6 +182,12 @@
 def ATTAsmParser : AsmParser {
   string AsmParserClassName  = "ATTAsmParser";
   int Variant = 0;
+
+  // Discard comments in assembly strings.
+  string CommentDelimiter = "#";
+
+  // Recognize hard coded registers.
+  string RegisterPrefix = "%";
 }
 
 // The X86 target supports two different syntaxes for emitting machine code.

Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=78716&r1=78715&r2=78716&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Tue Aug 11 15:59:47 2009
@@ -501,6 +501,15 @@
 
 class AsmMatcherInfo {
 public:
+  /// The tablegen AsmParser record.
+  Record *AsmParser;
+
+  /// The AsmParser "CommentDelimiter" value.
+  std::string CommentDelimiter;
+
+  /// The AsmParser "RegisterPrefix" value.
+  std::string RegisterPrefix;
+
   /// The classes which are needed for matching.
   std::vector<ClassInfo*> Classes;
   
@@ -537,6 +546,8 @@
   void BuildOperandClasses(CodeGenTarget &Target);
 
 public:
+  AsmMatcherInfo(Record *_AsmParser);
+
   /// BuildInfo - Construct the various tables used during matching.
   void BuildInfo(CodeGenTarget &Target);
 };
@@ -778,6 +789,13 @@
   }
 }
 
+AsmMatcherInfo::AsmMatcherInfo(Record *_AsmParser) 
+  : AsmParser(_AsmParser),
+    CommentDelimiter(AsmParser->getValueAsString("CommentDelimiter")),
+    RegisterPrefix(AsmParser->getValueAsString("RegisterPrefix"))
+{
+}
+
 void AsmMatcherInfo::BuildInfo(CodeGenTarget &Target) {
   // Build info for the register classes.
   BuildRegisterClasses(Target);
@@ -801,6 +819,13 @@
     II->Instr = &it->second;
     II->AsmString = FlattenVariants(CGI.AsmString, 0);
 
+    // Remove comments from the asm string.
+    if (!CommentDelimiter.empty()) {
+      size_t Idx = StringRef(II->AsmString).find(CommentDelimiter);
+      if (Idx != StringRef::npos)
+        II->AsmString = II->AsmString.substr(0, Idx);
+    }
+
     TokenizeAsmString(II->AsmString, II->Tokens);
 
     // Ignore instructions which shouldn't be matched.
@@ -1309,7 +1334,7 @@
   EmitMatchRegisterName(Target, AsmParser, OS);
 
   // Compute the information on the instructions to match.
-  AsmMatcherInfo Info;
+  AsmMatcherInfo Info(AsmParser);
   Info.BuildInfo(Target);
 
   // Sort the instruction table using the partial order on classes.





More information about the llvm-commits mailing list