- Timestamp:
- Apr 5, 2019, 9:26:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_rx/trunk/asp3_dcre/tecsgen/tecslib/core/tecsinfo.rb
r359 r374 4 4 # Generator for TOPPERS Embedded Component System 5 5 # 6 # Copyright (C) 2017 by TOPPERS Project6 # Copyright (C) 2017-2018 by TOPPERS Project 7 7 #-- 8 8 # 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ … … 49 49 #{indent0}region rTECSInfo { 50 50 EOT 51 # mikan 全部生成するのではなく、region 下のセルのセルタイプと、そこから参照されるシグニチャ、セルタイプに限定して出力する. 51 Type.reset_print_info 52 53 # mikan 全部生成するのではなく、region 下のセルのセルタイプと、そこから参照されるシグニチャ、セルタイプに限定して出力すべき 52 54 # しかし、意味解析後に出力するため、これは容易ではない.最適化とコード生成は、リンクルートごとに行われる. 53 55 Namespace.print_info f, indent … … 149 151 "#{tag.get_ID_str}_#{decl.get_name}", 150 152 "(uint32_t)(intptr_t)&(((#{tag.get_type_str}#{tag.get_type_str_post}*)0)->#{decl.get_name})" 153 f.printf "#define PLACE_OF_%-30s (%s)\n", 154 "#{tag.get_ID_str}_#{decl.get_name}", 155 "VARDECL_PLACE_STRUCT" 151 156 } 152 157 } … … 191 196 } 192 197 end 198 199 def print_entry_define f 200 @celltype_list.each { |ct| 201 if ct.get_cell_list.length > 0 then 202 ct.print_entry_define f 203 end 204 } 205 @namespace_list.each { |ns| 206 if ns.instance_of? Namespace then # region を含めない 207 ns.print_entry_define f 208 end 209 } 210 end 193 211 end 194 212 … … 200 218 name = @global_name 201 219 end 220 # p "region:#{get_name}" 202 221 f.print "\n#{indent}/*** #{get_namespace_path} region information cell ***/\n" 203 222 f.print <<EOT 204 223 #{indent}cell nTECSInfo::tRegionInfo #{name}RegionInfo{ 205 224 #{indent} name = "#{@name}"; 206 #{indent}}; 207 EOT 225 EOT 226 @cell_list.each{ |cell| 227 # print "cell class="+cell.get_celltype.class.name+", " + cell.get_celltype.get_name.to_s + " 1\n" 228 if ! cell.exclude_info? then 229 # print "cell class="+cell.get_celltype.class.name+", " + cell.get_celltype.get_name.to_s + " 2\n" 230 f.print "#{indent} cCellInfo[] = #{cell.get_global_name}CellInfo.eCellInfo;\n" 231 end 232 } 233 @namespace_list.each { |region| 234 if region.instance_of? Region then 235 f.print "#{indent} cRegionInfo[] = #{region.get_global_name}RegionInfo.eRegionInfo;\n" 236 end 237 } 238 f.print "#{indent}};\n" 239 @cell_list.each{ |cell| 240 if ! cell.exclude_info? then 241 cell.print_info f, indent 242 end 243 } 208 244 end 209 245 … … 221 257 self.print_info_region f, indent 222 258 end 259 260 def self.print_cell_define f 261 region.get_link_root.print_cell_define f 262 region.get_link_root.get_region{ |region| 263 if region.instance_of? Region then 264 region.print_cell_define_offset f 265 end 266 267 } 268 end 269 270 def print_cell_define f 271 ct_list = {} 272 @cell_list.each{ |cell| 273 next if cell.exclude_info_factory? 274 ct_list[ cell.get_celltype ] = true 275 } 276 f.print "#define TOPPERS_CB_TYPE_ONLY\n" 277 ct_list.each{ |ct, val| 278 f.print "#include \"#{ct.get_global_name}_tecsgen.h\"\n" 279 } 280 f.print "\n" 281 @cell_list.each{ |cell| 282 next if cell.exclude_info_factory? 283 name_array = cell.get_celltype.get_name_array cell 284 if cell.get_celltype.has_CB? 285 cb = "(void*)#{name_array[8]}" 286 cb_proto = "extern #{cell.get_celltype.get_global_name}_CB #{name_array[4]};\n" 287 else 288 cb = "0" 289 cb_proto = "" 290 end 291 if cell.get_celltype.has_INIB? 292 inib = "(void*)&#{name_array[5]}" 293 inib_proto = "extern #{cell.get_celltype.get_global_name}_INIB #{name_array[11]};\n" 294 else 295 inib = "0" 296 inib_proto = "" 297 end 298 if ! cell.exclude_info_factory? then 299 f.print <<EOT 300 #{cb_proto}#define #{cell.get_global_name}__CBP #{cb} 301 #{inib_proto}#define #{cell.get_global_name}__INIBP #{inib} 302 EOT 303 end 304 } 305 @namespace_list.each { |region| 306 if region.instance_of? Region then 307 region.print_cell_define f 308 end 309 } 310 end 311 312 def print_entry_descriptor_define f 313 @cell_list.each{ |cell| 314 next if cell.exclude_info_factory? 315 316 signatures = {} 317 cell.get_celltype.get_port_list.each{ |port| 318 next if port.get_port_type != :ENTRY 319 320 if signatures[ port.get_signature ] == nil then 321 f.print "#include \"#{port.get_signature.get_global_name}_tecsgen.h\"\n" 322 end 323 if cell.get_celltype.get_global_name == :nTECSInfo_tRawEntryDescriptorInfo then 324 f.print "const struct tag_#{cell.get_celltype.get_global_name}_#{port.get_name}_DES " 325 f.print "#{cell.get_global_name}_#{port.get_name}_des;\n" 326 else 327 f.print "extern struct tag_#{port.get_signature.get_global_name}_VDES " 328 f.print "#{cell.get_global_name}_#{port.get_name}_des;\n" 329 end 330 } 331 } 332 @namespace_list.each { |region| 333 if region.instance_of? Region then 334 region.print_entry_descriptor_define f 335 end 336 } 337 end 223 338 end 224 339 … … 227 342 f.print <<EOT 228 343 #{indent}cell nTECSInfo::tCelltypeInfo #{@global_name}CelltypeInfo { 229 #{indent} name = "#{@name}";230 #{indent} b_singleton = #{@singleton};231 #{indent} b_IDX_is_ID_act = C_EXP( "#{@global_name}__IDX_is_ID_act" );232 #{indent} b_hasCB = C_EXP( "#{@global_name}__hasCB" );233 #{indent} b_hasINIB = C_EXP( "#{@global_name}__hasINIB" );234 #{indent} n_cellInLin Unit = C_EXP( "#{@global_name}__NCELLINLINKUNIT" );235 #{indent} n_cellInSystem = #{@cell_list.length};344 #{indent} name = "#{@name}"; 345 #{indent} b_singleton = #{@singleton}; 346 #{indent} b_IDX_is_ID_act = C_EXP( "#{@global_name}__IDX_is_ID_act" ); 347 #{indent} sizeOfCB = C_EXP( "#{@global_name}__sizeOfCB" ); 348 #{indent} sizeOfINIB = C_EXP( "#{@global_name}__sizeOfINIB" ); 349 #{indent} n_cellInLinkUnit = C_EXP( "#{@global_name}__NCELLINLINKUNIT" ); 350 #{indent} n_cellInSystem = #{@cell_list.length}; 236 351 EOT 237 352 @port.each{ |port| … … 273 388 } 274 389 @attribute.each{ |decl| 275 decl.print_info f, @global_name, indent 390 decl.print_info f, @global_name, indent, :DECLTYPE_ATTR 276 391 } 277 392 @var.each{ |decl| 278 decl.print_info f, @global_name, indent 393 decl.print_info f, @global_name, indent, :DECLTYPE_VAR 279 394 } 280 395 end … … 295 410 if ! decl.is_omit? then 296 411 offset = "(uint32_t)(intptr_t)&(((#{@global_name}_#{inib_cb}*)0)->#{decl.get_name})" 412 place = inib_cb 297 413 else 298 414 offset = "0xffffffff" 415 place = "NON" 299 416 end 300 417 f.printf "#define OFFSET_OF_%-30s (%s)\n", "#{@global_name}_#{decl.get_name}", offset 418 f.printf "#define PLACE_OF_%-30s VARDECL_PLACE_%s\n", "#{@global_name}_#{decl.get_name}", place 301 419 } 302 420 @var.each{ |decl| 303 if decl.get_size_is then421 if decl.get_size_is && has_INIB? then 304 422 inib_cb = "INIB" 305 423 else 306 424 inib_cb = "CB" 307 425 end 308 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})" 426 place = inib_cb 427 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})" 428 f.printf "#define PLACE_OF_%-30s VARDECL_PLACE_%s\n", "#{@global_name}_#{decl.get_name}", place 309 429 } 310 430 else … … 316 436 @attribute.each{ |decl| 317 437 f.printf "#define OFFSET_OF_%-30s (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff" 438 f.printf "#define PLACE_OF_%-30s VARDECL_PLACE_NON\n", "#{@global_name}_#{decl.get_name}" 318 439 } 319 440 @var.each{ |decl| 320 441 f.printf "#define OFFSET_OF_%-30s (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff" 442 f.printf "#define PLACE_OF_%-30s VARDECL_PLACE_NON\n", "#{@global_name}_#{decl.get_name}" 321 443 } 322 444 end … … 324 446 325 447 def print_celltype_define f 326 f.printf "#define %-50s (#{@idx_is_id_act})\n", "#{@global_name}__IDX_is_ID_act" 327 f.printf "#define %-50s (#{has_CB?})\n", "#{@global_name}__hasCB" 328 f.printf "#define %-50s (#{has_INIB?})\n", "#{@global_name}__hasINIB" 329 f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen 448 if has_INIB? then 449 size_INIB = "(sizeof(#{@global_name}_INIB))" 450 else 451 size_INIB = "(0)" 452 end 453 if has_CB? then 454 size_CB = "(sizeof(#{@global_name}_CB))" 455 else 456 size_CB = "(0)" 457 end 458 459 if @n_cell_gen > 0 then 460 f.printf "\n#include \"#{@global_name}_tecsgen.h\"\n" 461 f.printf "#define %-50s (#{@idx_is_id_act})\n", "#{@global_name}__IDX_is_ID_act" 462 f.printf "#define %-50s (#{size_CB})\n", "#{@global_name}__sizeOfCB" 463 f.printf "#define %-50s (#{size_INIB})\n", "#{@global_name}__sizeOfINIB" 464 f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen 465 else 466 f.printf "#define %-50s (false)\n", "#{@global_name}__IDX_is_ID_act" 467 f.printf "#define %-50s (0)\n", "#{@global_name}__sizeOfCB" 468 f.printf "#define %-50s (0)\n", "#{@global_name}__sizeOfINIB" 469 f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen 470 end 330 471 end 331 472 … … 365 506 end 366 507 end 367 if ( port.is_VMT_useless? && port.is_cell_unique? ) || @n_cell_gen == 0 then508 if ( port.is_VMT_useless? && port.is_cell_unique? ) || port.is_omit? || @n_cell_gen == 0 then 368 509 offset = "0xffffffff" 369 510 else … … 375 516 offset = "(uint32_t)(intptr_t)&((#{@global_name}_#{cb_inib}*)0)->#{port.get_name}" 376 517 end 518 array_size = port.get_array_size 519 if array_size == "[]" then 520 array_size = "0xffffffff" 521 elsif array_size == nil then 522 array_size = "0" 523 end 524 377 525 f.printf "#define %-50s (#{offset})\n", "#{@global_name}_#{port.get_name}__offset" 526 f.printf "#define %-50s (#{array_size})\n", "#{@global_name}_#{port.get_name}__array_size" 378 527 f.printf "#define %-50s (#{place})\n", "#{@global_name}_#{port.get_name}__place" 379 528 f.printf "#define %-50s (#{port.is_VMT_useless?})\n", "#{@global_name}_#{port.get_name}__b_VMT_useless" … … 382 531 } 383 532 end 533 534 def print_entry_define f 535 @port.each{ |port| 536 next if port.get_port_type == :CALL 537 array_size = port.get_array_size 538 if array_size == "[]" then 539 array_size = "0xffffffff" 540 elsif array_size == nil then 541 array_size = "0" 542 end 543 544 f.printf "#define %-50s (#{array_size})\n", "#{@global_name}_#{port.get_name}__array_size" 545 } 546 end 384 547 end 385 548 … … 393 556 #{indent} cSignatureInfo = #{@signature.get_global_name}SignatureInfo.eSignatureInfo; 394 557 #{indent} b_inline = #{@b_inline}; 558 #{indent} array_size = C_EXP( "#{ct_global}_#{@name}__array_size" ); 395 559 #{indent}}; 396 560 EOT … … 401 565 #{indent} cSignatureInfo = #{@signature.get_global_name}SignatureInfo.eSignatureInfo; 402 566 #{indent} offset = C_EXP( "#{ct_global}_#{@name}__offset" ); 567 #{indent} array_size = C_EXP( "#{ct_global}_#{@name}__array_size" ); 403 568 #{indent} b_optional = #{@b_optional}; 404 569 #{indent} b_omit = #{@b_omit}; … … 418 583 end 419 584 585 class Cell 586 def print_info f, indent 587 if exclude_info? then 588 return 589 end 590 f.print <<EOT 591 592 #{indent}/*** #{@global_name} cell information ****/ 593 #{indent}cell nTECSInfo::tCellInfo #{@global_name}CellInfo { 594 #{indent} name = "#{@name}"; 595 #{indent} cbp = C_EXP( \"#{@global_name}__CBP\" ); 596 #{indent} inibp = C_EXP( \"#{@global_name}__INIBP\" ); 597 #{indent} cCelltypeInfo = #{@celltype.get_global_name}CelltypeInfo.eCelltypeInfo; 598 EOT 599 @celltype.get_port_list.each{ |port| 600 next if port.get_port_type != :ENTRY 601 602 f.print <<EOT 603 #{indent} cRawEntryDescriptor[] = #{@global_name}_#{port.get_name}RawEntryDescriptorInfo.eRawEntryDescriptor; 604 EOT 605 } 606 f.print "#{indent}};\n" 607 608 # RawEntryDescriptorInfo cells 609 @celltype.get_port_list.each{ |port| 610 next if port.get_port_type != :ENTRY 611 612 size = port.get_array_size 613 if size == nil then 614 size = 1 615 elsif size == "[]" then 616 size = @entry_array_max_subscript[ port ] 617 end 618 if ! port.is_omit? then 619 red = "C_EXP( \"&#{@global_name}_#{port.get_name}_des\" )" 620 else 621 red = "(void *)0" 622 end 623 # mikan 受け口配列 624 f.print <<EOT 625 #{indent}cell nTECSInfo::tRawEntryDescriptorInfo #{@global_name}_#{port.get_name}RawEntryDescriptorInfo { 626 #{indent} size = #{size}; 627 #{indent} rawEntryDescriptor = { #{red} }; 628 EOT 629 # #{indent} cEntryInfo = #{@celltype.get_global_name}_#{port.get_name}EntryInfo.eEntryInfo; 630 f.print "#{indent}};\n" 631 } 632 end 633 634 def exclude_info? 635 # print "exclude_info?: name=" + get_name.to_s 636 if @celltype == nil || 637 is_of_composite? || 638 @celltype.get_global_name == :nTECSInfo_tTECSInfoSub || 639 post_code_generated? || 640 @b_defined == false then 641 # print ": true celltype_is_of_composite=#{is_of_composite?} celltype_name=#{@celltype.get_global_name} celltype.need_generate=#{@celltype.need_generate?}\n" 642 return true 643 else 644 # print ": false\n" 645 return false 646 end 647 end 648 649 def exclude_info_factory? 650 # print "exclude_info_factory?: name=" + get_name.to_s 651 if @celltype == nil || 652 is_of_composite? || 653 @celltype.get_global_name == :nTECSInfo_tTECSInfoSub || 654 ! @celltype.need_generate? then 655 # print ": true celltype_is_of_composite=#{is_of_composite?} celltype_name=#{@celltype.get_global_name} celltype.need_generate=#{@celltype.need_generate?}\n" 656 return true 657 else 658 # print ": false\n" 659 return false 660 end 661 end 662 end 663 420 664 class Signature 421 665 def print_info f, indent … … 446 690 f.print <<EOT 447 691 #{indent}cell nTECSInfo::tFunctionInfo #{sig_name}_#{func_name}FunctionInfo { 448 #{indent} name = "#{ @owner.get_global_name}_#{@name}";692 #{indent} name = "#{get_name}"; 449 693 #{indent} bOneway = #{is_oneway?}; 450 694 EOT … … 502 746 503 747 class Decl 504 def print_info f, parent_ID_str, indent 748 def print_info f, parent_ID_str, indent, decl_type 505 749 if @size_is then 506 750 size = "\"mikan\""; … … 512 756 #{indent} name = "#{get_name}"; 513 757 #{indent} sizeIsExpr = #{size}; 514 #{indent} declType = DECLTYPE_STMEMBER;758 #{indent} declType = #{decl_type}; 515 759 #{indent} offset = C_EXP( "OFFSET_OF_#{parent_ID_str}_#{get_name}" ); 760 #{indent} place = C_EXP( "PLACE_OF_#{parent_ID_str}_#{get_name}" ); 516 761 #{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo; 517 762 #{indent}}; … … 523 768 class Type 524 769 @@typeinfo_printed = {} 770 771 def self.reset_print_info 772 @@typeinfo_printed = {} 773 end 774 525 775 def print_info f, indent 526 776 # Type の info は、最後にまとめて出力するので、ここでは記録するだけ … … 538 788 elsif self.kind_of? StructType then 539 789 get_members_decl.get_items.each{ |decl| 540 decl. get_type.print_info f, indent790 decl.print_info f, get_ID_str, indent, :DECLTYPE_STMEMBER 541 791 } 542 792 end … … 550 800 551 801 def print_info_post f, indent 552 bit_size = get_bit_size553 if bit_size == 0 then554 bit_size = "C_EXP( \"sizeof(#{get_type_str}#{get_type_str_post})\" )"555 end556 802 if self.class.superclass == Type then # 親クラスが Type の場合 types.rb のクラス 557 803 type_name = self.class.name … … 566 812 #{indent} name = "#{get_type_str}#{get_type_str_post}"; 567 813 #{indent} typeKind = TECSTypeKind_#{type_name}; 568 #{indent} bitSize = #{bit_size};814 #{indent} size = C_EXP( "sizeof(#{get_type_str}#{get_type_str_post})" ); 569 815 #{indent} b_const = #{is_const?}; 570 816 #{indent} b_volatile = #{is_volatile?}; 571 817 EOT 572 818 if self.kind_of? PtrType then 573 f.print "#{indent} cTypeInfo = #{get_referto.get_ID_str}TypeInfo.eTypeInfo;\n"819 f.print "#{indent} cTypeInfo = #{get_referto.get_ID_str}TypeInfo.eTypeInfo;\n" 574 820 elsif self.kind_of? ArrayType then 575 f.print "#{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"821 f.print "#{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n" 576 822 elsif self.kind_of? DefinedType then 577 f.print "#{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"823 f.print "#{indent} cTypeInfo = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n" 578 824 elsif self.kind_of? StructType then 579 825 get_members_decl.get_items.each{ |decl| 580 f.print "#{indent} c TypeInfo[] = #{decl.get_type.get_ID_str}TypeInfo.eTypeInfo;\n"826 f.print "#{indent} cVarDeclInfo[] = #{get_ID_str}_#{decl.get_name}VarDeclInfo.eVarDeclInfo;\n" 581 827 } 582 828 elsif self.kind_of? DescriptorType then
Note:
See TracChangeset
for help on using the changeset viewer.