summaryrefslogtreecommitdiff
path: root/lib/TableGen
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-07-05 21:22:55 +0000
committerTim Northover <tnorthover@apple.com>2016-07-05 21:22:55 +0000
commitedff0683c82e4cbf3c62f4d3b3ab24bf12368043 (patch)
tree9dce3f592ebde3e2fe20e2360d12763103e3d1f0 /lib/TableGen
parent7c103a2e09260341a6fd1e6402be773902d3a86f (diff)
TableGen: promote "code" type from syntactic sugar.
It's being immediately converted to a "string", but being able to tell what type the field was originally can be useful in backends. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274575 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen')
-rw-r--r--lib/TableGen/Record.cpp25
-rw-r--r--lib/TableGen/TGParser.cpp4
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp
index c98c5d3f0d7..9ee77816744 100644
--- a/lib/TableGen/Record.cpp
+++ b/lib/TableGen/Record.cpp
@@ -82,6 +82,7 @@ template<> struct DenseMapInfo<TableGenStringKey> {
//===----------------------------------------------------------------------===//
BitRecTy BitRecTy::Shared;
+CodeRecTy CodeRecTy::Shared;
IntRecTy IntRecTy::Shared;
StringRecTy StringRecTy::Shared;
DagRecTy DagRecTy::Shared;
@@ -453,6 +454,14 @@ IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
return BitsInit::get(NewBits);
}
+CodeInit *CodeInit::get(StringRef V) {
+ static StringMap<std::unique_ptr<CodeInit>> ThePool;
+
+ std::unique_ptr<CodeInit> &I = ThePool[V];
+ if (!I) I.reset(new CodeInit(V));
+ return I.get();
+}
+
StringInit *StringInit::get(StringRef V) {
static StringMap<std::unique_ptr<StringInit>> ThePool;
@@ -468,6 +477,13 @@ Init *StringInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
+Init *CodeInit::convertInitializerTo(RecTy *Ty) const {
+ if (isa<CodeRecTy>(Ty))
+ return const_cast<CodeInit *>(this);
+
+ return nullptr;
+}
+
static void ProfileListInit(FoldingSetNodeID &ID,
ArrayRef<Init *> Range,
RecTy *EltTy) {
@@ -1158,6 +1174,12 @@ TypedInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
+ if (isa<CodeRecTy>(Ty)) {
+ if (isa<CodeRecTy>(getType()))
+ return const_cast<TypedInit *>(this);
+ return nullptr;
+ }
+
if (isa<BitRecTy>(Ty)) {
// Accept variable if it is already of bit type!
if (isa<BitRecTy>(getType()))
@@ -1744,6 +1766,9 @@ std::string Record::getValueAsString(StringRef FieldName) const {
if (StringInit *SI = dyn_cast<StringInit>(R->getValue()))
return SI->getValue();
+ if (CodeInit *CI = dyn_cast<CodeInit>(R->getValue()))
+ return CI->getValue();
+
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
FieldName + "' does not have a string initializer!");
}
diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp
index 4239628498b..34e90925e92 100644
--- a/lib/TableGen/TGParser.cpp
+++ b/lib/TableGen/TGParser.cpp
@@ -660,7 +660,7 @@ RecTy *TGParser::ParseType() {
switch (Lex.getCode()) {
default: TokError("Unknown token when expecting a type"); return nullptr;
case tgtok::String: Lex.Lex(); return StringRecTy::get();
- case tgtok::Code: Lex.Lex(); return StringRecTy::get();
+ case tgtok::Code: Lex.Lex(); return CodeRecTy::get();
case tgtok::Bit: Lex.Lex(); return BitRecTy::get();
case tgtok::Int: Lex.Lex(); return IntRecTy::get();
case tgtok::Dag: Lex.Lex(); return DagRecTy::get();
@@ -1164,7 +1164,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
break;
}
case tgtok::CodeFragment:
- R = StringInit::get(Lex.getCurStrVal());
+ R = CodeInit::get(Lex.getCurStrVal());
Lex.Lex();
break;
case tgtok::question: