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