1 /******************************************************************************
2 *
3 * Copyright (C) 2006, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * Author: Alexey Krivonogov ( gentee )
11 *
12 * Contributors: Sergey ( SWR )
13 *
14 * Summary: The program genertaes cmdlist.h and cmdlist.с files
15 *
16 ******************************************************************************/
17
18 include : $"..\..\lib\gt\gt.g"
19
20 global
21 {
22 // OVM_TYPE flags size name subtype
23 // NAME | PACK | STACK
24 // Type description
25 buf types = '\h
26 \* TInt *\ 05 \h4 10003 \h 0B \"int" 0 4
27 \* TUInt *\ 05 \h4 10003 \h 0C \"uint" 0 4
28 \* TByte *\ 05 \h4 10003 \h 0C \"byte" 0 1
29 \* TUByte *\ 05 \h4 10003 \h 0D \"ubyte" 0 1
30 \* TShort *\ 05 \h4 10003 \h 0D \"short" 0 2
31 \* TUShort *\ 05 \h4 10003 \h 0E \"ushort" 0 2
32 \* TFloat *\ 05 \h4 10003 \h 0D \"float" 0 4
33 \* TDouble *\ 05 \h4 10003 \h 0E \"double" 0 8
34 \* TLong *\ 05 \h4 10003 \h 0C \"long" 0 8
35 \* TULong *\ 05 \h4 10003 \h 0D \"ulong" 0 8
36 \* TReserved *\ 05 \h4 00203 \h 12 \"reserved" 0
37 \* index = TUByte & indexof *\ 4 0 0
38 \* TBuf *\ 05 \h4 00203 \h 29 \"buf" 0
39 \* index = TUByte & indexof *\ 4 0 4
40 \* data type = TUInt & name *\ 2 1 \"data" 0
41 \* use type = TUInt & name *\ 2 1 \"use" 0
42 \* size type = TUInt & name *\ 2 1 \"size" 0
43 \* step type = TUInt & name *\ 2 1 \"step" 0 0
44 \* TStr *\ 05 \h4 00103 \h 0E \"str" 0
45 \* inherit = buf *\ 0C 1
46 \* type = TBuf *\ 0C 0
47 \* TArr *\ 05 \h4 00303 \h 28 \"arr" 0
48 \* inherit = buf *\ 0C
49 \* index = 0 & indexof *\ 0 0 4
50 \* type = TBuf *\ 0C 0
51 \* itype type = TUInt & name *\ 2 1 \"itype" 0
52 \* isize type = TUInt & name *\ 2 1 \"isize" 0
53 \* dim type = TReserved & name *\ 0B 5 \"dim" 0
54 \*dimcount*\ 1 \* 8 * sizeof( uint )*\ 20
55 \* TCollection *\ 05 \h4 00303 \h 26 \"collection" 0
56 \* inherit = buf *\ 0C
57 \* index = TUInt & indexof *\ 2 0 3
58 \* type = TBuf *\ 0C 0
59 \* count type = TUInt & name *\ 2 1 \"count" 0
60 \* flag type = TUInt & name *\ 2 1 \"flag" 0
61 \* TAny *\ 05 \h4 10003 \h 0B \"any" 0 4
62 \* TFordata *\ 05 \h4 00003 \h 16 \"fordata" 0
63 1
64 \* type = TUint *\ 2 1 \"icur" 0
65 '
66
67 arrstr typesnames = %{"/* TInt */", "/* TUInt */", "/* TByte */", "/* TUByte */", "/* TShort */",
68 "/* TUShort */", "/* TFloat */", "/* TDouble */", "/* TLong */", "/* TULong */",
69 "/* TReserved */", "/* TBuf */", "/* TStr */", "/* TArr */", "/* TCollection */",
70 "/* TAny */", "/* TFordata */" }
71 }
72
73
74
75
76 /*-----------------------------------------------------------------------------
77 *
78 * ID: headerout 12.10.06 1.1.A.
79 *
80 * Summary:
81 *
82 -----------------------------------------------------------------------------*/
83
84 text headerout( str name author summary )
85 /******************************************************************************
86 *
87 * Copyright (C) 2006, The Gentee Group. All rights reserved.
88 * This file is part of the Gentee open source project <http://www.gentee.com>.
89 *
90 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
91 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
92 * ACCEPTANCE OF THE AGREEMENT.
93 *
94 * \(name) \{
95 str sdate
96 datetime dt
97 getdatetime( dt.gettime(), sdate, 0->str )
98 @sdate
99 } 0.0.A.
100 *
101 * Author: \(author)
102 *
103 * Summary: \(summary)
104 *
105 ******************************************************************************/
106 \!
107
108 func str str12<result>(str n, int i){
109 int len = *n;
110 str ret = ",";
111 while len<13 {
112 len++;
113 ret += " ";
114 }
115 n += ret;
116 ret = "// ";
117 if(i<0x10){
118 ret += " "
119 }
120 n += ret + "0x" + hex2stru( i );
121 result = n;
122 }
123 /*-----------------------------------------------------------------------------
124 *
125 * ID: cmdlist_h 12.10.06 1.1.A.
126 *
127 * Summary: The .h output function.
128 *
129 -----------------------------------------------------------------------------*/
130 text cmdlist_h( arrstr acmd, arrstr cmt, arrstr shift )
131 \@headerout( "cmdlist_h", "Generated with 'cmdlist' program",
132 "This file contains a list of the embedded byte-code commands.")
133 #ifndef _CMDLIST_
134 #define _CMDLIST_
135
136 #ifdef __cplusplus
137 extern "C" {
138 #endif // __cplusplus
139
140 #include "../common/types.h"
141
142 #define CMDCOUNT \( *acmd )
143 #define STACK_COUNT \( *shift )
144
145 enum {
146 \{
147 uint i
148
149 fornum i, *acmd
150 {
151 @" \(str12(acmd[ i ], i)), \(i) \( cmt[i] )\l"
152 }
153 }
154 };
155
156 extern const ubyte shifts[];
157 extern const ubyte embtypes[];
158
159 #ifdef __cplusplus
160 }
161 #endif // __cplusplus
162
163 #endif // _CMDLIST_
164 \!
165
166 /*-----------------------------------------------------------------------------
167 *
168 * ID: cmdlist_h 12.10.06 1.1.A.
169 *
170 * Summary: The .c output function.
171 *
172 -----------------------------------------------------------------------------*/
173
174 text cmdlist_c( arrstr shift acmd )
175 \@headerout( "cmdlist_c", "Generated with 'cmdlist' program",
176 "This file contains shift types of the embedded byte-code commands.")
177
178 #include "cmdlist.h"
179 #include "bytecode.h"
180
181
182
183 const ubyte embtypes[] = {
184 \{
185 uint i, ii = 0, n = 0;
186
187 fornum i, *types
188 {
189 if ( types[i] == 5 && types[i+1] == 3){
190 if i != 0: @"\l"
191 @"\(typesnames[(ii++)]) "
192 n = 0;
193 }
194 if types[i]>0xF: @"0x\( hex2stru(types[i])),"
195 else: @"0x0\( hex2stru(types[i])),"
196 if(n++ == 18 ): @"\l "
197 }
198 }
199 };
200
201 const ubyte shifts[] = {
202 \{
203 ii = 1;
204 fornum i = 0, *shift
205 {
206 @"\(shift[i]), // \(acmd[i+18])\l"
207 }
208 }
209 };
210 \!
211
212 /*-----------------------------------------------------------------------------
213 *
214 * ID: cmdmain 12.10.06 1.1.A.ABKL
215 *
216 * Summary: The main function.
217 *
218 -----------------------------------------------------------------------------*/
219
220 func main<main>
221 {
222 arrstr shift
223 arrstr aout
224 arrstr cmt
225 str hout
226 gt cmdgt
227 // gtitems gtis
228
229 cmdgt.read( "cmdlist.gt" )
230 foreach cur, cmdgt.root()//.items( gtis )
231 {
232 str stemp
233 int shcmd shtop
234
235 cur as gtitem
236 if cur.comment : continue
237 aout += cur.name
238 cur.get("comment", stemp )
239 if cur.find("type")
240 {
241 // shift += "SH_TYPE"
242 }
243 else
244 {
245 shcmd = cur.getint("cmdshift" )
246 shtop = cur.getint("topshift" )
247 switch shtop
248 {
249 case -3
250 {
251 switch shcmd
252 {
253 case 0: shift += "SHN3_1"
254 default : print("Unknown shift \( cur.name )\n")
255 }
256 }
257 case -2
258 {
259 switch shcmd
260 {
261 case 0: shift += "SHN2_1"
262 default : print("Unknown shift \( cur.name )\n")
263 }
264 }
265 case -1
266 {
267 switch shcmd
268 {
269 case 0: shift += "SHN1_1"
270 case 1: shift += "SHN1_2"
271 default : print("Unknown shift \( cur.name )\n")
272 }
273 }
274 case 0
275 {
276 switch shcmd
277 {
278 case 0: shift += " SH0_1"
279 case 1: shift += " SH0_2"
280 default : print("Unknown shift \( cur.name )\n")
281 }
282 }
283 case 1
284 {
285 switch shcmd
286 {
287 case 0: shift += " SH1_1"
288 case 1: shift += " SH1_2"
289 case 2: shift += " SH1_3"
290 default : print("Unknown shift \( cur.name )\n")
291 }
292 }
293 case 2
294 {
295 switch shcmd
296 {
297 case 0: shift += " SH2_1"
298 case 2: shift += " SH2_3"
299 default : print("Unknown shift \( cur.name )\n")
300 }
301 }
302 }
303 }
304 cmt += stemp
305 }
306 hout@cmdlist_h( aout, cmt, shift )
307 hout.write( "cmdlist.h" )
308 hout.clear()
309 hout@cmdlist_c( shift, aout )
310 hout.write( "cmdlist.c" )
311 congetch("Press any key...")
312 }
313