diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h index c9bba98971d0b..7c5594bb4da4d 100644 --- a/llvm/lib/TableGen/TGLexer.h +++ b/llvm/lib/TableGen/TGLexer.h @@ -54,35 +54,59 @@ enum TokKind { paste, // # dotdotdot, // ... + // Boolean literals. + TrueVal, + FalseVal, + + // Integer value. + IntVal, + + // Binary constant. Note that these are sized according to the number of + // bits given. + BinaryIntVal, + + // Preprocessing tokens for internal usage by the lexer. + // They are never returned as a result of Lex(). + Ifdef, + Ifndef, + Else, + Endif, + Define, + // Reserved keywords. ('ElseKW' is named to distinguish it from the // existing 'Else' that means the preprocessor #else.) - Assert, Bit, Bits, - Class, Code, Dag, - Def, - Defm, - Defset, - Defvar, ElseKW, FalseKW, Field, - Foreach, - If, In, Include, Int, - Let, List, - MultiClass, String, Then, TrueKW, + // Object start tokens. + OBJECT_START_FIRST, + Assert = OBJECT_START_FIRST, + Class, + Def, + Defm, + Defset, + Defvar, + Foreach, + If, + Let, + MultiClass, + OBJECT_START_LAST = MultiClass, + // Bang operators. - XConcat, + BANG_OPERATOR_FIRST, + XConcat = BANG_OPERATOR_FIRST, XADD, XSUB, XMUL, @@ -131,33 +155,32 @@ enum TokKind { XGetDagName, XSetDagArg, XSetDagName, - - // Boolean literals. - TrueVal, - FalseVal, - - // Integer value. - IntVal, - - // Binary constant. Note that these are sized according to the number of - // bits given. - BinaryIntVal, + BANG_OPERATOR_LAST = XSetDagName, // String valued tokens. - Id, + STRING_VALUE_FIRST, + Id = STRING_VALUE_FIRST, StrVal, VarName, CodeFragment, - - // Preprocessing tokens for internal usage by the lexer. - // They are never returned as a result of Lex(). - Ifdef, - Ifndef, - Else, - Endif, - Define + STRING_VALUE_LAST = CodeFragment, }; + +/// isBangOperator - Return true if this is a bang operator. +static inline bool isBangOperator(tgtok::TokKind Kind) { + return tgtok::BANG_OPERATOR_FIRST <= Kind && Kind <= BANG_OPERATOR_LAST; +} + +/// isObjectStart - Return true if this is a valid first token for a statement. +static inline bool isObjectStart(tgtok::TokKind Kind) { + return tgtok::OBJECT_START_FIRST <= Kind && Kind <= OBJECT_START_LAST; +} + +/// isStringValue - Return true if this is a string value. +static inline bool isStringValue(tgtok::TokKind Kind) { + return tgtok::STRING_VALUE_FIRST <= Kind && Kind <= STRING_VALUE_LAST; } +} // namespace tgtok /// TGLexer - TableGen Lexer class. class TGLexer { @@ -197,8 +220,7 @@ class TGLexer { tgtok::TokKind getCode() const { return CurCode; } const std::string &getCurStrVal() const { - assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal || - CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) && + assert(tgtok::isStringValue(CurCode) && "This token doesn't have a string value"); return CurStrVal; } diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 759e15f4c443b..a3d6f837cb575 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -629,14 +629,6 @@ bool TGParser::resolveArgumentsOfMultiClass(SubstStack &Substs, MultiClass *MC, // Parser Code //===----------------------------------------------------------------------===// -/// isObjectStart - Return true if this is a valid first token for a statement. -static bool isObjectStart(tgtok::TokKind K) { - return K == tgtok::Assert || K == tgtok::Class || K == tgtok::Def || - K == tgtok::Defm || K == tgtok::Defset || K == tgtok::Defvar || - K == tgtok::Foreach || K == tgtok::If || K == tgtok::Let || - K == tgtok::MultiClass; -} - bool TGParser::consume(tgtok::TokKind K) { if (Lex.getCode() == K) { Lex.Lex(); @@ -2547,7 +2539,13 @@ Init *TGParser::ParseOperationCond(Record *CurRec, RecTy *ItemType) { Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) { Init *R = nullptr; - switch (Lex.getCode()) { + tgtok::TokKind Code = Lex.getCode(); + + // Parse bang operators. + if (tgtok::isBangOperator(Code)) + return ParseOperation(CurRec, ItemType); + + switch (Code) { default: TokError("Unknown or reserved token when parsing a value"); break; case tgtok::TrueVal: @@ -2802,58 +2800,6 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, return DagInit::get(Operator, OperatorName, DagArgs); } - - case tgtok::XHead: - case tgtok::XTail: - case tgtok::XSize: - case tgtok::XEmpty: - case tgtok::XCast: - case tgtok::XToLower: - case tgtok::XToUpper: - case tgtok::XGetDagOp: // Value ::= !unop '(' Value ')' - case tgtok::XExists: - case tgtok::XIsA: - case tgtok::XConcat: - case tgtok::XDag: - case tgtok::XADD: - case tgtok::XSUB: - case tgtok::XMUL: - case tgtok::XDIV: - case tgtok::XNOT: - case tgtok::XLOG2: - case tgtok::XAND: - case tgtok::XOR: - case tgtok::XXOR: - case tgtok::XSRA: - case tgtok::XSRL: - case tgtok::XSHL: - case tgtok::XEq: - case tgtok::XNe: - case tgtok::XLe: - case tgtok::XLt: - case tgtok::XGe: - case tgtok::XGt: - case tgtok::XListConcat: - case tgtok::XListSplat: - case tgtok::XListRemove: - case tgtok::XRange: - case tgtok::XStrConcat: - case tgtok::XInterleave: - case tgtok::XGetDagArg: - case tgtok::XGetDagName: - case tgtok::XSetDagOp: // Value ::= !binop '(' Value ',' Value ')' - case tgtok::XSetDagArg: - case tgtok::XSetDagName: - case tgtok::XIf: - case tgtok::XCond: - case tgtok::XFoldl: - case tgtok::XForEach: - case tgtok::XFilter: - case tgtok::XSubst: - case tgtok::XSubstr: - case tgtok::XFind: { // Value ::= !ternop '(' Value ',' Value ',' Value ')' - return ParseOperation(CurRec, ItemType); - } } return R; @@ -4275,7 +4221,7 @@ bool TGParser::ParseObject(MultiClass *MC) { /// ParseObjectList /// ObjectList :== Object* bool TGParser::ParseObjectList(MultiClass *MC) { - while (isObjectStart(Lex.getCode())) { + while (tgtok::isObjectStart(Lex.getCode())) { if (ParseObject(MC)) return true; }