source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/core/tecsinfo.rb@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

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