From 6a020a71173a3ea7738a9df69982e85ddbfe0303 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Thu, 25 Oct 2012 20:41:34 +0000 Subject: [PATCH] [ms-inline asm] Add support for creating AsmRewrites in the target specific AsmParser logic. To be used/tested in a subsequent commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166714 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCTargetAsmParser.h | 36 ++++++++++++++++++- lib/MC/MCDisassembler/EDDisassembler.cpp | 3 +- lib/MC/MCParser/AsmParser.cpp | 33 +++++------------ lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 6 ++-- .../MBlaze/AsmParser/MBlazeAsmParser.cpp | 5 +-- lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 5 +-- lib/Target/X86/AsmParser/X86AsmParser.cpp | 9 +++-- 7 files changed, 61 insertions(+), 36 deletions(-) diff --git a/include/llvm/MC/MCTargetAsmParser.h b/include/llvm/MC/MCTargetAsmParser.h index 05537f9211f..97ca78527e5 100644 --- a/include/llvm/MC/MCTargetAsmParser.h +++ b/include/llvm/MC/MCTargetAsmParser.h @@ -21,6 +21,39 @@ class MCParsedAsmOperand; class MCInst; template class SmallVectorImpl; +namespace { +enum AsmRewriteKind { + AOK_Imm, + AOK_Input, + AOK_Output, + AOK_SizeDirective, + AOK_Emit, + AOK_Skip, + AOK_DotOperator +}; + +struct AsmRewrite { + AsmRewriteKind Kind; + SMLoc Loc; + unsigned Len; + unsigned Val; +public: + AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, unsigned val = 0) + : Kind(kind), Loc(loc), Len(len), Val(val) {} +}; +} + +struct ParseInstructionInfo { + + SmallVectorImpl *AsmRewrites; + + ParseInstructionInfo() : AsmRewrites(0) {} + ParseInstructionInfo(SmallVectorImpl *rewrites) + : AsmRewrites(rewrites) {} + + ~ParseInstructionInfo() {} +}; + /// MCTargetAsmParser - Generic interface to target specific assembly parsers. class MCTargetAsmParser : public MCAsmParserExtension { public: @@ -77,7 +110,8 @@ public: /// \param Operands [out] - The list of parsed operands, this returns /// ownership of them to the caller. /// \return True on failure. - virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc, + virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, + SMLoc NameLoc, SmallVectorImpl &Operands) = 0; /// ParseDirective - Parse a target specific assembler directive diff --git a/lib/MC/MCDisassembler/EDDisassembler.cpp b/lib/MC/MCDisassembler/EDDisassembler.cpp index 1226f1a2e32..eed7a771b97 100644 --- a/lib/MC/MCDisassembler/EDDisassembler.cpp +++ b/lib/MC/MCDisassembler/EDDisassembler.cpp @@ -366,8 +366,9 @@ int EDDisassembler::parseInst(SmallVectorImpl &operands, instName = OpcodeToken.getString(); instLoc = OpcodeToken.getLoc(); + ParseInstructionInfo Info; if (NextToken.isNot(AsmToken::Eof) && - TargetParser->ParseInstruction(instName, instLoc, operands)) + TargetParser->ParseInstruction(Info, instName, instLoc, operands)) ret = -1; } else { ret = -1; diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 5e4447a321d..b47a6bdb540 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -86,7 +86,7 @@ public: MemoryBuffer *I); }; -struct AsmRewrite; +//struct AsmRewrite; struct ParseStatementInfo { /// ParsedOperands - The parsed operands from the last parsed statement. SmallVector ParsedOperands; @@ -1365,8 +1365,9 @@ bool AsmParser::ParseStatement(ParseStatementInfo &Info) { for (unsigned i = 0, e = IDVal.size(); i != e; ++i) OpcodeStr.push_back(tolower(IDVal[i])); - bool HadError = getTargetParser().ParseInstruction(OpcodeStr.str(), IDLoc, - Info.ParsedOperands); + ParseInstructionInfo IInfo(Info.AsmRewrites); + bool HadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr.str(), + IDLoc,Info.ParsedOperands); // Dump the parsed representation, if requested. if (getShowParsedOperands()) { @@ -3583,27 +3584,6 @@ bool AsmParser::ParseDirectiveEndr(SMLoc DirectiveLoc) { return false; } -namespace { -enum AsmRewriteKind { - AOK_Imm, - AOK_Input, - AOK_Output, - AOK_SizeDirective, - AOK_Emit, - AOK_Skip -}; - -struct AsmRewrite { - AsmRewriteKind Kind; - SMLoc Loc; - unsigned Len; - unsigned Size; -public: - AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, unsigned size = 0) - : Kind(kind), Loc(loc), Len(len), Size(size) { } -}; -} - bool AsmParser::ParseDirectiveEmit(SMLoc IDLoc, ParseStatementInfo &Info) { const MCExpr *Value; SMLoc ExprLoc = getLexer().getLoc(); @@ -3780,7 +3760,7 @@ bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString, OS << OutputIdx++; break; case AOK_SizeDirective: - switch((*I).Size) { + switch((*I).Val) { default: break; case 8: OS << "byte ptr "; break; case 16: OS << "word ptr "; break; @@ -3794,6 +3774,9 @@ bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString, case AOK_Emit: OS << ".byte"; break; + case AOK_DotOperator: + OS << (*I).Val; + break; } // Skip the original expression. diff --git a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index 0eec8622e97..c61e3bd99d7 100644 --- a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -253,7 +253,8 @@ public: // Implementation of the MCTargetAsmParser interface: bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc); - bool ParseInstruction(StringRef Name, SMLoc NameLoc, + bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, + SMLoc NameLoc, SmallVectorImpl &Operands); bool ParseDirective(AsmToken DirectiveID); @@ -4954,7 +4955,8 @@ static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) { static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features); /// Parse an arm instruction mnemonic followed by its operands. -bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc, +bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, + SMLoc NameLoc, SmallVectorImpl &Operands) { // Apply mnemonic aliases before doing anything else, as the destination // mnemnonic may include suffices and we want to handle them normally. diff --git a/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp b/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp index 9e28a3d7d09..f7809caeb32 100644 --- a/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp +++ b/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp @@ -61,7 +61,8 @@ public: MBlazeAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser) : MCTargetAsmParser(), Parser(_Parser) {} - virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc, + virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, + SMLoc NameLoc, SmallVectorImpl &Operands); virtual bool ParseDirective(AsmToken DirectiveID); @@ -477,7 +478,7 @@ ParseOperand(SmallVectorImpl &Operands) { /// Parse an mblaze instruction mnemonic followed by its operands. bool MBlazeAsmParser:: -ParseInstruction(StringRef Name, SMLoc NameLoc, +ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, SmallVectorImpl &Operands) { // The first operands is the token for the instruction name size_t dotLoc = Name.find('.'); diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 00649d2f187..67b524883cf 100644 --- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -74,7 +74,8 @@ class MipsAsmParser : public MCTargetAsmParser { bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc); - bool ParseInstruction(StringRef Name, SMLoc NameLoc, + bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, + SMLoc NameLoc, SmallVectorImpl &Operands); bool parseMathOperation(StringRef Name, SMLoc NameLoc, @@ -1056,7 +1057,7 @@ parseMathOperation(StringRef Name, SMLoc NameLoc, } bool MipsAsmParser:: -ParseInstruction(StringRef Name, SMLoc NameLoc, +ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, SmallVectorImpl &Operands) { // floating point instructions: should register be treated as double? if (requestsDoubleOperand(Name)) { diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index 7df8be7607a..00e95596a0a 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -35,6 +35,7 @@ struct X86Operand; class X86AsmParser : public MCTargetAsmParser { MCSubtargetInfo &STI; MCAsmParser &Parser; + ParseInstructionInfo *InstInfo; private: MCAsmParser &getParser() const { return Parser; } @@ -101,14 +102,15 @@ private: public: X86AsmParser(MCSubtargetInfo &sti, MCAsmParser &parser) - : MCTargetAsmParser(), STI(sti), Parser(parser) { + : MCTargetAsmParser(), STI(sti), Parser(parser), InstInfo(0) { // Initialize the set of available features. setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); } virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc); - virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc, + virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, + SMLoc NameLoc, SmallVectorImpl &Operands); virtual bool ParseDirective(AsmToken DirectiveID); @@ -1106,8 +1108,9 @@ X86Operand *X86AsmParser::ParseMemOperand(unsigned SegReg, SMLoc MemStart) { } bool X86AsmParser:: -ParseInstruction(StringRef Name, SMLoc NameLoc, +ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, SmallVectorImpl &Operands) { + InstInfo = &Info; StringRef PatchedName = Name; // FIXME: Hack to recognize setneb as setne. -- 2.34.1