blob: df07119944e4c5979b9176277eec23b516b54906 [file] [log] [blame]
Chris Lattner7b117122008-01-06 00:49:05 +00001//===- InstrEnumEmitter.cpp - Generate Instruction Set Enums --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tablegen backend is responsible for emitting enums for each machine
11// instruction.
12//
13//===----------------------------------------------------------------------===//
14
15#include "InstrEnumEmitter.h"
16#include "CodeGenTarget.h"
17#include "Record.h"
18using namespace llvm;
19
20// runEnums - Print out enum values for all of the instructions.
21void InstrEnumEmitter::run(std::ostream &OS) {
22 EmitSourceFileHeader("Target Instruction Enum Values", OS);
23 OS << "namespace llvm {\n\n";
24
25 CodeGenTarget Target;
26
27 // We must emit the PHI opcode first...
28 std::string Namespace;
29 for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
30 E = Target.inst_end(); II != E; ++II) {
31 if (II->second.Namespace != "TargetInstrInfo") {
32 Namespace = II->second.Namespace;
33 break;
34 }
35 }
36
37 if (Namespace.empty()) {
38 fprintf(stderr, "No instructions defined!\n");
39 exit(1);
40 }
41
42 std::vector<const CodeGenInstruction*> NumberedInstructions;
43 Target.getInstructionsByEnumValue(NumberedInstructions);
44
45 OS << "namespace " << Namespace << " {\n";
46 OS << " enum {\n";
47 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
48 OS << " " << NumberedInstructions[i]->TheDef->getName()
49 << "\t= " << i << ",\n";
50 }
51 OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n";
52 OS << " };\n}\n";
53 OS << "} // End llvm namespace \n";
54}