llvm.org GIT mirror llvm / 26f3bb9
In MC asm parsing, account for the possibility of whitespace within the "identifier" parsed by the frontend callback by skipping forward until we've consumed a token that ends at the point dictated by the callback. In addition, inform the callback when it's parsing an unevaluated operand (e.g. mov eax, LENGTH A::x) as opposed to an evaluated one (e.g. mov eax, [A::x]). This commit depends on a clang commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180978 91177308-0d34-0410-b5e6-96231b3b80d8 John McCall 7 years ago
2 changed file(s) with 26 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
4848
4949 virtual ~MCAsmParserSemaCallback();
5050 virtual void *LookupInlineAsmIdentifier(StringRef &LineBuf,
51 InlineAsmIdentifierInfo &Info) = 0;
51 InlineAsmIdentifierInfo &Info,
52 bool IsUnevaluatedContext) = 0;
5253
5354 virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
5455 unsigned &Offset) = 0;
499499 X86Operand *ParseIntelBracExpression(unsigned SegReg, SMLoc Start,
500500 int64_t ImmDisp, unsigned Size);
501501 X86Operand *ParseIntelIdentifier(const MCExpr *&Val, StringRef &Identifier,
502 InlineAsmIdentifierInfo &Info, SMLoc &End);
502 InlineAsmIdentifierInfo &Info,
503 bool IsUnevaluatedOperand, SMLoc &End);
503504
504505 X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
505506
12661267 return ErrorOperand(Tok.getLoc(), "Unexpected identifier!");
12671268 } else {
12681269 InlineAsmIdentifierInfo &Info = SM.getIdentifierInfo();
1269 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info, End))
1270 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1271 /*Unevaluated*/ false, End))
12701272 return Err;
12711273 }
12721274 SM.onIdentifierExpr(Val, Identifier);
13661368 X86Operand *X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val,
13671369 StringRef &Identifier,
13681370 InlineAsmIdentifierInfo &Info,
1371 bool IsUnevaluatedOperand,
13691372 SMLoc &End) {
13701373 assert (isParsingInlineAsm() && "Expected to be parsing inline assembly.");
13711374 Val = 0;
13721375
13731376 StringRef LineBuf(Identifier.data());
1374 SemaCallback->LookupInlineAsmIdentifier(LineBuf, Info);
1375 unsigned BufLen = LineBuf.size();
1376 assert (BufLen && "Expected a non-zero length identifier.");
1377
1378 // Advance the token stream based on what the frontend parsed.
1377 SemaCallback->LookupInlineAsmIdentifier(LineBuf, Info, IsUnevaluatedOperand);
1378
13791379 const AsmToken &Tok = Parser.getTok();
1380 AsmToken IdentEnd = Tok;
1381 while (BufLen > 0) {
1382 IdentEnd = Tok;
1383 BufLen -= Tok.getString().size();
1384 getLexer().Lex(); // Consume the token.
1385 }
1386 if (BufLen != 0)
1387 return ErrorOperand(IdentEnd.getLoc(),
1388 "Frontend parser mismatch with asm lexer!");
1389 End = IdentEnd.getEndLoc();
1380
1381 // Advance the token stream until the end of the current token is
1382 // after the end of what the frontend claimed.
1383 const char *EndPtr = Tok.getLoc().getPointer() + LineBuf.size();
1384 while (true) {
1385 End = Tok.getEndLoc();
1386 getLexer().Lex();
1387
1388 assert(End.getPointer() <= EndPtr && "frontend claimed part of a token?");
1389 if (End.getPointer() == EndPtr) break;
1390 }
13901391
13911392 // Create the symbol reference.
13921393 Identifier = LineBuf;
14461447
14471448 InlineAsmIdentifierInfo Info;
14481449 StringRef Identifier = Tok.getString();
1449 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info, End))
1450 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1451 /*Unevaluated*/ false, End))
14501452 return Err;
14511453 return CreateMemForInlineAsm(/*SegReg=*/0, Val, /*BaseReg=*/0,/*IndexReg=*/0,
14521454 /*Scale=*/1, Start, End, Size, Identifier, Info);
15051507 InlineAsmIdentifierInfo Info;
15061508 SMLoc Start = Tok.getLoc(), End;
15071509 StringRef Identifier = Tok.getString();
1508 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info, End))
1510 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1511 /*Unevaluated*/ false, End))
15091512 return Err;
15101513
15111514 // Don't emit the offset operator.
15401543 InlineAsmIdentifierInfo Info;
15411544 SMLoc Start = Tok.getLoc(), End;
15421545 StringRef Identifier = Tok.getString();
1543 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info, End))
1546 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, Info,
1547 /*Unevaluated*/ true, End))
15441548 return Err;
15451549
15461550 unsigned CVal = 0;