llvm.org GIT mirror llvm / 2fbc239
[ms-inline asm] Add support for the [] operator. Essentially, [expr1][expr2] is equivalent to [expr1 + expr2]. See test cases for more examples. rdar://12470392 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166949 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 7 years ago
3 changed file(s) with 195 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
694694 if (getLexer().isNot(AsmToken::RBrac))
695695 return ErrorOperand(Start, "Expected ']' token!");
696696 Parser.Lex();
697 End = Tok.getLoc();
697698 return X86Operand::CreateMem(Disp, Start, End, Size);
698699 }
699700 } else if (getLexer().is(AsmToken::Integer)) {
703704 if (getLexer().is(AsmToken::RBrac)) {
704705 // Handle '[' number ']'
705706 Parser.Lex();
707 End = Tok.getLoc();
706708 const MCExpr *Disp = MCConstantExpr::Create(Val, getContext());
707709 if (SegReg)
708710 return X86Operand::CreateMem(SegReg, Disp, 0, 0, Scale,
719721 return ErrorOperand(Loc, "Unexpected token");
720722 }
721723
722 if (getLexer().is(AsmToken::Plus) || getLexer().is(AsmToken::Minus)) {
723 bool isPlus = getLexer().is(AsmToken::Plus);
724 // Parse ][ as a plus.
725 bool ExpectRBrac = true;
726 if (getLexer().is(AsmToken::RBrac)) {
727 ExpectRBrac = false;
724728 Parser.Lex();
729 End = Tok.getLoc();
730 }
731
732 if (getLexer().is(AsmToken::Plus) || getLexer().is(AsmToken::Minus) ||
733 getLexer().is(AsmToken::LBrac)) {
734 ExpectRBrac = true;
735 bool isPlus = getLexer().is(AsmToken::Plus) ||
736 getLexer().is(AsmToken::LBrac);
737 Parser.Lex();
725738 SMLoc PlusLoc = Tok.getLoc();
726739 if (getLexer().is(AsmToken::Integer)) {
727740 int64_t Val = Tok.getIntVal();
745758 else if (getParser().ParseExpression(Disp, End)) return 0;
746759 }
747760 }
748
749 if (getLexer().isNot(AsmToken::RBrac))
750 if (getParser().ParseExpression(Disp, End)) return 0;
751
752 End = Tok.getLoc();
753 if (getLexer().isNot(AsmToken::RBrac))
754 return ErrorOperand(End, "expected ']' token!");
755 Parser.Lex();
756 End = Tok.getLoc();
761
762 // Parse ][ as a plus.
763 if (getLexer().is(AsmToken::RBrac)) {
764 ExpectRBrac = false;
765 Parser.Lex();
766 End = Tok.getLoc();
767 if (getLexer().is(AsmToken::LBrac)) {
768 ExpectRBrac = true;
769 Parser.Lex();
770 if (getParser().ParseExpression(Disp, End))
771 return 0;
772 }
773 } else if (ExpectRBrac) {
774 if (getParser().ParseExpression(Disp, End))
775 return 0;
776 }
777
778 if (ExpectRBrac) {
779 if (getLexer().isNot(AsmToken::RBrac))
780 return ErrorOperand(End, "expected ']' token!");
781 Parser.Lex();
782 End = Tok.getLoc();
783 }
757784
758785 // Parse the dot operator (e.g., [ebx].foo.bar).
759786 if (Tok.getString().startswith(".")) {
6060 ; CHECK: .att_syntax
6161 ; CHECK: {{## InlineAsm End|#NO_APP}}
6262 }
63
64 define void @t21() nounwind {
65 ; CHECK: t21
66 entry:
67 br label %foo
68
69 foo: ; preds = %entry
70 call void asm sideeffect inteldialect "mov eax, [4*eax + 4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
71 ; CHECK: {{## InlineAsm Start|#APP}}
72 ; CHECK: .intel_syntax
73 ; CHECK: mov eax, [4*eax + 4]
74 ; CHECK: .att_syntax
75 ; CHECK: {{## InlineAsm End|#NO_APP}}
76
77 call void asm sideeffect inteldialect "mov eax, [4*eax][4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
78 ; CHECK: {{## InlineAsm Start|#APP}}
79 ; CHECK: .intel_syntax
80 ; CHECK: mov eax, [4*eax][4]
81 ; CHECK: .att_syntax
82 ; CHECK: {{## InlineAsm End|#NO_APP}}
83
84 call void asm sideeffect inteldialect "mov eax, [esi + eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
85 ; CHECK: {{## InlineAsm Start|#APP}}
86 ; CHECK: .intel_syntax
87 ; CHECK: mov eax, [esi + eax]
88 ; CHECK: .att_syntax
89 ; CHECK: {{## InlineAsm End|#NO_APP}}
90
91 call void asm sideeffect inteldialect "mov eax, [esi][eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
92 ; CHECK: {{## InlineAsm Start|#APP}}
93 ; CHECK: .intel_syntax
94 ; CHECK: mov eax, [esi][eax]
95 ; CHECK: .att_syntax
96 ; CHECK: {{## InlineAsm End|#NO_APP}}
97
98 call void asm sideeffect inteldialect "mov eax, [esi + 4*eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
99 ; CHECK: {{## InlineAsm Start|#APP}}
100 ; CHECK: .intel_syntax
101 ; CHECK: mov eax, [esi + 4*eax]
102 ; CHECK: .att_syntax
103 ; CHECK: {{## InlineAsm End|#NO_APP}}
104
105 call void asm sideeffect inteldialect "mov eax, [esi][4*eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
106 ; CHECK: {{## InlineAsm Start|#APP}}
107 ; CHECK: .intel_syntax
108 ; CHECK: mov eax, [esi][4*eax]
109 ; CHECK: .att_syntax
110 ; CHECK: {{## InlineAsm End|#NO_APP}}
111
112 call void asm sideeffect inteldialect "mov eax, [esi + eax + 4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
113 ; CHECK: {{## InlineAsm Start|#APP}}
114 ; CHECK: .intel_syntax
115 ; CHECK: mov eax, [esi + eax + 4]
116 ; CHECK: .att_syntax
117 ; CHECK: {{## InlineAsm End|#NO_APP}}
118
119 call void asm sideeffect inteldialect "mov eax, [esi][eax + 4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
120 ; CHECK: {{## InlineAsm Start|#APP}}
121 ; CHECK: .intel_syntax
122 ; CHECK: mov eax, [esi][eax + 4]
123 ; CHECK: .att_syntax
124 ; CHECK: {{## InlineAsm End|#NO_APP}}
125
126 call void asm sideeffect inteldialect "mov eax, [esi + eax][4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
127 ; CHECK: {{## InlineAsm Start|#APP}}
128 ; CHECK: .intel_syntax
129 ; CHECK: mov eax, [esi + eax][4]
130 ; CHECK: .att_syntax
131 ; CHECK: {{## InlineAsm End|#NO_APP}}
132
133 call void asm sideeffect inteldialect "mov eax, [esi][eax][4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
134 ; CHECK: {{## InlineAsm Start|#APP}}
135 ; CHECK: .intel_syntax
136 ; CHECK: mov eax, [esi][eax][4]
137 ; CHECK: .att_syntax
138 ; CHECK: {{## InlineAsm End|#NO_APP}}
139
140 call void asm sideeffect inteldialect "mov eax, [esi + 2*eax + 4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
141 ; CHECK: {{## InlineAsm Start|#APP}}
142 ; CHECK: .intel_syntax
143 ; CHECK: mov eax, [esi + 2*eax + 4]
144 ; CHECK: .att_syntax
145 ; CHECK: {{## InlineAsm End|#NO_APP}}
146
147 call void asm sideeffect inteldialect "mov eax, [esi][2*eax + 4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
148 ; CHECK: {{## InlineAsm Start|#APP}}
149 ; CHECK: .intel_syntax
150 ; CHECK: mov eax, [esi][2*eax + 4]
151 ; CHECK: .att_syntax
152 ; CHECK: {{## InlineAsm End|#NO_APP}}
153
154 call void asm sideeffect inteldialect "mov eax, [esi + 2*eax][4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
155 ; CHECK: {{## InlineAsm Start|#APP}}
156 ; CHECK: .intel_syntax
157 ; CHECK: mov eax, [esi + 2*eax][4]
158 ; CHECK: .att_syntax
159 ; CHECK: {{## InlineAsm End|#NO_APP}}
160
161 call void asm sideeffect inteldialect "mov eax, [esi][2*eax][4]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
162 ; CHECK: {{## InlineAsm Start|#APP}}
163 ; CHECK: .intel_syntax
164 ; CHECK: mov eax, [esi][2*eax][4]
165 ; CHECK: .att_syntax
166 ; CHECK: {{## InlineAsm End|#NO_APP}}
167
168 ret void
169 }
77 // CHECK: movl %ecx, 4(%ebx)
88 // CHECK: encoding: [0x89,0x4b,0x04]
99
10 _t21: ## @t21
11 // CHECK: t21
12 mov eax, [4*eax + 4]
13 // CHECK: movl 4(,%eax,4), %eax
14 // CHECK: # encoding: [0x8b,0x04,0x85,0x04,0x00,0x00,0x00]
15 mov eax, [4*eax][4]
16 // CHECK: movl 4(,%eax,4), %eax
17 // CHECK: # encoding: [0x8b,0x04,0x85,0x04,0x00,0x00,0x00]
18
19 mov eax, [esi + eax]
20 // CHECK: movl (%esi,%eax), %eax
21 // CHECK: # encoding: [0x8b,0x04,0x06]
22 mov eax, [esi][eax]
23 // CHECK: movl (%esi,%eax), %eax
24 // CHECK: # encoding: [0x8b,0x04,0x06]
25
26 mov eax, [esi + 4*eax]
27 // CHECK: movl (%esi,%eax,4), %eax
28 // CHECK: # encoding: [0x8b,0x04,0x86]
29 mov eax, [esi][4*eax]
30 // CHECK: movl (%esi,%eax,4), %eax
31 // CHECK: # encoding: [0x8b,0x04,0x86]
32
33 mov eax, [esi + eax + 4]
34 // CHECK: movl 4(%esi,%eax), %eax
35 // CHECK: # encoding: [0x8b,0x44,0x06,0x04]
36 mov eax, [esi][eax + 4]
37 // CHECK: movl 4(%esi,%eax), %eax
38 // CHECK: # encoding: [0x8b,0x44,0x06,0x04]
39 mov eax, [esi + eax][4]
40 // CHECK: movl 4(%esi,%eax), %eax
41 // CHECK: # encoding: [0x8b,0x44,0x06,0x04]
42 mov eax, [esi][eax][4]
43 // CHECK: movl 4(%esi,%eax), %eax
44 // CHECK: # encoding: [0x8b,0x44,0x06,0x04]
45
46 mov eax, [esi + 2*eax + 4]
47 // CHECK: movl 4(%esi,%eax,2), %eax
48 // CHECK: # encoding: [0x8b,0x44,0x46,0x04]
49 mov eax, [esi][2*eax + 4]
50 // CHECK: movl 4(%esi,%eax,2), %eax
51 // CHECK: # encoding: [0x8b,0x44,0x46,0x04]
52 mov eax, [esi + 2*eax][4]
53 // CHECK: movl 4(%esi,%eax,2), %eax
54 // CHECK: # encoding: [0x8b,0x44,0x46,0x04]
55 mov eax, [esi][2*eax][4]
56 // CHECK: movl 4(%esi,%eax,2), %eax
57 // CHECK: # encoding: [0x8b,0x44,0x46,0x04]
58
59 ret