diff options
author | Alp Toker <alp@nuanti.com> | 2013-12-21 18:51:00 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2013-12-21 18:51:00 +0000 |
commit | cee93e95a4bb45e44d6029404fc47084e48b7775 (patch) | |
tree | 35ee8f09c82d0ecc0b99f0c4a4c5d0f642595541 /lib/TableGen | |
parent | efe6aa1adb625dc3027c5e47466e694b4ac2e1d8 (diff) | |
download | llvm-cee93e95a4bb45e44d6029404fc47084e48b7775.tar.gz llvm-cee93e95a4bb45e44d6029404fc47084e48b7775.tar.bz2 llvm-cee93e95a4bb45e44d6029404fc47084e48b7775.tar.xz |
TableGen: Generate valid identifiers for anonymous records
Backends like OptParserEmitter assume that record names can be used as valid
identifiers.
The period '.' in generated anonymous names broke that assumption, causing a
build-time error and in practice forcing all records to be named.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197869 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen')
-rw-r--r-- | lib/TableGen/TGParser.cpp | 12 | ||||
-rw-r--r-- | lib/TableGen/TGParser.h | 8 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index daac5747d3..38ab71184a 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, @@ -1215,10 +1216,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); diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h index 044e3a02ba..a575345810 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; |