Switch code over to being a TableGenBackend

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7627 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2003-08-06 04:32:07 +00:00
parent 18a6a94e1f
commit bc01723605
4 changed files with 18 additions and 58 deletions

View File

@ -8,27 +8,6 @@
#include "InstrInfoEmitter.h"
#include "Record.h"
static void EmitSourceHeader(const std::string &Desc, std::ostream &o) {
o << "//===- TableGen'erated file -------------------------------------*-"
" C++ -*-===//\n//\n// " << Desc << "\n//\n// Automatically generate"
"d file, do not edit!\n//\n//===------------------------------------"
"----------------------------------===//\n\n";
}
static std::string getQualifiedName(Record *R) {
std::string Namespace = R->getValueAsString("Namespace");
if (Namespace.empty()) return R->getName();
return Namespace + "::" + R->getName();
}
static Record *getTarget(RecordKeeper &RC) {
std::vector<Record*> Targets = RC.getAllDerivedDefinitions("Target");
if (Targets.size() != 1)
throw std::string("ERROR: Multiple subclasses of Target defined!");
return Targets[0];
}
// runEnums - Print out enum values for all of the instructions.
void InstrInfoEmitter::runEnums(std::ostream &OS) {
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
@ -38,7 +17,7 @@ void InstrInfoEmitter::runEnums(std::ostream &OS) {
std::string Namespace = Insts[0]->getValueAsString("Namespace");
EmitSourceHeader("Target Instruction Enum Values", OS);
EmitSourceFileHeader("Target Instruction Enum Values", OS);
if (!Namespace.empty())
OS << "namespace " << Namespace << " {\n";
@ -61,8 +40,8 @@ void InstrInfoEmitter::runEnums(std::ostream &OS) {
OS << "}\n";
}
static void printDefList(ListInit *LI, const std::string &Name,
std::ostream &OS) {
void InstrInfoEmitter::printDefList(ListInit *LI, const std::string &Name,
std::ostream &OS) const {
OS << "static const unsigned " << Name << "[] = { ";
for (unsigned j = 0, e = LI->getSize(); j != e; ++j)
if (DefInit *DI = dynamic_cast<DefInit*>(LI->getElement(j)))
@ -75,7 +54,7 @@ static void printDefList(ListInit *LI, const std::string &Name,
// run - Emit the main instruction description records for the target...
void InstrInfoEmitter::run(std::ostream &OS) {
EmitSourceHeader("Target Instruction Descriptors", OS);
EmitSourceFileHeader("Target Instruction Descriptors", OS);
Record *Target = getTarget(Records);
const std::string &TargetName = Target->getName();
Record *InstrInfo = Target->getValueAsDef("InstructionSet");

View File

@ -8,13 +8,12 @@
#ifndef INSTRINFO_EMITTER_H
#define INSTRINFO_EMITTER_H
#include <iosfwd>
class RecordKeeper;
class Record;
#include "TableGenBackend.h"
class StringInit;
class IntInit;
class ListInit;
class InstrInfoEmitter {
class InstrInfoEmitter : public TableGenBackend {
RecordKeeper &Records;
public:
InstrInfoEmitter(RecordKeeper &R) : Records(R) {}
@ -25,6 +24,8 @@ public:
// runEnums - Print out enum values for all of the instructions.
void runEnums(std::ostream &OS);
private:
void printDefList(ListInit *LI, const std::string &Name,
std::ostream &OS) const;
void emitRecord(Record *R, unsigned Num, Record *InstrInfo, std::ostream &OS);
void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
std::ostream &OS);

View File

@ -8,27 +8,6 @@
#include "InstrInfoEmitter.h"
#include "Record.h"
static void EmitSourceHeader(const std::string &Desc, std::ostream &o) {
o << "//===- TableGen'erated file -------------------------------------*-"
" C++ -*-===//\n//\n// " << Desc << "\n//\n// Automatically generate"
"d file, do not edit!\n//\n//===------------------------------------"
"----------------------------------===//\n\n";
}
static std::string getQualifiedName(Record *R) {
std::string Namespace = R->getValueAsString("Namespace");
if (Namespace.empty()) return R->getName();
return Namespace + "::" + R->getName();
}
static Record *getTarget(RecordKeeper &RC) {
std::vector<Record*> Targets = RC.getAllDerivedDefinitions("Target");
if (Targets.size() != 1)
throw std::string("ERROR: Multiple subclasses of Target defined!");
return Targets[0];
}
// runEnums - Print out enum values for all of the instructions.
void InstrInfoEmitter::runEnums(std::ostream &OS) {
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
@ -38,7 +17,7 @@ void InstrInfoEmitter::runEnums(std::ostream &OS) {
std::string Namespace = Insts[0]->getValueAsString("Namespace");
EmitSourceHeader("Target Instruction Enum Values", OS);
EmitSourceFileHeader("Target Instruction Enum Values", OS);
if (!Namespace.empty())
OS << "namespace " << Namespace << " {\n";
@ -61,8 +40,8 @@ void InstrInfoEmitter::runEnums(std::ostream &OS) {
OS << "}\n";
}
static void printDefList(ListInit *LI, const std::string &Name,
std::ostream &OS) {
void InstrInfoEmitter::printDefList(ListInit *LI, const std::string &Name,
std::ostream &OS) const {
OS << "static const unsigned " << Name << "[] = { ";
for (unsigned j = 0, e = LI->getSize(); j != e; ++j)
if (DefInit *DI = dynamic_cast<DefInit*>(LI->getElement(j)))
@ -75,7 +54,7 @@ static void printDefList(ListInit *LI, const std::string &Name,
// run - Emit the main instruction description records for the target...
void InstrInfoEmitter::run(std::ostream &OS) {
EmitSourceHeader("Target Instruction Descriptors", OS);
EmitSourceFileHeader("Target Instruction Descriptors", OS);
Record *Target = getTarget(Records);
const std::string &TargetName = Target->getName();
Record *InstrInfo = Target->getValueAsDef("InstructionSet");

View File

@ -8,13 +8,12 @@
#ifndef INSTRINFO_EMITTER_H
#define INSTRINFO_EMITTER_H
#include <iosfwd>
class RecordKeeper;
class Record;
#include "TableGenBackend.h"
class StringInit;
class IntInit;
class ListInit;
class InstrInfoEmitter {
class InstrInfoEmitter : public TableGenBackend {
RecordKeeper &Records;
public:
InstrInfoEmitter(RecordKeeper &R) : Records(R) {}
@ -25,6 +24,8 @@ public:
// runEnums - Print out enum values for all of the instructions.
void runEnums(std::ostream &OS);
private:
void printDefList(ListInit *LI, const std::string &Name,
std::ostream &OS) const;
void emitRecord(Record *R, unsigned Num, Record *InstrInfo, std::ostream &OS);
void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
std::ostream &OS);