-#include "Support/Statistic.h"
-#include "Record.h"
-#include "CodeEmitterGen.h"
-
-void CodeEmitterGen::createEmitter(std::ostream &o) {
- std::vector<Record*> Insts;
+//===- CodeEmitterGen.cpp - Code Emitter Generator ------------------------===//
+//
+// FIXME: Document.
+//
+//===----------------------------------------------------------------------===//
- const std::map<std::string, Record*> &Defs = Records.getDefs();
- Record *Inst = Records.getClass("Instruction");
- assert(Inst && "Couldn't find Instruction class!");
+#include "CodeEmitterGen.h"
+#include "Record.h"
+#include "Support/Statistic.h"
- for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
- E = Defs.end(); I != E; ++I)
- if (I->second->isSubClassOf(Inst))
- Insts.push_back(I->second);
+void CodeEmitterGen::run(std::ostream &o) {
+ std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
std::string Namespace = "V9::";
std::string ClassName = "SparcV9CodeEmitter::";
<< " DEBUG(std::cerr << MI);\n"
<< " switch (MI.getOpcode()) {\n";
for (std::vector<Record*>::iterator I = Insts.begin(), E = Insts.end();
- I != E; ++I)
- {
+ I != E; ++I) {
Record *R = *I;
o << " case " << Namespace << R->getName() << ": {\n"
<< " DEBUG(std::cerr << \"Emitting " << R->getName() << "\\n\");\n";
- const RecordVal *InstVal = R->getValue("Inst");
- Init *InitVal = InstVal->getValue();
-
- assert(dynamic_cast<BitsInit*>(InitVal) &&
- "Can only handle undefined bits<> types!");
- BitsInit *BI = (BitsInit*)InitVal;
+ BitsInit *BI = R->getValueAsBitsInit("Inst");
unsigned Value = 0;
const std::vector<RecordVal> &Vals = R->getValues();
}
DEBUG(o << "\n");
- DEBUG(o << " // " << *InstVal << "\n");
+ DEBUG(o << " // " << *R->getValue("Inst") << "\n");
o << " Value = " << Value << "U;\n\n";
// Loop over all of the fields in the instruction adding in any