200800fae627faf136835d0cc0905fe86b2fa997
[oota-llvm.git] / support / tools / TableGen / RegisterInfoEmitter.cpp
1 //===- RegisterInfoEmitter.cpp - Generate a Register File Desc. -*- C++ -*-===//
2 //
3 // This tablegen backend is responsible for emitting a description of a target
4 // register file for a code generator.  It uses instances of the Register,
5 // RegisterAliases, and RegisterClass classes to gather this information.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "RegisterInfoEmitter.h"
10 #include "Record.h"
11
12 static void EmitSourceHeader(const std::string &Desc, std::ostream &o) {
13   o << "//===- TableGen'erated file -------------------------------------*-"
14        " C++ -*-===//\n//\n// " << Desc << "\n//\n// Automatically generate"
15        "d file, do not edit!\n//\n//===------------------------------------"
16        "----------------------------------===//\n\n";
17 }
18
19 void RegisterInfoEmitter::runHeader(std::ostream &OS) {
20   std::vector<Record*> RegisterInfos =
21     Records.getAllDerivedDefinitions("RegisterInfo");
22
23   if (RegisterInfos.size() != 1)
24     throw std::string("ERROR: Multiple subclasses of RegisterInfo defined!");
25
26   EmitSourceHeader("Register Information Header Fragment", OS);
27
28   std::string ClassName = RegisterInfos[0]->getValueAsString("ClassName");
29
30   OS << "#include \"llvm/CodeGen/MRegisterInfo.h\"\n\n";
31
32   OS << "struct " << ClassName << ": public MRegisterInfo {\n"
33      << "  " << ClassName << "();\n"
34      << "  const unsigned* getCalleeSaveRegs() const;\n"
35      << "};\n\n";
36 }
37
38 void RegisterInfoEmitter::run(std::ostream &o) {
39
40 }