diff options
author | Quentin Colombet <qcolombet@apple.com> | 2016-03-08 00:57:31 +0000 |
---|---|---|
committer | Quentin Colombet <qcolombet@apple.com> | 2016-03-08 00:57:31 +0000 |
commit | 287c6bb5713f3c09367141dc7d23d00d2cdc2f50 (patch) | |
tree | f36109cca0296ce27640815084e9d75f0877700f /llvm/lib/CodeGen | |
parent | 89e9597a508e1ed4bfde08ee3f4769d80bd96174 (diff) | |
download | bcm5719-llvm-287c6bb5713f3c09367141dc7d23d00d2cdc2f50.tar.gz bcm5719-llvm-287c6bb5713f3c09367141dc7d23d00d2cdc2f50.zip |
[MIR] Teach the parser how to parse complex types of generic machine instructions.
By complex types, I mean aggregate or vector types.
llvm-svn: 262890
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.h | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.cpp | 43 |
3 files changed, 35 insertions, 14 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 28f9d4e298f..84cf186ca37 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -497,6 +497,10 @@ static MIToken::TokenKind symbolToken(char C) { return MIToken::plus; case '-': return MIToken::minus; + case '<': + return MIToken::lt; + case '>': + return MIToken::gt; default: return MIToken::Error; } diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index ff54aa3554d..cf7282f5989 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -45,6 +45,8 @@ struct MIToken { rbrace, plus, minus, + lt, + gt, // Keywords kw_implicit, diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 082d59d5749..141aeb57349 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -88,7 +88,9 @@ public: StringRef Source, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots); - void lex(); + /// \p SkipChar gives the number of characters to skip before looking + /// for the next token. + void lex(unsigned SkipChar = 0); /// Report an error at the current location with the given message. /// @@ -127,8 +129,10 @@ public: bool parseIRConstant(StringRef::iterator Loc, StringRef Source, const Constant *&C); bool parseIRConstant(StringRef::iterator Loc, const Constant *&C); - bool parseIRType(StringRef::iterator Loc, StringRef Source, Type *&Ty); - bool parseIRType(StringRef::iterator Loc, Type *&Ty); + bool parseIRType(StringRef::iterator Loc, StringRef Source, unsigned &Read, + Type *&Ty); + // \p MustBeSized defines whether or not \p Ty must be sized. + bool parseIRType(StringRef::iterator Loc, Type *&Ty, bool MustBeSized = true); bool parseTypedImmediateOperand(MachineOperand &Dest); bool parseFPImmediateOperand(MachineOperand &Dest); bool parseMBBReference(MachineBasicBlock *&MBB); @@ -254,9 +258,9 @@ MIParser::MIParser(SourceMgr &SM, MachineFunction &MF, SMDiagnostic &Error, : SM(SM), MF(MF), Error(Error), Source(Source), CurrentSource(Source), PFS(PFS), IRSlots(IRSlots) {} -void MIParser::lex() { +void MIParser::lex(unsigned SkipChar) { CurrentSource = lexMIToken( - CurrentSource, Token, + CurrentSource.data() + SkipChar, Token, [this](StringRef::iterator Loc, const Twine &Msg) { error(Loc, Msg); }); } @@ -597,10 +601,6 @@ bool MIParser::parse(MachineInstr *&MI) { auto Loc = Token.location(); if (parseIRType(Loc, Ty)) return true; - // The type must be sized, otherwise there is not much the backend - // can do with it. - if (!Ty->isSized()) - return error("expected a fully defined type for generic instruction"); } // Parse the remaining machine operands. @@ -1019,19 +1019,34 @@ bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) { } bool MIParser::parseIRType(StringRef::iterator Loc, StringRef StringValue, - Type *&Ty) { + unsigned &Read, Type *&Ty) { auto Source = StringValue.str(); // The source has to be null terminated. SMDiagnostic Err; - Ty = parseType(Source.c_str(), Err, *MF.getFunction()->getParent(), &IRSlots); + Ty = parseTypeAtBeginning(Source.c_str(), Read, Err, + *MF.getFunction()->getParent(), &IRSlots); if (!Ty) return error(Loc + Err.getColumnNo(), Err.getMessage()); return false; } -bool MIParser::parseIRType(StringRef::iterator Loc, Type *&Ty) { - if (parseIRType(Loc, StringRef(Loc, Token.range().end() - Loc), Ty)) +bool MIParser::parseIRType(StringRef::iterator Loc, Type *&Ty, + bool MustBeSized) { + // At this point we enter in the IR world, i.e., to get the correct type, + // we need to hand off the whole string, not just the current token. + // E.g., <4 x i64> would give '<' as a token and there is not much + // the IR parser can do with that. + unsigned Read = 0; + if (parseIRType(Loc, StringRef(Loc), Read, Ty)) return true; - lex(); + // The type must be sized, otherwise there is not much the backend + // can do with it. + if (MustBeSized && !Ty->isSized()) + return error("expected a sized type"); + // The next token is Read characters from the Loc. + // However, the current location is not Loc, but Loc + the length of Token. + // Therefore, subtract the length of Token (range().end() - Loc) to the + // number of characters to skip before the next token. + lex(Read - (Token.range().end() - Loc)); return false; } |