annotate dmd/AsmStatement.d @ 114:e28b18c23469

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