1 //===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend emits subtarget enumerations.
12 //===----------------------------------------------------------------------===//
14 #include "SubtargetEmitter.h"
15 #include "CodeGenTarget.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/Support/Debug.h"
24 typedef std::vector<Record*> RecordList;
25 typedef std::vector<Record*>::iterator RecordListIter;
28 // SubtargetEmitter::run - Main subtarget enumeration emitter.
30 void SubtargetEmitter::run(std::ostream &OS) {
31 EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
32 RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
33 RecordList Processors = Records.getAllDerivedDefinitions("Processor");
35 OS << "namespace llvm {\n\n";
37 { // Feature enumeration
42 for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;){
44 std::string Instance = R->getName();
49 << ((RI != E) ? ",\n" : "\n");
55 { // Feature key values
57 << "/// Sorted (by key) array of values for CPU features.\n"
58 << "static SubtargetFeatureKV FeatureKV[] = {\n";
59 for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;) {
61 std::string Instance = R->getName();
62 std::string Name = R->getValueAsString("Name");
63 std::string Desc = R->getValueAsString("Desc");
65 << "\"" << Name << "\", "
66 << "\"" << Desc << "\", "
68 << ((RI != E) ? " },\n" : " }\n");
73 { // Feature key values
75 << "/// Sorted (by key) array of values for CPU subtype.\n"
76 << "static const SubtargetFeatureKV SubTypeKV[] = {\n";
77 for (RecordListIter RI = Processors.begin(), E = Processors.end();
80 std::string Name = R->getValueAsString("Name");
81 Record *ProcItin = R->getValueAsDef("ProcItin");
82 ListInit *Features = R->getValueAsListInit("Features");
83 unsigned N = Features->getSize();
85 << "\"" << Name << "\", "
86 << "\"Select the " << Name << " processor\", ";
92 for (unsigned i = 0; i < N; ) {
93 if (DefInit *DI = dynamic_cast<DefInit*>(Features->getElement(i++))) {
94 Record *Feature = DI->getDef();
95 std::string Name = Feature->getName();
97 if (i != N) OS << " | ";
99 throw "Feature: " + Name +
100 " expected feature in processor feature list!";
105 OS << ((RI != E) ? " },\n" : " }\n");
110 OS << "\n} // End llvm namespace \n";