mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-27 13:30:05 +00:00
Use CodeGenRegister class to make reading in of register information more
systematic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15805 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8dab6ca9c6
commit
2669311320
@ -103,11 +103,24 @@ Record *CodeGenTarget::getAsmWriter() const {
|
|||||||
return TargetRec->getValueAsDef("AssemblyWriter");
|
return TargetRec->getValueAsDef("AssemblyWriter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodeGenTarget::ReadRegisters() const {
|
||||||
|
std::vector<Record*> Regs = Records.getAllDerivedDefinitions("Register");
|
||||||
|
if (Regs.empty())
|
||||||
|
throw std::string("No 'Register' subclasses defined!");
|
||||||
|
|
||||||
|
Registers.reserve(Regs.size());
|
||||||
|
Registers.assign(Regs.begin(), Regs.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &CodeGenRegister::getName() const {
|
||||||
|
return TheDef->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CodeGenTarget::ReadInstructions() const {
|
void CodeGenTarget::ReadInstructions() const {
|
||||||
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
|
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
|
||||||
|
|
||||||
if (Insts.size() == 0)
|
if (Insts.empty())
|
||||||
throw std::string("No 'Instruction' subclasses defined!");
|
throw std::string("No 'Instruction' subclasses defined!");
|
||||||
|
|
||||||
std::string InstFormatName =
|
std::string InstFormatName =
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#ifndef CODEGEN_TARGET_H
|
#ifndef CODEGEN_TARGET_H
|
||||||
#define CODEGEN_TARGET_H
|
#define CODEGEN_TARGET_H
|
||||||
|
|
||||||
|
#include "CodeGenRegisters.h"
|
||||||
#include "CodeGenInstruction.h"
|
#include "CodeGenInstruction.h"
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -25,6 +26,7 @@ namespace llvm {
|
|||||||
|
|
||||||
class Record;
|
class Record;
|
||||||
class RecordKeeper;
|
class RecordKeeper;
|
||||||
|
class CodeGenRegister;
|
||||||
|
|
||||||
/// getValueType - Return the MVT::ValueType that the specified TableGen record
|
/// getValueType - Return the MVT::ValueType that the specified TableGen record
|
||||||
/// corresponds to.
|
/// corresponds to.
|
||||||
@ -43,7 +45,9 @@ class CodeGenTarget {
|
|||||||
MVT::ValueType PointerType;
|
MVT::ValueType PointerType;
|
||||||
|
|
||||||
mutable std::map<std::string, CodeGenInstruction> Instructions;
|
mutable std::map<std::string, CodeGenInstruction> Instructions;
|
||||||
|
mutable std::vector<CodeGenRegister> Registers;
|
||||||
void ReadInstructions() const;
|
void ReadInstructions() const;
|
||||||
|
void ReadRegisters() const;
|
||||||
public:
|
public:
|
||||||
CodeGenTarget();
|
CodeGenTarget();
|
||||||
|
|
||||||
@ -64,8 +68,10 @@ public:
|
|||||||
///
|
///
|
||||||
Record *getAsmWriter() const;
|
Record *getAsmWriter() const;
|
||||||
|
|
||||||
/// getPHIInstruction - Return the designated PHI instruction.
|
const std::vector<CodeGenRegister> &getRegisters() {
|
||||||
const CodeGenInstruction &getPHIInstruction() const;
|
if (Registers.empty()) ReadRegisters();
|
||||||
|
return Registers;
|
||||||
|
}
|
||||||
|
|
||||||
/// getInstructions - Return all of the instructions defined for this target.
|
/// getInstructions - Return all of the instructions defined for this target.
|
||||||
///
|
///
|
||||||
@ -78,6 +84,10 @@ public:
|
|||||||
CodeGenInstruction>::const_iterator inst_iterator;
|
CodeGenInstruction>::const_iterator inst_iterator;
|
||||||
inst_iterator inst_begin() const { return getInstructions().begin(); }
|
inst_iterator inst_begin() const { return getInstructions().begin(); }
|
||||||
inst_iterator inst_end() const { return Instructions.end(); }
|
inst_iterator inst_end() const { return Instructions.end(); }
|
||||||
|
|
||||||
|
/// getPHIInstruction - Return the designated PHI instruction.
|
||||||
|
///
|
||||||
|
const CodeGenInstruction &getPHIInstruction() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "RegisterInfoEmitter.h"
|
#include "RegisterInfoEmitter.h"
|
||||||
#include "CodeGenTarget.h"
|
#include "CodeGenTarget.h"
|
||||||
|
#include "CodeGenRegisters.h"
|
||||||
#include "Record.h"
|
#include "Record.h"
|
||||||
#include "Support/StringExtras.h"
|
#include "Support/StringExtras.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -22,12 +23,10 @@ using namespace llvm;
|
|||||||
|
|
||||||
// runEnums - Print out enum values for all of the registers.
|
// runEnums - Print out enum values for all of the registers.
|
||||||
void RegisterInfoEmitter::runEnums(std::ostream &OS) {
|
void RegisterInfoEmitter::runEnums(std::ostream &OS) {
|
||||||
std::vector<Record*> Registers = Records.getAllDerivedDefinitions("Register");
|
CodeGenTarget Target;
|
||||||
|
const std::vector<CodeGenRegister> &Registers = Target.getRegisters();
|
||||||
|
|
||||||
if (Registers.size() == 0)
|
std::string Namespace = Registers[0].TheDef->getValueAsString("Namespace");
|
||||||
throw std::string("No 'Register' subclasses defined!");
|
|
||||||
|
|
||||||
std::string Namespace = Registers[0]->getValueAsString("Namespace");
|
|
||||||
|
|
||||||
EmitSourceFileHeader("Target Register Enum Values", OS);
|
EmitSourceFileHeader("Target Register Enum Values", OS);
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ void RegisterInfoEmitter::runEnums(std::ostream &OS) {
|
|||||||
OS << " enum {\n NoRegister,\n";
|
OS << " enum {\n NoRegister,\n";
|
||||||
|
|
||||||
for (unsigned i = 0, e = Registers.size(); i != e; ++i)
|
for (unsigned i = 0, e = Registers.size(); i != e; ++i)
|
||||||
OS << " " << Registers[i]->getName() << ", \t// " << i+1 << "\n";
|
OS << " " << Registers[i].getName() << ", \t// " << i+1 << "\n";
|
||||||
|
|
||||||
OS << " };\n";
|
OS << " };\n";
|
||||||
if (!Namespace.empty())
|
if (!Namespace.empty())
|
||||||
@ -46,7 +45,8 @@ void RegisterInfoEmitter::runEnums(std::ostream &OS) {
|
|||||||
|
|
||||||
void RegisterInfoEmitter::runHeader(std::ostream &OS) {
|
void RegisterInfoEmitter::runHeader(std::ostream &OS) {
|
||||||
EmitSourceFileHeader("Register Information Header Fragment", OS);
|
EmitSourceFileHeader("Register Information Header Fragment", OS);
|
||||||
const std::string &TargetName = CodeGenTarget().getName();
|
CodeGenTarget Target;
|
||||||
|
const std::string &TargetName = Target.getName();
|
||||||
std::string ClassName = TargetName + "GenRegisterInfo";
|
std::string ClassName = TargetName + "GenRegisterInfo";
|
||||||
|
|
||||||
OS << "#include \"llvm/Target/MRegisterInfo.h\"\n\n";
|
OS << "#include \"llvm/Target/MRegisterInfo.h\"\n\n";
|
||||||
@ -74,7 +74,6 @@ void RegisterInfoEmitter::runHeader(std::ostream &OS) {
|
|||||||
//
|
//
|
||||||
void RegisterInfoEmitter::run(std::ostream &OS) {
|
void RegisterInfoEmitter::run(std::ostream &OS) {
|
||||||
CodeGenTarget Target;
|
CodeGenTarget Target;
|
||||||
|
|
||||||
EmitSourceFileHeader("Register Information Source Fragment", OS);
|
EmitSourceFileHeader("Register Information Source Fragment", OS);
|
||||||
|
|
||||||
// Start out by emitting each of the register classes... to do this, we build
|
// Start out by emitting each of the register classes... to do this, we build
|
||||||
@ -84,8 +83,6 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
|
|||||||
std::vector<Record*> RegisterClasses =
|
std::vector<Record*> RegisterClasses =
|
||||||
Records.getAllDerivedDefinitions("RegisterClass");
|
Records.getAllDerivedDefinitions("RegisterClass");
|
||||||
|
|
||||||
std::vector<Record*> Registers = Records.getAllDerivedDefinitions("Register");
|
|
||||||
|
|
||||||
std::set<Record*> RegistersFound;
|
std::set<Record*> RegistersFound;
|
||||||
std::vector<std::string> RegClassNames;
|
std::vector<std::string> RegClassNames;
|
||||||
|
|
||||||
@ -189,18 +186,21 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
|
|||||||
|
|
||||||
OS << "\n const MRegisterDesc RegisterDescriptors[] = { // Descriptors\n";
|
OS << "\n const MRegisterDesc RegisterDescriptors[] = { // Descriptors\n";
|
||||||
OS << " { \"NOREG\",\t0,\t\t0,\t0 },\n";
|
OS << " { \"NOREG\",\t0,\t\t0,\t0 },\n";
|
||||||
|
|
||||||
|
|
||||||
// Now that register alias sets have been emitted, emit the register
|
// Now that register alias sets have been emitted, emit the register
|
||||||
// descriptors now.
|
// descriptors now.
|
||||||
|
const std::vector<CodeGenRegister> &Registers = Target.getRegisters();
|
||||||
for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
|
||||||
Record *Reg = Registers[i];
|
const CodeGenRegister &Reg = Registers[i];
|
||||||
OS << " { \"";
|
OS << " { \"";
|
||||||
if (!Reg->getValueAsString("Name").empty())
|
if (!Reg.TheDef->getValueAsString("Name").empty())
|
||||||
OS << Reg->getValueAsString("Name");
|
OS << Reg.TheDef->getValueAsString("Name");
|
||||||
else
|
else
|
||||||
OS << Reg->getName();
|
OS << Reg.getName();
|
||||||
OS << "\",\t";
|
OS << "\",\t";
|
||||||
if (RegisterAliases.count(Reg))
|
if (RegisterAliases.count(Reg.TheDef))
|
||||||
OS << Reg->getName() << "_AliasSet,\t";
|
OS << Reg.getName() << "_AliasSet,\t";
|
||||||
else
|
else
|
||||||
OS << "Empty_AliasSet,\t";
|
OS << "Empty_AliasSet,\t";
|
||||||
OS << "0, 0 },\n";
|
OS << "0, 0 },\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user