From 44021515d76ec9b529f2adbc252552869b1357d5 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Mon, 22 Apr 2013 17:01:46 +0000 Subject: [PATCH] [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 --- include/llvm/MC/MCParser/MCAsmParser.h | 17 +++++-- lib/MC/MCParser/AsmParser.cpp | 7 +-- lib/Target/X86/AsmParser/X86AsmParser.cpp | 57 +++++++++-------------- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/include/llvm/MC/MCParser/MCAsmParser.h b/include/llvm/MC/MCParser/MCAsmParser.h index 601f8f7734b..0b817727f0a 100644 --- a/include/llvm/MC/MCParser/MCAsmParser.h +++ b/include/llvm/MC/MCParser/MCAsmParser.h @@ -33,10 +33,21 @@ class Twine; /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser. class MCAsmParserSemaCallback { public: + typedef struct { + bool IsVarDecl; + unsigned Length, Size, Type; + + void clear() { + IsVarDecl = false; + Length = 1; + Size = 0; + Type = 0; + } + } InlineAsmIdentifierInfo; + virtual ~MCAsmParserSemaCallback(); - virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc, - unsigned &Length, unsigned &Size, - unsigned &Type, bool &IsVarDecl) = 0; + virtual void *LookupInlineAsmIdentifier(StringRef &LineBuf, + InlineAsmIdentifierInfo &Info) = 0; virtual bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset) = 0; diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index be55d53d90f..d23a0ab59a3 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -4115,15 +4115,12 @@ AsmParser::parseMSInlineAsm(void *AsmLoc, std::string &AsmString, } // Expr/Input or Output. - bool IsVarDecl; - unsigned Length, Size, Type; StringRef SymName = Operand->getSymName(); if (SymName.empty()) continue; - void *OpDecl = SI.LookupInlineAsmIdentifier(SymName, AsmLoc, - Length, Size, Type, - IsVarDecl); + MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info; + void *OpDecl = SI.LookupInlineAsmIdentifier(SymName, Info); if (!OpDecl) continue; diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index 395fd97f96a..cafef648a62 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -1119,29 +1119,26 @@ X86Operand * X86AsmParser::CreateMemForInlineAsm(unsigned SegReg, const MCExpr *Disp, unsigned BaseReg, unsigned IndexReg, unsigned Scale, SMLoc Start, SMLoc End, - unsigned Size, StringRef SymName) { + unsigned Size, StringRef Identifier) { bool NeedSizeDir = false; if (const MCSymbolRefExpr *SymRef = dyn_cast(Disp)) { const MCSymbol &Sym = SymRef->getSymbol(); - // FIXME: The SemaLookup will fail if the name is anything other then an - // identifier. - // FIXME: Pass a valid SMLoc. - bool IsVarDecl = false; - unsigned tLength, tSize, tType; - SemaCallback->LookupInlineAsmIdentifier(Sym.getName(), NULL, tLength, tSize, - tType, IsVarDecl); + StringRef SymName = Sym.getName(); + MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info; + SemaCallback->LookupInlineAsmIdentifier(SymName, Info); + 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; } // 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 // operand to ensure proper matching. Just pick a GPR based on the size of // a pointer. - if (!IsVarDecl) { + if (!Info.IsVarDecl) { unsigned RegNo = is64BitMode() ? X86::RBX : X86::EBX; 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. BaseReg = BaseReg ? BaseReg : 1; return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale, Start, - End, Size, SymName); + End, Size, Identifier); } static void @@ -1368,7 +1365,6 @@ X86Operand *X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val, const AsmToken &Tok = Parser.getTok(); AsmToken IdentEnd = Tok; while (!Done) { - End = Tok.getLoc(); switch (getLexer().getKind()) { default: Done = true; @@ -1388,7 +1384,7 @@ X86Operand *X86AsmParser::ParseIntelIdentifier(const MCExpr *&Val, break; } } - + End = IdentEnd.getEndLoc(); unsigned Len = IdentEnd.getLoc().getPointer() - Identifier.data(); Identifier = StringRef(Identifier.data(), Len + IdentEnd.getString().size()); MCSymbol *Sym = getContext().GetOrCreateSymbol(Identifier); @@ -1536,33 +1532,26 @@ X86Operand *X86AsmParser::ParseIntelOperator(unsigned OpKind) { Parser.Lex(); // Eat operator. const MCExpr *Val = 0; - AsmToken StartTok = Tok; SMLoc Start = Tok.getLoc(), End; StringRef Identifier = Tok.getString(); if (X86Operand *Err = ParseIntelIdentifier(Val, Identifier, End)) return Err; - unsigned Length = 0, Size = 0, Type = 0; + unsigned CVal = 0; if (const MCSymbolRefExpr *SymRef = dyn_cast(Val)) { const MCSymbol &Sym = SymRef->getSymbol(); - // FIXME: The SemaLookup will fail if the name is anything other then an - // identifier. - // FIXME: Pass a valid SMLoc. - bool IsVarDecl; - if (!SemaCallback->LookupInlineAsmIdentifier(Sym.getName(), NULL, Length, - Size, Type, IsVarDecl)) - // FIXME: We don't warn on variables with namespace alias qualifiers - // because support still needs to be added in the frontend. - if (Identifier.equals(StartTok.getString())) - return ErrorOperand(Start, "Unable to lookup expr!"); - } - unsigned CVal; - 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; - } + StringRef SymName = Sym.getName(); + MCAsmParserSemaCallback::InlineAsmIdentifierInfo Info; + SemaCallback->LookupInlineAsmIdentifier(SymName, Info); + + switch(OpKind) { + default: llvm_unreachable("Unexpected operand kind!"); + case IOK_LENGTH: CVal = Info.Length; break; + case IOK_SIZE: CVal = Info.Size; break; + case IOK_TYPE: CVal = Info.Type; break; + } + } else + return ErrorOperand(Start, "Expected a MCSymbolRefExpr!"); // Rewrite the type operator and the C or C++ type or variable in terms of an // immediate. E.g. TYPE foo -> $$4 -- 2.34.1