Support generating an MC'ized CodeEmitter directly. Maintain a reference to the
authorJim Grosbach <grosbach@apple.com>
Wed, 3 Nov 2010 23:38:14 +0000 (23:38 +0000)
committerJim Grosbach <grosbach@apple.com>
Wed, 3 Nov 2010 23:38:14 +0000 (23:38 +0000)
Fixups list for the instruction so the operand encoders can add to it as
needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118206 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/CodeEmitterGen.cpp

index fbe9947b096ebe965ed2da7c5f5eb4dc3a8a3a83..e86c18fb66382c8ef50c20a37299f35af5fe2684 100644 (file)
 #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 @@ void CodeEmitterGen::run(raw_ostream &o) {
     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 @@ void CodeEmitterGen::run(raw_ostream &o) {
                 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;
             }