[llvm-commits] [llvm] r74573 - in /llvm/trunk/tools/llvm-mc: AsmParser.cpp AsmParser.h MC-X86Specific.cpp

Daniel Dunbar daniel at zuster.org
Tue Jun 30 16:38:38 PDT 2009


Author: ddunbar
Date: Tue Jun 30 18:38:38 2009
New Revision: 74573

URL: http://llvm.org/viewvc/llvm-project?rev=74573&view=rev
Log:
llvm-mc: Introduce method to match a parsed x86 instruction into an MCInst.

Modified:
    llvm/trunk/tools/llvm-mc/AsmParser.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.h
    llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp

Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=74573&r1=74572&r2=74573&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jun 30 18:38:38 2009
@@ -506,7 +506,7 @@
   }
 
   MCInst Inst;
-  if (ParseX86InstOperands(Inst))
+  if (ParseX86InstOperands(IDVal, Inst))
     return true;
   
   if (Lexer.isNot(asmtok::EndOfStatement))

Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=74573&r1=74572&r2=74573&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jun 30 18:38:38 2009
@@ -25,12 +25,14 @@
 class MCValue;
 
 class AsmParser {
+public:
+  struct X86Operand;
+
+private:  
   AsmLexer Lexer;
   MCContext &Ctx;
   MCStreamer &Out;
   
-  struct X86Operand;
-  
 public:
   AsmParser(SourceMgr &SM, MCContext &ctx, MCStreamer &OutStr)
     : Lexer(SM), Ctx(ctx), Out(OutStr) {}
@@ -76,7 +78,7 @@
   bool ParseParenExpr(AsmExpr *&Res);
   
   // X86 specific.
-  bool ParseX86InstOperands(MCInst &Inst);
+  bool ParseX86InstOperands(const char *InstName, MCInst &Inst);
   bool ParseX86Operand(X86Operand &Op);
   bool ParseX86MemOperand(X86Operand &Op);
   

Modified: llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp?rev=74573&r1=74572&r2=74573&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp (original)
+++ llvm/trunk/tools/llvm-mc/MC-X86Specific.cpp Tue Jun 30 18:38:38 2009
@@ -65,10 +65,6 @@
     Res.Mem.ScaleReg = ScaleReg;
     return Res;
   }
-  
-  void AddToMCInst(MCInst &I) {
-    // FIXME: Add in x86 order here.
-  }
 };
 
 bool AsmParser::ParseX86Operand(X86Operand &Op) {
@@ -195,27 +191,34 @@
   return false;
 }
 
+/// MatchX86Inst - Convert a parsed instruction name and operand list into a
+/// concrete instruction.
+static bool MatchX86Inst(const char *Name, 
+                         llvm::SmallVector<AsmParser::X86Operand, 3> &Operands,
+                         MCInst &Inst) {
+  return false;
+}
+
 /// ParseX86InstOperands - Parse the operands of an X86 instruction and return
 /// them as the operands of an MCInst.
-bool AsmParser::ParseX86InstOperands(MCInst &Inst) {
-  // If no operands are present, just return.
-  if (Lexer.is(asmtok::EndOfStatement))
-    return false;
+bool AsmParser::ParseX86InstOperands(const char *InstName, MCInst &Inst) {
+  llvm::SmallVector<X86Operand, 3> Operands;
 
-  // Read the first operand.
-  X86Operand Op;
-  if (ParseX86Operand(Op))
-    return true;
-  Op.AddToMCInst(Inst);
-  
-  while (Lexer.is(asmtok::Comma)) {
-    Lexer.Lex();  // Eat the comma.
-    
-    // Parse and remember the operand.
-    Op = X86Operand();
-    if (ParseX86Operand(Op))
+  if (Lexer.isNot(asmtok::EndOfStatement)) {
+    // Read the first operand.
+    Operands.push_back(X86Operand());
+    if (ParseX86Operand(Operands.back()))
       return true;
-    Op.AddToMCInst(Inst);
+    
+    while (Lexer.is(asmtok::Comma)) {
+      Lexer.Lex();  // Eat the comma.
+      
+      // Parse and remember the operand.
+      Operands.push_back(X86Operand());
+      if (ParseX86Operand(Operands.back()))
+        return true;
+    }
   }
-  return false;
+
+  return MatchX86Inst(InstName, Operands, Inst);
 }





More information about the llvm-commits mailing list