[llvm-commits] [llvm] r118206 - /llvm/trunk/utils/TableGen/CodeEmitterGen.cpp

Jim Grosbach grosbach at apple.com
Wed Nov 3 16:38:14 PDT 2010


Author: grosbach
Date: Wed Nov  3 18:38:14 2010
New Revision: 118206

URL: http://llvm.org/viewvc/llvm-project?rev=118206&view=rev
Log:
Support generating an MC'ized CodeEmitter directly. Maintain a reference to the
Fixups list for the instruction so the operand encoders can add to it as
needed.

Modified:
    llvm/trunk/utils/TableGen/CodeEmitterGen.cpp

Modified: llvm/trunk/utils/TableGen/CodeEmitterGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeEmitterGen.cpp?rev=118206&r1=118205&r2=118206&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeEmitterGen.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeEmitterGen.cpp Wed Nov  3 18:38:14 2010
@@ -21,8 +21,11 @@
 #include "llvm/Support/Debug.h"
 using namespace llvm;
 
+// FIXME: Somewhat hackish to use a command line option for this. There should
+// be a CodeEmitter class in the Target.td that controls this sort of thing
+// instead.
 static cl::opt<bool>
-MCEmitter("mc-code-emitter",
+MCEmitter("mc-emitter",
           cl::desc("Generate CodeEmitter for use with the MC library."),
           cl::init(false));
 
@@ -84,8 +87,12 @@
     Target.getInstructionsByEnumValue();
 
   // Emit function declaration
-  o << "unsigned " << Target.getName() << "CodeEmitter::"
-    << "getBinaryCodeForInstr(const MachineInstr &MI) const {\n";
+  o << "unsigned " << Target.getName();
+  if (MCEmitter)
+    o << "MCCodeEmitter::getBinaryCodeForInstr(const MCInst &MI,\n"
+      << "    SmallVectorImpl<MCFixup> &Fixups) const {\n";
+  else
+    o << "CodeEmitter::getBinaryCodeForInstr(const MachineInstr &MI) const {\n";
 
   // Emit instruction base values
   o << "  static const unsigned InstBits[] = {\n";
@@ -188,12 +195,18 @@
                 if (SO.second == 0) {
                   Case += "      // op: " + VarName + "\n"
                        + "      op = " + EncoderMethodName + "(MI, "
-                       + utostr(OpIdx) + ");\n";
+                       + utostr(OpIdx);
+                  if (MCEmitter)
+                    Case += ", Fixups";
+                  Case += ");\n";
                 }
               } else {
                 Case += "      // op: " + VarName + "\n"
                      +  "      op = getMachineOpValue(MI, MI.getOperand("
-                     +  utostr(OpIdx) + "));\n";
+                     +  utostr(OpIdx) + ")";
+                if (MCEmitter)
+                  Case += ", Fixups";
+                Case += ");\n";
               }
               gotOp = true;
             }





More information about the llvm-commits mailing list