llvm.org GIT mirror llvm / 4402151
[ms-inline asm] Refactor/clean up the SemaLookup interface. No functional change indended. Part of rdar://13663589 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180028 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 7 years ago
3 changed file(s) with 39 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
3232 /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
3333 class MCAsmParserSemaCallback {
3434 public:
35 typedef struct {
36 bool IsVarDecl;
37 unsigned Length, Size, Type;
38
39 void clear() {
40 IsVarDecl = false;
41 Length = 1;
42 Size = 0;
43 Type = 0;
44 }
45 } InlineAsmIdentifierInfo;
46
3547 virtual ~MCAsmParserSemaCallback();
36 virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc,
37 unsigned &Length, unsigned &Size,
38 unsigned &Type, bool &IsVarDecl) = 0;
48 virtual void *LookupInlineAsmIdentifier(StringRef &LineBuf,
49 InlineAsmIdentifierInfo &Info) = 0;
3950
4051 virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
4152 unsigned &Offset) = 0;
41144114 }
41154115
41164116 // Expr/Input or Output.
4117 bool IsVarDecl;
4118 unsigned Length, Size, Type;
41194117 StringRef SymName = Operand->getSymName();
41204118 if (SymName.empty())
41214119 continue;
41224120
4123 void *OpDecl = SI.LookupInlineAsmIdentifier(SymName, AsmLoc,
4124 Length, Size, Type,
4125 IsVarDecl);
4121 MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info;
4122 void *OpDecl = SI.LookupInlineAsmIdentifier(SymName, Info);
41264123 if (!OpDecl)
41274124 continue;
41284125
11181118 X86AsmParser::CreateMemForInlineAsm(unsigned SegReg, const MCExpr *Disp,
11191119 unsigned BaseReg, unsigned IndexReg,
11201120 unsigned Scale, SMLoc Start, SMLoc End,
1121 unsigned Size, StringRef SymName) {
1121 unsigned Size, StringRef Identifier) {
11221122 bool NeedSizeDir = false;
11231123 if (const MCSymbolRefExpr *SymRef = dyn_cast(Disp)) {
11241124 const MCSymbol &Sym = SymRef->getSymbol();
1125 // FIXME: The SemaLookup will fail if the name is anything other then an
1126 // identifier.
1127 // FIXME: Pass a valid SMLoc.
1128 bool IsVarDecl = false;
1129 unsigned tLength, tSize, tType;
1130 SemaCallback->LookupInlineAsmIdentifier(Sym.getName(), NULL, tLength, tSize,
1131 tType, IsVarDecl);
1125 StringRef SymName = Sym.getName();
1126 MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info;
1127 SemaCallback->LookupInlineAsmIdentifier(SymName, Info);
1128
11321129 if (!Size) {
1133 Size = tType * 8; // Size is in terms of bits in this context.
1130 Size = Info.Type * 8; // Size is in terms of bits in this context.
11341131 NeedSizeDir = Size > 0;
11351132 }
11361133 // If this is not a VarDecl then assume it is a FuncDecl or some other label
11371134 // reference. We need an 'r' constraint here, so we need to create register
11381135 // operand to ensure proper matching. Just pick a GPR based on the size of
11391136 // a pointer.
1140 if (!IsVarDecl) {
1137 if (!Info.IsVarDecl) {
11411138 unsigned RegNo = is64BitMode() ? X86::RBX : X86::EBX;
11421139 return X86Operand::CreateReg(RegNo, Start, End, /*AddressOf=*/true,
1143 SMLoc(), SymName);
1140 SMLoc(), Identifier);
11441141 }
11451142 }
11461143
11531150 // get the matching correct in some cases.
11541151 BaseReg = BaseReg ? BaseReg : 1;
11551152 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
1156 End, Size, SymName);
1153 End, Size, Identifier);
11571154 }
11581155
11591156 static void
13671364 const AsmToken &Tok = Parser.getTok();
13681365 AsmToken IdentEnd = Tok;
13691366 while (!Done) {
1370 End = Tok.getLoc();
13711367 switch (getLexer().getKind()) {
13721368 default:
13731369 Done = true;
13871383 break;
13881384 }
13891385 }
1390
1386 End = IdentEnd.getEndLoc();
13911387 unsigned Len = IdentEnd.getLoc().getPointer() - Identifier.data();
13921388 Identifier = StringRef(Identifier.data(), Len + IdentEnd.getString().size());
13931389 MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier);
15351531 Parser.Lex(); // Eat operator.
15361532
15371533 const MCExpr *Val = 0;
1538 AsmToken StartTok = Tok;
15391534 SMLoc Start = Tok.getLoc(), End;
15401535 StringRef Identifier = Tok.getString();
15411536 if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, End))
15421537 return Err;
15431538
1544 unsigned Length = 0, Size = 0, Type = 0;
1539 unsigned CVal = 0;
15451540 if (const MCSymbolRefExpr *SymRef = dyn_cast(Val)) {
15461541 const MCSymbol &Sym = SymRef->getSymbol();
1547 // FIXME: The SemaLookup will fail if the name is anything other then an
1548 // identifier.
1549 // FIXME: Pass a valid SMLoc.
1550 bool IsVarDecl;
1551 if (!SemaCallback->LookupInlineAsmIdentifier(Sym.getName(), NULL, Length,
1552 Size, Type, IsVarDecl))
1553 // FIXME: We don't warn on variables with namespace alias qualifiers
1554 // because support still needs to be added in the frontend.
1555 if (Identifier.equals(StartTok.getString()))
1556 return ErrorOperand(Start, "Unable to lookup expr!");
1557 }
1558 unsigned CVal;
1559 switch(OpKind) {
1560 default: llvm_unreachable("Unexpected operand kind!");
1561 case IOK_LENGTH: CVal = Length; break;
1562 case IOK_SIZE: CVal = Size; break;
1563 case IOK_TYPE: CVal = Type; break;
1564 }
1542 StringRef SymName = Sym.getName();
1543 MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info;
1544 SemaCallback->LookupInlineAsmIdentifier(SymName, Info);
1545
1546 switch(OpKind) {
1547 default: llvm_unreachable("Unexpected operand kind!");
1548 case IOK_LENGTH: CVal = Info.Length; break;
1549 case IOK_SIZE: CVal = Info.Size; break;
1550 case IOK_TYPE: CVal = Info.Type; break;
1551 }
1552 } else
1553 return ErrorOperand(Start, "Expected a MCSymbolRefExpr!");
15651554
15661555 // Rewrite the type operator and the C or C++ type or variable in terms of an
15671556 // immediate. E.g. TYPE foo -> $$4