annotate dmd/AsmStatement.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents e3afd1303184
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.AsmStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.LabelStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.code;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.iasm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.backend.SFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import core.stdc.string : memset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import core.stdc.stdlib : exit, EXIT_FAILURE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
39 import std.stdio;
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
40
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
41 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
42
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 class AsmStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
45 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
46
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 Token* tokens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 code* asmcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 uint asmalign; // alignment of this statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 bool refparam; // true if function parameter is referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 bool naked; // true if function is to be naked
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 uint regs; // mask of registers modified
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 this(Loc loc, Token* tokens)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
56 register();
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
57
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 this.tokens = tokens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
62 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
67 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 //printf("AsmStatement.semantic()\n");
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
70 //static if (true) {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
71 if (sc.func && sc.func.isSafe())
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
72 error("inline assembler not allowed in @safe function %s", sc.func.toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
73 //} else {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
74 // if (global.params.safe && !sc.module_.safe)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
75 // {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
76 // error("inline assembler not allowed in safe mode");
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
77 // }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
78 //}
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
79
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 OP* o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 OPND* o1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 OPND* o2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 OPND* o3 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 PTRNTAB ptb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 uint usNumops;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 ubyte uchPrefix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 ubyte bAsmseen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 char* pszLabel = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 code* c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 FuncDeclaration fd = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 assert(fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 fd.inlineAsm = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (!tokens)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
99 auto asmstate = &global.asmstate;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
100
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
101 memset(asmstate, 0, (*asmstate).sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 asmstate.statement = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 asmstate.sc = sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 // don't use bReturnax anymore, and will fail anyway if we use return type inference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 // Scalar return values will always be in AX. So if it is a scalar
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 // then asm block sets return value if it modifies AX, if it is non-scalar
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 // then always assume that the ASM block sets up an appropriate return
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 // value.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 asmstate.bReturnax = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 if (sc.func.type.nextOf().isscalar())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 asmstate.bReturnax = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 // Assume assembler code takes care of setting the return value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 sc.func.hasReturnExp |= 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (!asmstate.bInit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 asmstate.bInit = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 init_optab();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 asmstate.psDollar = new LabelDsymbol(Id.__dollar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 //asmstate.psLocalsize = new VarDeclaration(0, Type.tint32, Id.__LOCAL_SIZE, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 asmstate.psLocalsize = new Dsymbol(Id.__LOCAL_SIZE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 cod3_set386();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 asmstate.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
133 global.asmtok = tokens;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
134 asm_token_trans(global.asmtok);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 if (setjmp(asmstate.env))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
137 global.asmtok = null; // skip rest of line
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
138 global.tok_value = TOK.TOKeof;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 exit(EXIT_FAILURE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 goto AFTER_EMIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
143 switch (cast(int)global.tok_value)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 case ASMTK.ASMTKnaked:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 naked = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 sc.func.naked = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 case ASMTK.ASMTKeven:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 asmalign = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 case TOK.TOKalign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 uint align_ = asm_getnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 if (ispow2(align_) == -1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 asmerr(ASMERRMSGS.EM_align, align_); // power of 2 expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 asmalign = align_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 // The following three convert the keywords 'int', 'in', 'out'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 // to identifiers, since they are x86 instructions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 case TOK.TOKint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 o = asm_op_lookup(Id.__int.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 goto Lopcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 o = asm_op_lookup(Id.___in.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 goto Lopcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 case TOK.TOKout:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 o = asm_op_lookup(Id.___out.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 goto Lopcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 case TOK.TOKidentifier:
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
182 o = asm_op_lookup(global.asmtok.ident.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 if (!o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 goto OPCODE_EXPECTED;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 Lopcode:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 asmstate.ucItype = o.usNumops & IT.ITMASK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (o.usNumops > 3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 switch (asmstate.ucItype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 case IT.ITdata:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 asmcode = asm_db_parse(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 goto AFTER_EMIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 case IT.ITaddr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 asmcode = asm_da_parse(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 goto AFTER_EMIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 // get the first part of an expr
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 o1 = asm_cond_exp();
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
207 if (global.tok_value == TOK.TOKcomma)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 o2 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
212 if (global.tok_value == TOK.TOKcomma)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 asm_token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 o3 = asm_cond_exp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 // match opcode and operands in ptrntab to verify legal inst and
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 // generate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 ptb = asm_classify(o, o1, o2, o3, &usNumops);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 assert(ptb.pptb0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 // The Multiply instruction takes 3 operands, but if only 2 are seen
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 // then the third should be the second and the second should
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 // be a duplicate of the first.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 //
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 if (asmstate.ucItype == IT.ITopt &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 (usNumops == 2) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 (ASM_GET_aopty(o2.usFlags) == ASM_OPERAND_TYPE._imm) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 ((o.usNumops & IT.ITSIZE) == 3))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 o3 = o2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 o2 = opnd_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 *o2 = *o1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 // Re-classify the opcode because the first classification
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 // assumed 2 operands.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 ptb = asm_classify(o, o1, o2, o3, &usNumops);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 if (asmstate.ucItype == IT.ITshift && (ptb.pptb2.usOp2 == 0 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 (ptb.pptb2.usOp2 & _cl))) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 opnd_free(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 o2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 usNumops = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 asmcode = asm_emit(loc, usNumops, ptb, o, o1, o2, o3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 OPCODE_EXPECTED:
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
260 asmerr(ASMERRMSGS.EM_opcode_exp, global.asmtok.toChars()); // assembler opcode expected
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 AFTER_EMIT:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 opnd_free(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 opnd_free(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 opnd_free(o3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 o1 = o2 = o3 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
270 if (global.tok_value != TOK.TOKeof)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 asmerr(ASMERRMSGS.EM_eol); // end of line expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 //return asmstate.bReturnax;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
277 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
282 override bool comeFrom()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
287 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
289 buf.writestring("asm { ");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
290 Token* t = tokens;
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
291 while (t)
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
292 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
293 buf.writestring(t.toChars());
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
294 if (t.next &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
295 t.value != TOKmin &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
296 t.value != TOKcomma &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
297 t.next.value != TOKcomma &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
298 t.value != TOKlbracket &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
299 t.next.value != TOKlbracket &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
300 t.next.value != TOKrbracket &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
301 t.value != TOKlparen &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
302 t.next.value != TOKlparen &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
303 t.next.value != TOKrparen &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
304 t.value != TOKdot &&
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
305 t.next.value != TOKdot)
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
306 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
307 buf.writebyte(' ');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
308 }
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
309 t = t.next;
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
310 }
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
311 buf.writestring("; }");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
312 buf.writenl();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
315 override AsmStatement isAsmStatement() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
317 override void toIR(IRState *irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 block* bpre;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 block* basm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 Declaration d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 // dumpCode(asmcode);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 //printf("AsmStatement::toIR(asmcode = %x)\n", asmcode);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 bpre = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 block_next(blx,BCgoto,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 basm = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 list_append(&bpre.Bsucc, basm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 basm.Bcode = asmcode;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 basm.Balign = cast(ubyte)asmalign;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
334
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 if (label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 block* b = labelToBlock(loc, blx, label);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 printf("AsmStatement::toIR() %p\n", b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 if (b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 list_append(&basm.Bsucc, b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 // Loop through each instruction, fixing Dsymbols into Symbol's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 for (code* c = asmcode; c; c = c.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 LabelDsymbol label;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 block* b;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
349
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 switch (c.IFL1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 case FLblockoff:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 case FLblock:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 // FLblock and FLblockoff have LabelDsymbol's - convert to blocks
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 label = c.IEVlsym1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 b = labelToBlock(loc, blx, label);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 list_append(&basm.Bsucc, b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 c.IEV1.Vblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 case FLdsymbol:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 case FLfunc:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 s = c.IEVdsym1.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 if (s.Sclass == SCauto && s.Ssymnum == -1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 symbol_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 c.IEVsym1() = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 c.IFL1 = s.Sfl ? s.Sfl : FLauto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 // Repeat for second operand
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 switch (c.IFL2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 case FLblockoff:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 case FLblock:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 label = c.IEVlsym2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 b = labelToBlock(loc, blx, label);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 list_append(&basm.Bsucc, b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 c.IEV2.Vblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 case FLdsymbol:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 case FLfunc:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 d = c.IEVdsym2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 s = d.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 if (s.Sclass == SCauto && s.Ssymnum == -1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 symbol_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 c.IEVsym2() = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 c.IFL2 = s.Sfl ? s.Sfl : FLauto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 if (d.isDataseg())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 s.Sflags |= SFLlivexit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 //c.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 basm.bIasmrefparam = refparam; // are parameters reference?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 basm.usIasmregs = cast(ushort)regs; // registers modified
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 block_next(blx,BCasm, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 list_prepend(&basm.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 if (naked)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 blx.funcsym.Stype.Tty |= mTYnaked;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 26
diff changeset
412 }