1 //===- 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 "llvm/TableGen/Record.h" 18 #include <cstdio> 19 using namespace llvm; 20 21 // runEnums - Print out enum values for all of the instructions. run(raw_ostream & OS)22void InstrEnumEmitter::run(raw_ostream &OS) { 23 EmitSourceFileHeader("Target Instruction Enum Values", OS); 24 OS << "namespace llvm {\n\n"; 25 26 CodeGenTarget Target(Records); 27 28 // We must emit the PHI opcode first... 29 std::string Namespace = Target.getInstNamespace(); 30 31 if (Namespace.empty()) { 32 fprintf(stderr, "No instructions defined!\n"); 33 exit(1); 34 } 35 36 const std::vector<const CodeGenInstruction*> &NumberedInstructions = 37 Target.getInstructionsByEnumValue(); 38 39 OS << "namespace " << Namespace << " {\n"; 40 OS << " enum {\n"; 41 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { 42 OS << " " << NumberedInstructions[i]->TheDef->getName() 43 << "\t= " << i << ",\n"; 44 } 45 OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n"; 46 OS << " };\n}\n"; 47 OS << "} // End llvm namespace \n"; 48 } 49