Sphinxify the Code Generator document.
[oota-llvm.git] / utils / TableGen / CallingConvEmitter.cpp
index 37758bc1cf5006dbc3b54b98c432fd4fd274d4eb..e9c4bd30f9143590efcdcbc26cf93fd17f3b8826 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#include "CallingConvEmitter.h"
-#include "Record.h"
 #include "CodeGenTarget.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/TableGenBackend.h"
+#include <cassert>
 using namespace llvm;
 
+namespace {
+class CallingConvEmitter {
+  RecordKeeper &Records;
+public:
+  explicit CallingConvEmitter(RecordKeeper &R) : Records(R) {}
+
+  void run(raw_ostream &o);
+
+private:
+  void EmitCallingConv(Record *CC, raw_ostream &O);
+  void EmitAction(Record *Action, unsigned Indent, raw_ostream &O);
+  unsigned Counter;
+};
+} // End anonymous namespace
+
 void CallingConvEmitter::run(raw_ostream &O) {
-  EmitSourceFileHeader("Calling Convention Implementation Fragment", O);
 
   std::vector<Record*> CCs = Records.getAllDerivedDefinitions("CallingConv");
   
@@ -40,7 +55,7 @@ void CallingConvEmitter::run(raw_ostream &O) {
 
 
 void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) {
-  const ListInit *CCActions = CC->getValueAsListInit("Actions");
+  ListInit *CCActions = CC->getValueAsListInit("Actions");
   Counter = 0;
 
   O << "\n\nstatic bool " << CC->getName()
@@ -67,7 +82,7 @@ void CallingConvEmitter::EmitAction(Record *Action,
     O << IndentStr << "if (";
     
     if (Action->isSubClassOf("CCIfType")) {
-      const ListInit *VTs = Action->getValueAsListInit("VTs");
+      ListInit *VTs = Action->getValueAsListInit("VTs");
       for (unsigned i = 0, e = VTs->getSize(); i != e; ++i) {
         Record *VT = VTs->getElementAsRecord(i);
         if (i != 0) O << " ||\n    " << IndentStr;
@@ -91,12 +106,12 @@ void CallingConvEmitter::EmitAction(Record *Action,
         << "(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))\n"
         << IndentStr << "  return false;\n";
     } else if (Action->isSubClassOf("CCAssignToReg")) {
-      const ListInit *RegList = Action->getValueAsListInit("RegList");
+      ListInit *RegList = Action->getValueAsListInit("RegList");
       if (RegList->getSize() == 1) {
         O << IndentStr << "if (unsigned Reg = State.AllocateReg(";
         O << getQualifiedName(RegList->getElementAsRecord(0)) << ")) {\n";
       } else {
-        O << IndentStr << "static const unsigned RegList" << ++Counter
+        O << IndentStr << "static const uint16_t RegList" << ++Counter
           << "[] = {\n";
         O << IndentStr << "  ";
         for (unsigned i = 0, e = RegList->getSize(); i != e; ++i) {
@@ -112,8 +127,8 @@ void CallingConvEmitter::EmitAction(Record *Action,
       O << IndentStr << "  return false;\n";
       O << IndentStr << "}\n";
     } else if (Action->isSubClassOf("CCAssignToRegWithShadow")) {
-      const ListInit *RegList = Action->getValueAsListInit("RegList");
-      const ListInit *ShadowRegList = Action->getValueAsListInit("ShadowRegList");
+      ListInit *RegList = Action->getValueAsListInit("RegList");
+      ListInit *ShadowRegList = Action->getValueAsListInit("ShadowRegList");
       if (ShadowRegList->getSize() >0 &&
           ShadowRegList->getSize() != RegList->getSize())
         throw "Invalid length of list of shadowed registers";
@@ -127,7 +142,7 @@ void CallingConvEmitter::EmitAction(Record *Action,
         unsigned RegListNumber = ++Counter;
         unsigned ShadowRegListNumber = ++Counter;
 
-        O << IndentStr << "static const unsigned RegList" << RegListNumber
+        O << IndentStr << "static const uint16_t RegList" << RegListNumber
           << "[] = {\n";
         O << IndentStr << "  ";
         for (unsigned i = 0, e = RegList->getSize(); i != e; ++i) {
@@ -136,7 +151,7 @@ void CallingConvEmitter::EmitAction(Record *Action,
         }
         O << "\n" << IndentStr << "};\n";
 
-        O << IndentStr << "static const unsigned RegList"
+        O << IndentStr << "static const uint16_t RegList"
           << ShadowRegListNumber << "[] = {\n";
         O << IndentStr << "  ";
         for (unsigned i = 0, e = ShadowRegList->getSize(); i != e; ++i) {
@@ -210,3 +225,12 @@ void CallingConvEmitter::EmitAction(Record *Action,
     }
   }
 }
+
+namespace llvm {
+
+void EmitCallingConv(RecordKeeper &RK, raw_ostream &OS) {
+  emitSourceFileHeader("Calling Convention Implementation Fragment", OS);
+  CallingConvEmitter(RK).run(OS);
+}
+
+} // End llvm namespace