MIR Serialization: Serialize immediate machine operands.

Reviewers: Duncan P. N. Exon Smith

Differential Revision: http://reviews.llvm.org/D10573


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240481 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz
2015-06-23 23:42:28 +00:00
parent c2d796297f
commit ac57f351bd
5 changed files with 79 additions and 2 deletions

View File

@@ -33,7 +33,7 @@ public:
bool isEOF() const { return Ptr == End; }
char peek() const { return isEOF() ? 0 : *Ptr; }
char peek(unsigned I = 0) const { return End - Ptr <= I ? 0 : Ptr[I]; }
void advance() { ++Ptr; }
@@ -77,6 +77,16 @@ static Cursor lexPercent(Cursor C, MIToken &Token) {
return C;
}
static Cursor lexIntegerLiteral(Cursor C, MIToken &Token) {
auto Range = C;
C.advance();
while (isdigit(C.peek()))
C.advance();
StringRef StrVal = Range.upto(C);
Token = MIToken(MIToken::IntegerLiteral, StrVal, APSInt(StrVal));
return C;
}
static MIToken::TokenKind symbolToken(char C) {
switch (C) {
case ',':
@@ -109,6 +119,8 @@ StringRef llvm::lexMIToken(
return lexIdentifier(C, Token).remaining();
if (Char == '%')
return lexPercent(C, Token).remaining();
if (isdigit(Char) || (Char == '-' && isdigit(C.peek(1))))
return lexIntegerLiteral(C, Token).remaining();
MIToken::TokenKind Kind = symbolToken(Char);
if (Kind != MIToken::Error)
return lexSymbol(C, Kind, Token).remaining();