annotate dmd/backend/code.d @ 34:544b922227c7

update to work with dmd 2.048
author korDen
date Sat, 21 Aug 2010 05:46:08 +0400
parents 10317f0c89a5
children e28b18c23469
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.backend.code;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.backend.targ_types;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.backend.Srcpos;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 * Code data type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 union evc
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 targ_int Vint; // also used for tmp numbers (FLtmp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 targ_uns Vuns;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 targ_long Vlong;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 struct EP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 targ_size_t Vpointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 int Vseg; // segment the pointer is in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 } EP _EP;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 Srcpos Vsrcpos; // source position for OPlinnum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 elem* Vtor; // OPctor/OPdtor elem
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 block* Vswitch; // when FLswitch and we have a switch table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 code* Vcode; // when code is target of a jump (FLcode)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 block* Vblock; // when block " (FLblock)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 struct SP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 targ_size_t Voffset; // offset from symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 Symbol* Vsym; // pointer to symbol table (FLfunc,FLextern)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 } SP sp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 version (MARS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 struct DSP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 targ_size_t Voffset; // offset from symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 Declaration Vsym; // pointer to D symbol table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 } DSP dsp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 version (MARS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 struct LAB
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 targ_size_t Voffset; // offset from symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 LabelDsymbol Vsym; // pointer to Label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 } LAB lab;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 struct AS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 uint len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 char* bytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 } AS as; // asm node (FLasm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 enum CF
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 CFes = 1, // generate an ES: segment override for this instr
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 CFjmp16 = 2, // need 16 bit jump offset (long branch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 CFtarg = 4, // this code is the target of a jump
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 CFseg = 8, // get segment of immediate value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 CFoff = 0x10, // get offset of immediate value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 CFss = 0x20, // generate an SS: segment override (not with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 // CFes at the same time, though!)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 CFpsw = 0x40, // we need the flags result after this instruction
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 CFopsize = 0x80, // prefix with operand size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 CFaddrsize = 0x100, // prefix with address size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 CFds = 0x200, // need DS override (not with es, ss, or cs )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 CFcs = 0x400, // need CS override
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 CFfs = 0x800, // need FS override
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 CFgs = (CFcs | CFfs), // need GS override
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 CFwait = 0x1000, // If I32 it indicates when to output a WAIT
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 CFselfrel = 0x2000, // if self-relative
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 CFunambig = 0x4000, // indicates cannot be accessed by other addressing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 // modes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 CFtarg2 = 0x8000, // like CFtarg, but we can't optimize this away
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 CFvolatile = 0x10000, // volatile reference, do not schedule
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 CFclassinit= 0x20000, // class init code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 CFSEG = (CFes | CFss | CFds | CFcs | CFfs | CFgs),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 CFPREFIX = (CFSEG | CFopsize | CFaddrsize),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 struct code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 code* next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 uint Iflags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 ubyte Ijty = 0; // type of operand, 0 if unknown
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 ubyte Iop;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 ubyte Irm; // reg/mode
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 ubyte Iop2; // second opcode byte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 ubyte Isib = 0; // SIB byte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 ubyte Iop3; // third opcode byte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 ubyte IFL1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 ubyte IFL2; // FLavors of 1st, 2nd operands
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 evc IEV1; // 1st operand, if any
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 ref targ_size_t IEVpointer1 () { return IEV1._EP.Vpointer; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 ref int IEVseg1 () { return IEV1._EP.Vseg; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 ref Symbol* IEVsym1 () { return IEV1.sp.Vsym; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 ref Declaration IEVdsym1 () { return IEV1.dsp.Vsym; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 ref targ_size_t IEVoffset1 () { return IEV1.sp.Voffset; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 ref LabelDsymbol IEVlsym1 () { return IEV1.lab.Vsym; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 ref targ_int IEVint1 () { return IEV1.Vint; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 evc IEV2; // 2nd operand, if any
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 ref targ_size_t IEVpointer2 () { return IEV2._EP.Vpointer; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 ref int IEVseg2 () { return IEV2._EP.Vseg; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ref Symbol* IEVsym2 () { return IEV2.sp.Vsym; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 ref Declaration IEVdsym2 () { return IEV2.dsp.Vsym; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 ref targ_size_t IEVoffset2 () { return IEV2.sp.Voffset; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 ref LabelDsymbol IEVlsym2 () { return IEV2.lab.Vsym; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 ref targ_int IEVint2 () { return IEV2.Vint; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 /+
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 void print(); // pretty-printer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 import std.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 void dumpCode(code* foo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 writefln("code.sizeof: %d", code.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 writefln("Srcpos.sizeof: %d", Srcpos.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 writefln("evc.sizeof: %d", evc.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 writefln("EP.sizeof: %d", evc.EP.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 writefln("SP.sizeof: %d", evc.SP.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 writefln("targ_long.sizeof: %d", targ_long.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 foreach (a, b; foo.tupleof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 0
diff changeset
143 ///std.stdio.writeln(foo.tupleof[a].stringof, " ", cast(char*)&foo.tupleof[a] - cast(char*)foo, " = ", foo.tupleof[a]);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 //std.stdio.writeln("printf(\"", foo.tupleof[a].stringof, " %d = %d\\n\",(char*)(&", foo.tupleof[a].stringof, ")-(char*)foo, ", foo.tupleof[a].stringof, ");");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 }