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";
28 // We must emit the PHI opcode first...
29 std::string Namespace
;
30 for (CodeGenTarget::inst_iterator II
= Target
.inst_begin(),
31 E
= Target
.inst_end(); II
!= E
; ++II
) {
32 if (II
->second
.Namespace
!= "TargetInstrInfo") {
33 Namespace
= II
->second
.Namespace
;
38 if (Namespace
.empty()) {
39 fprintf(stderr
, "No instructions defined!\n");
43 std::vector
<const CodeGenInstruction
*> NumberedInstructions
;
44 Target
.getInstructionsByEnumValue(NumberedInstructions
);
46 OS
<< "namespace " << Namespace
<< " {\n";
48 for (unsigned i
= 0, e
= NumberedInstructions
.size(); i
!= e
; ++i
) {
49 OS
<< " " << NumberedInstructions
[i
]->TheDef
->getName()
50 << "\t= " << i
<< ",\n";
52 OS
<< " INSTRUCTION_LIST_END = " << NumberedInstructions
.size() << "\n";
54 OS
<< "} // End llvm namespace \n";