blob: c0a67e339243c86483539e24cac8e6053a967d7e [file] [log] [blame]
Chris Lattner2c0f2c72003-08-06 04:23:04 +00001//===- TableGenBackend.cpp - Base class for TableGen Backends ---*- C++ -*-===//
2//
3// This file provides useful services for TableGen backends...
4//
5//===----------------------------------------------------------------------===//
6
7#include "TableGenBackend.h"
Chris Lattner18a6a942003-08-06 04:31:26 +00008#include "Record.h"
Chris Lattner2c0f2c72003-08-06 04:23:04 +00009#include <iostream>
10
11void TableGenBackend::EmitSourceFileHeader(const std::string &Desc,
Chris Lattner18a6a942003-08-06 04:31:26 +000012 std::ostream &OS) const {
Chris Lattner2c0f2c72003-08-06 04:23:04 +000013 OS << "//===- 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
Chris Lattner18a6a942003-08-06 04:31:26 +000019/// getQualifiedName - Return the name of the specified record, with a
20/// namespace qualifier if the record contains one.
21///
22std::string TableGenBackend::getQualifiedName(Record *R) const {
23 std::string Namespace = R->getValueAsString("Namespace");
24 if (Namespace.empty()) return R->getName();
25 return Namespace + "::" + R->getName();
26}
27
28/// getTarget - Return the current instance of the Target class.
29///
30Record *TableGenBackend::getTarget(RecordKeeper &RC) const {
31 std::vector<Record*> Targets = RC.getAllDerivedDefinitions("Target");
32
33 if (Targets.size() != 1)
34 throw std::string("ERROR: Multiple subclasses of Target defined!");
35 return Targets[0];
36}