1 //===- InstrEnumEmitter.cpp - Generate Instruction Set Enums --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend is responsible for emitting enums for each machine
13 //===----------------------------------------------------------------------===//
15 #include "InstrEnumEmitter.h"
16 #include "CodeGenTarget.h"
21 // runEnums - Print out enum values for all of the instructions.
22 void InstrEnumEmitter::run(raw_ostream &OS) {
23 EmitSourceFileHeader("Target Instruction Enum Values", OS);
24 OS << "namespace llvm {\n\n";
26 CodeGenTarget Target(Records);
28 // We must emit the PHI opcode first...
29 std::string Namespace = Target.getInstNamespace();
31 if (Namespace.empty()) {
32 fprintf(stderr, "No instructions defined!\n");
36 const std::vector<const CodeGenInstruction*> &NumberedInstructions =
37 Target.getInstructionsByEnumValue();
39 OS << "namespace " << Namespace << " {\n";
41 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
42 OS << " " << NumberedInstructions[i]->TheDef->getName()
43 << "\t= " << i << ",\n";
45 OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n";
47 OS << "} // End llvm namespace \n";