b98ff0a4242c25c664ba6965bafe8b7213d81594
[oota-llvm.git] / utils / TableGen / TableGenBackend.cpp
1 //===- TableGenBackend.cpp - Base class for TableGen Backends ---*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides useful services for TableGen backends...
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "TableGenBackend.h"
15 #include "Record.h"
16 #include <iostream>
17 using namespace llvm;
18
19 void TableGenBackend::EmitSourceFileHeader(const std::string &Desc,
20                                            std::ostream &OS) const {
21   OS << "//===- TableGen'erated file -------------------------------------*-"
22        " C++ -*-===//\n//\n// " << Desc << "\n//\n// Automatically generate"
23        "d file, do not edit!\n//\n//===------------------------------------"
24        "----------------------------------===//\n\nnamespace llvm {\n\n";
25 }
26
27 void TableGenBackend::EmitSourceFileTail( std::ostream& OS ) const {
28   OS << "} // End llvm namespace \n";
29 }
30
31 /// getQualifiedName - Return the name of the specified record, with a
32 /// namespace qualifier if the record contains one.
33 ///
34 std::string TableGenBackend::getQualifiedName(Record *R) const {
35   std::string Namespace = R->getValueAsString("Namespace");
36   if (Namespace.empty()) return R->getName();
37   return Namespace + "::" + R->getName();
38 }
39