Chris Lattner | 2c0f2c7 | 2003-08-06 04:23:04 +0000 | [diff] [blame] | 1 | //===- 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 Lattner | 18a6a94 | 2003-08-06 04:31:26 +0000 | [diff] [blame^] | 8 | #include "Record.h" |
Chris Lattner | 2c0f2c7 | 2003-08-06 04:23:04 +0000 | [diff] [blame] | 9 | #include <iostream> |
| 10 | |
| 11 | void TableGenBackend::EmitSourceFileHeader(const std::string &Desc, |
Chris Lattner | 18a6a94 | 2003-08-06 04:31:26 +0000 | [diff] [blame^] | 12 | std::ostream &OS) const { |
Chris Lattner | 2c0f2c7 | 2003-08-06 04:23:04 +0000 | [diff] [blame] | 13 | 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 Lattner | 18a6a94 | 2003-08-06 04:31:26 +0000 | [diff] [blame^] | 19 | /// getQualifiedName - Return the name of the specified record, with a |
| 20 | /// namespace qualifier if the record contains one. |
| 21 | /// |
| 22 | std::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 | /// |
| 30 | Record *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 | } |