diff options
Diffstat (limited to 'llvm/lib/TableGen')
-rw-r--r-- | llvm/lib/TableGen/TGLexer.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGLexer.h | 9 | ||||
-rw-r--r-- | llvm/lib/TableGen/TGParser.cpp | 9 |
3 files changed, 19 insertions, 1 deletions
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp index cfcc119f82d..63b85842d6a 100644 --- a/llvm/lib/TableGen/TGLexer.cpp +++ b/llvm/lib/TableGen/TGLexer.cpp @@ -411,7 +411,7 @@ tgtok::TokKind TGLexer::LexNumber() { if (CurPtr == NumStart) return ReturnError(CurPtr-2, "Invalid binary number"); CurIntVal = strtoll(NumStart, nullptr, 2); - return tgtok::IntVal; + return tgtok::BinaryIntVal; } } diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h index c7f7306a149..9fb2e3536e0 100644 --- a/llvm/lib/TableGen/TGLexer.h +++ b/llvm/lib/TableGen/TGLexer.h @@ -52,6 +52,10 @@ namespace tgtok { // Integer value. IntVal, + + // Binary constant. Note that these are sized according to the number of + // bits given. + BinaryIntVal, // String valued tokens. Id, StrVal, VarName, CodeFragment @@ -105,6 +109,11 @@ public: assert(CurCode == tgtok::IntVal && "This token isn't an integer"); return CurIntVal; } + std::pair<int64_t, unsigned> getCurBinaryIntVal() const { + assert(CurCode == tgtok::BinaryIntVal && + "This token isn't a binary integer"); + return std::make_pair(CurIntVal, (CurPtr - TokStart)-2); + } SMLoc getLoc() const; diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index d020a8bdc1a..709c7a52b9f 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -1182,6 +1182,15 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, Lex.Lex(); // Skip '#'. return ParseSimpleValue(CurRec, ItemType, Mode); case tgtok::IntVal: R = IntInit::get(Lex.getCurIntVal()); Lex.Lex(); break; + case tgtok::BinaryIntVal: { + auto BinaryVal = Lex.getCurBinaryIntVal(); + SmallVector<Init*, 16> Bits(BinaryVal.second); + for (unsigned i = 0, e = BinaryVal.second; i != e; ++i) + Bits[i] = BitInit::get(BinaryVal.first & (1 << i)); + R = BitsInit::get(Bits); + Lex.Lex(); + break; + } case tgtok::StrVal: { std::string Val = Lex.getCurStrVal(); Lex.Lex(); |