aboutsummaryrefslogtreecommitdiffstats
path: root/lib/TableGen
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-04-23 16:57:46 -0700
committerStephen Hines <srhines@google.com>2014-04-24 15:53:16 -0700
commit36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch)
treee6cfb69fbbd937f450eeb83bfb83b9da3b01275a /lib/TableGen
parent69a8640022b04415ae9fac62f8ab090601d8f889 (diff)
downloadexternal_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'lib/TableGen')
-rw-r--r--lib/TableGen/Android.mk2
-rw-r--r--lib/TableGen/Error.cpp6
-rw-r--r--lib/TableGen/Main.cpp9
-rw-r--r--lib/TableGen/Record.cpp40
-rw-r--r--lib/TableGen/TGParser.cpp77
-rw-r--r--lib/TableGen/TGParser.h11
6 files changed, 84 insertions, 61 deletions
diff --git a/lib/TableGen/Android.mk b/lib/TableGen/Android.mk
index 2169f33..1f01ef7 100644
--- a/lib/TableGen/Android.mk
+++ b/lib/TableGen/Android.mk
@@ -26,6 +26,7 @@ include $(BUILD_HOST_STATIC_LIBRARY)
## For the device
## =====================================================
+ifneq (true,$(DISABLE_LLVM_DEVICE_BUILDS))
#include $(CLEAR_VARS)
#
#LOCAL_SRC_FILES := $(libtablegen_SRC_FILES)
@@ -35,3 +36,4 @@ include $(BUILD_HOST_STATIC_LIBRARY)
#
#include $(LLVM_DEVICE_BUILD_MK)
#include $(BUILD_STATIC_LIBRARY)
+endif
diff --git a/lib/TableGen/Error.cpp b/lib/TableGen/Error.cpp
index 928b120..8d9ae20 100644
--- a/lib/TableGen/Error.cpp
+++ b/lib/TableGen/Error.cpp
@@ -62,12 +62,12 @@ void PrintError(const Twine &Msg) {
errs() << "error:" << Msg << "\n";
}
-void PrintFatalError(const std::string &Msg) {
- PrintError(Twine(Msg));
+void PrintFatalError(const Twine &Msg) {
+ PrintError(Msg);
std::exit(1);
}
-void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const std::string &Msg) {
+void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
PrintError(ErrorLoc, Msg);
std::exit(1);
}
diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp
index 7fe47bc..fd81ab4 100644
--- a/lib/TableGen/Main.cpp
+++ b/lib/TableGen/Main.cpp
@@ -16,7 +16,6 @@
//===----------------------------------------------------------------------===//
#include "TGParser.h"
-#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/ToolOutputFile.h"
@@ -57,7 +56,7 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
return 1;
}
std::string Error;
- tool_output_file DepOut(DependFilename.c_str(), Error);
+ tool_output_file DepOut(DependFilename.c_str(), Error, sys::fs::F_Text);
if (!Error.empty()) {
errs() << argv0 << ": error opening " << DependFilename
<< ":" << Error << "\n";
@@ -81,14 +80,14 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) {
RecordKeeper Records;
// Parse the input file.
- OwningPtr<MemoryBuffer> File;
+ std::unique_ptr<MemoryBuffer> File;
if (error_code ec =
MemoryBuffer::getFileOrSTDIN(InputFilename, File)) {
errs() << "Could not open input file '" << InputFilename << "': "
<< ec.message() <<"\n";
return 1;
}
- MemoryBuffer *F = File.take();
+ MemoryBuffer *F = File.release();
// Tell SrcMgr about this buffer, which is what TGParser will pick up.
SrcMgr.AddNewSourceBuffer(F, SMLoc());
@@ -103,7 +102,7 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) {
return 1;
std::string Error;
- tool_output_file Out(OutputFilename.c_str(), Error);
+ tool_output_file Out(OutputFilename.c_str(), Error, sys::fs::F_Text);
if (!Error.empty()) {
errs() << argv0 << ": error opening " << OutputFilename
<< ":" << Error << "\n";
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp
index 431f4aa..a43665b 100644
--- a/lib/TableGen/Record.cpp
+++ b/lib/TableGen/Record.cpp
@@ -152,7 +152,7 @@ Init *BitsRecTy::convertValue(UnsetInit *UI) {
Init *BitsRecTy::convertValue(BitInit *UI) {
if (Size != 1) return 0; // Can only convert single bit.
- return BitsInit::get(UI);
+ return BitsInit::get(UI);
}
/// canFitInBitfield - Return true if the number of bits is large enough to hold
@@ -1786,7 +1786,7 @@ Init *Record::getValueInit(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
return R->getValue();
}
@@ -1799,12 +1799,12 @@ std::string Record::getValueAsString(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
if (StringInit *SI = dyn_cast<StringInit>(R->getValue()))
return SI->getValue();
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a string initializer!");
+ FieldName + "' does not have a string initializer!");
}
/// getValueAsBitsInit - This method looks up the specified field and returns
@@ -1815,12 +1815,12 @@ BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
if (BitsInit *BI = dyn_cast<BitsInit>(R->getValue()))
return BI;
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a BitsInit initializer!");
+ FieldName + "' does not have a BitsInit initializer!");
}
/// getValueAsListInit - This method looks up the specified field and returns
@@ -1831,12 +1831,12 @@ ListInit *Record::getValueAsListInit(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
if (ListInit *LI = dyn_cast<ListInit>(R->getValue()))
return LI;
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a list initializer!");
+ FieldName + "' does not have a list initializer!");
}
/// getValueAsListOfDefs - This method looks up the specified field and returns
@@ -1852,7 +1852,7 @@ Record::getValueAsListOfDefs(StringRef FieldName) const {
Defs.push_back(DI->getDef());
} else {
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' list is not entirely DefInit!");
+ FieldName + "' list is not entirely DefInit!");
}
}
return Defs;
@@ -1866,12 +1866,12 @@ int64_t Record::getValueAsInt(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
if (IntInit *II = dyn_cast<IntInit>(R->getValue()))
return II->getValue();
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have an int initializer!");
+ FieldName + "' does not have an int initializer!");
}
/// getValueAsListOfInts - This method looks up the specified field and returns
@@ -1887,7 +1887,7 @@ Record::getValueAsListOfInts(StringRef FieldName) const {
Ints.push_back(II->getValue());
} else {
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a list of ints initializer!");
+ FieldName + "' does not have a list of ints initializer!");
}
}
return Ints;
@@ -1906,7 +1906,7 @@ Record::getValueAsListOfStrings(StringRef FieldName) const {
Strings.push_back(II->getValue());
} else {
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a list of strings initializer!");
+ FieldName + "' does not have a list of strings initializer!");
}
}
return Strings;
@@ -1920,12 +1920,12 @@ Record *Record::getValueAsDef(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
if (DefInit *DI = dyn_cast<DefInit>(R->getValue()))
return DI->getDef();
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a def initializer!");
+ FieldName + "' does not have a def initializer!");
}
/// getValueAsBit - This method looks up the specified field and returns its
@@ -1936,12 +1936,12 @@ bool Record::getValueAsBit(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
return BI->getValue();
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a bit initializer!");
+ FieldName + "' does not have a bit initializer!");
}
bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
@@ -1958,7 +1958,7 @@ bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
if (BitInit *BI = dyn_cast<BitInit>(R->getValue()))
return BI->getValue();
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a bit initializer!");
+ FieldName + "' does not have a bit initializer!");
}
/// getValueAsDag - This method looks up the specified field and returns its
@@ -1969,12 +1969,12 @@ DagInit *Record::getValueAsDag(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
PrintFatalError(getLoc(), "Record `" + getName() +
- "' does not have a field named `" + FieldName.str() + "'!\n");
+ "' does not have a field named `" + FieldName + "'!\n");
if (DagInit *DI = dyn_cast<DagInit>(R->getValue()))
return DI;
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
- FieldName.str() + "' does not have a dag initializer!");
+ FieldName + "' does not have a dag initializer!");
}
diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp
index daac574..4ba769c 100644
--- a/lib/TableGen/TGParser.cpp
+++ b/lib/TableGen/TGParser.cpp
@@ -380,10 +380,11 @@ static bool isObjectStart(tgtok::TokKind K) {
K == tgtok::MultiClass || K == tgtok::Foreach;
}
-static std::string GetNewAnonymousName() {
- static unsigned AnonCounter = 0;
+/// GetNewAnonymousName - Generate a unique anonymous name that can be used as
+/// an identifier.
+std::string TGParser::GetNewAnonymousName() {
unsigned Tmp = AnonCounter++; // MSVC2012 ICEs without this.
- return "anonymous." + utostr(Tmp);
+ return "anonymous_" + utostr(Tmp);
}
/// ParseObjectName - If an object name is specified, return it. Otherwise,
@@ -721,22 +722,6 @@ RecTy *TGParser::ParseType() {
}
}
-/// ParseIDValue - Parse an ID as a value and decode what it means.
-///
-/// IDValue ::= ID [def local value]
-/// IDValue ::= ID [def template arg]
-/// IDValue ::= ID [multiclass local value]
-/// IDValue ::= ID [multiclass template argument]
-/// IDValue ::= ID [def name]
-///
-Init *TGParser::ParseIDValue(Record *CurRec, IDParseMode Mode) {
- assert(Lex.getCode() == tgtok::Id && "Expected ID in ParseIDValue");
- std::string Name = Lex.getCurStrVal();
- SMLoc Loc = Lex.getLoc();
- Lex.Lex();
- return ParseIDValue(CurRec, Name, Loc);
-}
-
/// ParseIDValue - This is just like ParseIDValue above, but it assumes the ID
/// has already been read.
Init *TGParser::ParseIDValue(Record *CurRec,
@@ -1215,10 +1200,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
SMLoc EndLoc = Lex.getLoc();
// Create the new record, set it as CurRec temporarily.
- static unsigned AnonCounter = 0;
- Record *NewRec = new Record("anonymous.val."+utostr(AnonCounter++),
- NameLoc,
- Records,
+ Record *NewRec = new Record(GetNewAnonymousName(), NameLoc, Records,
/*IsAnonymous=*/true);
SubClassReference SCRef;
SCRef.RefRange = SMRange(NameLoc, EndLoc);
@@ -1227,8 +1209,36 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
// Add info about the subclass to NewRec.
if (AddSubClass(NewRec, SCRef))
return 0;
- NewRec->resolveReferences();
- Records.addDef(NewRec);
+ if (!CurMultiClass) {
+ NewRec->resolveReferences();
+ Records.addDef(NewRec);
+ } else {
+ // Otherwise, we're inside a multiclass, add it to the multiclass.
+ CurMultiClass->DefPrototypes.push_back(NewRec);
+
+ // Copy the template arguments for the multiclass into the def.
+ const std::vector<Init *> &TArgs =
+ CurMultiClass->Rec.getTemplateArgs();
+
+ for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
+ const RecordVal *RV = CurMultiClass->Rec.getValue(TArgs[i]);
+ assert(RV && "Template arg doesn't exist?");
+ NewRec->addValue(*RV);
+ }
+
+ // We can't return the prototype def here, instead return:
+ // !cast<ItemType>(!strconcat(NAME, AnonName)).
+ const RecordVal *MCNameRV = CurMultiClass->Rec.getValue("NAME");
+ assert(MCNameRV && "multiclass record must have a NAME");
+
+ return UnOpInit::get(UnOpInit::CAST,
+ BinOpInit::get(BinOpInit::STRCONCAT,
+ VarInit::get(MCNameRV->getName(),
+ MCNameRV->getType()),
+ NewRec->getNameInit(),
+ StringRecTy::get()),
+ Class->getDefInit()->getType());
+ }
// The result of the expression is a reference to the new record.
return DefInit::get(NewRec);
@@ -1964,7 +1974,18 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
return true;
}
Records.addDef(CurRec);
+
+ if (ParseObjectBody(CurRec))
+ return true;
} else if (CurMultiClass) {
+ // Parse the body before adding this prototype to the DefPrototypes vector.
+ // That way implicit definitions will be added to the DefPrototypes vector
+ // before this object, instantiated prior to defs derived from this object,
+ // and this available for indirect name resolution when defs derived from
+ // this object are instantiated.
+ if (ParseObjectBody(CurRec))
+ return true;
+
// Otherwise, a def inside a multiclass, add it to the multiclass.
for (unsigned i = 0, e = CurMultiClass->DefPrototypes.size(); i != e; ++i)
if (CurMultiClass->DefPrototypes[i]->getNameInit()
@@ -1974,9 +1995,7 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
return true;
}
CurMultiClass->DefPrototypes.push_back(CurRec);
- }
-
- if (ParseObjectBody(CurRec))
+ } else if (ParseObjectBody(CurRec))
return true;
if (CurMultiClass == 0) // Def's in multiclasses aren't really defs.
@@ -2271,7 +2290,7 @@ bool TGParser::ParseMultiClass() {
Record *TGParser::
InstantiateMulticlassDef(MultiClass &MC,
Record *DefProto,
- Init *DefmPrefix,
+ Init *&DefmPrefix,
SMRange DefmPrefixRange) {
// We need to preserve DefProto so it can be reused for later
// instantiations, so create a new Record to inherit from it.
diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h
index 044e3a0..ce31f8e 100644
--- a/lib/TableGen/TGParser.h
+++ b/lib/TableGen/TGParser.h
@@ -69,6 +69,8 @@ class TGParser {
// Record tracker
RecordKeeper &Records;
+ unsigned AnonCounter;
+
// A "named boolean" indicating how to parse identifiers. Usually
// identifiers map to some existing object but in special cases
// (e.g. parsing def names) no such object exists yet because we are
@@ -82,8 +84,8 @@ class TGParser {
};
public:
- TGParser(SourceMgr &SrcMgr, RecordKeeper &records) :
- Lex(SrcMgr), CurMultiClass(0), Records(records) {}
+ TGParser(SourceMgr &SrcMgr, RecordKeeper &records)
+ : Lex(SrcMgr), CurMultiClass(0), Records(records), AnonCounter(0) {}
/// ParseFile - Main entrypoint for parsing a tblgen file. These parser
/// routines return true on error, or false on success.
@@ -112,6 +114,8 @@ private: // Semantic analysis methods.
bool AddSubMultiClass(MultiClass *CurMC,
SubMultiClassReference &SubMultiClass);
+ std::string GetNewAnonymousName();
+
// IterRecord: Map an iterator name to a value.
struct IterRecord {
VarInit *IterVar;
@@ -133,7 +137,7 @@ private: // Parser methods.
bool ParseMultiClass();
Record *InstantiateMulticlassDef(MultiClass &MC,
Record *DefProto,
- Init *DefmPrefix,
+ Init *&DefmPrefix,
SMRange DefmPrefixRange);
bool ResolveMulticlassDefArgs(MultiClass &MC,
Record *DefProto,
@@ -163,7 +167,6 @@ private: // Parser methods.
SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
- Init *ParseIDValue(Record *CurRec, IDParseMode Mode = ParseValueMode);
Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc,
IDParseMode Mode = ParseValueMode);
Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0,