[ms-inline asm] Refactor/clean up the SemaLookup interface. No functional

change indended.
Part of rdar://13663589

llvm-svn: 180028
This commit is contained in:
Chad Rosier 2013-04-22 17:01:46 +00:00
parent b18a285525
commit f6675c3d3e
3 changed files with 39 additions and 42 deletions
llvm
include/llvm/MC/MCParser
lib
MC/MCParser
Target/X86/AsmParser

View File

@ -33,10 +33,21 @@ class Twine;
/// MCAsmParserSemaCallback - Generic Sema callback for assembly parser. /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
class MCAsmParserSemaCallback { class MCAsmParserSemaCallback {
public: public:
typedef struct {
bool IsVarDecl;
unsigned Length, Size, Type;
void clear() {
IsVarDecl = false;
Length = 1;
Size = 0;
Type = 0;
}
} InlineAsmIdentifierInfo;
virtual ~MCAsmParserSemaCallback(); virtual ~MCAsmParserSemaCallback();
virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc, virtual void *LookupInlineAsmIdentifier(StringRef &LineBuf,
unsigned &Length, unsigned &Size, InlineAsmIdentifierInfo &Info) = 0;
unsigned &Type, bool &IsVarDecl) = 0;
virtual bool LookupInlineAsmField(StringRef Base, StringRef Member, virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
unsigned &Offset) = 0; unsigned &Offset) = 0;

View File

@ -4115,15 +4115,12 @@ AsmParser::parseMSInlineAsm(void *AsmLoc, std::string &AsmString,
} }
// Expr/Input or Output. // Expr/Input or Output.
bool IsVarDecl;
unsigned Length, Size, Type;
StringRef SymName = Operand->getSymName(); StringRef SymName = Operand->getSymName();
if (SymName.empty()) if (SymName.empty())
continue; continue;
void *OpDecl = SI.LookupInlineAsmIdentifier(SymName, AsmLoc, MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info;
Length, Size, Type, void *OpDecl = SI.LookupInlineAsmIdentifier(SymName, Info);
IsVarDecl);
if (!OpDecl) if (!OpDecl)
continue; continue;

View File

@ -1119,29 +1119,26 @@ X86Operand *
X86AsmParser::CreateMemForInlineAsm(unsigned SegReg, const MCExpr *Disp, X86AsmParser::CreateMemForInlineAsm(unsigned SegReg, const MCExpr *Disp,
unsigned BaseReg, unsigned IndexReg, unsigned BaseReg, unsigned IndexReg,
unsigned Scale, SMLoc Start, SMLoc End, unsigned Scale, SMLoc Start, SMLoc End,
unsigned Size, StringRef SymName) { unsigned Size, StringRef Identifier) {
bool NeedSizeDir = false; bool NeedSizeDir = false;
if (const MCSymbolRefExpr *SymRef = dyn_cast<MCSymbolRefExpr>(Disp)) { if (const MCSymbolRefExpr *SymRef = dyn_cast<MCSymbolRefExpr>(Disp)) {
const MCSymbol &Sym = SymRef->getSymbol(); const MCSymbol &Sym = SymRef->getSymbol();
// FIXME: The SemaLookup will fail if the name is anything other then an StringRef SymName = Sym.getName();
// identifier. MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info;
// FIXME: Pass a valid SMLoc. SemaCallback->LookupInlineAsmIdentifier(SymName, Info);
bool IsVarDecl = false;
unsigned tLength, tSize, tType;
SemaCallback->LookupInlineAsmIdentifier(Sym.getName(), NULL, tLength, tSize,
tType, IsVarDecl);
if (!Size) { if (!Size) {
Size = tType * 8; // Size is in terms of bits in this context. Size = Info.Type * 8; // Size is in terms of bits in this context.
NeedSizeDir = Size > 0; NeedSizeDir = Size > 0;
} }
// If this is not a VarDecl then assume it is a FuncDecl or some other label // If this is not a VarDecl then assume it is a FuncDecl or some other label
// reference. We need an 'r' constraint here, so we need to create register // reference. We need an 'r' constraint here, so we need to create register
// operand to ensure proper matching. Just pick a GPR based on the size of // operand to ensure proper matching. Just pick a GPR based on the size of
// a pointer. // a pointer.
if (!IsVarDecl) { if (!Info.IsVarDecl) {
unsigned RegNo = is64BitMode() ? X86::RBX : X86::EBX; unsigned RegNo = is64BitMode() ? X86::RBX : X86::EBX;
return X86Operand::CreateReg(RegNo, Start, End, /*AddressOf=*/true, return X86Operand::CreateReg(RegNo, Start, End, /*AddressOf=*/true,
SMLoc(), SymName); SMLoc(), Identifier);
} }
} }
@ -1154,7 +1151,7 @@ X86AsmParser::CreateMemForInlineAsm(unsigned SegReg, const MCExpr *Disp,
// get the matching correct in some cases. // get the matching correct in some cases.
BaseReg = BaseReg ? BaseReg : 1; BaseReg = BaseReg ? BaseReg : 1;
return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start, return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start,
End, Size, SymName); End, Size, Identifier);
} }
static void static void
@ -1368,7 +1365,6 @@ X86Operand *X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val,
const AsmToken &Tok = Parser.getTok(); const AsmToken &Tok = Parser.getTok();
AsmToken IdentEnd = Tok; AsmToken IdentEnd = Tok;
while (!Done) { while (!Done) {
End = Tok.getLoc();
switch (getLexer().getKind()) { switch (getLexer().getKind()) {
default: default:
Done = true; Done = true;
@ -1388,7 +1384,7 @@ X86Operand *X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val,
break; break;
} }
} }
End = IdentEnd.getEndLoc();
unsigned Len = IdentEnd.getLoc().getPointer() - Identifier.data(); unsigned Len = IdentEnd.getLoc().getPointer() - Identifier.data();
Identifier = StringRef(Identifier.data(), Len + IdentEnd.getString().size()); Identifier = StringRef(Identifier.data(), Len + IdentEnd.getString().size());
MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier); MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier);
@ -1536,33 +1532,26 @@ X86Operand *X86AsmParser::ParseIntelOperator(unsigned OpKind) {
Parser.Lex(); // Eat operator. Parser.Lex(); // Eat operator.
const MCExpr *Val = 0; const MCExpr *Val = 0;
AsmToken StartTok = Tok;
SMLoc Start = Tok.getLoc(), End; SMLoc Start = Tok.getLoc(), End;
StringRef Identifier = Tok.getString(); StringRef Identifier = Tok.getString();
if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, End)) if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, End))
return Err; return Err;
unsigned Length = 0, Size = 0, Type = 0; unsigned CVal = 0;
if (const MCSymbolRefExpr *SymRef = dyn_cast<MCSymbolRefExpr>(Val)) { if (const MCSymbolRefExpr *SymRef = dyn_cast<MCSymbolRefExpr>(Val)) {
const MCSymbol &Sym = SymRef->getSymbol(); const MCSymbol &Sym = SymRef->getSymbol();
// FIXME: The SemaLookup will fail if the name is anything other then an StringRef SymName = Sym.getName();
// identifier. MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info;
// FIXME: Pass a valid SMLoc. SemaCallback->LookupInlineAsmIdentifier(SymName, Info);
bool IsVarDecl;
if (!SemaCallback->LookupInlineAsmIdentifier(Sym.getName(), NULL, Length, switch(OpKind) {
Size, Type, IsVarDecl)) default: llvm_unreachable("Unexpected operand kind!");
// FIXME: We don't warn on variables with namespace alias qualifiers case IOK_LENGTH: CVal = Info.Length; break;
// because support still needs to be added in the frontend. case IOK_SIZE: CVal = Info.Size; break;
if (Identifier.equals(StartTok.getString())) case IOK_TYPE: CVal = Info.Type; break;
return ErrorOperand(Start, "Unable to lookup expr!"); }
} } else
unsigned CVal; return ErrorOperand(Start, "Expected a MCSymbolRefExpr!");
switch(OpKind) {
default: llvm_unreachable("Unexpected operand kind!");
case IOK_LENGTH: CVal = Length; break;
case IOK_SIZE: CVal = Size; break;
case IOK_TYPE: CVal = Type; break;
}
// Rewrite the type operator and the C or C++ type or variable in terms of an // Rewrite the type operator and the C or C++ type or variable in terms of an
// immediate. E.g. TYPE foo -> $$4 // immediate. E.g. TYPE foo -> $$4