llvm.org GIT mirror llvm / 6a020a7
[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 Chad Rosier 7 years ago
7 changed file(s) with 61 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
1919 class MCParsedAsmOperand;
2020 class MCInst;
2121 template class SmallVectorImpl;
22
23 namespace {
24 enum AsmRewriteKind {
25 AOK_Imm,
26 AOK_Input,
27 AOK_Output,
28 AOK_SizeDirective,
29 AOK_Emit,
30 AOK_Skip,
31 AOK_DotOperator
32 };
33
34 struct AsmRewrite {
35 AsmRewriteKind Kind;
36 SMLoc Loc;
37 unsigned Len;
38 unsigned Val;
39 public:
40 AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, unsigned val = 0)
41 : Kind(kind), Loc(loc), Len(len), Val(val) {}
42 };
43 }
44
45 struct ParseInstructionInfo {
46
47 SmallVectorImpl *AsmRewrites;
48
49 ParseInstructionInfo() : AsmRewrites(0) {}
50 ParseInstructionInfo(SmallVectorImpl *rewrites)
51 : AsmRewrites(rewrites) {}
52
53 ~ParseInstructionInfo() {}
54 };
2255
2356 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
2457 class MCTargetAsmParser : public MCAsmParserExtension {
76109 /// \param Operands [out] - The list of parsed operands, this returns
77110 /// ownership of them to the caller.
78111 /// \return True on failure.
79 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
112 virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
113 SMLoc NameLoc,
80114 SmallVectorImpl &Operands) = 0;
81115
82116 /// ParseDirective - Parse a target specific assembler directive
365365 instName = OpcodeToken.getString();
366366 instLoc = OpcodeToken.getLoc();
367367
368 ParseInstructionInfo Info;
368369 if (NextToken.isNot(AsmToken::Eof) &&
369 TargetParser->ParseInstruction(instName, instLoc, operands))
370 TargetParser->ParseInstruction(Info, instName, instLoc, operands))
370371 ret = -1;
371372 } else {
372373 ret = -1;
8585 MemoryBuffer *I);
8686 };
8787
88 struct AsmRewrite;
88 //struct AsmRewrite;
8989 struct ParseStatementInfo {
9090 /// ParsedOperands - The parsed operands from the last parsed statement.
9191 SmallVector ParsedOperands;
13641364 for (unsigned i = 0, e = IDVal.size(); i != e; ++i)
13651365 OpcodeStr.push_back(tolower(IDVal[i]));
13661366
1367 bool HadError = getTargetParser().ParseInstruction(OpcodeStr.str(), IDLoc,
1368 Info.ParsedOperands);
1367 ParseInstructionInfo IInfo(Info.AsmRewrites);
1368 bool HadError = getTargetParser().ParseInstruction(IInfo, OpcodeStr.str(),
1369 IDLoc,Info.ParsedOperands);
13691370
13701371 // Dump the parsed representation, if requested.
13711372 if (getShowParsedOperands()) {
35823583 return false;
35833584 }
35843585
3585 namespace {
3586 enum AsmRewriteKind {
3587 AOK_Imm,
3588 AOK_Input,
3589 AOK_Output,
3590 AOK_SizeDirective,
3591 AOK_Emit,
3592 AOK_Skip
3593 };
3594
3595 struct AsmRewrite {
3596 AsmRewriteKind Kind;
3597 SMLoc Loc;
3598 unsigned Len;
3599 unsigned Size;
3600 public:
3601 AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, unsigned size = 0)
3602 : Kind(kind), Loc(loc), Len(len), Size(size) { }
3603 };
3604 }
3605
36063586 bool AsmParser::ParseDirectiveEmit(SMLoc IDLoc, ParseStatementInfo &Info) {
36073587 const MCExpr *Value;
36083588 SMLoc ExprLoc = getLexer().getLoc();
37793759 OS << OutputIdx++;
37803760 break;
37813761 case AOK_SizeDirective:
3782 switch((*I).Size) {
3762 switch((*I).Val) {
37833763 default: break;
37843764 case 8: OS << "byte ptr "; break;
37853765 case 16: OS << "word ptr "; break;
37933773 case AOK_Emit:
37943774 OS << ".byte";
37953775 break;
3776 case AOK_DotOperator:
3777 OS << (*I).Val;
3778 break;
37963779 }
37973780
37983781 // Skip the original expression.
252252
253253 // Implementation of the MCTargetAsmParser interface:
254254 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
255 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
255 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
256 SMLoc NameLoc,
256257 SmallVectorImpl &Operands);
257258 bool ParseDirective(AsmToken DirectiveID);
258259
49534954
49544955 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
49554956 /// Parse an arm instruction mnemonic followed by its operands.
4956 bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4957 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
4958 SMLoc NameLoc,
49574959 SmallVectorImpl &Operands) {
49584960 // Apply mnemonic aliases before doing anything else, as the destination
49594961 // mnemnonic may include suffices and we want to handle them normally.
6060 MBlazeAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
6161 : MCTargetAsmParser(), Parser(_Parser) {}
6262
63 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
63 virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
64 SMLoc NameLoc,
6465 SmallVectorImpl &Operands);
6566
6667 virtual bool ParseDirective(AsmToken DirectiveID);
476477
477478 /// Parse an mblaze instruction mnemonic followed by its operands.
478479 bool MBlazeAsmParser::
479 ParseInstruction(StringRef Name, SMLoc NameLoc,
480 ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
480481 SmallVectorImpl &Operands) {
481482 // The first operands is the token for the instruction name
482483 size_t dotLoc = Name.find('.');
7373
7474 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
7575
76 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
76 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
77 SMLoc NameLoc,
7778 SmallVectorImpl &Operands);
7879
7980 bool parseMathOperation(StringRef Name, SMLoc NameLoc,
10551056 }
10561057
10571058 bool MipsAsmParser::
1058 ParseInstruction(StringRef Name, SMLoc NameLoc,
1059 ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
10591060 SmallVectorImpl &Operands) {
10601061 // floating point instructions: should register be treated as double?
10611062 if (requestsDoubleOperand(Name)) {
3434 class X86AsmParser : public MCTargetAsmParser {
3535 MCSubtargetInfo &STI;
3636 MCAsmParser &Parser;
37 ParseInstructionInfo *InstInfo;
3738 private:
3839 MCAsmParser &getParser() const { return Parser; }
3940
100101
101102 public:
102103 X86AsmParser(MCSubtargetInfo &sti, MCAsmParser &parser)
103 : MCTargetAsmParser(), STI(sti), Parser(parser) {
104 : MCTargetAsmParser(), STI(sti), Parser(parser), InstInfo(0) {
104105
105106 // Initialize the set of available features.
106107 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
107108 }
108109 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
109110
110 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
111 virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
112 SMLoc NameLoc,
111113 SmallVectorImpl &Operands);
112114
113115 virtual bool ParseDirective(AsmToken DirectiveID);
11051107 }
11061108
11071109 bool X86AsmParser::
1108 ParseInstruction(StringRef Name, SMLoc NameLoc,
1110 ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
11091111 SmallVectorImpl &Operands) {
1112 InstInfo = &Info;
11101113 StringRef PatchedName = Name;
11111114
11121115 // FIXME: Hack to recognize setneb as setne.