2008-01-06 01:49:05 +01:00
|
|
|
//===- InstrEnumEmitter.cpp - Generate Instruction Set Enums --------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend is responsible for emitting enums for each machine
|
|
|
|
// instruction.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "InstrEnumEmitter.h"
|
|
|
|
#include "CodeGenTarget.h"
|
|
|
|
#include "Record.h"
|
2008-10-08 09:23:46 +02:00
|
|
|
#include <cstdio>
|
2008-01-06 01:49:05 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// runEnums - Print out enum values for all of the instructions.
|
2009-07-03 02:10:29 +02:00
|
|
|
void InstrEnumEmitter::run(raw_ostream &OS) {
|
2008-01-06 01:49:05 +01:00
|
|
|
EmitSourceFileHeader("Target Instruction Enum Values", OS);
|
|
|
|
OS << "namespace llvm {\n\n";
|
|
|
|
|
2010-12-13 01:23:57 +01:00
|
|
|
CodeGenTarget Target(Records);
|
2008-01-06 01:49:05 +01:00
|
|
|
|
|
|
|
// We must emit the PHI opcode first...
|
2010-03-19 02:00:55 +01:00
|
|
|
std::string Namespace = Target.getInstNamespace();
|
2008-01-06 01:49:05 +01:00
|
|
|
|
|
|
|
if (Namespace.empty()) {
|
|
|
|
fprintf(stderr, "No instructions defined!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-03-19 01:34:35 +01:00
|
|
|
const std::vector<const CodeGenInstruction*> &NumberedInstructions =
|
|
|
|
Target.getInstructionsByEnumValue();
|
2008-01-06 01:49:05 +01:00
|
|
|
|
|
|
|
OS << "namespace " << Namespace << " {\n";
|
|
|
|
OS << " enum {\n";
|
|
|
|
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
|
|
|
OS << " " << NumberedInstructions[i]->TheDef->getName()
|
|
|
|
<< "\t= " << i << ",\n";
|
|
|
|
}
|
|
|
|
OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n";
|
|
|
|
OS << " };\n}\n";
|
|
|
|
OS << "} // End llvm namespace \n";
|
|
|
|
}
|