1 | # -*- coding: utf-8 -*-
|
---|
2 | #
|
---|
3 | # TECS Generator
|
---|
4 | # Generator for TOPPERS Embedded Component System
|
---|
5 | #
|
---|
6 | # Copyright (C) 2017 by TOPPERS Project
|
---|
7 | #--
|
---|
8 | # 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
9 | # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
10 | # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
11 | # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
12 | # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
13 | # スコード中に含まれていること.
|
---|
14 | # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
15 | # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
16 | # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
17 | # の無保証規定を掲載すること.
|
---|
18 | # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
19 | # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
20 | # と.
|
---|
21 | # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
22 | # 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
23 | # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
24 | # 報告すること.
|
---|
25 | # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
26 | # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
27 | # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
28 | # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
29 | # 免責すること.
|
---|
30 | #
|
---|
31 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
32 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
33 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
34 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
35 | # の責任を負わない.
|
---|
36 | #
|
---|
37 | # $Id$
|
---|
38 | #++
|
---|
39 |
|
---|
40 | # TECS 情報セルの生成
|
---|
41 | module TECSInfo
|
---|
42 | # region は Link root のこと
|
---|
43 | def self.print_info f, region
|
---|
44 | # p "region: "+ region.get_name.to_s
|
---|
45 | nest = region.gen_region_str_pre f
|
---|
46 | indent0 = " " * nest
|
---|
47 | indent = " " * ( nest + 1 )
|
---|
48 | f.print <<EOT
|
---|
49 | #{indent0}region rTECSInfo {
|
---|
50 | EOT
|
---|
51 | # mikan 全部生成するのではなく、region 下のセルのセルタイプと、そこから参照されるシグニチャ、セルタイプに限定して出力する.
|
---|
52 | # しかし、意味解析後に出力するため、これは容易ではない.最適化とコード生成は、リンクルートごとに行われる.
|
---|
53 | Namespace.print_info f, indent
|
---|
54 | region.get_link_root.print_info f, indent
|
---|
55 |
|
---|
56 | f.print "\n#{indent}/*** TYPE information cell ***/\n"
|
---|
57 | Type.print_info_post f, indent
|
---|
58 |
|
---|
59 | f.print "\n#{indent}/*** TECS information cell ***/\n"
|
---|
60 | f.print <<EOT
|
---|
61 | #{indent}cell nTECSInfo::tTECSInfoSub TECSInfoSub {
|
---|
62 | #{indent} cNamespaceInfo = _RootNamespaceInfo.eNamespaceInfo;
|
---|
63 | #{indent} cRegionInfo = _LinkRootRegionInfo.eRegionInfo;
|
---|
64 | #{indent}} /* TECSInfoSub */;
|
---|
65 | #{indent0}}; /* rTECSInfo */
|
---|
66 | EOT
|
---|
67 | region.gen_region_str_post f
|
---|
68 | end
|
---|
69 | end
|
---|
70 |
|
---|
71 | class Namespace
|
---|
72 | # RootRegion と LinkRegion は同じ Region クラスのオブジェクトである
|
---|
73 | # 子ネームスペースは Namespace クラスの、子リージョンは Region クラスのオブジェクトである
|
---|
74 | # これは、意味解析段階で呼び出されるため、リンクユニットごとに出しわけることができない
|
---|
75 | # 出しわけるには、2パスにする必要がある
|
---|
76 | def print_info_ns_sub f, indent
|
---|
77 | if @name == "::" then
|
---|
78 | name = "_Root"
|
---|
79 | else
|
---|
80 | name = @global_name
|
---|
81 | end
|
---|
82 | f.print "\n#{indent}/*** #{get_namespace_path} namespace information cell ***/\n"
|
---|
83 | f.print <<EOT
|
---|
84 | #{indent}cell nTECSInfo::tNamespaceInfo #{name}NamespaceInfo{
|
---|
85 | #{indent} name = "#{@name}";
|
---|
86 | EOT
|
---|
87 | if @signature_list.length > 0 then
|
---|
88 | f.print "\n#{indent} /* SIGNATURE info */\n"
|
---|
89 | end
|
---|
90 | @signature_list.each{ |sig|
|
---|
91 | f.print <<EOT
|
---|
92 | #{indent} cSignatureInfo[] = #{sig.get_global_name}SignatureInfo.eSignatureInfo;
|
---|
93 | EOT
|
---|
94 | }
|
---|
95 | if @celltype_list.length > 0 then
|
---|
96 | f.print "\n#{indent} /* CELLTYPE info */\n"
|
---|
97 | end
|
---|
98 | @celltype_list.each{ |ct|
|
---|
99 | if ct.get_cell_list.length > 0 then
|
---|
100 | f.print <<EOT
|
---|
101 | #{indent} cCelltypeInfo[] = #{ct.get_global_name}CelltypeInfo.eCelltypeInfo;
|
---|
102 | EOT
|
---|
103 | end
|
---|
104 | }
|
---|
105 | if @namespace_list.length > 0 then
|
---|
106 | f.print "\n#{indent} /* NAMESPACE info */\n"
|
---|
107 | end
|
---|
108 | @namespace_list.each{ |ns|
|
---|
109 | if ns.instance_of? Namespace then
|
---|
110 | f.print <<EOT
|
---|
111 | #{indent} cNamespaceInfo[] = #{ns.get_global_name}NamespaceInfo.eNamespaceInfo;
|
---|
112 | EOT
|
---|
113 | end
|
---|
114 | }
|
---|
115 | f.print <<EOT
|
---|
116 | #{indent}}; /* cell nTECSInfo::tNamespaceInfo #{name}NamespaceInfo */
|
---|
117 | EOT
|
---|
118 | end
|
---|
119 |
|
---|
120 | def print_info_ns f, indent
|
---|
121 | # p "print_info: #{self.get_global_name}"
|
---|
122 | print_info_ns_sub f, indent
|
---|
123 | @signature_list.each { |sig|
|
---|
124 | sig.print_info f, indent
|
---|
125 | }
|
---|
126 | @celltype_list.each { |ct|
|
---|
127 | if ct.get_cell_list.length > 0 then
|
---|
128 | ct.print_info f, indent
|
---|
129 | end
|
---|
130 | }
|
---|
131 | @namespace_list.each { |ns|
|
---|
132 | if ns.instance_of? Namespace then # region を含めない
|
---|
133 | ns.print_info_ns f, indent
|
---|
134 | end
|
---|
135 | }
|
---|
136 | end
|
---|
137 |
|
---|
138 | def self.print_info( f, indent )
|
---|
139 | @@root_namespace.print_info_ns f, indent
|
---|
140 | end
|
---|
141 |
|
---|
142 | #=== Namespace# 構造体メンバーのオフセット定義
|
---|
143 | def print_struct_define f
|
---|
144 | f.print "\n/***** Offset of members of structures *****/\n"
|
---|
145 | @struct_tag_list.get_items.each{ |tag, sttype|
|
---|
146 | # print "sttype: #{tag.get_name} #{sttype}\n"
|
---|
147 | tag.get_members_decl.get_items.each{ |decl|
|
---|
148 | f.printf "#define OFFSET_OF_%-30s (%s)\n",
|
---|
149 | "#{tag.get_ID_str}_#{decl.get_name}",
|
---|
150 | "(uint32_t)(intptr_t)&(((#{tag.get_type_str}#{tag.get_type_str_post}*)0)->#{decl.get_name})"
|
---|
151 | }
|
---|
152 | }
|
---|
153 | end
|
---|
154 |
|
---|
155 | def print_celltype_define_offset f
|
---|
156 | @celltype_list.each { |ct|
|
---|
157 | if ct.get_cell_list.length > 0 then
|
---|
158 | ct.print_define_offset f
|
---|
159 | end
|
---|
160 | }
|
---|
161 | @namespace_list.each { |ns|
|
---|
162 | if ns.instance_of? Namespace then # region を含めない
|
---|
163 | ns.print_celltype_define_offset f
|
---|
164 | end
|
---|
165 | }
|
---|
166 | end
|
---|
167 |
|
---|
168 | def print_celltype_define f
|
---|
169 | @celltype_list.each { |ct|
|
---|
170 | if ct.get_cell_list.length > 0 then
|
---|
171 | ct.print_celltype_define f
|
---|
172 | end
|
---|
173 | }
|
---|
174 | @namespace_list.each { |ns|
|
---|
175 | if ns.instance_of? Namespace then # region を含めない
|
---|
176 | ns.print_celltype_define f
|
---|
177 | end
|
---|
178 | }
|
---|
179 | end
|
---|
180 |
|
---|
181 | def print_call_define f
|
---|
182 | @celltype_list.each { |ct|
|
---|
183 | if ct.get_cell_list.length > 0 then
|
---|
184 | ct.print_call_define f
|
---|
185 | end
|
---|
186 | }
|
---|
187 | @namespace_list.each { |ns|
|
---|
188 | if ns.instance_of? Namespace then # region を含めない
|
---|
189 | ns.print_call_define f
|
---|
190 | end
|
---|
191 | }
|
---|
192 | end
|
---|
193 |
|
---|
194 | def print_entry_define f
|
---|
195 | @celltype_list.each { |ct|
|
---|
196 | if ct.get_cell_list.length > 0 then
|
---|
197 | ct.print_entry_define f
|
---|
198 | end
|
---|
199 | }
|
---|
200 | @namespace_list.each { |ns|
|
---|
201 | if ns.instance_of? Namespace then # region を含めない
|
---|
202 | ns.print_entry_define f
|
---|
203 | end
|
---|
204 | }
|
---|
205 | end
|
---|
206 | end
|
---|
207 |
|
---|
208 | class Region
|
---|
209 | def print_info_region_sub f, indent
|
---|
210 | if get_link_root == self then
|
---|
211 | name = "_LinkRoot"
|
---|
212 | else
|
---|
213 | name = @global_name
|
---|
214 | end
|
---|
215 | f.print "\n#{indent}/*** #{get_namespace_path} region information cell ***/\n"
|
---|
216 | f.print <<EOT
|
---|
217 | #{indent}cell nTECSInfo::tRegionInfo #{name}RegionInfo{
|
---|
218 | #{indent} name = "#{@name}";
|
---|
219 | EOT
|
---|
220 | @cell_list.each{ |cell|
|
---|
221 | if cell.get_global_name != :rTECSInfo_TECSInfoSub then
|
---|
222 | f.print "#{indent} cCellInfo[] = #{cell.get_global_name}CellInfo.eCellInfo;\n"
|
---|
223 | end
|
---|
224 | }
|
---|
225 | f.print "#{indent}};\n"
|
---|
226 | @cell_list.each{ |cell|
|
---|
227 | cell.print_info f, indent
|
---|
228 | }
|
---|
229 | end
|
---|
230 |
|
---|
231 | def print_info_region( f, indent )
|
---|
232 | self.print_info_region_sub f, indent
|
---|
233 | @namespace_list.each { |region|
|
---|
234 | if region.instance_of? Region then
|
---|
235 | region.print_info_region f, indent
|
---|
236 | end
|
---|
237 | }
|
---|
238 | end
|
---|
239 |
|
---|
240 | def print_info( f, indent )
|
---|
241 | #p "print_info: #{self.get_global_name}"
|
---|
242 | self.print_info_region f, indent
|
---|
243 | end
|
---|
244 |
|
---|
245 | def self.print_cell_define f
|
---|
246 | region.get_link_root.print_cell_define f
|
---|
247 | region.get_link_root.get_region{ |region|
|
---|
248 | if region.instance_of? Region then
|
---|
249 | region.print_cell_define_offset f
|
---|
250 | end
|
---|
251 |
|
---|
252 | }
|
---|
253 | end
|
---|
254 |
|
---|
255 | def print_cell_define f
|
---|
256 | ct_list = {}
|
---|
257 | @cell_list.each{ |cell|
|
---|
258 | ct_list[ cell.get_celltype ] = true
|
---|
259 | }
|
---|
260 | f.print "#define TOPPERS_CB_TYPE_ONLY\n"
|
---|
261 | ct_list.each{ |ct, val|
|
---|
262 | f.print "#include \"#{ct.get_global_name}_tecsgen.h\"\n"
|
---|
263 | }
|
---|
264 | f.print "\n"
|
---|
265 | @cell_list.each{ |cell|
|
---|
266 | name_array = cell.get_celltype.get_name_array cell
|
---|
267 | if cell.get_celltype.has_CB?
|
---|
268 | cb = "(void*)#{name_array[8]}"
|
---|
269 | else
|
---|
270 | cb = "0"
|
---|
271 | end
|
---|
272 | if cell.get_celltype.has_INIB?
|
---|
273 | inib = "(void*)&#{name_array[5]}"
|
---|
274 | inib_proto = "extern #{cell.get_celltype.get_global_name}_INIB #{name_array[11]};\n"
|
---|
275 | else
|
---|
276 | inib = "0"
|
---|
277 | inib_proto = ""
|
---|
278 | end
|
---|
279 | if cell.get_global_name != :rTECSInfo_TECSInfoSub then
|
---|
280 | f.print <<EOT
|
---|
281 | #define #{cell.get_global_name}__CBP #{cb}
|
---|
282 | #{inib_proto}#define #{cell.get_global_name}__INIBP #{inib}
|
---|
283 | EOT
|
---|
284 | end
|
---|
285 | }
|
---|
286 | @namespace_list.each { |region|
|
---|
287 | if region.instance_of? Region then
|
---|
288 | region.print_cell_define f
|
---|
289 | end
|
---|
290 | }
|
---|
291 | end
|
---|
292 | end
|
---|
293 |
|
---|
294 | class Celltype
|
---|
295 | def print_info f, indent
|
---|
296 | f.print <<EOT
|
---|
297 | #{indent}cell nTECSInfo::tCelltypeInfo #{@global_name}CelltypeInfo {
|
---|
298 | #{indent} name = "#{@name}";
|
---|
299 | #{indent} b_singleton = #{@singleton};
|
---|
300 | #{indent} b_IDX_is_ID_act = C_EXP( "#{@global_name}__IDX_is_ID_act" );
|
---|
301 | #{indent} sizeOfCB = C_EXP( "#{@global_name}__sizeOfCB" );
|
---|
302 | #{indent} sizeOfINIB = C_EXP( "#{@global_name}__sizeOfINIB" );
|
---|
303 | #{indent} n_cellInLinkUnit = C_EXP( "#{@global_name}__NCELLINLINKUNIT" );
|
---|
304 | #{indent} n_cellInSystem = #{@cell_list.length};
|
---|
305 | EOT
|
---|
306 | @port.each{ |port|
|
---|
307 | if port.get_port_type == :ENTRY then
|
---|
308 | f.print <<EOT
|
---|
309 | #{indent} cEntryInfo[] = #{@global_name}_#{port.get_name}EntryInfo.eEntryInfo;
|
---|
310 | EOT
|
---|
311 | end
|
---|
312 | }
|
---|
313 | @port.each{ |port|
|
---|
314 | if port.get_port_type == :CALL then
|
---|
315 | f.print <<EOT
|
---|
316 | #{indent} cCallInfo[] = #{@global_name}_#{port.get_name}CallInfo.eCallInfo;
|
---|
317 | EOT
|
---|
318 | end
|
---|
319 | }
|
---|
320 | @attribute.each{ |decl|
|
---|
321 | f.print <<EOT
|
---|
322 | #{indent} cAttrInfo[] = #{@global_name}_#{decl.get_name}VarDeclInfo.eVarDeclInfo;
|
---|
323 | EOT
|
---|
324 | }
|
---|
325 | @var.each{ |decl|
|
---|
326 | f.print <<EOT
|
---|
327 | #{indent} cVarInfo[] = #{@global_name}_#{decl.get_name}VarDeclInfo.eVarDeclInfo;
|
---|
328 | EOT
|
---|
329 | }
|
---|
330 | f.print <<EOT
|
---|
331 | #{indent}};
|
---|
332 | EOT
|
---|
333 | @port.each{ |port|
|
---|
334 | if port.get_port_type == :ENTRY then
|
---|
335 | port.print_info f, @global_name, indent
|
---|
336 | end
|
---|
337 | }
|
---|
338 | @port.each{ |port|
|
---|
339 | if port.get_port_type == :CALL then
|
---|
340 | port.print_info f, @global_name, indent
|
---|
341 | end
|
---|
342 | }
|
---|
343 | @attribute.each{ |decl|
|
---|
344 | decl.print_info f, @global_name, indent
|
---|
345 | }
|
---|
346 | @var.each{ |decl|
|
---|
347 | decl.print_info f, @global_name, indent
|
---|
348 | }
|
---|
349 | end
|
---|
350 |
|
---|
351 | def print_define_offset f
|
---|
352 | # intptr_t に一回キャストするのは 64bit 版を考量してのこと.しかし 32bit としているので 4GB を超える構造体等は扱えない
|
---|
353 | if @n_cell_gen > 0 then
|
---|
354 | f.print <<EOT
|
---|
355 |
|
---|
356 | #include "#{@global_name}_tecsgen.h"
|
---|
357 | EOT
|
---|
358 | @attribute.each{ |decl|
|
---|
359 | if has_INIB? then
|
---|
360 | inib_cb = "INIB"
|
---|
361 | else
|
---|
362 | inib_cb = "CB"
|
---|
363 | end
|
---|
364 | if ! decl.is_omit? then
|
---|
365 | offset = "(uint32_t)(intptr_t)&(((#{@global_name}_#{inib_cb}*)0)->#{decl.get_name})"
|
---|
366 | else
|
---|
367 | offset = "0xffffffff"
|
---|
368 | end
|
---|
369 | f.printf "#define OFFSET_OF_%-30s (%s)\n", "#{@global_name}_#{decl.get_name}", offset
|
---|
370 | }
|
---|
371 | @var.each{ |decl|
|
---|
372 | if decl.get_size_is then
|
---|
373 | inib_cb = "INIB"
|
---|
374 | else
|
---|
375 | inib_cb = "CB"
|
---|
376 | end
|
---|
377 | f.printf "#define OFFSET_OF_%-30s (%s)\n", "#{@global_name}_#{decl.get_name}", "(uint32_t)(intptr_t)&(((#{@global_name}_#{inib_cb}*)0)->#{decl.get_name})"
|
---|
378 | }
|
---|
379 | else
|
---|
380 | f.print <<EOT
|
---|
381 |
|
---|
382 | // #include "#{@global_name}_tecsgen.h" // no cell exist
|
---|
383 | EOT
|
---|
384 | # 生成されないセルタイプ
|
---|
385 | @attribute.each{ |decl|
|
---|
386 | f.printf "#define OFFSET_OF_%-30s (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff"
|
---|
387 | }
|
---|
388 | @var.each{ |decl|
|
---|
389 | f.printf "#define OFFSET_OF_%-30s (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff"
|
---|
390 | }
|
---|
391 | end
|
---|
392 | end
|
---|
393 |
|
---|
394 | def print_celltype_define f
|
---|
395 | if has_INIB? then
|
---|
396 | size_INIB = "(sizeof(#{@global_name}_INIB))"
|
---|
397 | else
|
---|
398 | size_INIB = "(0)"
|
---|
399 | end
|
---|
400 | if has_CB? then
|
---|
401 | size_CB = "(sizeof(#{@global_name}_CB))"
|
---|
402 | else
|
---|
403 | size_CB = "(0)"
|
---|
404 | end
|
---|
405 |
|
---|
406 | f.printf "\n#include \"#{@global_name}_tecsgen.h\"\n"
|
---|
407 | f.printf "#define %-50s (#{@idx_is_id_act})\n", "#{@global_name}__IDX_is_ID_act"
|
---|
408 | f.printf "#define %-50s (#{size_CB})\n", "#{@global_name}__sizeOfCB"
|
---|
409 | f.printf "#define %-50s (#{size_INIB})\n", "#{@global_name}__sizeOfINIB"
|
---|
410 | f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen
|
---|
411 | end
|
---|
412 |
|
---|
413 | def print_call_define f
|
---|
414 | if @n_cell_gen > 0 then
|
---|
415 | f.print <<EOT
|
---|
416 |
|
---|
417 | #include "#{@global_name}_tecsgen.h"
|
---|
418 | EOT
|
---|
419 | else
|
---|
420 | f.print <<EOT
|
---|
421 |
|
---|
422 | // #include "#{@global_name}_tecsgen.h" // no cell exist
|
---|
423 | EOT
|
---|
424 | end
|
---|
425 | @port.each{ |port|
|
---|
426 | next if port.get_port_type == :ENTRY
|
---|
427 | if port.is_omit? || ( port.is_VMT_useless? && port.is_cell_unique? ) || @n_cell_gen == 0 then
|
---|
428 | place = "CALL_PLACE_NON"
|
---|
429 | elsif port.is_dynamic?
|
---|
430 | if port.get_array_size then
|
---|
431 | place = "CALL_PLACE_INIB_DES"
|
---|
432 | else
|
---|
433 | place = "CALL_PLACE_CB_DES"
|
---|
434 | end
|
---|
435 | elsif ! has_INIB? then
|
---|
436 | if port.is_VMT_useless? then
|
---|
437 | place = "CALL_PLACE_CB_IDX"
|
---|
438 | else
|
---|
439 | place = "CALL_PLACE_CB_DES"
|
---|
440 | end
|
---|
441 | else
|
---|
442 | if port.is_VMT_useless? then
|
---|
443 | place = "CALL_PLACE_INIB_IDX"
|
---|
444 | else
|
---|
445 | place = "CALL_PLACE_INIB_DES"
|
---|
446 | end
|
---|
447 | end
|
---|
448 | if ( port.is_VMT_useless? && port.is_cell_unique? ) || @n_cell_gen == 0 then
|
---|
449 | offset = "0xffffffff"
|
---|
450 | else
|
---|
451 | if port.is_dynamic? || ! has_INIB? then
|
---|
452 | cb_inib = "CB"
|
---|
453 | else
|
---|
454 | cb_inib = "INIB"
|
---|
455 | end
|
---|
456 | offset = "(uint32_t)(intptr_t)&((#{@global_name}_#{cb_inib}*)0)->#{port.get_name}"
|
---|
457 | end
|
---|
458 | array_size = port.get_array_size
|
---|
459 | if array_size == "[]" then
|
---|
460 | array_size = "0xffffffff"
|
---|
461 | elsif array_size == nil then
|
---|
462 | array_size = "0"
|
---|
463 | end
|
---|
464 |
|
---|
465 | f.printf "#define %-50s (#{offset})\n", "#{@global_name}_#{port.get_name}__offset"
|
---|
466 | f.printf "#define %-50s (#{array_size})\n", "#{@global_name}_#{port.get_name}__array_size"
|
---|
467 | f.printf "#define %-50s (#{place})\n", "#{@global_name}_#{port.get_name}__place"
|
---|
468 | f.printf "#define %-50s (#{port.is_VMT_useless?})\n", "#{@global_name}_#{port.get_name}__b_VMT_useless"
|
---|
469 | f.printf "#define %-50s (#{port.is_skelton_useless?})\n", "#{@global_name}_#{port.get_name}__b_skelton_useless"
|
---|
470 | f.printf "#define %-50s (#{port.is_cell_unique?})\n", "#{@global_name}_#{port.get_name}__b_cell_unique"
|
---|
471 | }
|
---|
472 | end
|
---|
473 |
|
---|
474 | def print_entry_define f
|
---|
475 | @port.each{ |port|
|
---|
476 | next if port.get_port_type == :CALL
|
---|
477 | array_size = port.get_array_size
|
---|
478 | if array_size == "[]" then
|
---|
479 | array_size = "0xffffffff"
|
---|
480 | elsif array_size == nil then
|
---|
481 | array_size = "0"
|
---|
482 | end
|
---|
483 |
|
---|
484 | f.printf "#define %-50s (#{array_size})\n", "#{@global_name}_#{port.get_name}__array_size"
|
---|
485 | }
|
---|
486 | end
|
---|
487 | end
|
---|
488 |
|
---|
489 | class Port
|
---|
490 | def print_info f, ct_global, indent
|
---|
491 | return if @signature == nil # signature not found error in cdl
|
---|
492 | if @port_type == :ENTRY then
|
---|
493 | f.print <<EOT
|
---|
494 | #{indent}cell nTECSInfo::tEntryInfo #{ct_global}_#{@name}EntryInfo{
|
---|
495 | #{indent} name = "#{@name}";
|
---|
496 | #{indent} cSignatureInfo = #{@signature.get_global_name}SignatureInfo.eSignatureInfo;
|
---|
497 | #{indent} b_inline = #{@b_inline};
|
---|
498 | #{indent} array_size = C_EXP( "#{ct_global}_#{@name}__array_size" );
|
---|
499 | #{indent}};
|
---|
500 | EOT
|
---|
501 | else
|
---|
502 | f.print <<EOT
|
---|
503 | #{indent}cell nTECSInfo::tCallInfo #{ct_global}_#{@name}CallInfo{
|
---|
504 | #{indent} name = "#{@name}";
|
---|
505 | #{indent} cSignatureInfo = #{@signature.get_global_name}SignatureInfo.eSignatureInfo;
|
---|
506 | #{indent} offset = C_EXP( "#{ct_global}_#{@name}__offset" );
|
---|
507 | #{indent} array_size = C_EXP( "#{ct_global}_#{@name}__array_size" );
|
---|
508 | #{indent} b_optional = #{@b_optional};
|
---|
509 | #{indent} b_omit = #{@b_omit};
|
---|
510 | #{indent} b_dynamic = #{@b_dynamic};
|
---|
511 | #{indent} b_ref_desc = #{@b_ref_desc};
|
---|
512 | #{indent} b_allocator_port = #{@allocator_port!=nil ? true : false};
|
---|
513 | #{indent} b_require_port = #{@b_require};
|
---|
514 | #{indent} place = C_EXP( "#{ct_global}_#{@name}__place" );
|
---|
515 | #{indent} b_VMT_useless = C_EXP( "#{ct_global}_#{@name}__b_VMT_useless" );
|
---|
516 | #{indent} b_skelton_useless = C_EXP( "#{ct_global}_#{@name}__b_skelton_useless" );
|
---|
517 | #{indent} b_cell_unique = C_EXP( "#{ct_global}_#{@name}__b_cell_unique" );
|
---|
518 |
|
---|
519 | #{indent}};
|
---|
520 | EOT
|
---|
521 | end
|
---|
522 | end
|
---|
523 | end
|
---|
524 |
|
---|
525 | class Cell
|
---|
526 | def print_info f, indent
|
---|
527 | if @global_name == :rTECSInfo_TECSInfoSub then
|
---|
528 | return
|
---|
529 | end
|
---|
530 | f.print <<EOT
|
---|
531 |
|
---|
532 | #{indent}/*** #{@global_name} cell information ****/
|
---|
533 | #{indent}cell nTECSInfo::tCellInfo #{@global_name}CellInfo {
|
---|
534 | #{indent} name = "#{@name}";
|
---|
535 | #{indent} cbp = C_EXP( \"#{@global_name}__CBP\" );
|
---|
536 | #{indent} inibp = C_EXP( \"#{@global_name}__INIBP\" );
|
---|
537 | #{indent} cCelltypeInfo = #{@celltype.get_global_name}CelltypeInfo.eCelltypeInfo;
|
---|
538 | #{indent}};
|
---|
539 | EOT
|
---|
540 | end
|
---|
541 | end
|
---|
542 |
|
---|
543 | class Signature
|
---|
544 | def print_info f, indent
|
---|
545 | f.print <<EOT
|
---|
546 |
|
---|
547 | #{indent}/*** #{@global_name} signature information ****/
|
---|
548 | #{indent}cell nTECSInfo::tSignatureInfo #{@global_name}SignatureInfo {
|
---|
549 | #{indent} name = "#{@name}";
|
---|
550 | EOT
|
---|
551 | @function_head_list.get_items.each{ |fh|
|
---|
552 | f.print <<EOT
|
---|
553 | #{indent} cFunctionInfo[] = #{@global_name}_#{fh.get_name}FunctionInfo.eFunctionInfo;
|
---|
554 | EOT
|
---|
555 | }
|
---|
556 | f.print <<EOT
|
---|
557 | #{indent}};
|
---|
558 | EOT
|
---|
559 | @function_head_list.get_items.each{ |fh|
|
---|
560 | fh.print_info f, indent
|
---|
561 | }
|
---|
562 | end
|
---|
563 | end
|
---|
564 |
|
---|
565 | class FuncHead
|
---|
566 | def print_info f, indent
|
---|
567 | sig_name = @owner.get_global_name
|
---|
568 | func_name = get_name
|
---|
569 | f.print <<EOT
|
---|
570 | #{indent}cell nTECSInfo::tFunctionInfo #{sig_name}_#{func_name}FunctionInfo {
|
---|
571 | #{indent} name = "#{@owner.get_global_name}_#{@name}";
|
---|
572 | #{indent} bOneway = #{is_oneway?};
|
---|
573 | EOT
|
---|
574 | get_paramlist.get_items.each{ |param|
|
---|
575 | f.print <<EOT
|
---|
576 | #{indent} cParamInfo[] = #{sig_name}_#{func_name}_#{param.get_name}ParamInfo.eParamInfo;
|
---|
577 | EOT
|
---|
578 | }
|
---|
579 | f.print <<EOT
|
---|
580 | #{indent} cReturnTypeInfo = #{get_return_type.get_ID_str}TypeInfo.eTypeInfo;
|
---|
581 | #{indent}};
|
---|
582 | EOT
|
---|
583 | get_paramlist.get_items.each{ |param|
|
---|
584 | dbgPrint "param_list #{sig_name}, #{func_name}, #{param.get_name}\n"
|
---|
585 | param.print_info f, sig_name, func_name, get_paramlist, indent
|
---|
586 | }
|
---|
587 | get_return_type.print_info f, indent
|
---|
588 | end
|
---|
589 | end
|
---|
590 |
|
---|
591 | class ParamDecl
|
---|
592 | def print_info f, signature_global_name, func_name, paramdecl_list, indent
|
---|
593 | if @size then
|
---|
594 | size = "\"#{@size.get_rpn( paramdecl_list )}\""
|
---|
595 | else
|
---|
596 | size = "(char_t*)0";
|
---|
597 | end
|
---|
598 | if @count then
|
---|
599 | count = "\"#{@count.get_rpn( paramdecl_list )}\""
|
---|
600 | else
|
---|
601 | count = "(char_t*)0";
|
---|
602 | end
|
---|
603 | if @string then
|
---|
604 | if @string == -1 then
|
---|
605 | string = '""'
|
---|
606 | else
|
---|
607 | string = "\"#{@string.get_rpn( paramdecl_list )}\""
|
---|
608 | end
|
---|
609 | else
|
---|
610 | string = "(char_t*)0";
|
---|
611 | end
|
---|
612 | f.print <<EOT
|
---|
613 | #{indent}cell nTECSInfo::tParamInfo #{signature_global_name}_#{func_name}_#{get_name}ParamInfo {
|
---|
614 | #{indent} name = "#{get_name}";
|
---|
615 | #{indent} dir = PARAM_DIR_#{@direction};
|
---|
616 | #{indent} sizeIsExpr = #{size};
|
---|
617 | #{indent} countIsExpr = #{count};
|
---|
618 | #{indent} stringExpr = #{string};
|
---|
619 | #{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;
|
---|
620 | #{indent}};
|
---|
621 | EOT
|
---|
622 | get_type.print_info f, indent
|
---|
623 | end
|
---|
624 | end
|
---|
625 |
|
---|
626 | class Decl
|
---|
627 | def print_info f, parent_ID_str, indent
|
---|
628 | if @size_is then
|
---|
629 | size = "\"mikan\"";
|
---|
630 | else
|
---|
631 | size = "(char_t*)0";
|
---|
632 | end
|
---|
633 | f.print <<EOT
|
---|
634 | #{indent}cell nTECSInfo::tVarDeclInfo #{parent_ID_str}_#{get_name}VarDeclInfo {
|
---|
635 | #{indent} name = "#{get_name}";
|
---|
636 | #{indent} sizeIsExpr = #{size};
|
---|
637 | #{indent} declType = DECLTYPE_STMEMBER;
|
---|
638 | #{indent} offset = C_EXP( "OFFSET_OF_#{parent_ID_str}_#{get_name}" );
|
---|
639 | #{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;
|
---|
640 | #{indent}};
|
---|
641 | EOT
|
---|
642 | get_type.print_info f, indent
|
---|
643 | end
|
---|
644 | end
|
---|
645 |
|
---|
646 | class Type
|
---|
647 | @@typeinfo_printed = {}
|
---|
648 | def print_info f, indent
|
---|
649 | # Type の info は、最後にまとめて出力するので、ここでは記録するだけ
|
---|
650 | if @@typeinfo_printed[ get_ID_str ] then
|
---|
651 | return
|
---|
652 | end
|
---|
653 | # p "ID Str: #{get_ID_str}"
|
---|
654 | @@typeinfo_printed[ get_ID_str ] = self
|
---|
655 | if self.kind_of? PtrType then
|
---|
656 | get_referto.print_info f, indent
|
---|
657 | elsif self.kind_of? ArrayType then
|
---|
658 | get_type.print_info f, indent
|
---|
659 | elsif self.kind_of? DefinedType then
|
---|
660 | get_type.print_info f, indent
|
---|
661 | elsif self.kind_of? StructType then
|
---|
662 | get_members_decl.get_items.each{ |decl|
|
---|
663 | decl.get_type.print_info f, indent
|
---|
664 | }
|
---|
665 | end
|
---|
666 | end
|
---|
667 |
|
---|
668 | def self.print_info_post f, indent
|
---|
669 | @@typeinfo_printed.each{ |nm, type|
|
---|
670 | type.print_info_post f, indent
|
---|
671 | }
|
---|
672 | end
|
---|
673 |
|
---|
674 | def print_info_post f, indent
|
---|
675 | bit_size = get_bit_size
|
---|
676 | if bit_size <= 0 then
|
---|
677 | bit_size = "C_EXP( \"sizeof(#{get_type_str}#{get_type_str_post})\" )"
|
---|
678 | end
|
---|
679 | if self.class.superclass == Type then # 親クラスが Type の場合 types.rb のクラス
|
---|
680 | type_name = self.class.name
|
---|
681 | else
|
---|
682 | type_name = self.class.superclass.name # ctypes.rb のクラス (親クラスが types.rb のクラス)
|
---|
683 | end
|
---|
684 | # p "type: #{type_name}, #{self.class.name}"
|
---|
685 |
|
---|
686 | # p "class=#{self.class.name} size=#{bit_size}"
|
---|
687 | f.print <<EOT
|
---|
688 | #{indent}cell nTECSInfo::t#{type_name}Info #{get_ID_str}TypeInfo{
|
---|
689 | #{indent} name = "#{get_type_str}#{get_type_str_post}";
|
---|
690 | #{indent} typeKind = TECSTypeKind_#{type_name};
|
---|
691 | #{indent} size = #{bit_size};
|
---|
692 | #{indent} b_const = #{is_const?};
|
---|
693 | #{indent} b_volatile = #{is_volatile?};
|
---|
694 | EOT
|
---|
695 | if self.kind_of? PtrType then
|
---|
696 | f.print "#{indent} cTypeInfo = #{get_referto.get_ID_str}TypeInfo.eTypeInfo;\n"
|
---|
697 | elsif self.kind_of? ArrayType then
|
---|
698 | f.print "#{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
|
---|
699 | elsif self.kind_of? DefinedType then
|
---|
700 | f.print "#{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
|
---|
701 | elsif self.kind_of? StructType then
|
---|
702 | get_members_decl.get_items.each{ |decl|
|
---|
703 | f.print "#{indent} cTypeInfo[] = #{decl.get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
|
---|
704 | }
|
---|
705 | elsif self.kind_of? DescriptorType then
|
---|
706 | f.print "#{indent} cSignatureInfo = #{get_signature.get_global_name}SignatureInfo.eSignatureInfo;\n"
|
---|
707 | end
|
---|
708 |
|
---|
709 | f.print <<EOT
|
---|
710 | #{indent}};
|
---|
711 | EOT
|
---|
712 | end
|
---|
713 |
|
---|
714 | #=== Type# 型文字列の識別子化
|
---|
715 | #型文字列に含まれる識別子として用いることのできない文字を用いることのできる文字列に置き換える
|
---|
716 | # 空白 => __
|
---|
717 | # * => _Ptr_
|
---|
718 | # [] => _Array_
|
---|
719 | # Descriptor() => Descriptor_of_
|
---|
720 | def get_ID_str
|
---|
721 | # puts "get_ID_str: #{self.class.name}"
|
---|
722 | if kind_of? PtrType then
|
---|
723 | str = get_referto.get_ID_str + "_Ptr_"
|
---|
724 | elsif kind_of? ArrayType then
|
---|
725 | str = get_type.get_ID_str + "_Array" + get_subscript.eval_const( nil ).to_s + "_"
|
---|
726 | elsif kind_of? StructType then
|
---|
727 | str = "struct #{@tag}"
|
---|
728 | elsif kind_of? DescriptorType then
|
---|
729 | str = "Descriptor_of_" + get_signature.get_global_name.to_s
|
---|
730 | else
|
---|
731 | str = get_type_str + get_type_str_post
|
---|
732 | end
|
---|
733 | # p "before: #{str}"
|
---|
734 | str.gsub!( / /, "__" )
|
---|
735 | # p "after: #{str}"
|
---|
736 | return str
|
---|
737 | end
|
---|
738 | end
|
---|
739 |
|
---|