Class: Celltype

Inherits:
NSBDNode show all
Includes:
CelltypePluginModule, PluginModule
Defined in:
lib/tecsgen/core/componentobj.rb,
lib/tecsgen/core/gen_xml.rb,
lib/tecsgen/core/generate.rb,
lib/tecsgen/core/optimize.rb,
lib/tecsgen/core/tecsinfo.rb,
lib/tecsgen/core/unjoin_plugin.rb

Overview

CelltypePluginModule

Constant Summary collapse

ID_BASE =

reset_optimize でリセットする

1
@@ID_BASE =
ID_BASE
@@nest_stack_index =
-1
@@nest_stack =
[]
@@current_object =
nil
@@celltype_list =
[]
@@dynamic_join_checked_list =
{}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CelltypePluginModule

#apply_plugin, #apply_plugin_cell, #celltype_plugin, #celltype_plugin_new_cell

Methods included from PluginModule

gen_plugin_post_code, #generate_and_parse, #load_plugin

Methods inherited from NSBDNode

#get_namespace, #get_namespace_path, #is_imported?, #set_namespace_path

Methods inherited from BDNode

#get_owner, #set_owner

Methods inherited from Node

#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale

Constructor Details

#initialize(name) ⇒ Celltype

Returns a new instance of Celltype.



605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/tecsgen/core/componentobj.rb', line 605

def initialize(name)
  super()
  @@current_object = self
  @name = name
  if Namespace.get_global_name&.empty?
    @global_name = name
  else
    @global_name = :"#{Namespace.get_global_name}_#{@name}"
  end

  @name_list = NamedList.new(nil, "symbol in celltype #{name}")
  @port = []
  @attribute = []
  @var = []
  @require = []
  @factory_list = []
  @ct_factory_list = []
  @cell_list = []
  @singleton = false
  @active = false
  @generate = nil
  @generate_list = []

  @n_attribute_ro = 0
  @n_attribute_rw = 0
  @n_attribute_omit = 0
  @n_var = 0
  @n_var_omit = 0
  @n_var_size_is = 0
  @n_var_init = 0
  @n_call_port = 0
  @n_call_port_array = 0
  @n_call_port_omitted_in_CB = 0
  @n_call_port_dynamic = 0
  @n_call_port_array_dynamic = 0
  @n_call_port_ref_desc = 0
  @n_call_port_array_ref_desc = 0
  @n_entry_port = 0
  @n_entry_port_array = 0
  @n_entry_port_array_ns = 0
  @n_entry_port_inline = 0
  @n_cell_gen = 0

  @b_cp_optimized = false

  @plugin = Generator.get_plugin
    # plugin の場合 PluginObject が返される
  # 元の Generator から呼出された Generator の中でパースおよび意味チェックされている

  # if @plugin then
  #  # plugin 生成されるセルタイプは再利用ではない   #833 不具合修正
  #  @b_reuse = false
  # else
    @b_reuse = Generator.is_reuse?
  # end

  if $idx_is_id
    @idx_is_id = true
  else
    @idx_is_id = false
  end
  @idx_is_id_act = @idx_is_id

  Namespace.new_celltype(self)
  set_namespace_path # @NamespacePath の設定
  set_specifier_list(Generator.get_statement_specifier)

  @included_header = {}
  @domain_roots = {}
  @@celltype_list << self
end

Class Method Details

.check_dynamic_joinObject



1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/tecsgen/core/componentobj.rb', line 1008

def self.check_dynamic_join
  Namespace.get_root.travers_all_celltype{|ct|
    if @@dynamic_join_checked_list[ct].nil?
      @@dynamic_join_checked_list[ct] = true
      ct.check_dynamic_join
    end
  }
end

.get_celltype_listObject

Celltype.get_celltype_list



1308
1309
1310
# File 'lib/tecsgen/core/componentobj.rb', line 1308

def self.get_celltype_list
  @@celltype_list
end

.new_attribute(attribute) ⇒ Object



746
747
748
# File 'lib/tecsgen/core/componentobj.rb', line 746

def self.new_attribute(attribute)
  @@current_object.new_attribute(attribute)
end

.new_factory(factory) ⇒ Object



992
993
994
# File 'lib/tecsgen/core/componentobj.rb', line 992

def self.new_factory(factory)
  @@current_object.new_factory(factory)
end

.new_port(port) ⇒ Object



714
715
716
# File 'lib/tecsgen/core/componentobj.rb', line 714

def self.new_port(port)
  @@current_object.new_port(port)
end

.new_require(ct_or_cell_nsp, ep_name, cp_name = nil) ⇒ Object



912
913
914
# File 'lib/tecsgen/core/componentobj.rb', line 912

def self.new_require(ct_or_cell_nsp, ep_name, cp_name = nil)
  @@current_object.new_require(ct_or_cell_nsp, ep_name.to_sym, cp_name)
end

.new_var(var) ⇒ Object



851
852
853
# File 'lib/tecsgen/core/componentobj.rb', line 851

def self.new_var(var)
  @@current_object.new_var(var)
end

.popObject



597
598
599
600
601
602
603
# File 'lib/tecsgen/core/componentobj.rb', line 597

def self.pop
  @@current_object = @@nest_stack[@@nest_stack_index]
  @@nest_stack_index -= 1
  if @@nest_stack_index < -1
    raise "TooManyRestore"
  end
end

.pushObject



591
592
593
594
595
# File 'lib/tecsgen/core/componentobj.rb', line 591

def self.push
  @@nest_stack_index += 1
  @@nest_stack[@@nest_stack_index] = @@current_object
  @@current_object = nil
end

Instance Method Details

#check_attributeObject

Celltype# celltype の attribute/var のチェック

STAGE: S

このメソッドは celltype のパースが完了した時点で呼出される.



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/tecsgen/core/componentobj.rb', line 775

def check_attribute
  # attribute の size_is 指定が妥当かチェック
  (@attribute + @var).each{|a|
    if a.get_size_is
      if !a.get_type.is_a?(PtrType)
        # size_is がポインタ型以外に指定された
        cdl_error("S1011 $1: size_is specified for non-pointer type", a.get_identifier)
      else

        # 参照する変数が存在し、計算可能な型かチェックする
        size = a.get_size_is.eval_const(@name_list) # C_EXP の可能性あり
        init = a.get_initializer
        if init
          if !init.instance_of?(Array)
            # 初期化子が配列ではない
            cdl_error("S1012 $1: unsuitable initializer, need array initializer", a.get_identifier)
          elsif size.is_a?(Integer) && size < init.length
            # size_is 指定された個数よりも初期化子の配列要素が多い
            cdl_error("S1013 $1: too many initializer, $2 for $3", a.get_identifier, init.length, size)
          # elsif a.get_size_is.eval_const( nil ) == nil  # C_EXP の可能性あり
          end

        end
      end
    else
      if a.get_type.is_a?(PtrType)
        if a.get_initializer.instance_of?(Array) ||
            (a.get_initializer.instance_of?(Expression) &&
              a.get_initializer.eval_const2(@name_list).instance_of?(Array))
          # size_is 指定されていないポインタが Array で初期化されていたら、エラー
          cdl_error("S1159 $1: non-size_is pointer cannot be initialized with array initializer", a.get_identifier)
        end
      end
    end
  }
end

#check_dynamic_joinObject

Celltype#dynamic の適合性チェック



1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
# File 'lib/tecsgen/core/componentobj.rb', line 1018

def check_dynamic_join
  @port.each{|port|
    signature = port.get_signature
    next if signature.nil? # すでにエラー
    if port.is_dynamic?
      dbgPrint("[DYNAMIC] checking dynamic port: #{@global_name}.#{port.get_name}\n")
      # print( "[DYNAMIC] checking dynamic port: #{@global_name}.#{port.get_name}\n" )
      next if find_ref_desc_port signature
      next if find_descriptor_param signature, :DYNAMIC
      cdl_warning("W9999 $1 cannot get information for dynamic port $2", @name, port.get_name)
    elsif port.is_ref_desc?
      dbgPrint("[DYNAMIC] checking ref_desc port: #{@global_name}.#{port.get_name}\n")
      # print( "[DYNAMIC] checking ref_desc port: #{@global_name}.#{port.get_name}\n" )
      next if find_dynamic_port signature
      next if find_descriptor_param signature, :REF_DESC
      cdl_warning("W9999 $1 cannot put information from ref_desc port $2", @name, port.get_name)
    elsif port.get_signature
      if port.get_signature.has_descriptor?
        port.get_signature.get_descriptor_list.each{|signature, param|
          dbgPrint("[DYNAMIC] checking Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n")
          # print( "[DYNAMIC] checking Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n" )
          if port.get_port_type == :CALL
            if param.get_direction == :IN
              next if find_ref_desc_port signature
              next if find_descriptor_param signature, :DYNAMIC
            elsif param.get_direction == :OUT
              next if find_dynamic_port signature
              next if find_descriptor_param signature, :REF_DESC
            end
          else # :ENTRY
            if param.get_direction == :IN
              next if find_dynamic_port signature
              next if find_descriptor_param signature, :REF_DESC
            elsif param.get_direction == :OUT
              next if find_ref_desc_port signature
              next if find_descriptor_param signature, :DYNAMIC
            end
          end
          cdl_warning('W9999 "$1" cannot handle Descriptor "$2" infromation for port "$3"', @name, param.get_name, port.get_name)
        }
      end
    end
  }
end

#create_reverse_require_join(cell) ⇒ Object

Celltype# 逆require の結合を生成する



1197
1198
1199
1200
1201
# File 'lib/tecsgen/core/componentobj.rb', line 1197

def create_reverse_require_join(cell)
  @port.each{|p|
    p.create_reverse_require_join cell
  }
end

#end_of_parseObject

Celltype# end_of_parse



688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'lib/tecsgen/core/componentobj.rb', line 688

def end_of_parse
  # 属性・変数のチェック
  check_attribute

  # アロケータ呼び口を内部生成
  generate_allocator_port

  # リレーアロケータ、内部アロケータの設定
  @port.each {|p|
    p.set_allocator_instance
  }

  if @n_entry_port == 0 && @active == false && @factory_list.length == 0 &&
      (@singleton && @ct_factory_list.length == 0 || !@singleton)
    cdl_warning("W1002 $1: non-active celltype has no entry port & factory", @name)
  end

  if @generate
    celltype_plugin
  end

  # check_dynamic_join ##

  @@current_object = nil
end

#find(name) ⇒ Object



1227
1228
1229
# File 'lib/tecsgen/core/componentobj.rb', line 1227

def find(name)
  @name_list.get_item(name)
end

#find_descriptor_param(signature, dyn_ref) ⇒ Object

Celltype#ディスクリプタ型でシグニチャが一致し dyn_ref に対応づく引数を探す

dyn_ref::Symbol: :DYNAMIC=ディスクリプタを得る手段となる引数を探す.:REF_DESC=渡す手段となる引数を探す



1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
# File 'lib/tecsgen/core/componentobj.rb', line 1086

def find_descriptor_param(signature, dyn_ref)
  param_list = []
  @port.each{|port|
    port.each_param{|port, func, param|
      type = param.get_type
      while type.is_a? PtrType
        type = type.get_type
      end
      dbgPrint("[DYNAMIC] dyn_ref=#{dyn_ref} port_type=#{port.get_port_type} dir=#{param.get_direction} paramName=#{param.get_name} paramType=#{type.class}\n")
      # print( "[DYNAMIC] dyn_ref=#{dyn_ref} port_type=#{port.get_port_type} dir=#{param.get_direction} paramName=#{param.get_name} paramType=#{type.class}\n" )
      if type.is_a? DescriptorType
        if type.get_signature == signature
          dir = param.get_direction
          if dir == :INOUT
            dbgPrint("[DYNAMIC] found INOUT Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n")
            # print( "[DYNAMIC] found INOUT Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n" )
            return param
          elsif dyn_ref == :DYNAMIC
            if dir == :IN && port.get_port_type == :ENTRY ||
               dir == :OUT && port.get_port_type == :CALL
              dbgPrint("[DYNAMIC] found INBOUND Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n")
              # print( "[DYNAMIC] found INBOUND Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n" )
              return param
            end
          elsif dyn_ref == :REF_DESC
            if dir == :IN && port.get_port_type == :CALL ||
               dir == :OUT && port.get_port_type == :ENTRY
              dbgPrint("[DYNAMIC] found OUTBOUND Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n")
              # print( "[DYNAMIC] found OUTBOUND Descriptor parameter: #{@global_name}.#{port.get_name} ... #{param.get_name}\n" )
              return param
            end
          else
            raise "unknown ref_desc"
          end
        end
      end
    }
  }
  return nil
end

#find_dynamic_port(signature) ⇒ Object



1063
1064
1065
1066
1067
1068
1069
1070
# File 'lib/tecsgen/core/componentobj.rb', line 1063

def find_dynamic_port(signature)
  dbgPrint "[DYNAMIC] find_dynamic_port signature=#{signature.get_name}"
  @port.each{|port|
    dbgPrint "[DYNAMIC] port=#{port.get_name} signature=#{port.get_signature.get_name} dynamic=#{port.is_dynamic?}"
    return port if port.is_dynamic? && port.get_signature == signature
  }
  return nil
end

#find_ref_desc_port(signature) ⇒ Object



1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
# File 'lib/tecsgen/core/componentobj.rb', line 1072

def find_ref_desc_port(signature)
  if signature.nil? # すでにエラー
    return nil
  end
  dbgPrint "[DYNAMIC] find_ref_desc_port signature=#{signature.get_name}"
  @port.each{|port|
    dbgPrint "[DYNAMIC] port=#{port.get_name} signature=#{port.get_signature.get_name} ref_desc=#{port.is_ref_desc?}"
    return port if port.is_ref_desc? && port.get_signature == signature
  }
  return nil
end

#gen_cell_cb(fs) ⇒ Object



3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
# File 'lib/tecsgen/core/generate.rb', line 3522

def gen_cell_cb(fs)
  if has_INIB?
    if @n_cell_gen > 0
      fs.each{|r, f| f.printf(TECSMsg.get(:INIB_comment), "#_INIB_#") }
    end
    if @singleton
      fs.each{|r, f| f.print "#{@global_name}_INIB #{@global_name}_SINGLE_CELL_INIB = \n" }
      indent = 0
    elsif !@idx_is_id_act
      fs.each{|r, f| f.print "#{@global_name}_INIB #{@global_name}_INIB_tab[] = {\n" }
      indent = 1
    else
      indent = 0
    end

    @ordered_cell_list.each{|c|
      next if !c.is_generate?

      f = fs[c.get_region.get_domain_root]

      name_array = get_name_array(c)

      unless @singleton
        print_indent(f, indent)
        f.print "/* cell: #{name_array[2]}:  #{name_array[1]} id=#{c.get_id} */\n"
        # name_array[2]: cell_CB_name
      end

      print_indent(f, indent)
      if @idx_is_id_act
        f.print "const #{@global_name}_INIB #{name_array[5]} = "
      end
      f.print "{\n"

      gen_cell_cb_port(c, indent, f, name_array, :INIB)
      gen_cell_cb_attribute(c, indent, f, name_array, :INIB)

      unless @singleton
        # 1 つの cell INIB の終わり
        if @idx_is_id_act
          f.print("};\n\n")
        else
          f.print("    },\n")
        end
      end
    }
    if !@idx_is_id_act
      fs.each{|r, f| f.print("};\n\n") }
    end
  end # has_INIB?

  if has_CB?
    if @n_cell_gen > 0
      fs.each{|r, f| f.printf(TECSMsg.get(:CB_comment), "#_CB_#") }
    end

    # RAM initializer を使用しない、または ROM 化しない
    if $ram_initializer == false || $rom == false
      if @singleton
        fs.each{|r, f| f.print "struct tag_#{@global_name}_CB #{@global_name}_SINGLE_CELL_CB = \n" }
        indent = 0
      elsif !@idx_is_id_act
        fs.each{|r, f| f.print "struct tag_#{@global_name}_CB #{@global_name}_CB_tab[] = {\n" }
        indent = 1
      else
        indent = 0
      end

      @ordered_cell_list.each{|c|
        next if !c.is_generate?

        f = fs[c.get_region.get_domain_root]

        name_array = get_name_array(c)

        unless @singleton
          print_indent(f, indent)
          f.print "/* cell: #{name_array[2]}:  #{name_array[1]} id=#{c.get_id} */\n"
          # name_array[2]: cell_CB_name
        end

        print_indent(f, indent)
        if @idx_is_id_act
          f.print "#{@global_name}_CB #{name_array[2]} = "
        end
        f.print "{\n"

        if has_INIB?
          print_indent(f, indent + 1)
          f.printf("&%-39s /* _inib */\n", "#{name_array[5]},")
        end

        # if ! has_INIB? then
        if $rom == false
          gen_cell_cb_port(c, indent, f, name_array, :CB_ALL)
        else
          gen_cell_cb_port(c, indent, f, name_array, :CB_DYNAMIC)
        end

        gen_cell_cb_attribute(c, indent, f, name_array, :CB)
        gen_cell_cb_var(c, indent, f, name_array)

        unless @singleton
          # 1 つの cell CB の終わり
          if @idx_is_id_act
            f.print("};\n\n")
          else
            f.print("    },\n")
          end
        end
      }
      if !@idx_is_id_act
        fs.each{|r, f| f.print("};\n\n") }
      end
    else
      if @singleton
        fs.each{|r, f| f.print "struct tag_#{@global_name}_CB #{@global_name}_SINGLE_CELL_CB;\n" }
        indent = 0
      elsif @idx_is_id_act
        @ordered_cell_list.each{|c|
          next if !c.is_generate?

          f = fs[c.get_region.get_domain_root]

          name_array = get_name_array(c)
          f.print "/* cell: #{name_array[2]}:  #{name_array[1]} id=#{c.get_id} */\n"
          f.print "#{@global_name}_CB #{name_array[2]} = {};\n"
        }
      else
        fs.each{|r, f| f.print "struct tag_#{@global_name}_CB #{@global_name}_CB_tab[#{@n_cell_gen}];\n" }
      end
    end
  end # has_CB?
end

#gen_cell_cb_attribute(cell, indent, f, name_array, cb_inib) ⇒ Object

attribute と size_is 指定された var (ポインタ)の初期化データを出力

ROM 化サポートの有無、および出力対象が CB か INIB かにより出力される内容が異なる



3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
# File 'lib/tecsgen/core/generate.rb', line 3780

def gen_cell_cb_attribute(cell, indent, f, name_array, cb_inib)
  ct = self
  jl = cell.get_join_list

  if cb_inib == :INIB
    return if @n_attribute_ro == 0 && @n_var_size_is == 0
    print_indent(f, indent + 1)
    f.print "/* attribute(RO) */ \n"
  elsif $rom # && cb_inib == CB
    # CB で rw と var
    return if @n_attribute_rw == 0
    print_indent(f, indent + 1)
    f.print "/* attribute(RW) */ \n"
  else # cb_inib == CB && $rom == false
    # CB に全部
    return if @n_attribute_rw == 0 && @n_attribute_ro == 0 && @n_var_size_is == 0
    print_indent(f, indent + 1)
    f.print "/* attribute */ \n"
  end

  attribute = ct.get_attribute_list
  attribute.each{|a| # a: Decl
    next if a.is_omit?
    if cb_inib == :INIB && a.is_rw? == true
      # $rom == true でしか、ここへ来ない
      next
    elsif cb_inib == :CB && $rom && !a.is_rw?
      next
    end

    j = jl.get_item(a.get_identifier)
    if j
      # cell の初期値指定あり
      gen_cell_cb_init(f, cell, name_array, a.get_type, j.get_rhs, a.get_identifier, indent + 1)
    elsif a.get_initializer
      # celltype の default の初期値あり
      gen_cell_cb_init(f, cell, name_array, a.get_type, a.get_initializer, a.get_identifier, indent + 1)
    else
      # 初期値未指定
      gen_cell_cb_init(f, cell, name_array, a.get_type, nil, a.get_identifier, indent + 1)
    end
  }
  @var.each{|v|
    next if v.is_omit?
    next if v.get_size_is.nil? # size_is 指定がある場合 attribute の一部として出力

    if v.get_initializer && $ram_initializer == false
      gen_cell_cb_init(f, cell, name_array, v.get_type, v.get_initializer, v.get_identifier, indent + 1)
    else
      # 初期値未指定 または RAM initializer 使用
      gen_cell_cb_init(f, cell, name_array, v.get_type, nil, v.get_identifier, indent + 1)
    end
  }
end

#gen_cell_cb_call_port(cell, indent, f, name_array, inib_cb) ⇒ Object

呼び口の初期化コードの生成



3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
# File 'lib/tecsgen/core/generate.rb', line 3864

def gen_cell_cb_call_port(cell, indent, f, name_array, inib_cb)
  jl = cell.get_join_list

  port = get_port_list
  if inib_cb == :INIB && (@n_call_port - @n_call_port_omitted_in_CB -
                           ($ram_initializer ? 0 : (@n_call_port_dynamic - @n_call_port_array_dynamic)) > 0) ||
     inib_cb == :CB_ALL && @n_call_port > 0 ||
     inib_cb == :CB_DYNAMIC && (@n_call_port_dynamic - @n_call_port_array_dynamic) > 0
    print_indent(f, indent + 1)
    f.print "/* call port (#{inib_cb}) #_CP_# */ \n"
    port.each{|p|
      next if p.get_port_type != :CALL
      next if p.is_omit?
      next if p.is_cell_unique? # 最適化(単一セルで呼び口マクロに埋め込まれる)
      next if inib_cb == :INIB && p.is_dynamic? && p.get_array_size.nil? && !$ram_initializer
      next if inib_cb == :CB_DYNAMIC && (!p.is_dynamic? || !p.get_array_size.nil?)

      j = jl.get_item(p.get_name)
      print_indent(f, indent + 1)

      # debug
      if j.nil?
        dbgPrint "cell_cb_call_port: #{p.get_name} array size=#{p.get_array_size}\n"
        # optional 呼び口
        # cdl_error( "H1003 internal error: cell \'$1\' port \'$2\': initializer not found\n" , cell.get_name, p.get_name )
        # exit( 1 )
        if p.get_array_size
          if p.is_dynamic?
            if inib_cb == :INIB
              if $ram_initializer
                f.printf("%-40s /* #_CCP7_# _init_ */\n", "#{cell.get_global_name}_#{p.get_name}_init_,")
                print_indent(f, indent + 1)
              end
              f.printf("%-40s /* #_CCP7B_# */\n", "#{cell.get_global_name}_#{p.get_name},")
            elsif $rom == false
              f.printf("%-40s /* #_CCP8_# */\n",  "#{cell.get_global_name}_#{p.get_name},")
            end
          else
            f.printf("%-40s /* #_CCP9_# */\n", "0,")
          end
          if p.get_array_size == "[]"
            # 添数省略の呼び口配列
            print_indent(f, indent + 1)
            f.printf("%-40s /* %s #_CCP6_# */\n", "0,", "length of #{p.get_name} (n_#{p.get_name})")
          end
        else
          f.printf("%-40s /* #_CCP5_# */\n", "0,")
        end
        next
      end

      am = j.get_array_member2
      if am
        # 呼び口配列の場合
        if inib_cb == :INIB && p.is_dynamic? && !p.get_array_size.nil? && $ram_initializer
          f.printf("%-40s /* #_CCP3_# _init_ */\n", "#{cell.get_global_name}_#{j.get_name}_init_,")
          print_indent(f, indent + 1)
        end
        f.printf("%-40s /* #_CCP3B_# */\n", "#{cell.get_global_name}_#{j.get_name},")
        if p.get_array_size == "[]"
          # 添数省略の呼び口配列
          print_indent(f, indent + 1)
          f.printf("%-40s /* %s #_CCP4_# */\n", "#{am.length},", "length of #{p.get_name} (n_#{p.get_name})")
        end
      else
        # 同一セルタイプの結合の場合、VDES 型へのキャストが必要
        # print "CCP0/CCP1 #{p.get_name}, #{j.get_rhs_cell.get_celltype.get_name}, #{@name}\n"
        if j.get_rhs_cell.get_celltype == self
          definition = j.get_definition
          des_type_cast = "(struct tag_#{definition.get_signature.get_global_name}_VDES *)"
        else
          des_type_cast = ""
        end

        init = (p.is_dynamic? && inib_cb == :INIB) ? "_init_" : ""

        if j.get_rhs_subscript
          # 受け口配列の場合
          subscript = j.get_rhs_subscript
          f.printf("%-40s /* %s #_CCP0_# */\n",
                    # "&#{j.get_cell_global_name}_#{j.get_port_name}_des#{subscript},",
                    "#{des_type_cast}&#{j.get_port_global_name}_des#{subscript},",
                    p.get_name.to_s + init)
        else
          # 呼び口配列でも、受け口配列でもない
          if !p.is_skelton_useless?
            f.printf("%-40s /* %s #_CCP1_# */\n",
                      "#{des_type_cast}&#{j.get_port_global_name}_des,",
                      p.get_name.to_s + init)
          else
            # スケルトン不要最適化(CB (INIB) へのポインタを埋め込む)
            c = j.get_rhs_cell                    # 呼び先セル
            ct = c.get_celltype                   # 呼び先セルタイプ
            if ct.has_INIB? || ct.has_CB?
              name_array = ct.get_name_array(c)   # 呼び先セルタイプで name_array を得る
              f.printf("%-40s /* %s #_CCP2_# */\n", "#{name_array[7]},", p.get_name)
            else
              # 呼び先は CB も INIB も持たない(NULL に初期化)
              f.printf("%-40s /* %s #_CCP2B_# */\n", "0,", p.get_name)
            end
          end
        end
      end

    }
    end
end

#gen_cell_cb_entry_port(cell, indent, f, name_array) ⇒ Object

受け口の初期化コードの生成



3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
# File 'lib/tecsgen/core/generate.rb', line 3973

def gen_cell_cb_entry_port(cell, indent, f, name_array)
  jl = cell.get_join_list

  port = get_port_list
  if @n_entry_port != 0
    print_indent(f, indent + 1)
    f.print "/* entry port #_EP_# */ \n"
    @port.each{|p|
      # next if p.is_omit?  # 受け口配列の個数は省略しない
      if p.get_port_type == :ENTRY && p.get_array_size == "[]"
        print_indent(f, indent + 1)
        f.printf("%-40s /*  #_EEP_# */\n", "#{cell.get_entry_port_max_subscript(p) + 1},")
      end
    }
  end
end

#gen_cell_cb_init(f, cell, name_array, type, init, identifier, indent, f_get_str = false) ⇒ Object

セルの attribute の初期値を出力

f_get_str

true の場合、文字列を返す、false の場合、ファイル f に出力する.

文字列を返すとき、末尾に ‘,’ は含まれない. ファイルへ出力するとき、末尾に ‘,’ が出力される.構造体要素、配列要素の初期値を出力すると ‘,’ が二重に出力される. ただし現状では、ファイルへ出力することはない



3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
# File 'lib/tecsgen/core/generate.rb', line 3997

def gen_cell_cb_init(f, cell, name_array, type, init, identifier, indent, f_get_str = false)
  cell_CB_name = name_array[2]
  cell_CB_INIT = name_array[3]

  while type.is_a?(DefinedType)
    type = type.get_type
  end

  if init.nil?

    if f_get_str
      # 初期値未指定
      if type.is_a?(BoolType)
        str = "false" # formerly tecs_false
      elsif type.is_a?(IntType)
        str = "0"
      elsif type.is_a?(FloatType)
        str = "0.0"
      elsif type.is_a?(EnumType)
        str = "0"
      elsif type.is_a?(ArrayType)
        str = "{}"
      elsif type.is_a?(StructType)
        str = "{}"
      elsif type.is_a?(PtrType)
        if type.get_size
          str = "#{cell_CB_INIT}_#{identifier}_INIT"
        else
          str = "0"
        end
      else
        raise "UnknownType"
      end
      return str
    else
      # 初期値未指定
      if type.is_a?(BoolType)
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "false,", identifier) # formerly tecs_false
      elsif type.is_a?(IntType)
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "0,", identifier)
      elsif type.is_a?(FloatType)
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "0.0,", identifier)
      elsif type.is_a?(EnumType)
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "0,", identifier)
      elsif type.is_a?(ArrayType)
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "{},", identifier)
      elsif type.is_a?(StructType)
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "{},", identifier)
      elsif type.is_a?(PtrType)
        if type.get_size
          f.print "    " * indent
          f.printf("%-40s /* %s */\n", "#{cell_CB_INIT}_#{identifier}_INIT,", identifier)
        else
          f.print "    " * indent
          f.printf("%-40s /* %s */\n", "0,", identifier)
        end
      else
        raise "UnknownType"
      end
    end
    return
  end

  # このメソッドは Celltype のものである必要は無い(上に続くのでここに置く)
  # 初期値指定あり
  if type.is_a?(BoolType)
    if init.instance_of?(C_EXP)
      init_str = subst_name(init.get_c_exp_string, name_array)
    else
      init_str = init.eval_const2(cell.get_join_list, @name_list)
    end

    if f_get_str
      return init_str.to_s
    else
      f.print "    " * indent
      f.printf("%-40s /* %s */\n", "#{init_str},", identifier)
    end
#      if f_get_str then
#        return "#{init.eval_const2(nil)}"
#      else
#        f.print "    " * indent
#        f.printf( "%-40s /* %s */\n", "#{init.eval_const2(nil)},", identifier )
#      end
  elsif type.is_a?(IntType)
    if init.instance_of?(C_EXP)
      init_str = subst_name(init.get_c_exp_string, name_array)
    else
      init_str = init.eval_const2(cell.get_join_list, @name_list)
    end

    if f_get_str
      return init_str.to_s
    else
      f.print "    " * indent
      f.printf("%-40s /* %s */\n", "#{init_str},", identifier)
    end
  elsif type.is_a?(FloatType)
    # mikan C_EXP for FloatType
    if f_get_str
      return init.eval_const2(cell.get_join_list, @name_list).to_s
    else
      f.print "    " * indent
      f.printf("%-40s /* %s */\n", "#{init.eval_const2(cell.get_join_list, @name_list)},", identifier)
    end
  elsif type.is_a?(EnumType)
    # mikan C_EXP for EnumType
    if f_get_str
      return init.eval_const2(cell.get_join_list, @name_list).to_s
    else
      f.print "    " * indent
      f.printf("%-40s /* %s */\n", "#{init.eval_const2(cell.get_join_list, @name_list)},", identifier)
    end
  elsif type.is_a?(ArrayType)
    if type.get_subscript
      len = type.get_subscript.eval_const(cell.get_join_list, @name_list)
    else
      len = init.length
    end

    at = type.get_type
    i = 0
    if f_get_str
      str = "{ "
    else
      f.print "    " * indent
      f.print("{\n")
    end

    len.times {
      next if !init[i] # mikan この処置は適切?
      if f_get_str
        str += gen_cell_cb_init(f, cell, name_array, at, init[i], "#{identifier}[#{i}]", indent + 1, f_get_str)
        str += ", "
      else
        gen_cell_cb_init(f, cell, name_array, at, init[i], "#{identifier}[#{i}]", indent + 1, f_get_str)
      end
      i += 1
    }

    if f_get_str
      str += "}"
    else
      f.print "    " * indent
      f.print("},\n")
    end

  elsif type.is_a?(StructType)
    i = 0
    decls = type.get_members_decl.get_items
    if f_get_str
      str = "{ "
    else
      f.print "    " * indent
      f.print("{                                        /* #{identifier} */\n")
    end

    decls.each{|d|
      # p "#{d.get_identifier}: #{init}"
      next if !init[i]

      if f_get_str
        str += gen_cell_cb_init(f, cell, name_array, d.get_type, init[i], d.get_identifier, indent + 1, f_get_str)
        str += ", "
      else
        gen_cell_cb_init(f, cell, name_array, d.get_type, init[i], d.get_identifier, indent + 1, f_get_str)
      end
      i += 1
    }
    if f_get_str
      str += "}"
    else
      f.print "    " * indent
      f.print("},\n")
    end

  elsif type.is_a?(PtrType)

    if init.instance_of?(Array)
      if f_get_str
        return "#{cell_CB_INIT}_#{identifier}_INIT"
      else
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "#{cell_CB_INIT}_#{identifier}_INIT,", identifier)
      end
    elsif init.instance_of?(C_EXP)
      init_str = subst_name(init.get_c_exp_string, name_array)

      if f_get_str
        return init_str.to_s
      else
        f.print "    " * indent
        f.printf("%-40s /* %s */\n", "#{init_str},", identifier)
      end

    else
      if f_get_str
        return init.eval_const2(cell.get_join_list, @name_list).to_s
      else
        f.print "    " * indent
# p init.eval_const2(cell.get_join_list,@name_list).class
# p init.eval_const2(cell.get_join_list,@name_list)
# p identifier
        f.printf("%-40s /* %s */\n", "#{init.eval_const2(cell.get_join_list, @name_list)},", identifier)

      end
    end
  else
    raise "UnknownType"
  end
end

#gen_cell_cb_initialize_code(f) ⇒ Object

CB を初期化するプログラムの生成



3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
# File 'lib/tecsgen/core/generate.rb', line 3365

def gen_cell_cb_initialize_code(f)
  if !need_CB_initializer?
    return
  end
  f.printf(TECSMsg.get(:CIC_comment), "#_CIC_#")
  f.print <<EOT
void
#{@global_name}_CB_initialize()
{
EOT
  if @singleton
    f.print <<EOT
  SET_CB_INIB_POINTER(i,p_cb)
  INITIALIZE_CB()
EOT
  else
    f.print <<EOT
  #{@global_name}_CB	*p_cb;
  int		i;
  FOREACH_CELL(i,p_cb)
      SET_CB_INIB_POINTER(i,p_cb)
      INITIALIZE_CB(p_cb)
  END_FOREACH_CELL
EOT
  end

  f.print <<EOT
}
EOT
end

#gen_cell_cb_out_init(fs) ⇒ Object

CB/INIB の外で初期化される変数の出力



3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
# File 'lib/tecsgen/core/generate.rb', line 3397

def gen_cell_cb_out_init(fs)
  # セルがなければ、出力しない
  if @n_cell_gen == 0
    return
  end

  fs.each{|r, f| f.printf(TECSMsg.get(:AVAI_comment), "#_AVAI_#") }

  # attribute, var のポインタ型の参照する配列を生成
  @ordered_cell_list.each{|c|
    next if !c.is_generate?

    f = fs[c.get_region.get_domain_root]
    name_array = get_name_array(c)

    ct = c.get_celltype
    jl = c.get_join_list

    # attribute, var のポインタ変数が配列により初期化される場合の、配列を出力
    av_list = ct.get_attribute_list + ct.get_var_list
    if av_list.length != 0
      av_list.each{|a| # a: Decl
        j = jl.get_item(a.get_identifier)
        if j
          init = j.get_rhs
        else
          init = a.get_initializer
        end

        if a.is_type?(PtrType) && ((init && init.instance_of?(Array)) || init.nil?)
          ptr_type = a.get_type
          size = ptr_type.get_size

          if size
            # 式を評価する(attribute, var に含まれる変数を参照可能)
            sz = size.eval_const(c.get_join_list, c.get_celltype.get_name_list)
            # 式を生成しなおす (変数を含まない形にする)  不完全な形で Token を生成 (エラー発生しないから)
            size = Expression.new([:INTEGER_CONSTANT, Token.new(sz, nil, 0, 0)])
            array_type = ArrayType.new(size)
            type = a.get_type.get_referto
            if !type.is_const? && a.get_kind == :ATTRIBUTE
              type.set_qualifier :CONST
            end
            array_type.set_type(type)
            if a.get_kind == :ATTRIBUTE
              f.print "const "
            end
            f.printf("#{a.get_type.get_referto.get_type_str} #{name_array[3]}_#{a.get_identifier}_INIT[%d]#{a.get_type.get_referto.get_type_str_post}", sz)
            # name_array[3]: cell_CB_INIT
            if !($ram_initializer && a.get_kind == :VAR)
              # -R (ram initializer 使用) の場合 var は初期化コードを出力しない
              if init
                str = " = #{gen_cell_cb_init(f, c, name_array, array_type, init, a.get_identifier, 1, true)}"
                str = str.sub(/\}$/, "};\n")
              else
                str = ";\n"
              end
              f.print(str)
            else
              f.print(";\n")
            end
          end
        end
      }
    end
  }
end

#gen_cell_cb_port(cell, indent, f, name_array, inib_cb = :INIB) ⇒ Object

inib_cb::Symbol: :INIB, :CB_ALL, :CB_DYNAMIC



3858
3859
3860
3861
# File 'lib/tecsgen/core/generate.rb', line 3858

def gen_cell_cb_port(cell, indent, f, name_array, inib_cb = :INIB)
  gen_cell_cb_call_port(cell, indent, f, name_array, inib_cb)
  gen_cell_cb_entry_port(cell, indent, f, name_array)
end

#gen_cell_cb_tab(f) ⇒ Object



3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
# File 'lib/tecsgen/core/generate.rb', line 3657

def gen_cell_cb_tab(f)
  indent = 0
  if @idx_is_id_act
    if has_INIB? && ($ram_initializer || !has_CB?)
      f.print "/* ID to INIB table #_INTAB_# */\n"
      @ordered_cell_list.each{|c|
        if c.is_generate? && (c.get_region.get_domain_root != Region.get_root) # 生成対象かつ、ルート以外か
          name_array = get_name_array(c)
          print_indent(f, indent + 1)
          f.print "extern #{@global_name}_INIB  #{name_array[5]};\n"
        end
      }

      f.print "#{@global_name}_INIB *const #{@global_name}_INIB_tab[] ={\n"
      @ordered_cell_list.each{|c|
        if c.is_generate? # 生成対象か?
          name_array = get_name_array(c)
          print_indent(f, indent + 1)
          f.print "&#{name_array[5]},\n"
        end
      }
      f.print "};\n"
    end
    if has_CB?
      f.print "/* ID to CB table #_CBTAB_# */\n"
      @ordered_cell_list.each{|c|
        if c.is_generate? && (c.get_region.get_domain_root != Region.get_root) # 生成対象かつ、ルート以外か
          name_array = get_name_array(c)
          print_indent(f, indent + 1)
          f.print "extern #{@global_name}_CB  #{name_array[2]};\n"
        end
      }

      f.print "#{@global_name}_CB *#{@global_name}_CB_tab[] ={\n"
      @ordered_cell_list.each{|c|
        if c.is_generate? # 生成対象か?
          name_array = get_name_array(c)
          print_indent(f, indent + 1)
          f.print "&#{name_array[2]},\n"
        end
      }
      f.print "};\n"
    end
  end
end

#gen_cell_cb_type_attribute(f, inib_cb) ⇒ Object

attribute の型宣言出力

inib_cb

:INIB または :CB



2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
# File 'lib/tecsgen/core/generate.rb', line 2613

def gen_cell_cb_type_attribute(f, inib_cb)
  if inib_cb == :INIB && @n_attribute_ro > 0
    f.print "    /* attribute(RO) #_ATO_# */ \n"
  elsif inib_cb == :CB
    if $rom
      if @n_attribute_rw > 0
        f.print "    /* attribute(RW) #_ATW_# */ \n"
      end
    else
      if @n_attribute_rw > 0 || @n_attribute_ro > 0
        f.print "    /* attribute #_AT_# */ \n"
      end
    end
  end

  @attribute.each{|a|
    next if a.is_omit?
    next if inib_cb == :INIB && a.is_rw?
    next if has_INIB? && inib_cb == :CB && !a.is_rw?

    if a.get_type.is_a?(PtrType) && !a.get_type.is_const? && a.get_size_is
      const_str = "const "
    else
      const_str = ""
    end
    f.print "    "
    f.printf("#{const_str}%-14s", a.get_type.get_type_str)
    f.print " #{a.get_name}#{a.get_type.get_type_str_post};\n"
  }
  @var.each {|v|
    next if v.is_omit?
    next if v.get_size_is.nil?
    next if $rom && inib_cb == :CB # size_is 指定されたものは INIB にのみ出力する

    f.print "    "
    f.printf("%-14s", v.get_type.get_type_str)
    f.print " #{v.get_name}#{v.get_type.get_type_str_post};\n"
  }
end

#gen_cell_cb_type_call_port(f, inib_cb) ⇒ Object



2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
# File 'lib/tecsgen/core/generate.rb', line 2675

def gen_cell_cb_type_call_port(f, inib_cb)
  # 呼び口
  if @n_call_port > 0
    f.print "    /* call port #_TCP_# */\n"
  end

  @port.each{|p|
    next if p.get_port_type != :CALL
    next if p.is_omit?
    next if inib_cb == :INIB && p.is_dynamic? && p.get_array_size.nil? && !$ram_initializer
    next if inib_cb == :CB_DYNAMIC && (!p.is_dynamic? || !p.get_array_size.nil?)
    # bprint "cb_type #{inib_cb} #{p.get_name} dynamic=#{p.is_dynamic?}\n"

    ptr = p.get_array_size ? "*" : ""

    if !p.is_cell_unique?
      const = p.is_dynamic? ? "" : "const"
      if inib_cb == :INIB && p.is_dynamic? && p.get_array_size.nil? && $ram_initializer
        init = "_init_"
        const2 = "const"
      else
        init = ""
        const2 = "const"
      end

      if !p.is_skelton_useless?
        # 標準形
        if inib_cb == :INIB && p.is_dynamic? && !p.get_array_size.nil? && $ram_initializer
          f.print("    struct tag_#{p.get_signature.get_global_name}_VDES #{ptr}#{const2}*#{p.get_name;}_init_;\n")
        end
        f.print("    struct tag_#{p.get_signature.get_global_name}_VDES #{ptr}#{const}*#{p.get_name;}#{init};\n")
#          f.print( "    struct tag_#{p.get_signature.get_global_name}_VDES #{ptr}*#{p.get_name;};\n" )
        if p.get_array_size == "[]"
          f.print("    int_t n_#{p.get_name};\n")
        end
      else
        # 最適化 skelton 関数を呼出さない(受け口関数を直接呼出す)
        # 呼び先セルタイプの CB の IDX 型
        if p.get_real_callee_cell
          f.print("    ")
          p.get_real_callee_cell.get_celltype.gen_ph_idx_type f
          f.print(" #{ptr}#{p.get_name;};\n")
          # 相互参照に備えて、typedef した型を使わない
          # f.print( "    #{p.get_real_callee_cell.get_celltype.get_global_name}_IDX #{ptr}#{p.get_name;};\n" )
          if p.get_array_size == "[]"
            f.print("    int_t n_#{p.get_name};\n")
          end
        # else
        #  optional で未結合
        end
      end
    # else
      # 最適化 一つしかセルがない場合、受け口ディスクリプタまたは受け側の IDX は呼び口関数マクロに埋め込まれる
    end
  }
end

#gen_cell_cb_type_entry_port(f, inib_cb) ⇒ Object

Celltype#受け口配列添数を記憶する変数の定義



2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
# File 'lib/tecsgen/core/generate.rb', line 2733

def gen_cell_cb_type_entry_port(f, inib_cb)
  # 呼び口
  if @n_entry_port > 0
    f.print "    /* call port #_NEP_# */ \n"
  end

  @port.each{|p|
    # next if p.is_omit?                       # 受け口配列の個数は省略しない
    if p.get_port_type == :ENTRY && p.get_array_size == "[]"
      f.print("    int_t n_#{p.get_name};\n")
    end
  }
end

#gen_cell_cb_type_port(f, inib_cb) ⇒ Object



2670
2671
2672
2673
# File 'lib/tecsgen/core/generate.rb', line 2670

def gen_cell_cb_type_port(f, inib_cb)
  gen_cell_cb_type_call_port(f, inib_cb)
  gen_cell_cb_type_entry_port(f, inib_cb)
end

#gen_cell_cb_type_var(f) ⇒ Object



2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
# File 'lib/tecsgen/core/generate.rb', line 2653

def gen_cell_cb_type_var(f)
  # 変数の出力
  if @n_var > 0
    f.print "    /* var #_VA_# */ \n"
  end

  @var.each{|v|

    next if v.is_omit?
    next if !v.get_size_is.nil? # size_is 指定された var は attribute へ出力する

    f.print "    "
    f.printf("%-14s", v.get_type.get_type_str)
    f.print " #{v.get_name}#{v.get_type.get_type_str_post};\n"
  }
end

#gen_cell_cb_var(cell, indent, f, name_array) ⇒ Object

var の初期化データを出力



3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
# File 'lib/tecsgen/core/generate.rb', line 3836

def gen_cell_cb_var(cell, indent, f, name_array)
  jl = cell.get_join_list
  var = get_var_list
  if @n_var - @n_var_size_is > 0
    print_indent(f, indent + 1)
    f.print "/* var */ \n"
    var.each{|v|

      next if v.is_omit?
      next if v.get_size_is # size_is 指定がある場合 attribute の一部として出力

      if v.get_initializer && $ram_initializer == false
        gen_cell_cb_init(f, cell, name_array, v.get_type, v.get_initializer, v.get_identifier, indent + 1)
      else
        # 初期値未指定 または RAM initializer 使用
        gen_cell_cb_init(f, cell, name_array, v.get_type, nil, v.get_identifier, indent + 1)
      end
    }
  end
end

#gen_cell_ep_des(fs) ⇒ Object

受け口ディスクリプタの定義を生成



4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
# File 'lib/tecsgen/core/generate.rb', line 4231

def gen_cell_ep_des(fs)
  if @n_cell_gen > 0
    fs.each{|r, f| f.printf(TECSMsg.get(:EPD_comment), "#_EPD_#") }
  end

  index = 0
  @ordered_cell_list.each{|c|

    next if !c.is_generate?

    f = fs[c.get_region.get_domain_root]

    ct = c.get_celltype
    jl = c.get_join_list

    port = ct.get_port_list
    if port.length != 0
      port.each{|p|
        next if p.get_port_type != :ENTRY
        next if p.is_omit?
        if p.is_skelton_useless? # 受け口最適化n ep_opt
          f.print("/* #{p.get_name} : omitted by entry port optimize */\n")
          next
        end

        len = p.get_array_size
        if len == "[]"
          len = c.get_entry_port_max_subscript(p) + 1
        end

        if !len.nil?
          # 受け口配列の場合
          i = 0
          while i < len
            f.print "extern const struct tag_#{@global_name}_#{p.get_name}_DES"
            f.print " #{c.get_global_name}_#{p.get_name}_des#{i};\n"
            f.print "const struct tag_#{@global_name}_#{p.get_name}_DES"
            # f.print " #{c.get_name}_#{p.get_name}_des#{i} = {\n"
            f.print " #{c.get_global_name}_#{p.get_name}_des#{i} = {\n"
            if p.is_VMT_useless?
              f.print "    0,\n"
            else
              f.print "    &#{@global_name}_#{p.get_name}_MT_,\n"
            end
            if @idx_is_id_act
              f.print "    #{c.get_id},           /* ID */\n"
            else
              if has_CB?
                if @singleton
                  f.print "    &#{@global_name}_SINGLE_CELL_CB,        /* CB 1 */\n"
                else
                  # f.print "    &#{@global_name}_#{c.get_name}_CB,\n"
                  f.print "    &#{@global_name}_CB_tab[#{index}],      /* CB 2 */\n"
                end
              elsif has_INIB?
                if @singleton
                  f.print "    &#{@global_name}_SINGLE_CELL_INIB,      /* INIB 1 */\n"
                else
                  f.print "    &#{@global_name}_INIB_tab[#{index}],    /* INIB 2 */\n"
                end
              else
                f.print "    0,\n"
              end
            end
            f.print "    #{i}\n"
            f.print "};\n"
            i += 1
          end
        else
          f.print "extern const struct tag_#{@global_name}_#{p.get_name}_DES"
          f.print " #{c.get_global_name}_#{p.get_name}_des;\n"
          f.print "const struct tag_#{@global_name}_#{p.get_name}_DES"
          # f.print " #{c.get_name}_#{p.get_name}_des = {\n"
          f.print " #{c.get_global_name}_#{p.get_name}_des = {\n"
          if p.is_VMT_useless?
            f.print "    0,\n"
          else
            f.print "    &#{@global_name}_#{p.get_name}_MT_,\n"
          end
          if @idx_is_id_act
            f.print "    #{c.get_id},     /* ID */\n"
          else
            if has_CB?
              if @singleton
                f.print "    &#{@global_name}_SINGLE_CELL_CB,       /* CB 3 */\n"
              else
                f.print "    &#{@global_name}_CB_tab[#{index}],     /* CB 4 */\n"
                # f.print "    &#{@global_name}_#{c.get_name}_CB,\n"
              end
            elsif has_INIB?
              if @singleton
                f.print "    &#{@global_name}_SINGLE_CELL_INIB,     /* INIB 3 */\n"
              else
                f.print "    &#{@global_name}_INIB_tab[#{index}],   /* INIB 4 */\n"
              end
            else
              f.print "    0,\n"
            end
          end
          f.print "};\n"
        end
      }
    end
    index += 1
  }
end

#gen_cell_ep_des_type(f) ⇒ Object



2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
# File 'lib/tecsgen/core/generate.rb', line 2996

def gen_cell_ep_des_type(f)
  if @n_entry_port > 0
    f.printf(TECSMsg.get(:EDT_comment), "#_EDT_#")
  end

  @port.each {|p|
    next if p.get_port_type != :ENTRY
    next if p.is_omit?
    if p.is_skelton_useless? # 受け口最適化
      f.print("/* #{p.get_name} : omitted by entry port optimize */\n\n")
      next
    end

    f.print("/* #{p.get_name} */\n")
    f.print("struct tag_#{@global_name}_#{p.get_name}_DES {\n")
    f.print("    const struct tag_#{p.get_signature.get_global_name}_VMT *vmt;\n")
    if has_CB? || has_INIB?
      f.print("    #{@name}_IDX  idx;\n")
    else
      # CB も INIB も存在しない (ので、idx として整数で初期化しておく)
      f.print("    int           idx;\n")
    end
    if p.get_array_size
      f.print("    int_t  subscript;\n")
    end
    f.print("};\n\n")
  }
end

#gen_cell_ep_vdes(fs) ⇒ Object



3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
# File 'lib/tecsgen/core/generate.rb', line 3137

def gen_cell_ep_vdes(fs)
  if @n_cell_gen > 0
    fs.each{|r, f| f.printf(TECSMsg.get(:CPEPD_comment), "#_CPEPD_#") }
  end

  # このセルタイプのすべてのセルについて
  @ordered_cell_list.each{|c|
    if c.is_generate? # 生成対象か?

      f = fs[c.get_region.get_domain_root]

      # 結合のリスト (NamedList)
      jl = c.get_join_list

      # 全ての結合リストについて
      jl.get_items.each{|j|

        # 左辺の定義を得る
        definition = j.get_definition

        # 呼び口ではない? (属性)
        next unless definition.instance_of? Port

        port = find j.get_name # celltype の Port (こちらに最適化情報がある)
        # port = definition    # definition は composite の Port が得られることがある
        next if port.is_cell_unique?
        next if port.is_omit?

        # 配列要素を得る(受け口配列でなければ nil が返る)
        am = j.get_array_member2

        # 呼び口配列か?
        if am
          i = 0
          while i < am.length
            j = am[i]
            if j
              if am[i].get_rhs_cell.get_celltype == self
                # 同じセルタイプへ結合している場合(VDES では type conflict になる)
                p = am[i].get_rhs_port
                des_type = "const struct tag_#{@global_name}_#{p.get_name}_DES"
              else
                des_type = "struct tag_#{definition.get_signature.get_global_name}_VDES"
              end

              # 右辺は受け口配列か?
              if j.get_rhs_subscript

                # 受け口の配列添数
                subscript = j.get_rhs_subscript

                f.printf("extern %s %s%d;\n",
                          des_type,
                          "#{j.get_port_global_name(i)}_des",
                          subscript)
              else
                f.printf("extern %s %s;\n",
                          des_type,
                          "#{j.get_port_global_name(i)}_des")
              end
            # else if j == nil
            #  optioanl で配列要素が初期化されていない
            end
            i += 1
          end
        else
          dbgPrint "me=#{@name} callee=#{j.get_rhs_cell.get_celltype.get_name} #{j.get_cell.get_celltype.get_name} \n"
          if j.get_rhs_cell.get_celltype == self
            # 同じセルタイプへ結合している場合(VDES では type conflict になる)
            p = j.get_rhs_port
            des_type = "const struct tag_#{@global_name}_#{p.get_name}_DES"
          else
            des_type = "struct tag_#{definition.get_signature.get_global_name}_VDES"
          end

          if j.get_rhs_subscript
            # 受け口配列
            subscript = j.get_rhs_subscript
            f.printf("extern %s %s%d;\n",
                      des_type,
                      "#{j.get_port_global_name}_des",
                      subscript)
          else
            f.printf("extern %s %s;\n",
                      des_type,
                      "#{j.get_port_global_name}_des")
          end
        end
        # mikan   cell の namespace 未対応、Join で Cell オブジェクトを引当ておく必要あり
      }

      f.print "\n"
    end
  }
end

#gen_cell_ep_vdes_array(fs) ⇒ Object



3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
# File 'lib/tecsgen/core/generate.rb', line 3233

def gen_cell_ep_vdes_array(fs)
  if @n_cell_gen > 0
    fs.each{|r, f| f.printf(TECSMsg.get(:CPA_comment), "#_CPA_#") } # mikan 呼び口配列が無い場合も出てしまう
  end

  @ordered_cell_list.each{|c|
    if c.is_generate?
      f = fs[c.get_region.get_domain_root]

      jl = c.get_join_list
      # ループを回す変数を jl から @port に変更
      # dynamic, optional
#        jl.get_items.each{ |j|
      @port.each {|port|
        next if port.get_port_type != :CALL
        dbgPrint("gen_cell_ep_vdes_array: #{c.get_name}.#{port.get_name}\n")

#          definition = j.get_definition
#          next unless definition.instance_of? Port
        j = jl.get_item(port.get_name)

        # port = definition    # definition は composite の Port が得られることがある
        # port = find j.get_name # celltype の Port (こちらに最適化情報がある)
        next if port.is_cell_unique?
        next if port.is_omit?

        b_array = false
        am = nil
        if j
          am = j.get_array_member2
          if am
            b_array = true
          end
        else
          if port.get_array_size == "[]"
            # this case is dynamic optional and nothing joined
            next
          elsif port.get_array_size
            b_array = true
          end
        end
        if b_array
#          if am then
          # 左辺は配列
          const = (port.is_dynamic? && !$ram_initializer) ? "" : "const "
          init = (port.is_dynamic? && $ram_initializer) ? "_init_" : ""

          if !port.is_skelton_useless?
            f.printf("struct %s * #{const}%s_%s[] = {\n",
                      "tag_#{port.get_signature.get_global_name}_VDES",
                      c.get_global_name,
                      port.get_name.to_s + init)
          else

#              スケルトン関数不要最適化の場合、この配列は参照されない
            # mikan このケースがテストされていない
            f.printf("#{const}%s_IDX  %s_%s[] = {\n",
#                        "#{j.get_celltype.get_global_name}",   # 右辺 composite に対応できない
                      j.get_rhs_cell.get_celltype.get_global_name,
                      c.get_global_name,
                      j.get_name.to_s)
          end
          if port.get_array_size == "[]"
            length = am.length
          else
            length = port.get_array_size
          end
          # am.each { |j|
          i = 0
          while i < length
            if am.nil?
              f.print("    0,\n")
              i += 1
              next
            end
            j = am[i]
            i += 1

            if j
              # 同一セルタイプの結合の場合、VDES 型へのキャストが必要
              if j.get_rhs_cell.get_celltype == self
                definition = j.get_definition
                des_type_cast = "(struct tag_#{definition.get_signature.get_global_name}_VDES *)"
              else
                des_type_cast = ""
              end


              if j.get_rhs_subscript
                # 右辺配列の場合(最適化はない)
                subscript = j.get_rhs_subscript
                f.printf("    %s%d,\n",
                          "#{des_type_cast}&#{j.get_port_global_name}_des",
                          subscript)
                # p "1: #{j.get_port_global_name}_des"
                # p "2: #{j.get_cell_global_name}_#{j.get_port_name}_des"

              else
                # 右辺非配列の場合 */
                if !port.is_skelton_useless?
                  f.printf("    %s,\n",
                            "#{des_type_cast}&#{j.get_port_global_name}_des")
                else
                  cell = j.get_rhs_cell
                  name_array = cell.get_celltype.get_name_array(cell)
                  f.printf("    #{name_array[7]},\n")
                end
              end
            else
              # optional で呼び口配列要素が初期化されていない
              f.printf("    0,\n")
            end
          # }
          end
          # mikan   cell の namespace 未対応、Join で Cell オブジェクトを引当ておく必要あり
          f.print "};\n"
          # dynamic の呼び口配列
          if port.is_dynamic? && $ram_initializer
            f.printf("struct %s * %s_%s[ #{length} ];\n",
                      "tag_#{port.get_signature.get_global_name}_VDES",
                      c.get_global_name,
                      port.get_name)
          end
        end
      }

      f.print "\n"
    end
  }
end

#gen_cell_extern_mt(fs) ⇒ Object

関数テーブルの外部参照



4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
# File 'lib/tecsgen/core/generate.rb', line 4216

def gen_cell_extern_mt(fs)
  fs.each{|r, f|
    if !r.is_root?
      @port.each{|p|
        next if p.is_omit?
        if p.get_port_type == :ENTRY && !p.is_VMT_useless?
          f.print "extern const struct tag_#{p.get_signature.get_global_name}_VMT"
          f.print " #{@global_name}_#{p.get_name}_MT_;\n"
        end
      }
    end
  }
end

#gen_cell_factory_header(f) ⇒ Object



2992
2993
2994
# File 'lib/tecsgen/core/generate.rb', line 2992

def gen_cell_factory_header(f)
  f.print "#include \"#{@global_name}_factory.#{$h_suffix}\"\n\n"
end

#gen_cell_fun_table(f) ⇒ Object



3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
# File 'lib/tecsgen/core/generate.rb', line 3109

def gen_cell_fun_table(f)
  if @n_entry_port > 0
    f.printf(TECSMsg.get(:EPSFT_comment), "#_EPSFT_#")
  end

  @port.each {|p|
    next if p.get_port_type != :ENTRY
    next if p.is_omit?
    if p.is_VMT_useless? # 受け口最適化
      f.print "/* #{p.get_name} : omitted by entry port optimize */\n"
      next
    end

    f.print "/* #{p.get_name} */\n"

    # f.print "static const struct tag_#{p.get_signature.get_global_name}_VMT"
    f.print "const struct tag_#{p.get_signature.get_global_name}_VMT"
    f.print " #{@global_name}_#{p.get_name}_MT_ = {\n"

    p.get_signature.get_function_head_array.each{|fun|
      f.print "    #{@global_name}_#{p.get_name}_#{fun.get_name}_skel,\n"
    }

    f.print "};\n"
  }
  f.print "\n"
end

#gen_cell_private_header(f) ⇒ Object

celltype glue code



2988
2989
2990
# File 'lib/tecsgen/core/generate.rb', line 2988

def gen_cell_private_header(f)
  f.print "#include \"#{@global_name}_tecsgen.#{$h_suffix}\"\n"
end

#gen_cell_skel_fun(f) ⇒ Object



3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
# File 'lib/tecsgen/core/generate.rb', line 3025

def gen_cell_skel_fun(f)
  if @n_entry_port > 0
    f.printf(TECSMsg.get(:EPSF_comment), "#_EPSF_#")
  end

  @port.each {|p|
    next if p.get_port_type != :ENTRY
    next if p.is_omit?
    if p.is_skelton_useless? # 受け口最適化
      f.print("/* #{p.get_name} : omitted by entry port optimize */\n")
      next
    end

    f.print("/* #{p.get_name} */\n")

    p.get_signature.get_function_head_array.each{|fun|
      functype = fun.get_declarator.get_type
      f.printf "%-14s", functype.get_type_str

      f.print " #{@global_name}_#{p.get_name}_#{fun.get_name}_skel("
      f.print " const struct tag_#{p.get_signature.get_global_name}_VDES *epd"
      delim = ","

      if functype.get_paramlist
        items = functype.get_paramlist.get_items
        len = items.length
      else
        # ここで nil になるのは、引数なしの時に void がなかった場合
        items = []
        len = 0
      end
      i = 0
      items.each{|param|
        f.print "#{delim} "
        delim = ","
        f.print param.get_type.get_type_str
        f.print " "
        f.print param.get_name
        f.print param.get_type.get_type_str_post
        i += 1
      }
      f.print ")\n"

      f.print "{\n"
      if !@singleton || !p.get_array_size.nil?
        f.print "    struct tag_#{@global_name}_#{p.get_name}_DES *lepd\n"
        f.print "        = (struct tag_#{@global_name}_#{p.get_name}_DES *)epd;\n"
      end

      if functype.get_type_str == "void" # mikan "void" の typedef に未対応
        f.print "    "
      else
        f.print "    return "
      end

      f.print "#{@global_name}_#{p.get_name}_#{fun.get_name}("
      if @singleton
        delim = ""
      else
        f.print " lepd->idx"
        delim = ","
      end

      if p.get_array_size
        f.print "#{delim} lepd->subscript"
        delim = ","
      end

      items.each{|param|
        f.print "#{delim} "
        delim = ","
        f.print param.get_name
        i += 1
      }
      f.print " );\n"

      f.print "}\n"
    }
  }
  if @n_entry_port > 0
    f.print("\n")
  end
end

#gen_cell_var_init(f) ⇒ Object

var の初期値の ROM 部への



3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
# File 'lib/tecsgen/core/generate.rb', line 3466

def gen_cell_var_init(f)
  # var の{ }で囲まれた初期値指定があるか調べる
  n_init = 0
  @var.each {|v|
    init = v.get_initializer
    if init && init.instance_of?(Array)
      n_init += 1
    end
  }

  if n_init > 0
    f.printf(TECSMsg.get(:AVI_comment), "#_AVI_#")
    @var.each {|v|
      init = v.get_initializer
      if init && init.instance_of?(Array)
        type = v.get_type
        org_type = v.get_type.get_original_type

        if org_type.is_a? PtrType
          # PtrType は ArrayType にすり替える

          # 初期化子の要素数だけとする(後は 0)
          t2 = ArrayType.new(Expression.create_integer_constant(init.length, nil))
          t2.set_type(type.get_type)
          type = t2
          org_type = t2
        end

        c = @ordered_cell_list[0] # 仮の cell (実際には使われない)
        name_array = get_name_array(c)
        # f.print "const #{type0.get_type_str}\t#{@global_name}_#{v.get_name}_VAR_INIT#{type0.get_type_str_post} = "
        f.print "const #{type.get_type_str}\t#{@global_name}_#{v.get_name}_VAR_INIT#{type.get_type_str_post} = "
        if org_type.is_a? StructType
          # celltype の default の初期値あり
          str = gen_cell_cb_init(f, c, name_array, type, init, v.get_identifier, 1, true)
        elsif org_type.is_a?(PtrType) || org_type.is_a?(ArrayType)
          str = "{ "
          type = org_type.get_type
          # mikan ポインタではなく、配列型としないと、ポインタ変数の領域の分、損する
          init.each {|i|
            str += gen_cell_cb_init(f, c, name_array, type, i, v.get_identifier, 1, true)
            str += ", "
          }
          str += "}"
        else
          p type.class
          raise "Unknown Type"
        end
        f.print str
        f.print ";\n"
      end
    }
    f.print "\n"
  end
end

#gen_dealloc_code_for_type(f, type, dealloc_func_name, pre, name, post, level, b_reset, count_str = nil) ⇒ Object

decl 用の dealloc コードを生成

b_reset

Bool: リセット用の dealloc コードの生成 (NULL ポインタの場合 dealloc しない)

mikan string 修飾されたポインタの先にポインタが来ないと仮定。ポインタ型を持つ構造体の可能性を排除していない このメソッドでは、行を出力する直前に “ \n” を出力し、行末で改行文字を出力しない



4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
# File 'lib/tecsgen/core/generate.rb', line 4923

def gen_dealloc_code_for_type(f, type, dealloc_func_name, pre, name, post, level, b_reset, count_str = nil)
  type = type.get_original_type
  indent = "	" + "  " * (level + 1)
  if !type.has_pointer?
    return
  elsif type.is_a?(ArrayType)
    if type.get_type.has_pointer?
      loop_str = "i#{level}__"
      count_str = type.get_subscript.eval_const(nil).to_s
      f.print " \\\n"
      f.print "#{indent}{ int_t  #{loop_str};"
      f.print " \\\n"
      f.print "#{indent}  for( #{loop_str} = 0; #{loop_str} < #{count_str}; #{loop_str}++ ){ "

      gen_dealloc_code_for_type(f, type.get_type, dealloc_func_name, pre, name, "#{post}[#{loop_str}]", level + 2, b_reset)

      f.print " \\\n"
      f.print "#{indent}  }"
      f.print " \\\n"
      f.print "#{indent}}"
    end
  elsif type.is_a?(StructType)
    members_decl = type.get_members_decl
    members_decl.get_items.each {|md|
      pre2 = pre + name.to_s + post + "."
      name2 = md.get_name
      post2 = ""
      type2 = md.get_type.get_original_type
      if type2.is_a? PtrType # mikan typedef された型
        if type2.get_count
          count_str = type2.get_count.to_str(members_decl, pre2, post2)
        elsif type2.get_size
          count_str = type2.get_size.to_str(members_decl, pre2, post2)
        else
          count_str = nil
        end
      else
        count_str = nil
      end
      gen_dealloc_code_for_type(f, md.get_type, dealloc_func_name, pre2, name2, post2, level, b_reset, count_str)
    }

  elsif type.is_a?(PtrType)

    if b_reset || type.is_nullable?
      nullable = ""
      if !b_reset && type.is_nullable?
        nullable = "\t/* nullable */"
      end
      level2 = level + 1
      indent2 = indent + "  "
      f.print " \\\n"
      f.print "#{indent}if( #{pre}#{name}#{post} ){#{nullable}"
    else
      level2 = level
      indent2 = indent
    end

    if type.get_type.has_pointer?
      if count_str
        loop_str = "i#{level}__"
        f.print " \\\n"
        f.print "#{indent2}{ int_t  #{loop_str};"
        f.print " \\\n"
        f.print "#{indent2}  for( #{loop_str} = 0; #{loop_str} < #{count_str}; #{loop_str}++ ){ "

        gen_dealloc_code_for_type(f, type.get_type, dealloc_func_name, pre, name, "#{post}[#{loop_str}]", level2 + 2, b_reset)

        f.print " \\\n"
        f.print "#{indent2}  }"
        f.print " \\\n"
        f.print "#{indent2}}"
      else
        gen_dealloc_code_for_type(f, type.get_type, dealloc_func_name, "(*#{pre}", name, "#{post})", level2, b_reset)
      end
    end
    f.print " \\\n"
    f.print "#{indent2}#{dealloc_func_name}( #{pre}#{name}#{post} ); "

    if b_reset || type.is_nullable?
      f.print " \\\n"
      f.print "#{indent}}"
    end
  else
    raise "UnknownType"
  end
end

#gen_ph_attr_access(f) ⇒ Object

attribute, var をアクセスするマクロを出力

セルタイプヘッダへ出力


1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
# File 'lib/tecsgen/core/generate.rb', line 1764

def gen_ph_attr_access(f)
  if @n_attribute_rw > 0 || @n_attribute_ro > 0
    f.printf(TECSMsg.get(:AAM_comment), "#_AAM_#")
  end

  @attribute.each {|a|

    next if a.is_omit?

    # mikan const_value の場合
    f.print("#define ")
    if @singleton
      if has_INIB?
        inib = "INIB"
      else
        inib = "CB"
      end
      f.printf("%-20s", "#{@global_name}_ATTR_#{a.get_name}")
      f.print("\t(#{@global_name}_SINGLE_CELL_#{inib}.#{a.get_name})\n")
      # mikan ここでは cell ではなく celltype の名前
    else
      if !a.is_rw? && has_CB? && has_INIB?
        inib = "->_inib"
      else
        inib = ""
      end
      f.printf("%-20s", "#{@global_name}_ATTR_#{a.get_name}( p_that )")
      f.print("\t((p_that)#{inib}->#{a.get_name})\n")
    end
  }
  f.print("\n")

  @attribute.each {|a|

    next if a.is_omit?

    if @singleton
      if has_INIB?
        inib = "INIB"
      else
        inib = "CB"
      end
    else
      if !a.is_rw? && has_CB? && has_INIB?
        inib = "->_inib"
      else
        inib = ""
      end
    end

    # mikan const_value の場合
    f.print("#define ")
    if @singleton
      f.printf("%-20s", "#{@global_name}_GET_#{a.get_name}()")
      f.print("\t(#{@global_name}_SINGLE_CELL_#{inib}.#{a.get_name})\n")
      # mikan ここでは cell ではなく celltype の名前
    else
      f.printf("%-20s", "#{@global_name}_GET_#{a.get_name}(p_that)")
      f.print("\t((p_that)#{inib}->#{a.get_name})\n")
    end

    if a.is_rw?
      f.print("#define ")
      if @singleton
        f.printf("%-20s", "#{@global_name}_SET_#{a.get_name}(val)")
        f.print("\t(#{@global_name}_SINGLE_CELL_#{inib}.#{a.get_name} = (val))\n")
        # mikan ここでは cell ではなく celltype の名前
      else
        f.printf("%-20s", "#{@global_name}_SET_#{a.get_name}(p_that,val)")
        f.print("\t((p_that)#{inib}->#{a.get_name}=(val))\n")
      end
    end

  }
  f.print("\n")

  if @n_var > 0
    f.printf(TECSMsg.get(:VAM_comment), "#_VAM_#")
  end

  @var.each {|v|

    next if v.is_omit?

    if @singleton
      if v.get_size_is && has_INIB?
        inib = "INIB"
      else
        inib = "CB"
      end
    else
      if v.get_size_is && has_CB? && has_INIB?
        inib = "->_inib"
      else
        inib = ""
      end
    end

    # mikan const_value の場合
    f.print("#define ")
    if @singleton
      f.printf("%-20s", "#{@global_name}_VAR_#{v.get_name}")
      f.print("\t(#{@global_name}_SINGLE_CELL_#{inib}.#{v.get_name})\n")
      # mikan ここでは cell ではなく celltype の名前
    else
      f.printf("%-20s", "#{@global_name}_VAR_#{v.get_name}(p_that)")
      f.print("\t((p_that)#{inib}->#{v.get_name})\n")
    end
  }
  f.print("\n")
  @var.each {|v|

    next if v.is_omit?

    # mikan const_value の場合
    f.print("#define ")
    if @singleton
      f.printf("%-20s", "#{@global_name}_GET_#{v.get_name}()")
      f.print("\t(#{@global_name}_SINGLE_CELL_CB.#{v.get_name})\n")
      # mikan ここでは cell ではなく celltype の名前
    else
      f.printf("%-20s", "#{@global_name}_GET_#{v.get_name}(p_that)")
      f.print("\t((p_that)->#{v.get_name})\n")
    end

    f.print("#define ")
    if @singleton
      f.printf("%-20s", "#{@global_name}_SET_#{v.get_name}(val)")
      f.print("\t(#{@global_name}_SINGLE_CELL_CB.#{v.get_name}=(val))\n")
      # mikan ここでは cell ではなく celltype の名前
    else
      f.printf("%-20s", "#{@global_name}_SET_#{v.get_name}(p_that,val)")
      f.print("\t((p_that)->#{v.get_name}=(val))\n")
    end
  }
  f.print("\n")
end

#gen_ph_attr_access_abbrev(f) ⇒ Object

attribute/var アクセスマクロ(短縮形)コードの生成



1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
# File 'lib/tecsgen/core/generate.rb', line 1903

def gen_ph_attr_access_abbrev(f)
  if @n_attribute_rw > 0 || @n_attribute_ro > 0
    f.printf(TECSMsg.get(:AAMA_comment), "#_AAMA_#")
  end

  @attribute.each {|a|
    next if a.is_omit?

    # mikan const_value の場合
    f.print("#define ")
    f.printf("%-20s", "ATTR_#{a.get_name}")
    f.print(" #{@global_name}_ATTR_#{a.get_name}")
    if !@singleton
      f.print("( p_cellcb )")
    end
    f.print "\n"
  }
  f.print("\n")

  if @n_var > 0
    f.printf(TECSMsg.get(:VAMA_comment), "#_VAMA_#")
  end

  @var.each {|v|
    next if v.is_omit?

    # mikan const_value の場合
    f.print("#define ")
    f.printf("%-20s", "VAR_#{v.get_name}")
    f.print(" #{@global_name}_VAR_#{v.get_name}")
    if !@singleton
      f.print("( p_cellcb )")
    end
    f.print("\n")
  }
  f.print("\n")
end

#gen_ph_base(f) ⇒ Object



1497
1498
1499
1500
1501
1502
1503
# File 'lib/tecsgen/core/generate.rb', line 1497

def gen_ph_base(f)
  return if @singleton

  # ID の基数および個数の define を出力
  f.printf("#define %-20s %10s  /* %s #_NIDB_# */\n", "#{@global_name}_ID_BASE", "(#{@id_base})", TECSMsg.get(:NIDB_comment))
  f.printf("#define %-20s %10s  /* %s  #_NCEL_# */\n\n", "#{@global_name}_N_CELL", "(#{@n_cell_gen})", TECSMsg.get(:NCEL_comment))
end

#gen_ph_cb_initialize_macro(f) ⇒ Object

変数var初期化コード



2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
# File 'lib/tecsgen/core/generate.rb', line 2829

def gen_ph_cb_initialize_macro(f)
  f.printf(TECSMsg.get(:CIM_comment), "#_CIM_#")

  @var.each {|v|
    init = v.get_initializer
    if init.instance_of? Array
      type = v.get_type
      if type.is_a? PtrType
        # PtrType は ArrayType にすり替える

        # 初期化子の要素数とする (後は 0 である)
        t2 = ArrayType.new(Expression.create_integer_constant(init.length, nil))
        t2.set_type(type.get_type)
        type = t2
      end
      f.print "extern const #{type.get_type_str} #{@global_name}_#{v.get_name}_VAR_INIT#{type.get_type_str_post};\n"
    end
  }
  if @singleton
    arg = "()"
    p_that = ""
    that = "#{@global_name}_SINGLE_CELL_CB."
  else
    arg = "(p_that)"
    p_that = "(p_that)"
    that = "(p_that)->"
  end

  if @n_cell_gen > 0 && need_CB_initializer?
    b_var_init = false
    f.print "#define INITIALIZE_CB#{arg}"
    @var.each {|v|
      init = v.get_initializer
      next if init.nil?

      b_var_init = true
      type = v.get_type.get_original_type
      f.print "\\\n"
#        print v.get_name, type.class, "\n"
#        if init.instance_of? Array || type.kind_of?( StructType ) then
      if init.instance_of? Array
        if type.is_a?(ArrayType) || type.is_a?(PtrType)
          pre = "&"
          post = "[0]"
        elsif type.is_a? StructType
          pre = "&"
          post = ""
#          elsif type.kind_of? PtrType then
#            pre = ""
#            post = ""
        end
        f.print "\tmemcpy((void*)#{pre}#{@global_name}_VAR_#{v.get_name}#{p_that}#{post}, "
        f.print "(void*)#{pre}#{@global_name}_#{v.get_name}_VAR_INIT#{post}, sizeof(#{@global_name}_#{v.get_name}_VAR_INIT));"
      elsif init.instance_of? C_EXP
        f.print "\t#{that}#{v.get_name} = #{init.get_c_exp_string};"
      else
        pre = "#{get_global_name}_ATTR_"
        if @singleton
          post = ""
        else
          post = p_that.to_s
        end
        f.print "\t#{that}#{v.get_name} = #{init.to_str(@name_list, pre, post)};"
      end
    }

    # dynamic call port の初期化コード
    b_dyn_port = false
    @port.each{|p|
      next if p.get_port_type != :CALL
      if p.is_dynamic? && $ram_initializer
        if p.get_array_size.nil?
          f.print "\\\n\t#{that}#{p.get_name} = #{that}_inib->#{p.get_name}_init_;"
        else
          if @singleton || p.get_array_size != "[]"
            p_that = ""
          else
            p_that = "(p_that)"
          end
          if @singleton
            that = "#{@global_name}_SINGLE_CELL_INIB."
          else
            that = "(p_that)->"
          end
          if has_CB?
            init = "_init->"
          else
            init = ""
          end
          f.printf("\\\n%-80s\\\n", "     {")
          f.printf("%-80s\\\n", "        int_t   j;")
          f.printf("%-80s\\\n", "        for( j = 0; j < N_CP_#{p.get_name}#{p_that}; j++ ){")
          f.printf("%-80s\\\n", "            #{that}#{p.get_name}[j] = #{that}#{init}#{p.get_name}_init_[j];")
          f.printf("%-80s\\\n", "        }")
          f.printf("%-80s", "       }")
        end
        b_dyn_port = true
      end
    }
    if b_dyn_port
      f.print("\n")
    end

    if b_var_init == false && b_dyn_port == false && !@singleton
      f.print "\t(void)(p_that);"
    end
    f.print "\n"

    f.print "#define SET_CB_INIB_POINTER(i,p_that)\\\n"
    if has_CB? && has_INIB?
      if @singleton
        f.print "\t#{that}_inib = &#{@global_name}_SINGLE_CELL_INIB;\n\n"
      elsif @idx_is_id_act
        f.print "\t#{that}_inib = #{@global_name}_INIB_tab[(i)];\n\n"
      else
        f.print "\t#{that}_inib = &#{@global_name}_INIB_tab[(i)];\n\n"
      end
    else
      f.print "\t/* empty */\n"
    end

  # else
  #   セルが一つもなければ出力しない
  end
end

#gen_ph_cell_cb_type(f) ⇒ Object



2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
# File 'lib/tecsgen/core/generate.rb', line 2562

def gen_ph_cell_cb_type(f)
  if $rom
    # 定数部は ROM, 変数部は RAM

    if has_INIB?

      f.printf(TECSMsg.get(:CIP_comment), "#_CIP_#")
      f.print("typedef const struct tag_#{@global_name}_INIB {\n")

      gen_cell_cb_type_port(f, :INIB)
      gen_cell_cb_type_attribute(f, :INIB)

      f.print("}  #{@global_name}_INIB;\n")

    end

    if has_CB?
      f.printf(TECSMsg.get(:CCTPA_comment), "#_CCTPA_#")
      f.print("typedef struct tag_#{@global_name}_CB {\n")
      if has_INIB?
        f.print "    #{@global_name}_INIB  *_inib;\n"
      end
      gen_cell_cb_type_port(f, :CB_DYNAMIC)
      gen_cell_cb_type_attribute(f, :CB)
      gen_cell_cb_type_var f
      f.print("}  #{@global_name}_CB;\n")
    end

    if !has_CB? && !has_INIB?
      f.printf(TECSMsg.get(:CCDP_comment), "#_CCDP_#")
      f.print("typedef struct tag_#{@global_name}_CB {\n")
      f.print("    int  dummy;\n")
      f.print("} #{@global_name}_CB;\n")
   end

  else
    # 全て RAM
    f.printf(TECSMsg.get(:CCTPO_comment), "#_CCTPO_#")

    f.print("typedef struct tag_#{@global_name}_CB {\n")

    gen_cell_cb_type_port(f, :CB)
    gen_cell_cb_type_attribute(f, :CB)
    gen_cell_cb_type_var f

    f.print("}  #{@global_name}_CB;\n")
  end
end

#gen_ph_cp_fun_macro(f, b_flow) ⇒ Object



1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
# File 'lib/tecsgen/core/generate.rb', line 1941

def gen_ph_cp_fun_macro(f, b_flow)
  if @n_call_port > 0 && b_flow == false
    f.printf(TECSMsg.get(:CPM_comment), "#_CPM_#")
  end

  @port.each {|p|
    next if p.get_port_type != :CALL
    next if p.is_omit?

    p.get_signature.get_function_head_array.each{|fun|
      if @singleton
        if has_INIB?
          inib = "INIB"
        else
          inib = "CB"
        end
        if p.is_dynamic? && p.get_array_size.nil?
          # dynamic call port (not array)
          inib = "CB"
        end
      else
        if has_CB? && has_INIB?
          inib = "->_inib"
        else
          inib = ""
        end
        if p.is_dynamic? && p.get_array_size.nil?
          # dynamic call port (not array)
          inib = ""
        end
      end

      f.print("#define #{@global_name}_#{p.get_name}_#{fun.get_name}(")
      ft = fun.get_declarator.get_type
      delim = ""

      if !@singleton
        f.print("#{delim} p_that")
        delim = ","
      end

      if p.get_array_size
        f.print("#{delim} subscript")
        delim = ","
      end

      ft.get_paramlist.get_items.each{|param|
        f.print("#{delim} #{param.get_name}")
        delim = ","
      }
      f.print(" ) \\\n")

      subsc = ""
      subsc = "[subscript]" if p.get_array_size
      delim = ""

      # 関数名の出力(標準:受け口ディスクリプタから VMT の関数名、最適化:受け口関数 or 受け口ディスクリプタ)
      if b_flow
        f.print("\t  (p_that)->#{p.get_name}#{subsc}.#{fun.get_name}__T( \\\n")
      elsif !p.is_VMT_useless?
        # 標準コード
        if @singleton
          f.print("\t  #{@global_name}_SINGLE_CELL_#{inib}.#{p.get_name}")
        else
          f.print("\t  (p_that)#{inib}->#{p.get_name}")
        end
        f.print("#{subsc}->VMT->#{fun.get_name}__T( \\\n")
      else
        # 最適化コード (optimize) # VMT 不要
        p2 = p.get_real_callee_port
        if p2
          ct = p2.get_celltype
          if p.is_skelton_useless?
            # 受け口関数を直接呼出す
            f.print("\t  #{ct.get_global_name}_#{p2.get_name}_#{fun.get_name}( \\\n")
          else
            # 受け口スケルトン関数を直接呼出す
            f.print("\t  #{ct.get_global_name}_#{p2.get_name}_#{fun.get_name}_skel( \\\n")
            # print "skelton: #{@name} #{ct.get_global_name}_#{p2.get_name}\n"
          end
        else
          # optional で未結合
          f.print("\t  ((#{fun.get_declarator.get_type.get_type.get_type_str} (*)()")
          f.print("#{fun.get_declarator.get_type.get_type.get_type_str_post})0)()\n")
          f.print("\t  /* optional no entry port joined */\n")
          if !p.is_optional?
            raise "unjoined but not optional celltype: #{@name} #{p.get_name}"
          end
        end
      end

      b_join = true # optional で結合していない場合 false

      # 受け口情報の出力(標準:受け口ディスクリプタ、最適化:IDX など)
      if b_flow
      elsif !p.is_skelton_useless? && !p.is_cell_unique?
        # 標準コード
        if @singleton
          f.print("\t  #{@global_name}_SINGLE_CELL_#{inib}.#{p.get_name}#{subsc}")
          delim = ","
        else
          f.print("\t   (p_that)#{inib}->#{p.get_name}#{subsc}")
          delim = ","
        end
      else
        # 最適化コード (optimize) # スケルトン不要
        c2 = p.get_real_callee_cell               # 唯一のセル(でない場合もある、複数セルがある場合)
        p2 = p.get_real_callee_port               # 唯一のポート(でない場合は、ない)
        if p2
          ct = p2.get_celltype                    # 呼び先のセルタイプ
          if !ct.is_singleton?
            if ct.has_CB? || ct.has_INIB?
              if p.is_cell_unique?
                name_array = ct.get_name_array(c2)
                f.print("\t   #{name_array[7]}")
              else
                # CELLCB IDX を渡す (標準コードと同じだが、扱う型は異なる)
                # p.is_skelton_useless? == true/false ともに同じ
                f.print("\t   (p_that)#{inib}->#{p.get_name}#{subsc}")
              end
            else
              f.print("\t   (#{ct.get_global_name}_IDX)0")
            end
            delim = ","
          else
            f.print("\t   ")
          end
        else
          # optional で未結合
          b_join = false
        end
      end

      if b_join
        ft.get_paramlist.get_items.each{|param|
          f.print("#{delim} (#{param.get_name})")
          delim = ","
        }
        f.print(" )\n")
      end
    }
  }
  f.print("\n")
end

#gen_ph_cp_fun_macro_abbrev(f) ⇒ Object



2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
# File 'lib/tecsgen/core/generate.rb', line 2271

def gen_ph_cp_fun_macro_abbrev(f)
  if @n_call_port > 0
    f.printf(TECSMsg.get(:CPMA_comment), "#_CPMA_#")
  end

  @port.each {|p|
    next if p.get_port_type != :CALL
    # next if p.is_omit?  呼び出すとエラーを起こすコードを生成

    p.get_signature.get_function_head_array.each{|fun|
      if p.is_VMT_useless? && !@singleton
        dummy_p_cell_access_pre = "((void)p_cellcb, "
        dummy_p_cell_access_post = ")"
      else
        dummy_p_cell_access_pre = ""
        dummy_p_cell_access_post = ""
      end

      if !p.is_require? || p.has_name?
        f.print("#define #{p.get_name}_#{fun.get_name}(")
      else
        f.print("#define #{fun.get_name}(")
      end
      ft = fun.get_declarator.get_type
      delim = ""

#        if ! @singleton then
#          f.print( "#{delim} p_that" )
#          delim = ","
#        end

      if p.get_array_size
        f.print("#{delim} subscript")
        delim = ","
      end

      ft.get_paramlist.get_items.each{|param|
        f.print("#{delim} #{param.get_name}")
        delim = ","
      }
      f.print(" ) \\\n")

      if p.is_omit?
        f.print("          #{dummy_p_cell_access_pre}omitted #{p.get_name}_#{fun.get_name}(")
      else
        f.print("          #{dummy_p_cell_access_pre}#{@global_name}_#{p.get_name}_#{fun.get_name}(")
      end
      ft = fun.get_declarator.get_type
      delim = ""

      if !@singleton
        f.print("#{delim} p_cellcb")
        delim = ","
      end

      if p.get_array_size
        f.print("#{delim} subscript")
        delim = ","
      end

      ft.get_paramlist.get_items.each{|param|
        f.print("#{delim} #{param.get_name}")
        delim = ","
      }
      f.print(" )#{dummy_p_cell_access_post}\n")
    }
  }
  f.print("\n")
end

#gen_ph_dealloc_code(f, append_name, b_undef = false) ⇒ Object

send/receive で受け取ったメモリ領域を dealloc するマクロコード

f

File

b_undef

bool : true = #undef コードの生成, false = #define コードの生成



2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
# File 'lib/tecsgen/core/generate.rb', line 2216

def gen_ph_dealloc_code(f, append_name, b_undef = false)
  b_msg = false
  @port.each{|p|
    next if p.is_omit?

    p.each_param{|port, fd, par|
      case par.get_direction # 引数の方向指定子 (in, out, inout, send, receive )
      when :SEND
        # next if port.get_port_type == :CALL
        type = par.get_declarator.get_type
        pre = "("
        post = ")"
      when :RECEIVE
        # next if port.get_port_type == :ENTRY
        type = par.get_declarator.get_type.get_type
#          pre = "(*"
#          post = ")"
        pre = "("
        post = ")"
      else
        next
      end

      #                      ポート名         関数名         パラメータ名
      dealloc_func_name = "#{port.get_name}_#{fd.get_name}_#{par.get_name}_dealloc"
      dealloc_macro_name = dealloc_func_name.upcase
      name = par.get_name

      if b_undef == false
        if (type.get_size || type.get_count) && type.get_type.has_pointer?
          count_str = "count__"
          count_str2 = ", count__"
        else
          count_str = nil
          count_str2 = nil
        end
        if !b_msg
          f.print "\n"
          f.printf TECSMsg.get(:DAL_comment), "#_DAL_#  #{append_name}"
          b_msg = true
        end
        f.print "#define #{dealloc_macro_name}#{append_name}(#{name}#{count_str2})"
        if append_name == "_RESET"
          gen_dealloc_code_for_type(f, type, dealloc_func_name, pre, name, post, 0, true, count_str)
        else
          gen_dealloc_code_for_type(f, type, dealloc_func_name, pre, name, post, 0, false, count_str)
        end
        f.print "\n"
      else
        f.print "#undef #{dealloc_macro_name}#{append_name}\n"
      end
    }
  }
end

#gen_ph_endif(f, post = "TECSGEN") ⇒ Object



2963
2964
2965
# File 'lib/tecsgen/core/generate.rb', line 2963

def gen_ph_endif(f, post = "TECSGEN")
  f.print("#endif /* #{@global_name}_#{post}H */\n")
end

#gen_ph_ep_fun_macro(f) ⇒ Object



2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
# File 'lib/tecsgen/core/generate.rb', line 2411

def gen_ph_ep_fun_macro(f)
  if @n_entry_port > 0
    f.printf(TECSMsg.get(:EPM_comment), "#_EPM_#")
  end

  @port.each {|p|
    next if p.get_port_type != :ENTRY
    next if p.is_omit?

    p.get_signature.get_function_head_array.each{|fun|
      f.printf("#define %-16s %s\n",
                "#{p.get_name}_#{fun.get_name}",
                "#{@global_name}_#{p.get_name}_#{fun.get_name}")
    }
  }
  f.print("\n")
end

#gen_ph_ep_fun_prototype(f) ⇒ Object



2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
# File 'lib/tecsgen/core/generate.rb', line 2459

def gen_ph_ep_fun_prototype(f)
  if @n_entry_port > 0
    f.printf(TECSMsg.get(:EPP_comment), "#_EPP_#")
  end

  @port.each {|p|
    next if p.get_port_type != :ENTRY
    next if p.is_omit?

    f.print("/* #{p.get_signature.get_global_name} */\n")

    p.get_signature.get_function_head_array.each{|fun|
      if p.is_inline?
        f.print("Inline ")
      end
      functype = fun.get_declarator.get_type
      f.printf("%-12s", functype.get_type_str)

      f.print(" #{@global_name}_#{p.get_name}_#{fun.get_name}(")
      if @singleton
        delim = ""
      else
        f.print("#{@global_name}_IDX idx")
        delim = ","
      end

      if p.get_array_size
        f.print("#{delim} int_t subscript") # mikan singleton 時の ',' の始末
        delim = ","
      end

      if functype.get_paramlist
        items = functype.get_paramlist.get_items
        len = items.length
      else
        # ここで nil になるのは、引数なしの時に void がなかった場合
        items = []
        len = 0
      end
      i = 0
      items.each{|param|
        f.print "#{delim} "
        delim = ","
        f.print(param.get_type.get_type_str)
        f.print(" ")
        f.print(param.get_name)
        f.print(param.get_type.get_type_str_post)
        i += 1
      }
      f.print(");\n")

    }
  }
end

#gen_ph_ep_skel_prototype(f) ⇒ Object



2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
# File 'lib/tecsgen/core/generate.rb', line 2514

def gen_ph_ep_skel_prototype(f)
  # 受け口スケルトン関数のプロトタイプ宣言を出力
  if @n_entry_port > 0
    f.printf(TECSMsg.get(:EPSP_comment), "#_EPSP_#")
  end
  @port.each {|p|
    next if p.get_port_type != :ENTRY
    next if p.is_omit?
#      if p.is_skelton_useless? || ! p.is_VMT_useless? then    # 受け口最適化
    if p.is_skelton_useless? # 受け口最適化
#        f.print( "/* #{p.get_name} : omitted by entry port optimize */\n" )
      next
    end

    f.print("/* #{p.get_name} */\n")

    p.get_signature.get_function_head_array.each{|fun|
      functype = fun.get_declarator.get_type
      f.printf "%-14s", functype.get_type_str

      f.print " #{@global_name}_#{p.get_name}_#{fun.get_name}_skel("
      f.print " const struct tag_#{p.get_signature.get_global_name}_VDES *epd"
      delim = ","

      if functype.get_paramlist
        items = functype.get_paramlist.get_items
        len = items.length
      else
        # ここで nil になるのは、引数なしの時に void がなかった場合
        items = []
        len = 0
      end
      i = 0
      items.each{|param|
        f.print "#{delim} "
        delim = ","
        f.print param.get_type.get_type_str
        f.print " "
        f.print param.get_name
        f.print param.get_type.get_type_str_post
        i += 1
      }
      f.print ");\n"
    }
  }
  f.print("\n")
end

#gen_ph_extern_cell(f) ⇒ Object



2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
# File 'lib/tecsgen/core/generate.rb', line 2747

def gen_ph_extern_cell(f)
  if @singleton
    f.printf(TECSMsg.get(:SCP_comment), "#_SCP_#")
    if has_CB?
      f.print "extern  #{@global_name}_CB  #{@global_name}_SINGLE_CELL_CB;\n"
    end
    if has_INIB?
      f.print "extern  #{@global_name}_INIB  #{@global_name}_SINGLE_CELL_INIB;\n"
    end
    f.print "\n"
  elsif @idx_is_id_act
    if has_CB?
      f.print "extern #{@global_name}_CB  *#{@global_name}_CB_tab[];\n"
    elsif has_INIB?
      f.print "extern #{@global_name}_INIB  *const #{@global_name}_INIB_tab[];\n"
    end
  else
    if has_CB?
      f.print "extern #{@global_name}_CB  #{@global_name}_CB_tab[];\n"
    elsif has_INIB?
      f.print "extern #{@global_name}_INIB  #{@global_name}_INIB_tab[];\n"
    end
  end
end

#gen_ph_foreach_cell(f) ⇒ Object

イテレータコード (FOREACH_CELL)の生成

singleton では出力しない


2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
# File 'lib/tecsgen/core/generate.rb', line 2789

def gen_ph_foreach_cell(f)
  return if @singleton

  if has_CB? || has_INIB?

    if need_CB_initializer?
      necessity = ""
    else
      necessity = "//"
    end

    f.printf(TECSMsg.get(:FEC_comment), "#_FEC_#")

    if @idx_is_id_act
      amp = ""
    else
      amp = "&"
    end
    f.print <<EOT
#define FOREACH_CELL(i,p_cb)   \\
  for( (i) = 0; (i) < #{@global_name}_N_CELL; (i)++ ){ \\
     #{necessity}(p_cb) = #{amp}#{@global_name}_CB_tab[i];

#define END_FOREACH_CELL   }

EOT
  else
    f.printf(TECSMsg.get(:NFEC_comment), "#_NFEC_#")
    f.print <<EOT
#define FOREACH_CELL(i,p_cb)   \\
  for((i)=0;(i)<0;(i)++){

#define END_FOREACH_CELL   }

EOT
  end
end

#gen_ph_get_cellcb(f) ⇒ Object

CELLCB へのポインタを得るマクロを出力

セルタイプヘッダへ出力


1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
# File 'lib/tecsgen/core/generate.rb', line 1734

def gen_ph_get_cellcb(f)
  f.printf(TECSMsg.get(:GCB_comment), "#_GCB_#")
  if (!has_CB? && !has_INIB?) || @singleton
    f.print("#define #{@global_name}_GET_CELLCB(idx) ((void *)0)\n")
  elsif @idx_is_id_act # mikan 単一のセルの場合の最適化, idx_is_id でない場合
    f.print("#define #{@global_name}_GET_CELLCB(idx) (#{@global_name}_CB_tab[(idx) - #{@global_name}_ID_BASE])\n")
  else
    f.print("#define #{@global_name}_GET_CELLCB(idx) (idx)\n")
  end
end

#gen_ph_get_cellcb_abbrev(f) ⇒ Object

CELLCB へのポインタを得るマクロ(短縮形)を出力

セルタイプヘッダへ出力


1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
# File 'lib/tecsgen/core/generate.rb', line 1747

def gen_ph_get_cellcb_abbrev(f)
  f.printf(TECSMsg.get(:GCBA_comment), "#_GCBA_#")
  f.print("#define GET_CELLCB(idx)  #{@global_name}_GET_CELLCB(idx)\n\n")

  f.printf(TECSMsg.get(:CCT_comment), "#_CCT_#")
  f.print("#define CELLCB\t#{@global_name}_CB\n\n")

  f.printf(TECSMsg.get(:CTIXA_comment), "#_CTIXA_#")
  f.print("#define CELLIDX\t#{@global_name}_IDX\n\n")

  if @name != @global_name
    f.print("#define #{@name}_IDX  #{@global_name}_IDX\n")
  end
end

#gen_ph_guard(f, post = "TECSGEN") ⇒ Object

celltype header



1392
1393
1394
1395
# File 'lib/tecsgen/core/generate.rb', line 1392

def gen_ph_guard(f, post = "TECSGEN")
  f.print("#ifndef #{@global_name}_#{post}_H\n")
  f.print("#define #{@global_name}_#{post}_H\n\n")
end

#gen_ph_idx_type(f) ⇒ Object



2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
# File 'lib/tecsgen/core/generate.rb', line 2444

def gen_ph_idx_type(f)
  if @idx_is_id_act
    f.print("ID")
  else
    if has_CB?
      f.print("struct tag_#{@global_name}_CB *")
    elsif has_INIB?
      # f.print( "struct tag_#{@global_name}_INIB *" )  # const を出力していない
      f.print("const struct tag_#{@global_name}_INIB *")
    else
      f.print("int")
    end
  end
end

#gen_ph_include(f) ⇒ Object



1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
# File 'lib/tecsgen/core/generate.rb', line 1425

def gen_ph_include(f)
  # ランタイムヘッダの include
#    f.printf TECSMsg.get( :IRTH_comment), "#_IRTH_#"
#    f.print "#include \"tecs.#{$h_suffix}\"\n\n"

  # グローバルヘッダの include
  f.printf TECSMsg.get(:IGH_comment), "#_IGH_#"
  f.print "#include \"global_tecsgen.#{$h_suffix}\"\n\n"

  # シグニチャヘッダの include
  f.printf TECSMsg.get(:ISH_comment), "#_ISH_#"
  @port.each {|p|
    next if p.is_omit?
    hname = "#{p.get_signature.get_global_name}_tecsgen.#{$h_suffix}".to_sym
    if header_included?(hname) == false
      f.print "#include \"#{hname}\"\n"
    end
  }
  f.print "\n"
end

#gen_ph_include_cb_type(f) ⇒ Object



1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
# File 'lib/tecsgen/core/generate.rb', line 1446

def gen_ph_include_cb_type(f)
  if !@b_cp_optimized
    return
  end

  # 最適化のため参照するセルタイプの CB 型の定義を取込む
  # _CB_TYPE_ONLY を定義した上で include する
  f.printf(TECSMsg.get(:ICT_comment), "#_ICT_#")

  f.print("#ifndef  TOPPERS_CB_TYPE_ONLY\n")
  f.print("#define  #{@global_name}_CB_TYPE_ONLY\n")
  f.print("#define TOPPERS_CB_TYPE_ONLY\n")
  f.print("#endif  /* TOPPERS_CB_TYPE_ONLY */\n")

  @port.each {|p|
    next if p.get_port_type != :CALL
    next if p.is_omit?

    if p.is_skelton_useless? || p.is_cell_unique? || p.is_VMT_useless?
      # 最適化コード (optimize) # スケルトン不要など
      p2 = p.get_real_callee_port
      if p2
        ct = p2.get_celltype
        hname = "#{ct.get_global_name}_tecsgen.#{$h_suffix}".to_sym
        if header_included?(hname) == false
          f.print("#include \"#{hname}\"\n")
        end
      # else
        # optional で未結合
      end
    end

  }
  f.print("#ifdef  #{@global_name}_CB_TYPE_ONLY\n")
  f.print("#undef TOPPERS_CB_TYPE_ONLY\n")
  f.print("#endif /* #{@global_name}_CB_TYPE_ONLY */\n")

#    @port.each { |p|
#      next if p.get_port_type != :CALL
#      if p.is_skelton_useless? || p.is_cell_unique? || p.is_VMT_useless? then
#        # 最適化コード (optimize) # スケルトン不要など
#        p2 = p.get_real_callee_port
#        ct = p2.get_celltype
#        ct.gen_ph_typedef_idx f
#        ct.gen_ph_INIB_as_CB f
#        ct.gen_ph_extern_cell f
#        f.print "\n"
#      end
#    }
end

#gen_ph_info(f) ⇒ Object



1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'lib/tecsgen/core/generate.rb', line 1397

def gen_ph_info(f)
  yn_idx_is_id = "no"
  yn_idx_is_id = "yes" if @idx_is_id
  yn_idx_is_id_act = "no"
  yn_idx_is_id_act = "yes" if @idx_is_id_act
  yn_singleton = "no"
  yn_singleton = "yes" if @singleton
  yn_rom       = "no"
  yn_rom       = "yes" if $rom
  yn_cb_init   = "no"
  yn_cb_init   = "yes" if need_CB_initializer?
  # @singleton = false    # mikan singleton  060827

  f.print <<EOT
/*
 * celltype          :  #{@name}
 * global name       :  #{@global_name}
 * idx_is_id(actual) :  #{yn_idx_is_id}(#{yn_idx_is_id_act})
 * singleton         :  #{yn_singleton}
 * has_CB            :  #{has_CB?}
 * has_INIB          :  #{has_INIB?}
 * rom               :  #{yn_rom}
 * CB initializer    :  #{yn_cb_init}
 */

EOT
end

#gen_ph_INIB_as_CB(f) ⇒ Object



2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
# File 'lib/tecsgen/core/generate.rb', line 2772

def gen_ph_INIB_as_CB(f)
  # ここは、手抜きである。本来なら INIB を出力すべき
  if !has_CB? && has_INIB?
    f.printf(TECSMsg.get(:DCI_comment), "#_DCI_#")
    if @singleton
      f.print "#define #{@global_name}_SINGLE_CELL_CB   #{@global_name}_SINGLE_CELL_INIB\n"
    else
      f.print "#define #{@global_name}_CB_tab           #{@global_name}_INIB_tab\n"
    end
    f.print "#define #{@global_name}_CB               #{@global_name}_INIB\n"
    f.print "#define tag_#{@global_name}_CB           tag_#{@global_name}_INIB\n"
    f.print "\n"
  end
end

#gen_ph_inline(f) ⇒ Object



2955
2956
2957
2958
2959
2960
2961
# File 'lib/tecsgen/core/generate.rb', line 2955

def gen_ph_inline(f)
  # inline ポートが一つでもあれば、inline.h の include
  if @n_entry_port_inline > 0
    f.printf(TECSMsg.get(:INL_comment), "#_INL_#")
    f.print("#include \"#{@global_name}_inline.#{$h_suffix}\"\n\n")
  end
end

#gen_ph_n_cp(f) ⇒ Object

呼び口配列の大きさを得るマクロの出力

セルタイプヘッダへ呼び口の個数を出力



1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
# File 'lib/tecsgen/core/generate.rb', line 1529

def gen_ph_n_cp(f)
  b_comment = false
  @port.each {|p|
    next if p.get_port_type != :CALL
    next if p.is_omit?
    next if p.get_array_size.nil?

    if !b_comment
      f.printf(TECSMsg.get(:NCPA_comment), "#_NCPA_#")
      b_comment = true
    end

    if p.get_array_size != "[]" # 固定長配列
      f.print("#define N_CP_#{p.get_name}    (#{p.get_array_size})\n")
      f.print("#define NCP_#{p.get_name}     (#{p.get_array_size})\n")
    else # 可変長配列
      if @singleton
        if has_INIB?
          inib = "INIB"
        else
          inib = "CB"
        end
        f.print("#define N_CP_#{p.get_name}  (#{@global_name}_SINGLE_CELL_#{inib}.n_#{p.get_name})\n")
        f.print("#define NCP_#{p.get_name}   (#{@global_name}_SINGLE_CELL_#{inib}.n_#{p.get_name})\n")
        # mikan singleton ならば、固定長化できる
      else
        if has_CB? && has_INIB?
          inib = "->_inib"
        else
          inib = ""
        end
        f.print("#define N_CP_#{p.get_name}(p_that)  ((p_that)#{inib}->n_#{p.get_name})\n")
        f.print("#define NCP_#{p.get_name}           (N_CP_#{p.get_name}(p_cellcb))\n")
      end
    end
  }
end

#gen_ph_n_ep(f) ⇒ Object

受け口配列の大きさを得るマクロの出力

セルタイプヘッダへ受け口の個数を出力



1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
# File 'lib/tecsgen/core/generate.rb', line 1570

def gen_ph_n_ep(f)
  b_comment = false
  @port.each {|p|
    next if p.get_port_type != :ENTRY
    # next if p.is_omit?                       # 受け口配列の個数は省略しない
    next if p.get_array_size.nil?

    if !b_comment
      f.printf(TECSMsg.get(:NEPA_comment), "#_NEPA_#")
      b_comment = true
    end

    if p.get_array_size != "[]" # 固定長配列
      f.print("#define NEP_#{p.get_name}     (#{p.get_array_size})\n")
    else # 可変長配列
      if @singleton
        if has_INIB?
          inib = "INIB"
        else
          inib = "CB"
        end
        f.print("#define NEP_#{p.get_name}   (#{@global_name}_SINGLE_CELL_#{inib}.n_#{p.get_name})\n")
        # mikan singleton ならば、固定長化できる
      else
        if has_CB? && has_INIB?
          inib = "->_inib"
        else
          inib = ""
        end
        f.print("#define NEP_#{p.get_name}           ((p_cellcb)#{inib}->n_#{p.get_name})\n")
      end
    end
  }
end

#gen_ph_ref_desc_func(f) ⇒ Object

ref_desc 指定された呼び口に対するディスクリプタ参照関数の生成



2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
# File 'lib/tecsgen/core/generate.rb', line 2087

def gen_ph_ref_desc_func(f)
  if @n_call_port_ref_desc > 0
    f.printf(TECSMsg.get(:CRD_comment), "#_CRD_#")
  end

  if has_CB? && has_INIB?
    inib = "->_inib"
  else
    inib = ""
  end
  @port.each {|p|
    next if p.get_port_type != :CALL
    next if !p.is_ref_desc?

    if @singleton
      p_that = ""
      p_cellcb = ""
      delim = ""
      if has_INIB?
        cb = "#{@global_name}_SINGLE_CELL_INIB."
      else
        cb = "#{@global_name}_SINGLE_CELL_CB."
      end
    else
      p_that = "#{@global_name}_CB  *p_that"
      p_cellcb = "    #{@global_name}_CB *p_cellcb = p_that;\n"
      delim = ", "
      cb = "p_that#{inib}->"
    end

    if p.get_array_size
      array = "#{delim}int_t  i "
      array2 = "[ i ]"
      assert = "    assert( 0 <= i && i < NCP_#{p.get_name} );\n"
    else
      array = ""
      array2 = ""
      assert = ""
    end
    f.print <<EOT
/* [ref_desc] #{p.get_name} */
Inline Descriptor( #{p.get_signature.get_global_name} )
#{@global_name}_#{p.get_name}_refer_to_descriptor( #{p_that}#{array} )
{
  Descriptor( #{p.get_signature.get_global_name} )  des;
#{p_cellcb}    /* cast is ncecessary for removing 'const'  */
#{assert}    des.vdes = (struct tag_#{p.get_signature.get_global_name}_VDES *)#{cb}#{p.get_name}#{array2};
  return des;
}

EOT
  }
end

#gen_ph_ref_desc_macro_abbrev(f) ⇒ Object



2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
# File 'lib/tecsgen/core/generate.rb', line 2341

def gen_ph_ref_desc_macro_abbrev(f)
  if @n_call_port_ref_desc > 0
    f.printf(TECSMsg.get(:CRDA_comment), "#_CRDA_#")
  end

  @port.each {|p|
    next if p.get_port_type != :CALL
    next if !p.is_ref_desc?

    if @singleton
      p_cellcb = ""
      delim = ""
    else
      p_cellcb = "p_cellcb"
      delim = ", "
    end

    if p.get_array_size
      array = " i "
      array2 = "#{delim}i"
    else
      array = ""
      array2 = ""
    end

    f.printf("#define %s_refer_to_descriptor(#{array})\\\n          %s_refer_to_descriptor( #{p_cellcb}#{array2} )\n",
             p.get_name,
             "#{@global_name}_#{p.get_name}")
    f.printf("#define %s_ref_desc(#{array})\\\n          %s_refer_to_descriptor(#{array})\n",
             p.get_name,
             p.get_name)
  }
  f.print("\n")
end

#gen_ph_set_desc_func(f) ⇒ Object

dynamic 指定された呼び口に対するディスクリプタ設定関数の生成



2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
# File 'lib/tecsgen/core/generate.rb', line 2142

def gen_ph_set_desc_func(f)
  if @n_call_port_dynamic > 0
    f.printf(TECSMsg.get(:SDF_comment), "#_SDF_#")
  end

  @port.each {|p|
    next if p.get_port_type != :CALL
    next if !p.is_dynamic?
    if has_CB? && has_INIB? && p.get_array_size
      inib = "->_inib"
    else
      inib = ""
    end
    if @singleton
      # p "main== #{@global_name} #{p.get_name} #{p.get_array_size}"
      p_that = ""
      p_that2 = ""
      p_cellcb = ""
      if p.get_array_size && $rom
        cb = "#{@global_name}_SINGLE_CELL_INIB."
      else
        cb = "#{@global_name}_SINGLE_CELL_CB."
      end
    else
      p_that = "#{@global_name}_CB  *p_that, "
      p_that2 = "#{@global_name}_CB  *p_that "
      p_cellcb = "    #{@global_name}_CB *p_cellcb = p_that;\n"
      cb = "(p_cellcb)->#{inib}"
    end

    if p.get_array_size
      array = "int_t  i, "
      array2 = "[ i ]"
      array3 = " int_t  i "
      assert2 = "    assert( 0 <= i && i < NCP_#{p.get_name} );\n"
    else
      array = ""
      array2 = ""
      array3 = ""
      assert2 = ""
    end
    f.print <<EOT
/* [dynamic] #{p.get_name} */
Inline void
#{@global_name}_#{p.get_name}_set_descriptor( #{p_that}#{array}Descriptor( #{p.get_signature.get_global_name} ) des )
{
#{p_cellcb}    assert( des.vdes != NULL );
#{assert2}    #{cb}#{p.get_name}#{array2} = des.vdes;
}

EOT

    if p.is_optional?
      if p_that2 != "" && array3 != ""
        delim = ", "
      else
        delim = ""
      end
      f.print <<EOT
/* [dynamic,optional] #{p.get_name} */
Inline void
#{@global_name}_#{p.get_name}_unjoin( #{p_that2}#{delim}#{array3} )
{
#{p_cellcb}    #{cb}#{p.get_name}#{array2} = NULL;
}

EOT
    end
  }
end

#gen_ph_set_desc_macro_abbrev(f) ⇒ Object



2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
# File 'lib/tecsgen/core/generate.rb', line 2376

def gen_ph_set_desc_macro_abbrev(f)
  if @n_call_port_dynamic > 0
    f.printf(TECSMsg.get(:SDMA_comment), "#_SDMA_#")
  end

  if @singleton
    p_cellcb = ""
    delim = ""
  else
    p_cellcb = "p_cellcb"
    delim = ", "
  end
  @port.each {|p|
    next if p.get_port_type != :CALL
    next if !p.is_dynamic?

    if p.get_array_size
      subsc = "i, "
      subsc2 = "i"
      subsc3 = delim + subsc2
    else
      subsc = ""
      subsc2 = ""
      subsc3 = ""
    end
    f.printf("#define %s_set_descriptor( #{subsc}desc )\\\n          %s_set_descriptor( #{p_cellcb}#{delim}#{subsc}desc )\n",
              p.get_name,
              "#{@global_name}_#{p.get_name}")
    f.printf("#define %s_unjoin( #{subsc2} )\\\n          %s_unjoin( #{p_cellcb}#{subsc3} )\n",
              p.get_name,
              "#{@global_name}_#{p.get_name}")
  }
  f.print("\n")
end

#gen_ph_test_optional_call_port(f) ⇒ Object

optional な呼び口が結合されているかテストするコードの生成



1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
# File 'lib/tecsgen/core/generate.rb', line 1606

def gen_ph_test_optional_call_port(f)
  b_comment = false

  if @singleton
    if has_INIB?
      inib = "INIB"
    else
      inib = "CB"
    end
  else
    if has_CB? && has_INIB?
      inib = "->_inib"
    else
      inib = ""
    end
  end

  @port.each {|p|
    next if p.get_port_type != :CALL
    next if !p.is_optional?
    # next if p.is_omit?  # omit でも test コードは生成する

    if b_comment == false
      f.printf(TECSMsg.get(:TOCP_comment), "#_TOCP_#")
      b_comment = true
    end

    if @singleton
      param = ""
      delim = ""
    else
      param = "p_that"
      delim = ","
    end
    if !p.get_array_size.nil?
      param = param + delim + "subscript"
    end
    f.print("#define #{@global_name}_is_#{p.get_name}_joined(#{param}) \\\n")

    if p.is_omit?
      f.print("   omit  is_#{p.get_name}_joined\n")
      next
    end

    # 関数名の出力(標準:受け口ディスクリプタから VMT の関数名、最適化:受け口関数 or 受け口ディスクリプタ)
    # mikan  全部つながっているかどうかで (1) を判定する
    if !p.is_VMT_useless?
      if p.is_dynamic?
        if @singleton
          inib_tmp = "CB"
        else
          inib_tmp = ""
        end
      else
        inib_tmp = inib
      end

      # 標準コード
      if p.get_array_size.nil?
        if @singleton
          f.print("\t  (#{@global_name}_SINGLE_CELL_#{inib_tmp}.#{p.get_name}!=0)\n")
        else
          f.print("\t  ((p_that)#{inib_tmp}->#{p.get_name}!=0)\n")
        end
      else
        # 配列の場合
        if @singleton
          f.print("\t  ((#{@global_name}_SINGLE_CELL_#{inib_tmp}.#{p.get_name}!=0) \\\n")
          f.print("\t  &&(#{@global_name}_SINGLE_CELL_#{inib_tmp}.#{p.get_name}[subscript]!=0))\n")
        else
          f.print("\t  (((p_that)#{inib_tmp}->#{p.get_name}!=0)\\\n")
          f.print("\t  &&((p_that)#{inib_tmp}->#{p.get_name}[subscript]!=0))\n")
        end
      end
    else
      # 最適化コード (optimize) # VMT 不要(配列要素すべて同じ)
      p2 = p.get_real_callee_port
      if p2
        ct = p2.get_celltype
        if p.is_skelton_useless?
          # 受け口関数を直接呼出す
          f.print("\t  (1)\n")
        else
          # 受け口スケルトン関数を直接呼出す
          f.print("\t  (1)\n")
        end
      else
        # optional で未結合
        f.print("\t  (0)    /* not joined */\n")
      end
    end
  }
end

#gen_ph_test_optional_call_port_abbrev(f) ⇒ Object

optional な呼び口が結合されているかテストするコードの生成(短縮形)



1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
# File 'lib/tecsgen/core/generate.rb', line 1701

def gen_ph_test_optional_call_port_abbrev(f)
  b_comment = false

  @port.each {|p|
    next if p.get_port_type != :CALL
    next if !p.is_optional?
    # next if p.is_omit?  # omit でも test コードは生成する

    if b_comment == false
      f.printf(TECSMsg.get(:TOCPA_comment), "#_TOCPA_#")
      b_comment = true
    end

    if @singleton
      param = ""
      delim = ""
    else
      param = "p_cellcb"
      delim = ","
    end

    if p.get_array_size.nil?
      subscript = ""
    else
      subscript = "subscript"
      param = param + delim + subscript
    end
    f.print("#define is_#{p.get_name}_joined(#{subscript})\\\n\t\t#{@global_name}_is_#{p.get_name}_joined(#{param})\n")
  }
end

#gen_ph_typedef_idx(f) ⇒ Object



2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
# File 'lib/tecsgen/core/generate.rb', line 2429

def gen_ph_typedef_idx(f)
  f.printf(TECSMsg.get(:CTIX_comment), "#_CTIX_#")
  if @idx_is_id_act
    f.print("typedef ID #{@global_name}_IDX;\n")
  else
    if has_CB?
      f.print("typedef struct tag_#{@global_name}_CB *#{@global_name}_IDX;\n")
    elsif has_INIB?
      f.print("typedef const struct tag_#{@global_name}_INIB *#{@global_name}_IDX;\n")
    else
      f.print("typedef int   #{@global_name}_IDX;\n")
    end
  end
end

#gen_ph_valid_idx(f) ⇒ Object



1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
# File 'lib/tecsgen/core/generate.rb', line 1505

def gen_ph_valid_idx(f)
  return if @singleton

  # mikan  最適化
  # IDX 正当性チェックマクロの出力
  f.printf(TECSMsg.get(:CVI_comment), "#_CVI_#")
  if @idx_is_id_act
    f.print("#define #{@global_name}_VALID_IDX(IDX) (#{@global_name}_ID_BASE <= (IDX) && (IDX) < #{@global_name}_ID_BASE+#{@global_name}_N_CELL)\n\n")
  else
    f.print("#define #{@global_name}_VALID_IDX(IDX) (1)\n\n")
  end
end

#gen_ph_valid_idx_abbrev(f) ⇒ Object



1518
1519
1520
1521
1522
1523
1524
# File 'lib/tecsgen/core/generate.rb', line 1518

def gen_ph_valid_idx_abbrev(f)
  return if @singleton

  # IDX 正当性チェックマクロ(短縮形)の出力
  f.printf(TECSMsg.get(:CVIA_comment), "#_CVIA_#")
  f.print("#define VALID_IDX(IDX)  #{@global_name}_VALID_IDX(IDX)\n\n")
end

#gen_template_attr_access(f) ⇒ Object



4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
# File 'lib/tecsgen/core/generate.rb', line 4399

def gen_template_attr_access(f)
  if @n_attribute_rw > 0 || @n_attribute_ro > 0 || @n_var > 0
    f.printf(TECSMsg.get(:CAAM_comment), "#_CAAM_#")
  end

  @attribute.each {|a|

    next if a.is_omit?

    f.printf(" * %-16s %-16s %-16s\n", a.get_name, "#{a.get_type.get_type_str} #{a.get_type.get_type_str_post}", "ATTR_#{a.get_name}")

  }

  @var.each {|v|

    next if v.is_omit?

    f.printf(" * %-16s %-16s %-16s\n", v.get_name, "#{v.get_type.get_type_str} #{v.get_type.get_type_str_post}", "VAR_#{v.get_name}")
  }
end

#gen_template_cp_fun(f) ⇒ Object



4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
# File 'lib/tecsgen/core/generate.rb', line 4424

def gen_template_cp_fun(f)
  if @n_call_port > 0
    f.print " *\n"
    f.printf(TECSMsg.get(:TCPF_comment), "#_TCPF_#")
  end

  @port.each {|p|
    next if p.get_port_type != :CALL
    # next if p.is_omit?

    sig_name = p.get_signature.get_global_name
    con_tmp = p.get_signature.get_context
    if con_tmp
      context = " context:#{con_tmp}"
    else
      context = ""
    end

    if p.is_optional?
      optional = " optional:true"
      if p.get_array_size
        is_join = " *   bool_t     is_#{p.get_name}_joined(int subscript)        check if joined\n"
      else
        is_join = " *   bool_t     is_#{p.get_name}_joined()                     check if joined\n"
      end
    else
      optional = ""
      is_join = ""
    end

    if p.is_omit?
      omit = " omit:true"
    else
      omit = ""
    end

    if p.is_allocator_port?
      f.print " * allocator port for #{p.get_port_type.to_s.downcase} port:#{p.get_allocator_port.get_name} func:#{p.get_allocator_func_decl.get_name} param: #{p.get_allocator_param_decl.get_name}\n"
    elsif !p.is_require?
      f.print " * call port: #{p.get_name} signature: #{sig_name}#{context}#{optional}#{omit}\n#{is_join}"
    else
      f.print " * require port: signature:#{sig_name}#{context}\n"
    end

    p.get_signature.get_function_head_array.each{|fun|

      ft = fun.get_declarator.get_type

      f.printf(" *   %-14s ", ft.get_type.get_type_str)
      if !p.is_require? || p.has_name?
        f.print("#{p.get_name}_#{fun.get_name}(")
      else
        f.print("#{fun.get_name}(")
      end
      delim = ""

#        if ! @singleton then
#          f.print( "#{delim} p_that" )
#          delim = ","
#        end

      if p.get_array_size
        f.print("#{delim} subscript")
        delim = ","
      end

      ft.get_paramlist.get_items.each{|param|
        # p "type_str: #{param.get_type.get_type_str}"
        f.print("#{delim} #{param.get_type.get_type_str}")
        f.print(" #{param.get_name}#{param.get_type.get_type_str_post}")
        delim = ","
      }
      f.print(" );\n")

#        subsc = ""
#        subsc = "[subscript]" if p.get_array_size
#
#        if @singleton then
#          f.print( " *        #{@global_name}_#{p.get_name}" )
#        else
#          f.print( " *        (p_that)->#{p.get_name}" )
#        end
#        f.print( "#{subsc}->VMT->#{fun.get_name}(" )
#        f.print( " (p_that)->#{p.get_name}#{subsc}" )
#        ft.get_paramlist.get_items.each{ |param|
#          f.print( ", (#{param.get_name})" )
#        }
#        f.print( " )\n" )

    }

    if p.get_array_size
      f.print " *       subscript:  0...(NCP_#{p.get_name}-1)\n"
    end

    if p.is_ref_desc?
      subsc = p.get_array_size ? " int_t subscript " : ""
      f.print " *   [ref_desc]\n"
      f.printf(" *      %-14s %s;\n",
                "Descriptor( #{p.get_signature.get_global_name} )",
                "#{p.get_name}_refer_to_descriptor(#{subsc})")
      f.printf(" *      %-14s %s;\n",
                "Descriptor( #{p.get_signature.get_global_name} )",
                "#{p.get_name}_ref_desc(#{subsc})      (same as above; abbreviated version)")
    end
    if p.is_dynamic?
      subsc = p.get_array_size ? "int_t subscript, " : ""
      subsc2 = p.get_array_size ? " int_t subscript" : ""
      if p.is_optional?
        f.print " *   [dynamic, optional]\n"
      else
        f.print " *   [dynamic]\n"
      end
      f.printf(" *      %-14s %s;\n",
                "void",
                "#{p.get_name}_set_descriptor( #{subsc}Descriptor( #{p.get_signature.get_global_name} ) desc )")
      if p.is_optional?
        f.printf(" *      %-14s %s;\n",
                  "void",
                  "#{p.get_name}_unjoin( #{subsc2} )")
      end
    end
  }
end

#gen_template_ep_fun(f, b_inline = false) ⇒ Object



4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
# File 'lib/tecsgen/core/generate.rb', line 4549

def gen_template_ep_fun(f, b_inline = false)
  if @n_entry_port > 0
    f.printf(TECSMsg.get(:TEPF_comment), "#_TEPF_#")
  end

  @port.each {|p|
    next if p.get_port_type != :ENTRY
    next if p.is_omit?
    next if b_inline && !p.is_inline?  # inline ポート
    next if !b_inline && p.is_inline?  # 非 inline ポート

    inline_prefix = ""
    nCELLIDX = "CELLIDX"
    nCELLCB = "CELLCB"
    nVALID_IDX = "VALID_IDX"
    nGET_CELLCB = "GET_CELLCB"

    f.print <<EOT
/* #[<ENTRY_PORT>]# #{p.get_name}
 * entry port: #{p.get_name}
 * signature:  #{p.get_signature.get_global_name}
 * context:    #{p.get_signature.get_context}
EOT

    if !p.get_array_size.nil?
      f.print <<EOT
 * entry port array size:  NEP_#{p.get_name}
EOT
    end

    f.print <<EOT
 * #[</ENTRY_PORT>]# */

EOT

    p.get_signature.get_function_head_array.each{|fun|
      f.print <<EOT
/* #[<ENTRY_FUNC>]# #{p.get_name}_#{fun.get_name}
 * name:         #{p.get_name}_#{fun.get_name}
 * global_name:  #{@global_name}_#{p.get_name}_#{fun.get_name}
 * oneway:       #{fun.is_oneway?}
 * #[</ENTRY_FUNC>]# */
EOT

      if b_inline
        f.print "Inline "
      end
      functype = fun.get_declarator.get_type
      f.printf "%s\n", functype.get_type_str
      f.print "#{inline_prefix}#{p.get_name}_#{fun.get_name}("
      if @singleton
        delim = ""
      else
        f.print "#{nCELLIDX} idx"
        delim = ", "
      end

      if p.get_array_size
        f.print "#{delim}int_t subscript"
        delim = ", "
      end

      if functype.get_paramlist
        items = functype.get_paramlist.get_items
        len = items.length
      else
        # ここで nil になるのは、引数なしの時に void がなかった場合
        items = []
        len = 0
      end

      i = 0
      items.each{|param|
        f.print delim.to_s
        delim = ", "
        f.print param.get_type.get_type_str
        # p "type_str2: #{param.get_type.get_type_str}"
        f.print " "
        f.print param.get_name
        f.print param.get_type.get_type_str_post
        i += 1
      }
      f.print ")\n"

      f.print "{\n"

      if @plugin && @plugin.gen_ep_func?
        # このメソッドの引数は plugin.rb の説明を見よ
        @plugin.gen_ep_func_body(f, @singleton, @name, @global_name, p.get_signature.get_global_name, p.get_name, fun.get_name, "#{@global_name}_#{p.get_name}_#{fun.get_name}", functype, items)

      else
        if !@singleton
          if functype.get_type.is_a?(DefinedType) && (functype.get_type.get_type_str == "ER" || functype.get_type.get_type_str == "ER_UINT")
            if !fun.is_oneway?
              f.print "	ER\t\tercd = E_OK;\n"
              er_cd = "return(E_ID);"
              ret_cd = "return(ercd);"
            else
              er_cd = "#{TECSMsg.get(:oneway_ercd_note)}\n		return(E_OK);"
              ret_cd = "#{TECSMsg.get(:oneway_ercd_note)}\n	return(E_OK);"
            end
          else
            er_cd = TECSMsg.get(:ercd_note).to_s
            ret_cd = nil
          end
          f.print <<EOT
	#{nCELLCB}	*p_cellcb;
	if (#{nVALID_IDX}(idx)) {
p_cellcb = #{nGET_CELLCB}(idx);
	}
	else {
#{er_cd}
	} /* end if #{nVALID_IDX}(idx) */

EOT
          f.printf(TECSMsg.get(:TEFB_comment), "#_TEFB_#")
          f.printf("\n")

          if ret_cd
            f.print "	#{ret_cd}\n"
          end
        else
        end # ! @singleton
      end # @plugin

      f.print "}\n\n"
    }
  }
end

#gen_template_private_header(f) ⇒ Object

celltype template



4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
# File 'lib/tecsgen/core/generate.rb', line 4388

def gen_template_private_header(f)
  f.print "#include \"#{@global_name}_tecsgen.#{$h_suffix}\"\n\n"
  f.print <<EOT
#ifndef E_OK
#define	E_OK	0		/* success */
#define	E_ID	(-18)	/* illegal ID */
#endif

EOT
end

#gen_template_types(f) ⇒ Object



4420
4421
4422
# File 'lib/tecsgen/core/generate.rb', line 4420

def gen_template_types(f)
  f.printf(TECSMsg.get(:TYP_comment), "#_TYP_#", "#{@global_name}_CB", "#{@name}_IDX")
end

#gen_XML(file, nest) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/tecsgen/core/gen_xml.rb', line 148

def gen_XML(file, nest)
  indent = XML_INDENT * nest
  if is_imported?
    file.print <<EOT
#{indent}<import path='#{@import.get_cdl_name}'>
EOT
    nest += 1
    indent = XML_INDENT * nest
  end

  file.print <<EOT
#{indent}<celltype>
#{indent}#{XML_INDENT}<name> #{@name} </name>
EOT
  if @active
    file.print <<EOT
#{indent}#{XML_INDENT}<active />
EOT
  end
  if @singleton
    file.print <<EOT
#{indent}#{XML_INDENT}<singleton />
EOT
  end

  @attribute.each{|attr|
    file.print <<EOT
#{indent}#{XML_INDENT}<attr>
#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{attr.get_name} </name>
#{indent}#{XML_INDENT}#{XML_INDENT}<type> #{attr.get_type.get_type_str}#{attr.get_type.get_type_str_post} </type>
EOT
    if attr.get_initializer
      file.print <<EOT
#{indent}#{XML_INDENT}#{XML_INDENT}<initializer> #{attr.get_initializer.to_CDL_str} </initializer>
EOT
    end

    if attr.get_choice_list
      file.print <<EOT
#{indent}#{XML_INDENT}#{XML_INDENT}<choice>
EOT

      attr.get_choice_list.each {|choiceElement|
        file.print <<EOT
#{indent}#{XML_INDENT}#{XML_INDENT}#{XML_INDENT}<choiceElement>#{choiceElement}</choiceElement>
EOT
      }

      file.print <<EOT
#{indent}#{XML_INDENT}#{XML_INDENT}</choice>
EOT
    end

    file.print <<EOT
#{indent}#{XML_INDENT}</attr>
EOT
  }
  @port.each{|port|
    port_type = port.get_port_type == :CALL ? "call" : "entry"
    file.print <<EOT
#{indent}#{XML_INDENT}<#{port_type}>
#{indent}#{XML_INDENT}#{XML_INDENT}<name> #{port.get_name} </name>
#{indent}#{XML_INDENT}#{XML_INDENT}<signame> #{port.get_signature.get_name} </signame>
EOT
    if port.get_array_size
      file.print <<EOT
#{indent}#{XML_INDENT}#{XML_INDENT}<subscript> #{port.get_array_size} </subscript>
EOT
    end
    file.print <<EOT
#{indent}#{XML_INDENT}</#{port_type}>
EOT
  }
  file.print <<EOT
#{indent}</celltype>
EOT
  if is_imported?
    nest -= 1
    indent = XML_INDENT * nest
    file.print <<EOT
#{indent}</import>
EOT
  end
end

#generateObject



1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
# File 'lib/tecsgen/core/generate.rb', line 1110

def generate
  if need_generate? # セルのないセルタイプは生成しない

    generate_private_header
    generate_factory_header
    generate_cell_code
    generate_template_code
    generate_inline_template_code
    generate_celltype_factory_code
    generate_cell_factory_code
    generate_makefile

  elsif $generate_all_template # テンプレートコード生成オプション

    generate_template_code
    generate_inline_template_code

    # generate_makefile_template は Makefile に追記するものだから、呼び出さない

  end
end

#generate_allocator_portObject

Celltype# アロケータ呼び口を生成

send, receive 引数のアロケータを呼出すための呼び口を生成


818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
# File 'lib/tecsgen/core/componentobj.rb', line 818

def generate_allocator_port
  @port.each {|port|
    # ポートのすべてのパラメータを辿る
    port.each_param {|port, fd, par|
      case par.get_direction # 引数の方向指定子 (in, out, inout, send, receive )
      when :SEND, :RECEIVE
        if par.get_allocator
          cp_name = :"#{port.get_name}_#{fd.get_name}_#{par.get_name}" # アロケータ呼び口の名前
          #           ポート名          関数名         パラメータ名
          # alloc_sig_path = [ par.get_allocator.get_name ]  # mikan Namespace アロケータ呼び口のシグニチャ #1
          alloc_sig_path = par.get_allocator.get_namespace_path
          array_size = port.get_array_size # 呼び口または受け口配列のサイズ
          created_port = Port.new(cp_name, alloc_sig_path, :CALL, array_size) # 呼び口を生成
          created_port.set_allocator_port(port, fd, par)
          if port.is_optional?
            created_port.set_optional
          end
          if port.is_omit?
            created_port.set_omit
          end
          new_port(created_port) # セルタイプに新しい呼び口を追加
        # else
        #  already error "not found or not signature" in class ParamDecl
        end
      end
    }
  }
end

#generate_cell_codeObject

CELLTYPE_tecsgen.c を生成



1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
# File 'lib/tecsgen/core/generate.rb', line 1309

def generate_cell_code
  fs = { }
  f = nil
  @domain_roots.each{|domain_type_name, regions|
    regions.each{|r|
      if r.is_root?
        nsp = ""
      else
        nsp = "_#{r.get_namespace_path.get_global_name}"
      end
      # p "celltype:#{@name} dn:#{domain_type_name} nsp:#{nsp}"
      fs[r] = AppFile.open("#{$gen}/#{@global_name}#{nsp}_tecsgen.#{$c_suffix}")
      if r.is_root?
        f = fs[r]
      end
    }
  }

  # in case that domain_roots does not include root region
  if f.nil?
    regions = nil
    @domain_roots.each{|domain_type_name, regions_|
      regions = regions_ # domain_type_name is unique
    }
    if regions.length > 1
      # if domain_roots.length >= 2 && no cell in root region
      # shared code are placed in root region
      f = AppFile.open("#{$gen}/#{@global_name}_tecsgen.#{$c_suffix}")
    else
      # shared code are placed in unique region
      f = fs[regions[0]]
    end
  end

  # すべての _tecsgen.c に出力
  print_note f
  gen_cell_private_header f
  gen_cell_factory_header f
  gen_cell_ep_des_type f

  # すべての _tecsgen.c に出力
  fs.each{|r, f2|
    if f == f2
      next
    end
    print_note f2
    gen_cell_private_header f2
    gen_cell_factory_header f2
    gen_cell_ep_des_type f2
  }

  # 一つの _tecsgen.c に出力
  gen_cell_skel_fun f
  gen_cell_fun_table f
  gen_cell_var_init f

  # セルごとに _tecsgen.c に出力
  gen_cell_ep_vdes fs
  gen_cell_ep_vdes_array fs
  gen_cell_cb_out_init fs # INITIALIZE_CB で参照されるため ram_initializer=false でも消せない
  gen_cell_cb fs
  gen_cell_extern_mt fs
  gen_cell_ep_des fs

  # 一つの _tecsgen.c に出力
  gen_cell_cb_tab f
  if $ram_initializer
    gen_cell_cb_initialize_code f
  end

  fs.each{|r, f2|
    f2.close
    if f == f2
      f = nil
    end
  }
  if f
    f.close
  end
end

#generate_cell_factory_codeObject



4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
# File 'lib/tecsgen/core/generate.rb', line 4769

def generate_cell_factory_code
  @ordered_cell_list.each{|c|

    # cell のプロトタイプ宣言なら無視
    next if !c.is_generate?

    name_array = get_name_array(c)

    @factory_list.each {|fa|

      if fa.get_name == :write

        # 前後の " を取り除く
        # file_name = fa.get_file_name.sub( /^\"(.*)\"$/, "\\1" )
        file_name = CDLString.remove_dquote fa.get_file_name
        file_name = subst_name(file_name, name_array)
        # format    = fa.get_format.sub( /^\"(.*)\"$/, "\\1" )        # 前後の "" を取り除く
        format    = CDLString.remove_dquote fa.get_format
        # format    = fa.get_format.sub( /^\"(.*)/, "\\1" )        # 前の " を取り除く
        # format    = format.sub( /(.*)\"\z/, "\\1" )              # 後の " を取り除く
        format    = format.gsub(/\\\n/, "\n") # \\\n => \n

        format    = subst_name(format, name_array)

        arg_list  = fa.get_arg_list

        if file_name[0] != ?/
          file_name = "#{$gen}/#{file_name}"
        end

        na = [] # シンボルを attribute の値に置き換えた後の引数
        if arg_list
          arg_list.each {|a|
            case a[0]
            when :STRING_LITERAL # 文字列定数
              # s = a[1].sub( /^\"(.*)\"$/, "\\1" )            # 前後の "" を取り除く
              s = CDLString.remove_dquote a[1]
              s = subst_name(s, name_array)
              # s = subst_name( a[1], name_array )

              na << s
            when :IDENTIFIER
              param_name = a[1] # 識別子(属性の名前)
              attr = self.find(param_name)
              init = attr.get_initializer # celltype で指定された初期値

              # cell の join のリストから名前を探す
              j = c.get_join_list.get_item(param_name)
              if j # param_name の cell のジョインがあるか
                init = j.get_rhs # cell で指定された初期値を優先
              end

              str = gen_cell_cb_init(nil, c, name_array, attr.get_type, init, attr.get_identifier, 0, true)
                                    # file,cell, name_array, type,          init, identifier,       indent, f_get_str

              # str = str.sub( /^\"(.*)\"$/, "\\1" )            # 前後の "" を取り除く mikan ここで置換でよい?
              str = CDLString.remove_dquote str
              na << str
            end
          }
        end

        begin
          cfg_file = AppFile.open(file_name)

          if $debug
            print "'#{c.get_name}' : factory format: "
            print(format)
            print(" arg: ")
            na.each {|n| print "'#{n}' " }
            print("\n")
          end

          # format 中の \n, \r, \t, \f と \" などを置換
          fmt = CDLString.escape format
          cfg_file.printf(fmt, *na)
          cfg_file.puts("\n")
          cfg_file.close
        rescue => evar
          cdl_error("H1005 \'$1\' : write error while writing factory (specify -t to get more info)", file_name)
          print_exception(evar)
        end
      end
    }
  }
end

#generate_celltype_factory_codeObject

generate tecsgen.cfg



4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
# File 'lib/tecsgen/core/generate.rb', line 4726

def generate_celltype_factory_code
  @ct_factory_list.each {|fa|
    if fa.get_name == :write

      # 前後の " を取り除く
      # file_name = fa.get_file_name.sub( /^\"(.*)\"$/, "\\1" )
      file_name = CDLString.remove_dquote fa.get_file_name
      format = CDLString.remove_dquote fa.get_format
      # format    = fa.get_format.sub( /^\"(.*)/, "\\1" )        # 前の " を取り除く
      # format    = format.sub( /(.*)\"\z/, "\\1" )              # 後の " を取り除く
      format    = format.gsub(/\\\n/, "\n") # \\\n => \n


      # mikan 以下は subst_name で置換するように変更すべき
      file_name = file_name.gsub(/(^|[^\$])\$ct\$/, "\\1#{@name}") # $ct$ をセルタイプ名に置換
      file_name = file_name.gsub(/(^|[^\$])\$ct_global\$/, "\\1#{@global_name}") # $ct$ をセルタイプ名に置換
      format    = format.gsub(/(^|[^\$])\$ct\$/, "\\1#{@name}") # $ct$ をセルタイプ名に置換
      format    = format.gsub(/(^|[^\$])\$ct_global\$/, "\\1#{@global_name}") # $ct$ をセルタイプ名に置換
      format    = format.gsub(/\$\$/, "\$") # $$ を $ に置換

      if file_name[0] != ?/
        file_name = "#{$gen}/#{file_name}"
      end

      begin
        cfg_file = AppFile.open(file_name)
        if $debug
          print "'#{@name}' : celltype factory format: "
          puts(format)
        end
        # format 中の \n, \r, \t, \f と \" などを置換
        fmt = CDLString.escape format
        cfg_file.print(fmt)
        cfg_file.puts("\n")
        cfg_file.close
      rescue => evar
        cdl_error("H1004 \'$1\' : write error while writing factory (specify -t to get more info)", file_name)
        print_exception(evar)
      end
    end
  }
end

#generate_factory_headerObject

celltype factory header



2968
2969
2970
2971
2972
2973
# File 'lib/tecsgen/core/generate.rb', line 2968

def generate_factory_header
  f = AppFile.open("#{$gen}/#{@global_name}_factory.#{$h_suffix}")
  f.print("#ifndef #{@name}_FACTORY_H\n")
  f.print("#define #{@name}_FACTORY_H\n")
  f.close
end

#generate_factory_header_postObject



2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
# File 'lib/tecsgen/core/generate.rb', line 2975

def generate_factory_header_post
  f = AppFile.open("#{$gen}/#{@global_name}_factory.#{$h_suffix}")

  plugin_obj = get_celltype_plugin
  if plugin_obj
    plugin_obj.gen_factory f
  end

  f.print("#endif /* #{@name}_FACTORY_H */\n")
  f.close
end

#generate_inline_template_codeObject



4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
# File 'lib/tecsgen/core/generate.rb', line 4679

def generate_inline_template_code
  return if @n_entry_port_inline == 0
  return if @b_reuse && !$generate_all_template
  if !(@plugin && @plugin.gen_ep_func?)
    return if @b_reuse && !$generate_all_template
    return if $generate_no_template # $generate_all_template より優先される

    # 参考として出力するテンプレートファイルであることを示すために "_templ" を付加する
    fname = "#{$gen}/#{@global_name}_inline_templ.#{$h_suffix}"
  else
    # Plugin により生成されたセルタイプについては、原則的にテンプレートではなく、
    # 修正不要なセルタイプの実装コードを生成する.
    # このため、ファイル名に _temp を付加しない
    fname = "#{$gen}/#{@global_name}_inline.#{$h_suffix}"
  end
  f = AppFile.open(fname)

  gen_ph_guard f, "_INLINE"

  unless @plugin && @plugin.gen_ep_func?
    f.printf(TECSMsg.get(:inline_template_note), @name, @name)
  else
    print_note(f, true)
  end

  f.print TECSMsg.get(:preamble_note)
  gen_template_attr_access f
  gen_template_cp_fun f
  f.print(" *\n * #[</PREAMBLE>]# */\n\n")

  gen_template_ep_fun(f, true)

  f.print TECSMsg.get(:postamble_note)

  if @plugin
    # このメソッドの引数は plugin.rb の説明を見よ
    @plugin.gen_postamble(f, @singleton, @name, @global_name)
  end

  f.print "\n"
  gen_ph_endif f, "INLINE"
  f.close
end

#generate_makefileObject



4856
4857
4858
4859
# File 'lib/tecsgen/core/generate.rb', line 4856

def generate_makefile
  generate_makefile_template
  generate_makefile_depend
end

#generate_makefile_dependObject



4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
# File 'lib/tecsgen/core/generate.rb', line 4886

def generate_makefile_depend
  headers = ["$(GEN_DIR)/#{@global_name}_tecsgen.#{$h_suffix}", "$(GEN_DIR)/#{@global_name}_factory.#{$h_suffix}", "$(GEN_DIR)/global_tecsgen.#{$h_suffix}"]

  # inline 受け口を持つか?
  if @n_entry_port_inline > 0
    headers << "#{@global_name}_inline.#{$h_suffix}"
  end

  # 呼び口または受け口のシグニチャのヘッダ
  @port.each {|p|
    next if p.is_omit?
    headers << "$(GEN_DIR)/#{p.get_signature.get_global_name}_tecsgen.#{$h_suffix}"
  }

  headers += get_depend_header_list
  headers.sort!
  headers.uniq!
  headers = headers.join " "

  f = AppFile.open("#{$gen}/Makefile.depend")

#    print_Makefile_note f

  f.print <<EOT
# Celltype: #{@name}  #_MDEP_#
$(_TECS_OBJ_DIR)#{@global_name}_tecsgen.o : #{@global_name}_tecsgen.#{$c_suffix} #{headers}
$(_TECS_OBJ_DIR)#{@global_name}_templ.o : #{@global_name}_templ.#{$c_suffix} #{headers}
$(_TECS_OBJ_DIR)#{@global_name}.o : #{@global_name}.#{$c_suffix} #{headers}

EOT
  f.close
end

#generate_makefile_templateObject



4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
# File 'lib/tecsgen/core/generate.rb', line 4861

def generate_makefile_template
  return if $generate_no_template

  # Makefile.templ の生成(追記)

  f = AppFile.open("#{$gen}/Makefile.templ")
  f.print <<EOT
$(_TECS_OBJ_DIR)#{@global_name}.o : #{@global_name}.#{$c_suffix}
	$(CC) -c $(CFLAGS) -o $@ $<

EOT
# この生成規則は2点で意味がない
#  ・$(GEN_DIR) に .o を生成するルールがない
#  ・テンプレートコードをそのままビルドするのは紛らわしい
# # Celltype: #{@name}
# $(GEN_DIR)/#{@global_name}_tecsgen.o : $(GEN_DIR)/#{@global_name}_tecsgen.#{$c_suffix}
#   $(CC) -c $(CFLAGS) -o $@ $<
#
# $(GEN_DIR)/#{@global_name}_templ.o : $(GEN_DIR)/#{@global_name}_templ.#{$c_suffix}
#   $(CC) -c $(CFLAGS) -o $@ $<
#

  f.close
end

#generate_postObject



1132
1133
1134
1135
1136
1137
# File 'lib/tecsgen/core/generate.rb', line 1132

def generate_post
  return if !need_generate? # セルのないセルタイプは生成しない

  generate_private_header_post
  generate_factory_header_post
end

#generate_private_headerObject



1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
# File 'lib/tecsgen/core/generate.rb', line 1139

def generate_private_header
  f = AppFile.open("#{$gen}/#{@global_name}_tecsgen.#{$h_suffix}")

  print_note f

  gen_ph_guard f
  gen_ph_info f
  gen_ph_include f
  #
  ifndef_macro_only f
  begin_extern_C f
  gen_ph_cell_cb_type f
  gen_ph_INIB_as_CB f
  gen_ph_extern_cell f          # セルタイプグルコード以外は参照しない
  gen_ph_typedef_idx f          # mikan 参照するものができていない
  gen_ph_ep_fun_prototype f
  end_extern_C f
  endif_macro_only f

  gen_ph_include_cb_type f

  if @n_entry_port_inline == 0
    # inline がなければ CB_TYPE_ONLY とする
    # inline ありの場合、いったん define しておいて、後ですべて undef する
    ifndef_cb_type_only f
  end

  gen_ph_base f
  gen_ph_valid_idx f
  gen_ph_n_cp f                 if @n_call_port_array > 0
  gen_ph_n_ep f                 if @n_entry_port_array > 0
  gen_ph_test_optional_call_port f
  gen_ph_get_cellcb f
  gen_ph_attr_access f          if @n_attribute_rw > 0 || @n_attribute_ro > 0 || @n_var > 0
  f.print "#ifndef TECSFLOW\n"
  gen_ph_cp_fun_macro f, false  if @n_call_port > 0
  f.print "#else  /* TECSFLOW */\n"
  gen_ph_cp_fun_macro f, true   if @n_call_port > 0
  f.print "#endif /* TECSFLOW */\n"
  # gen_ph_abstract_ep_des_type f

  if @n_entry_port_inline == 0
    endif_cb_type_only f
  end

  ifndef_macro_only f
  begin_extern_C f
  # gen_ph_cell_cb_type f
  # gen_ph_INIB_as_CB f
  # gen_ph_extern_cell f          # セルタイプグルコード以外は参照しない
  # gen_ph_typedef_idx f          # mikan 参照するものができていない
  # gen_ph_ep_fun_prototype f
  gen_ph_ep_skel_prototype f

  #--- CB_TYPE_ONLY の場合、ref_desc, set_desc 関数は含めない (マクロ参照するため)
  if @n_entry_port_inline == 0
    ifndef_cb_type_only f
  end
  gen_ph_ref_desc_func f
  gen_ph_set_desc_func f
  if @n_entry_port_inline == 0
    endif_cb_type_only f
  end
  end_extern_C f
  endif_macro_only f

  # 短縮形などのマクロ出力
  if @n_entry_port_inline == 0
    ifndef_cb_type_only f
  end
  gen_ph_valid_idx_abbrev f
  gen_ph_get_cellcb_abbrev f
  gen_ph_attr_access_abbrev f   if @n_attribute_rw > 0 || @n_attribute_ro > 0 || @n_var > 0
  gen_ph_cp_fun_macro_abbrev f  if @n_call_port > 0
  gen_ph_ref_desc_macro_abbrev f
  gen_ph_set_desc_macro_abbrev f
  gen_ph_test_optional_call_port_abbrev f
  gen_ph_ep_fun_macro f if @n_entry_port > 0
  gen_ph_foreach_cell f # FOREACH マクロの出力
  gen_ph_cb_initialize_macro f # CB 初期化マクロの出力.消費しないので ram_initializer フラグに関わらず出力
  gen_ph_dealloc_code f, ""
  gen_ph_dealloc_code f, "_RESET"
  if @n_entry_port_inline == 0
    endif_cb_type_only f
  end

  f.close
end

#generate_private_header_postObject



1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
# File 'lib/tecsgen/core/generate.rb', line 1228

def generate_private_header_post
  f = AppFile.open("#{$gen}/#{@global_name}_tecsgen.#{$h_suffix}")

  ifndef_macro_only f
  gen_ph_inline f
  endif_macro_only f

  if @n_entry_port_inline > 0
    ifdef_cb_type_only f
    f.printf TECSMsg.get(:UDF_comment), "#_UDF_#"
    f.print "#undef VALID_IDX\n"
    f.print "#undef GET_CELLCB\n"
    f.print "#undef CELLCB\n"
    f.print "#undef CELLIDX\n"
    f.print "#undef #{@name}_IDX\n"

    f.print "#undef FOREACH_CELL\n"
    f.print "#undef END_FOREACH_CELL\n"
    f.print "#undef INITIALIZE_CB\n"
    f.print "#undef SET_CB_INIB_POINTER\n"

    @attribute.each {|a|
      f.print("#undef ATTR_#{a.get_name}\n")
      f.print("#undef #{@global_name}_ATTR_#{a.get_name}\n")
      f.print("#undef #{@global_name}_GET_#{a.get_name}\n")
    }
    @var.each {|v|
      f.print("#undef VAR_#{v.get_name}\n")
      f.print("#undef VAR_#{v.get_name}\n")
      f.print("#undef #{@global_name}_VAR_#{v.get_name}\n")
      f.print("#undef #{@global_name}_GET_#{v.get_name}\n")
      f.print("#undef #{@global_name}_SET_#{v.get_name}\n")
    }
    @port.each {|p|
      next if p.get_port_type != :CALL

      # is_...joined は omit するケースでも出力されるため、omit を検査する前に出力
      if p.is_optional?
        f.print("#undef is_#{p.get_name}_joined\n")
      end

      next if p.is_omit?

      p.get_signature.get_function_head_array.each{|fun|
        f.print("#undef #{@global_name}_#{p.get_name}_#{fun.get_name}\n")
        if !p.is_require? || p.has_name?
          f.print("#undef #{p.get_name}_#{fun.get_name}\n")
        else
          f.print("#undef #{fun.get_name}\n")
        end
      }
      if p.is_dynamic?
        f.print("#undef #{p.get_name}_set_descriptor\n")
        if p.is_optional?
          f.print("#undef #{p.get_name}_unjoin\n")
        end
      elsif p.is_ref_desc?
        f.print("#undef #{p.get_name}_refer_to_descriptor\n")
        f.print("#undef #{p.get_name}_ref_desc\n")
      end
    }
    @port.each {|p|
      next if p.get_port_type != :ENTRY
      next if p.is_omit?
      p.get_signature.get_function_head_array.each{|fun|
        f.print("#undef #{p.get_name}_#{fun.get_name}\n")
      }
    }

    gen_ph_dealloc_code(f, "", true)
    gen_ph_dealloc_code(f, "_RESET", true)

    endif_cb_type_only f
  end

  gen_ph_endif f

  f.close
end

#generate_template_codeObject



4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
# File 'lib/tecsgen/core/generate.rb', line 4338

def generate_template_code
  return if is_all_entry_inline?
  return if @b_reuse && !$generate_all_template
  if !(@plugin && @plugin.gen_ep_func?)
    return if $generate_no_template # $generate_all_template より優先される

    # 参考として出力するテンプレートファイルであることを示すために "_templ" を付加する
    fname = "#{$gen}/#{@global_name}_templ.#{$c_suffix}"
  else
    # Plugin により生成されたセルタイプについては、原則的にテンプレートではなく、
    # 修正不要なセルタイプの実装コードを生成する.
    # このため、ファイル名に _temp を付加しない
    fname = "#{$gen}/#{@global_name}.#{$c_suffix}"
  end

  f = AppFile.open(fname)

  unless @plugin && @plugin.gen_ep_func?
    f.printf(TECSMsg.get(:template_note), @name, @name)
  else
    print_note(f, true)
  end

  f.print TECSMsg.get(:preamble_note)
  gen_template_attr_access f
  gen_template_cp_fun f
  # gen_template_types f     # 0805503 追加してみたが、やっぱりやめる
  f.print(" *\n * #[</PREAMBLE>]# */\n\n")
  f.printf TECSMsg.get(:PAC_comment), "#_PAC_#"

  gen_template_private_header f
  if @plugin
    # このメソッドの引数は plugin.rb の説明を見よ
    @plugin.gen_preamble(f, @singleton, @name, @global_name)
  end

  gen_template_ep_fun f

  f.print TECSMsg.get(:postamble_note)

  if @plugin
    # このメソッドの引数は plugin.rb の説明を見よ
    @plugin.gen_postamble(f, @singleton, @name, @global_name)
  end

  f.close
end

#get_attribute_listObject



812
813
814
# File 'lib/tecsgen/core/componentobj.rb', line 812

def get_attribute_list
  @attribute
end

#get_cell_listObject



1297
1298
1299
# File 'lib/tecsgen/core/componentobj.rb', line 1297

def get_cell_list
  @cell_list
end

#get_celltype_pluginObject

Celltype# セルタイププラグインを得る



1232
1233
1234
1235
1236
# File 'lib/tecsgen/core/componentobj.rb', line 1232

def get_celltype_plugin
  if @generate
    return @generate[2]
  end
end

#get_depend_header_listObject



5011
5012
5013
# File 'lib/tecsgen/core/generate.rb', line 5011

def get_depend_header_list
  get_depend_header_list_([])
end

#get_depend_header_list_(celltype_list) ⇒ Object



5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
# File 'lib/tecsgen/core/generate.rb', line 5015

def get_depend_header_list_(celltype_list)
  headers = []

  if celltype_list.include? self
    return headers
  else
    celltype_list << self
  end

  # 呼び口の結合先のセルタイプのヘッダ(最適化の場合のみ)
  # 結合先の受け口が inline の場合、inline ヘッダも
  @port.each {|p|
    next if p.get_port_type != :CALL
    next if p.is_omit?

    if p.is_skelton_useless? || p.is_cell_unique? || p.is_VMT_useless?
      # 最適化コード (optimize) # スケルトン不要など
      p2 = p.get_real_callee_port
      if p2
        ct = p2.get_celltype
        headers << " $(GEN_DIR)/#{ct.get_global_name}_tecsgen.#{$h_suffix}"
        if p2.is_inline?
          headers << " #{ct.get_global_name}_inline.#{$h_suffix}"
        end
        headers += ct.get_depend_header_list_(celltype_list)
      # else
      #  optional で未結合
      end
    end
  }
  return headers
end

#get_domain_rootsObject

Celltype#ドメインルートを返す



683
684
685
# File 'lib/tecsgen/core/componentobj.rb', line 683

def get_domain_roots
  @domain_roots
end

#get_global_nameObject



1238
1239
1240
# File 'lib/tecsgen/core/componentobj.rb', line 1238

def get_global_name
  @global_name
end

#get_id_baseObject



1264
1265
1266
# File 'lib/tecsgen/core/componentobj.rb', line 1264

def get_id_base
  @id_base
end

#get_nameObject



677
678
679
# File 'lib/tecsgen/core/componentobj.rb', line 677

def get_name
  @name
end

#get_name_array(cell) ⇒ Object

name_array を生成

IN: cell : Cell

index : CB, INIB 配列の添数

RETURN: name_array

name_array[0] = @name           # celltype name
name_array[1] = cell.get_name   # cell name
name_array[2] = cell_CB_name    # cell_CB_name
name_array[3] = cell_CB_INIT    # cell_CB_INIT # CB の外側で初期化が必要な配列の名前
name_array[4] = cell_CB_proto   # CB name for prototype
name_array[5] = cell_INIB       # INIB name
name_array[6] = cell_ID         # ID
name_array[7] = cell_IDX        # IDX
name_array[8] = cell_CBP        # CB pointer
name_array[9] = @global_name    # celltype global name
name_array[10] = cell.get_global_name # cell global name
name_array[11] = cell_INIB_proto #INIB name for proto type


3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
# File 'lib/tecsgen/core/generate.rb', line 3721

def get_name_array(cell)
  if @singleton
    cell_CB_name = "#{@global_name}_SINGLE_CELL_CB"
    cell_CB_INIT = cell_CB_name
    cell_CB_proto = "#{@global_name}_SINGLE_CELL_CB"
    cell_INIB_name = "#{@global_name}_SINGLE_CELL_INIB"
    cell_INIB_proto = cell_INIB_name
    cell_ID = 0
  else
    if !@idx_is_id_act
      index = cell.get_id - cell.get_celltype.get_id_base
      cell_CB_name = "#{@global_name}_CB_tab[#{index}]"
      cell_CB_INIT = "#{@global_name}_#{cell.get_name}_CB"
      cell_CB_proto = "#{@global_name}_CB_tab[]"
      cell_INIB_name = "#{@global_name}_INIB_tab[#{index}]"
      cell_INIB_proto = "#{@global_name}_INIB_tab[]"
    else
      cell_CB_name = "#{cell.get_global_name}_CB"
      cell_CB_INIT = cell_CB_name
      cell_CB_proto = cell_CB_name
      cell_INIB_name = "#{cell.get_global_name}_INIB"
      cell_INIB_proto = cell_INIB_name
    end
    cell_ID = cell.get_id
  end
  if @idx_is_id_act
    cell_IDX = cell_ID
  else
    cell_IDX = "&#{cell_CB_name}"
  end

  if has_CB?
    cell_CBP = "&#{cell_CB_name}"
  elsif has_INIB?
    cell_CBP = "&#{cell_INIB_name}"
  else
    cell_CBP = "NULL" # CB も INIB もなければ NULL に置換
  end

  name_array = []
  name_array[0] = @name           # celltype name
  name_array[1] = cell.get_name   # cell name
  name_array[2] = cell_CB_name    # cell_CB_name
  name_array[3] = cell_CB_INIT    # cell_CB_INIT
  name_array[4] = cell_CB_proto   # CB name for prototype
  name_array[5] = cell_INIB_name  # cell INIB name
  name_array[6] = cell_ID         # cell ID
  name_array[7] = cell_IDX        # cell IDX
  name_array[8] = cell_CBP        # cell CBP
  name_array[9] = @global_name    # celltype global name
  name_array[10] = cell.get_global_name # cell global name
  name_array[11] = cell_INIB_proto # INIB name for prototype

  return name_array
end

#get_name_listObject



847
848
849
# File 'lib/tecsgen/core/componentobj.rb', line 847

def get_name_list
  @name_list
end

#get_pluginObject



1268
1269
1270
# File 'lib/tecsgen/core/componentobj.rb', line 1268

def get_plugin
  @plugin
end

#get_port_listObject



742
743
744
# File 'lib/tecsgen/core/componentobj.rb', line 742

def get_port_list
  @port
end

#get_requireObject



1272
1273
1274
# File 'lib/tecsgen/core/componentobj.rb', line 1272

def get_require
  @require
end

#get_singleton_cell(region) ⇒ Object

Celltype# singleton セルを得る

region

Region : singleton を探す Region

距離が最も近いものを返す mikan 本当は region の範囲の singleton を探す必要がある



1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
# File 'lib/tecsgen/core/componentobj.rb', line 1207

def get_singleton_cell(region)
  cell = nil
  dist = 999999999 # mikan 制限値(これは十分すぎるほどデカイが)
  # require: celltype で指定
  @cell_list.each{|c|
    # 到達可能で最も近いセルを探す(複数の singleton があるかもしれない)
    d = region.distance(c.get_region)
    # debug
    dbgPrint "distance #{d} from #{region.get_name} to #{c.get_name} in #{c.get_region.get_name}\n"
    # print "DOMAIN: distance #{d} from #{region.get_name} to #{c.get_name} in #{c.get_region.get_name}\n"
    if !d.nil?
      if d < dist
        cell = c
        dist = d
      end
    end
  }
  return cell
end

#get_var_listObject



880
881
882
# File 'lib/tecsgen/core/componentobj.rb', line 880

def get_var_list
  @var
end

#has_CB?Boolean

Celltype# セルタイプは CB を持つか?

$rom == true のとき、いかのものが置かれる.それらの一つでも存在すれば CB を持つ

size_is が指定されていない var
rw 指定された attribute (現仕様では存在しない)

$rom == false のとき、いかのものが置かれる.それらの一つでも存在すれば CB を持つ

attribute
var
呼び口(ただし、最適化で不要となるものは除く)

Returns:

  • (Boolean)


1182
1183
1184
1185
1186
1187
1188
1189
# File 'lib/tecsgen/core/componentobj.rb', line 1182

def has_CB?
  if $rom
    return @n_attribute_rw > 0 || (@n_var - @n_var_size_is) > 0 || (@n_call_port_dynamic - @n_call_port_array_dynamic) > 0
    # return @n_attribute_rw > 0 || @n_var > 0
  else
    return @n_attribute_rw > 0 || @n_attribute_ro > 0 || @n_var > 0 || (@n_call_port - @n_call_port_omitted_in_CB) > 0 || @n_entry_port_array_ns > 0
  end
end

#has_INIB?Boolean

Celltype# セルタイプは INIB を持つか?

セルタイプが INIB を持つかどうかを判定する $rom == false のとき: INIB を持たない. (すべては CB に置かれる) $rom == true のとき、INIB に置かれるものが一つでも存在すれば INIB を持つ

INIB に置かれるものは
  attribute (omit のものは除く.現仕様では rw のものはない)
  size_is を伴う var
  呼び口(ただし、最適化で不要となるものは除く)

Returns:

  • (Boolean)


1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
# File 'lib/tecsgen/core/componentobj.rb', line 1162

def has_INIB?
  result = $rom &&
           (@n_attribute_ro > 0 ||
            @n_var_size_is > 0 ||
            (@n_call_port - @n_call_port_omitted_in_CB - (@n_call_port_dynamic - @n_call_port_array_dynamic)) > 0 ||
            $ram_initializer && @n_call_port_dynamic > 0 ||
            @n_entry_port_array_ns > 0)
  # print "name=#{@name} n_attribute_ro=#{@n_attribute_ro}  n_var_size_is=#{@n_var_size_is} n_call_port=#{@n_call_port} n_call_port_omitted_in_CB=#{@n_call_port_omitted_in_CB} n_call_port_dynamic=#{@n_call_port_dynamic} n_call_port_array_dynamic=#{@n_call_port_array_dynamic} n_entry_port_array_ns=#{@n_entry_port_array_ns} has_INIB?=#{result}\n"

  return result
end

#header_included?(hname) ⇒ Boolean

Celltype# ヘッダは include されているか hname::Symbol : ヘッダ名

RETURN

bool_t: false インクルードされていない、true インクルードされている

#ISH#, #ICT# でヘッダが取り込まれているかチェックする false が返った場合、hname は登録されて、次回の呼び出しでは true が返る

Returns:

  • (Boolean)


448
449
450
451
452
453
454
455
# File 'lib/tecsgen/core/optimize.rb', line 448

def header_included?(hname)
  if @included_header[hname].nil?
    @included_header[hname] = true
    return false
  else
    return true
  end
end

#idx_is_id_act?Boolean

Returns:

  • (Boolean)


1250
1251
1252
# File 'lib/tecsgen/core/componentobj.rb', line 1250

def idx_is_id_act?
  @idx_is_id_act
end

#is_active?Boolean

Returns:

  • (Boolean)


1246
1247
1248
# File 'lib/tecsgen/core/componentobj.rb', line 1246

def is_active?
  @active
end

#is_all_entry_inline?Boolean

Celltype# inline 受け口しかないか?

受け口が無い場合、すべての受け口が inline とはしない

Returns:

  • (Boolean)


1303
1304
1305
# File 'lib/tecsgen/core/componentobj.rb', line 1303

def is_all_entry_inline?
  @n_entry_port == @n_entry_port_inline && @n_entry_port > 0
end

#is_inactive?Boolean

Celltype# アクティブではないか

このメソッドでは active の他に factory (singleton においては FACTORYを含む)がなければ inactive とする

Returns:

  • (Boolean)


1256
1257
1258
1259
1260
1261
1262
# File 'lib/tecsgen/core/componentobj.rb', line 1256

def is_inactive?
  if @active == false && @factory_list.length == 0 &&
      (@singleton && @ct_factory_list.length == 0 || !@singleton)
    return true
  end
  return false
end

#is_singleton?Boolean

Returns:

  • (Boolean)


1242
1243
1244
# File 'lib/tecsgen/core/componentobj.rb', line 1242

def is_singleton?
  @singleton
end

#need_CB_initializer?Boolean

Celltype# SET_CB_INIB_POINTER, INITIALIZE_CB が必要か

Returns:

  • (Boolean)


1192
1193
1194
# File 'lib/tecsgen/core/componentobj.rb', line 1192

def need_CB_initializer?
  @n_var_init > 0 || has_CB? || (@n_call_port_dynamic && $ram_initializer)
end

#need_generate?Boolean

Celltype# コード生成する必要があるか判定

セルの個数が 0 ならセルタイプコードは生成不要

Returns:

  • (Boolean)


1278
1279
1280
# File 'lib/tecsgen/core/componentobj.rb', line 1278

def need_generate?
  @n_cell_gen > 0
end

#new_attribute(attribute) ⇒ Object

Celltype# new_attribute for Celltype

attribute
Decl


752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
# File 'lib/tecsgen/core/componentobj.rb', line 752

def new_attribute(attribute)
  @attribute += attribute
  attribute.each {|a|
    a.set_owner self
    @name_list.add_item(a)
    if a.is_omit?
      @n_attribute_omit += 1
    elsif a.is_rw?
      @n_attribute_rw += 1
    else
      @n_attribute_ro += 1
    end
    if a.get_initializer
      # 登録後にチェックしても問題ない(attr を参照できないので、自己参照しない)
      a.get_type.check_init(@locale, a.get_identifier, a.get_initializer, :ATTRIBUTE)
    end
  }
end

#new_cell(cell) ⇒ Object

Celltype# celltype に新しい cell を追加

cell

Cell

新しいセルをセルタイプに追加. セルの構文解釈の最後でこのメソドを呼出される. シングルトンセルが同じ linkunit に複数ないかチェック



1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
# File 'lib/tecsgen/core/componentobj.rb', line 1132

def new_cell(cell)
  dbgPrint "Celltype#new_cell( #{cell.get_name} )\n"
  # Celltype では Cell の set_owner しない
  # シングルトンで、プロトタイプ宣言でない場合、コード生成対象リージョンの場合
  if @singleton
    @cell_list.each{|c|
      if c.get_region.get_link_root == cell.get_region.get_link_root
        cdl_error("S1024 $1: multiple cell for singleton celltype", @name)
      end
    }
  end
  @cell_list << cell

  # プラグインにより生成されたセルタイプか ?
  if @plugin
    @plugin.new_cell cell
  end

  # セルタイププラグインの適用
  celltype_plugin_new_cell cell
end

#new_factory(factory) ⇒ Object



996
997
998
999
1000
1001
1002
1003
1004
1005
# File 'lib/tecsgen/core/componentobj.rb', line 996

def new_factory(factory)
  factory.set_owner self
  if factory.get_f_celltype
    @ct_factory_list << factory
  else
    @factory_list << factory
  end

  factory.check_arg(self)
end

#new_port(port) ⇒ Object



718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'lib/tecsgen/core/componentobj.rb', line 718

def new_port(port)
  port.set_owner self
  @port << port
  @name_list.add_item(port)
  if port.get_port_type == :CALL
    @n_call_port += 1
    @n_call_port_array += 1 if !port.get_array_size.nil?
    if port.is_dynamic?
      @n_call_port_dynamic += 1
      @n_call_port_array_dynamic += 1 if !port.get_array_size.nil?
    end
    if port.is_ref_desc?
      @n_call_port_ref_desc += 1
      @n_call_port_array_ref_desc += 1 if !port.get_array_size.nil?
    end
  else
    @n_entry_port += 1
    @n_entry_port_array += 1 if !port.get_array_size.nil?
    @n_entry_port_array_ns += 1 if port.get_array_size == "[]"
    @n_entry_port_inline += 1 if port.is_inline?
  end
  port.set_celltype self
end

#new_require(ct_or_cell_nsp, ep_name, cp_name) ⇒ Object



916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
# File 'lib/tecsgen/core/componentobj.rb', line 916

def new_require(ct_or_cell_nsp, ep_name, cp_name)
  # Require: set_owner するものがない
  obj = Namespace.find(ct_or_cell_nsp) # 1
  if obj.instance_of? Celltype
    # Celltype 名で指定
    ct = obj
  elsif obj.instance_of? Cell
    # Cell 名で指定
    ct = obj.get_celltype
  elsif obj.nil?
    cdl_error("S1016 $1 not found", ct_or_cell_nsp.get_path_str)
    return
  else
    cdl_error("S1017 $1 : neither celltype nor cell", ct_or_cell_nsp.get_path_str)
    return
  end

  if !ct.is_singleton?
    # シングルトンではない
    cdl_error("S1018 $1 : not singleton cell", obj.get_name)
  end

  # 受け口を探す
  obj2 = ct.find(ep_name)
  if (!obj2.instance_of? Port) || obj2.get_port_type != :ENTRY
    cdl_error("S1019 \'$1\' : not entry port", ep_name)
    return
  elsif obj2.get_array_size
    cdl_error("S1020 \'$1\' : required port cannot be array", ep_name)
    return
  end

  if obj2.get_signature.nil?
    # signature が未定義:既にエラー
    return
  end

  require_call_port_prefix = :_require_call_port
  if cp_name.nil?
    # 関数名重複チェック
    @require.each{|req|
      unless req[0].to_s =~ /^#{require_call_port_prefix}/
        next # 名前ありの require は関数名重複チェックしない
      end
      port = req[2]
      if port.get_signature == obj2.get_signature
        # 同じ signature (すべて同じ関数名を持つ)個別に出すのではなく、まとめてエラーとする
        cdl_error("S1021 $1 : require cannot have same signature with \'$2\'", obj2.get_name, port.get_name)
        next
      end
      port.get_signature.get_function_head_array.each{|f|
        # mikan ここは、namedList からの検索にならないの?(効率が悪い)
        obj2.get_signature.get_function_head_array.each{|f2|
          if f.get_name == f2.get_name
            cdl_error("S1022 $1.$2 : \'$3\' conflict function name in $4.$5", obj.get_name, obj2.get_name, f.get_name, req[1].get_name, req[2].get_name)
          end
        }
      }
    }
  end

  if cp_name.nil?
    b_has_name = false
    cp_name = :"#{require_call_port_prefix}_#{ct.get_name}_#{obj2.get_name}"
  else
    b_has_name = true
  end
  # require を追加
  @require << [cp_name, obj, obj2] # [ lhs:cp_name, rhs:Celltype, rhs:Port ]

  # require port を追加 (呼び口として追加する。ただし require をセットしておく)
  port = Port.new(cp_name, obj2.get_signature.get_namespace_path, :CALL)
  port.set_require(b_has_name)
  self.new_port port
end

#new_var(var) ⇒ Object

Celltype# 新しい内部変数

var
Decl


857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'lib/tecsgen/core/componentobj.rb', line 857

def new_var(var)
  @var += var
  var.each {|i| # i: Decl
    i.set_owner self
    if i.is_omit?
      @n_var_omit += 1
    else
      @n_var += 1
    end
    @name_list.add_item(i)

    # size_is 指定された配列? mikan  count_is
    if i.get_size_is
      @n_var_size_is += 1
    end

    if i.get_initializer
      i.get_type.check_init(@locale, i.get_identifier, i.get_initializer, :VAR, @name_list)
      @n_var_init += 1
    end
  }
end

#optimizeObject



236
237
238
239
240
241
242
243
244
245
246
# File 'lib/tecsgen/core/optimize.rb', line 236

def optimize
  # port の参照するセルタイプの数、セルの数を求める
  if $verbose
    print "=== optimizing celltype #{get_namespace_path} ===\n"
  end

  optimize_call
  if $unopt_entry == false
    optimize_entry
  end
end

#optimize_callObject

Celltype#呼び口最適化



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/tecsgen/core/optimize.rb', line 249

def optimize_call
  @port.each{|port|
    next if port.get_port_type != :CALL
    if port.is_omit?
      # 呼び口最適化実施
      @b_cp_optimized = true
      @n_call_port_omitted_in_CB += 1               # CB で省略する呼び口
      port.set_skelton_useless                      # スケルトン関数不要最適化
      port.set_VMT_useless                          # VMT 不要最適化 (直接受け口関数を呼出す)
      if $verbose
        print "optimized by omit: port: #{port.get_name} : o\n"
      end
      next
    elsif port.is_dynamic?
      if $verbose
        print "unoptimized by dynamic: port: #{port.get_name}\n"
      end
      next
    elsif port.is_ref_desc?
      if $verbose
        print "unoptimized by ref_desc: port: #{port.get_name}\n"
      end
      next
    end

    if $verbose
      print "optimizing port : #{port.get_name}\n"
    end

    port_cells = []    # 呼び先セル
    port_ports = []    # 呼び先のポート

    # セルの参照するセルを集める(ポートも一緒に集める)
    @cell_list.each{|cell|

      if !cell.is_generate?
        next
      end

      jl = cell.get_join_list
      j = jl.get_item(port.get_name)

      if j
        if j.get_array_member2
          # 呼び口配列の場合、全部の結合先を集める
          j.get_array_member2.each {|j2|
            if j2
              port_cells << j2.get_rhs_cell
              port_ports << j2.get_rhs_port # 右辺のポート
            else
              # optional で、ある添数のみ初期化されていない(すべて初期化されない場合は、下)
              port_cells << nil
              port_ports << nil
            end
          }
        else
          # 全ての結合先を集める
          port_cells << j.get_rhs_cell
          port_ports << j.get_rhs_port # 右辺のポート
        end
      else
        # optional で初期化されていない(nil を要素に加えておく)
        port_cells << nil
        port_ports << nil # 右辺のポート
      end
    }

    # 重複要素を取り除く
    port_cells.uniq!
    port_ports.uniq!

    # 呼び口の呼び先が一つのポートだけか?
    if port_ports.length == 1

      # 呼び口配列が可変長の場合、最適化しない
           # mikan 呼び口配列要素数マクロ不具合暫定対策
           # より望ましい修正は、受け口へのポインタは省略するが、配列個数は出力する(#_CP_#, #_TCP_#)
           # さらに配列個数が定数化できるのであれば、定数マクロを出力 (#_NCPA_#)
      next if port.get_array_size == "[]"

      # 呼び口最適化実施
      @b_cp_optimized = true

      # 呼び先が一つのセルだけか?
      if port_cells.length == 1

        # 呼び口は optional で初期化されていない、または受け口は配列ではないか?
        if port_ports[0].nil? || port_ports[0].get_array_size.nil?

          @n_call_port_omitted_in_CB += 1               # CB で省略する呼び口
          port.set_cell_unique                          # セル一つだけ最適化
          port.set_skelton_useless                      # スケルトン関数不要最適化
          port.set_VMT_useless                          # VMT 不要最適化 (直接受け口関数を呼出す)

          if $verbose
            print "cell_unique, VMT_useless & skelton_useless optimize\n"
          end
        else
          port.set_VMT_useless                          # VMT 不要最適化 (スケルトン関数を呼出す)

          if $verbose
            print "VMT_useless optimize\n"
          end
        end

      else # 呼び先が複数のセル(単一のポート)

        # 呼び口は optional で初期化されていない、または受け口は配列ではないか?
        if port_ports[0].nil? || port_ports[0].get_array_size.nil?
          if !@singleton
            port.set_skelton_useless                    # スケルトン関数不要最適化
            port.set_VMT_useless                        # VMT 不要最適化 (スケルトン関数 or 受け口関数を呼出す)

            if $verbose
              print "VMT_useless & skelton useless optimize\n"
            end
          else
            port.set_VMT_useless # VMT 不要最適化 (スケルトン関数 or 受け口関数を呼出す)

            if $verbose
              print "VMT_useless optimize\n"
            end
          end
        end
      end

      port.set_only_callee(port_ports[0], port_cells[0])
         # set_cell_unique でない場合 cell は意味がない

    end

    # debug
    dbgPrint "#{port.get_name} : # of cells : #{port_cells.length}  # of ports : #{port_ports.length}\n"
  }
end

#optimize_entryObject

Celltype#受け口最適化

optimize_entry は、呼び口最適化の結果を使用している



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/tecsgen/core/optimize.rb', line 387

def optimize_entry
  # 受け口最適化の設定
  @port.each{|port|
    next if port.get_port_type != :CALL

    # 呼び口側の最適化状態
    b_VMT_useless     = port.is_VMT_useless?
    b_skelton_useless = port.is_skelton_useless?

    # セルの参照するセルを集める(ポートも一緒に集める)
    @cell_list.each{|cell|

      if !cell.is_generate?
        next
      end

      jl = cell.get_join_list
      j = jl.get_item(port.get_name)

      if j # optional で結合されていない場合 nil
        if j.get_array_member2
          # 呼び口配列
          j.get_array_member2.each {|j2|
            if j2
              port2 = j2.get_rhs_port # 右辺のポート
              # 受け口側の最適化可能性を設定
              port2.set_entry_VMT_skelton_useless(b_VMT_useless, b_skelton_useless)
            # else
            #  optional で呼び口配列要素が初期化されていない
            end
          }
        else
          port2 = j.get_rhs_port # 右辺のポート
          # 受け口側の最適化可能性を設定
          port2.set_entry_VMT_skelton_useless(b_VMT_useless, b_skelton_useless)
        end
      end
    }
  }
end


472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/tecsgen/core/tecsinfo.rb', line 472

def print_call_define(f)
  if @n_cell_gen > 0
    f.print <<EOT

#include "#{@global_name}_tecsgen.h"
EOT
  else
    f.print <<EOT

// #include "#{@global_name}_tecsgen.h"   // no cell exist
EOT
  end
  @port.each{|port|
    next if port.get_port_type == :ENTRY
    if port.is_omit? || (port.is_VMT_useless? && port.is_cell_unique?) || @n_cell_gen == 0
      place = "CALL_PLACE_NON"
    elsif port.is_dynamic?
      if port.get_array_size
        place = "CALL_PLACE_INIB_DES"
      else
        place = "CALL_PLACE_CB_DES"
      end
    elsif !has_INIB?
      if port.is_VMT_useless?
        place = "CALL_PLACE_CB_IDX"
      else
        place = "CALL_PLACE_CB_DES"
      end
    else
      if port.is_VMT_useless?
        place = "CALL_PLACE_INIB_IDX"
      else
        place = "CALL_PLACE_INIB_DES"
      end
    end
    if (port.is_VMT_useless? && port.is_cell_unique?) || port.is_omit? || @n_cell_gen == 0
      offset = "0xffffffff"
    else
      if port.is_dynamic? || !has_INIB?
        cb_inib = "CB"
      else
        cb_inib = "INIB"
      end
      offset = "(uint32_t)(intptr_t)&((#{@global_name}_#{cb_inib}*)0)->#{port.get_name}"
    end
    array_size = port.get_array_size
    if array_size == "[]"
      array_size = "0xffffffff"
    elsif array_size.nil?
      array_size = "0"
    end

    f.printf "#define %-50s (#{offset})\n",                   "#{@global_name}_#{port.get_name}__offset"
    f.printf "#define %-50s (#{array_size})\n",               "#{@global_name}_#{port.get_name}__array_size"
    f.printf "#define %-50s (#{place})\n",                    "#{@global_name}_#{port.get_name}__place"
    f.printf "#define %-50s (#{port.is_VMT_useless?})\n",     "#{@global_name}_#{port.get_name}__b_VMT_useless"
    f.printf "#define %-50s (#{port.is_skelton_useless?})\n", "#{@global_name}_#{port.get_name}__b_skelton_useless"
    f.printf "#define %-50s (#{port.is_cell_unique?})\n",     "#{@global_name}_#{port.get_name}__b_cell_unique"
  }
end


446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/tecsgen/core/tecsinfo.rb', line 446

def print_celltype_define(f)
  if has_INIB?
    size_INIB = "(sizeof(#{@global_name}_INIB))"
  else
    size_INIB = "(0)"
  end
  if has_CB?
    size_CB = "(sizeof(#{@global_name}_CB))"
  else
    size_CB = "(0)"
  end

  if @n_cell_gen > 0
    f.printf "\n#include \"#{@global_name}_tecsgen.h\"\n"
    f.printf "#define %-50s (#{@idx_is_id_act})\n",     "#{@global_name}__IDX_is_ID_act"
    f.printf "#define %-50s (#{size_CB})\n",            "#{@global_name}__sizeOfCB"
    f.printf "#define %-50s (#{size_INIB})\n",          "#{@global_name}__sizeOfINIB"
    f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen
  else
    f.printf "#define %-50s (false)\n",                 "#{@global_name}__IDX_is_ID_act"
    f.printf "#define %-50s (0)\n",                     "#{@global_name}__sizeOfCB"
    f.printf "#define %-50s (0)\n",                     "#{@global_name}__sizeOfINIB"
    f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen
  end
end


396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/tecsgen/core/tecsinfo.rb', line 396

def print_define_offset(f)
  # intptr_t に一回キャストするのは 64bit 版を考量してのこと.しかし 32bit としているので 4GB を超える構造体等は扱えない
  if @n_cell_gen > 0
    f.print <<EOT

#include "#{@global_name}_tecsgen.h"
EOT
    @attribute.each{|decl|
      if has_INIB?
        inib_cb = "INIB"
      else
        inib_cb = "CB"
      end
      if !decl.is_omit?
        offset = "(uint32_t)(intptr_t)&(((#{@global_name}_#{inib_cb}*)0)->#{decl.get_name})"
        place = inib_cb
      else
        offset = "0xffffffff"
        place = "NON"
      end
      f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", offset
      f.printf "#define PLACE_OF_%-30s  VARDECL_PLACE_%s\n", "#{@global_name}_#{decl.get_name}", place
    }
    @var.each{|decl|
      if decl.get_size_is && has_INIB?
        inib_cb = "INIB"
      else
        inib_cb = "CB"
      end
      place = inib_cb
      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})"
      f.printf "#define PLACE_OF_%-30s  VARDECL_PLACE_%s\n", "#{@global_name}_#{decl.get_name}", place
    }
  else
    f.print <<EOT

// #include "#{@global_name}_tecsgen.h"   // no cell exist
EOT
    # 生成されないセルタイプ
    @attribute.each{|decl|
      f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff"
      f.printf "#define PLACE_OF_%-30s   VARDECL_PLACE_NON\n", "#{@global_name}_#{decl.get_name}"
    }
    @var.each{|decl|
      f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff"
      f.printf "#define PLACE_OF_%-30s   VARDECL_PLACE_NON\n", "#{@global_name}_#{decl.get_name}"
    }
  end
end

#print_entry_define(f) ⇒ Object



533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/tecsgen/core/tecsinfo.rb', line 533

def print_entry_define(f)
  @port.each{|port|
    next if port.get_port_type == :CALL
    array_size = port.get_array_size
    if array_size == "[]"
      array_size = "0xffffffff"
    elsif array_size.nil?
      array_size = "0"
    end

    f.printf "#define %-50s (#{array_size})\n", "#{@global_name}_#{port.get_name}__array_size"
  }
end


340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/tecsgen/core/tecsinfo.rb', line 340

def print_info(f, indent)
  f.print <<EOT
#{indent}cell nTECSInfo::tCelltypeInfo #{@global_name}CelltypeInfo {
#{indent}    name             = "#{@name}";
#{indent}    b_singleton      = #{@singleton};
#{indent}    b_IDX_is_ID_act  = C_EXP( "#{@global_name}__IDX_is_ID_act" );
#{indent}    sizeOfCB         = C_EXP( "#{@global_name}__sizeOfCB" );
#{indent}    sizeOfINIB       = C_EXP( "#{@global_name}__sizeOfINIB" );
#{indent}    n_cellInLinkUnit = C_EXP( "#{@global_name}__NCELLINLINKUNIT" );
#{indent}    n_cellInSystem   = #{@cell_list.length};
EOT
  @port.each{|port|
    if port.get_port_type == :ENTRY
      f.print <<EOT
#{indent}    cEntryInfo[]    = #{@global_name}_#{port.get_name}EntryInfo.eEntryInfo;
EOT
    end
  }
  @port.each{|port|
    if port.get_port_type == :CALL
      f.print <<EOT
#{indent}    cCallInfo[]     = #{@global_name}_#{port.get_name}CallInfo.eCallInfo;
EOT
    end
  }
  @attribute.each{|decl|
    f.print <<EOT
#{indent}    cAttrInfo[]     = #{@global_name}_#{decl.get_name}VarDeclInfo.eVarDeclInfo;
EOT
  }
  @var.each{|decl|
    f.print <<EOT
#{indent}    cVarInfo[]      = #{@global_name}_#{decl.get_name}VarDeclInfo.eVarDeclInfo;
EOT
  }
  f.print <<EOT
#{indent}};
EOT
  @port.each{|port|
    if port.get_port_type == :ENTRY
      port.print_info f, @global_name, indent
    end
  }
  @port.each{|port|
    if port.get_port_type == :CALL
      port.print_info f, @global_name, indent
    end
  }
  @attribute.each{|decl|
    decl.print_info f, @global_name, indent, :DECLTYPE_ATTR
  }
  @var.each{|decl|
    decl.print_info f, @global_name, indent, :DECLTYPE_VAR
  }
end

#reset_optimizeObject

Celltype# リセットする



429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/tecsgen/core/optimize.rb', line 429

def reset_optimize
  @@ID_BASE = ID_BASE      # 本当は一回だけでよい
  @id_base = 1             # set_cell_id でリセットされるので不要

  @b_cp_optimized = false  # 呼び口最適化
  @n_call_port_omitted_in_CB = 0 # 呼び口最適化により不生成となったポートの数
  @n_cell_gen = 0 # 生成セル個数
  @port.each{|p|
    p.reset_optimize
  }
  @included_header = {}
  @domain_roots = {}
end

#set_cell_idObject

各セルに ID (整数値)を割付ける



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/tecsgen/core/optimize.rb', line 99

def set_cell_id
  if $verbose
    print("=== id for the cells of celltype #{get_namespace_path} ===\n")
  end

  if $unique_id
    @id_base = @@ID_BASE   # id をシステム全体で連番にする
  else
    @id_base = 1           # base を常に 1 から始める
  end

  id_specified_cells = []
  no_id_specified_cells = []

  # プロトタイプを除いた数を求める
  @cell_list.each{|c|
    if c.is_generate?
      # c.set_id( @id_base + @n_cell_gen )
      id = c.get_specified_id
      if id
        id_specified_cells << c
      else
        no_id_specified_cells << c
      end

      # p "#{c.get_name} #{@id_base+@n_cell_gen}"
      @@ID_BASE     += 1
      @n_cell_gen   += 1
    end
  }

  @ordered_cell_list = [] # id = 1 が添数 0 に格納される
  # ID 指定されているセルに id 番号を与える
  id_specified_cells.each{|c|
    id = c.get_specified_id
    if id > 0
      if id >= @n_cell_gen
        cdl_error("S3001 $1: id too large $2 (max=$3)", c.get_name, id, @n_cell_gen)
        next
      end
    else
      if - id >= @n_cell_gen
        cdl_error("S3002 $1: id too large $2 (max=$3)", c.get_name, id, @n_cell_gen)
        next
      end
      id = @n_cell_gen + id + 1
    end

    if @ordered_cell_list[id - 1]
      cdl_error("S3003 $1: id number '$2' conflict with $3", c.get_name, id, @ordered_cell_list[id - 1].get_name)
    end
    @ordered_cell_list[id - 1] = c
    # 通し番号とする場合のため @id_base を加える
    c.set_id(@id_base - 1 + id)
    if $verbose
      print("#{c.get_name}: id=#{c.get_id}  specified id=#{c.get_specified_id}\n")
    end
  }

  # ID 指定されていないセルに id 番号を与える
  i = 0
  no_id_specified_cells.each{|c|
    while !@ordered_cell_list[i].nil?
      i += 1
    end
    @ordered_cell_list[i] = c
    c.set_id(@id_base + i)
    if $verbose
      print("#{c.get_name}: id=#{c.get_id}\n")
    end
  }
  if @n_cell_gen > 0 && i >= @n_cell_gen
    raise "id over id=#{i} N=#{@n_cell_gen}"
  end
end

#set_cell_id_and_domainObject



93
94
95
96
# File 'lib/tecsgen/core/optimize.rb', line 93

def set_cell_id_and_domain
  set_cell_id
  set_domain
end

#set_domainObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/tecsgen/core/optimize.rb', line 175

def set_domain
  domain_cells = {}
  @cell_list.each{|c|
    if c.is_generate?
      dr = c.get_region.get_domain_root
      if dr.get_domain_type
        dn = dr.get_domain_type.get_name
      else
        dn = nil
      end
      if @domain_roots[dn]
        @domain_roots[dn] << dr
      else
        @domain_roots[dn] = [dr]
      end
      if domain_cells[dr]
        domain_cells[dr] << c
      else
        domain_cells[dr] = [c]
      end
    end
  }

  @domain_roots.each{|dn, drs|
    drs.uniq!
    if $verbose && dn
      print "[domain] celltype=#{@name} domainType=#{dn} domainRootRegions={"
      delim = ""
      drs.each{|r|
        print delim, r.get_name
        delim = ", "
      }
      print "}\n"
      drs.each{|r|
        print "[domain] celltype=#{@name} domainRootRegion=#{r.get_name} domainType=#{dn} domainKind=#{r.get_domain_root.get_domain_type.get_kind} domainCells={"
        delim = ""
        domain_cells[r].each{|c|
          print delim, c.get_name
          delim = ", "
        }
        print "}\n"
      }
    end
  }
  if @domain_roots.length > 1
    p @domain_roots
    raise "ambigous DomainType"
  end

  @domain_roots.each{|dn, regions|
    # domain_type は一つのノードに一つしかないので、一つの要素を無条件で取り出す
    if regions.length > 1
      cdl_info("I9999 celltype '$1' has cells in multi-domain.\n", @name)
      if @idx_is_id == false
        cdl_info("I9999 celltype '$1' forcely set idx_is_id\n", @name)
      end
      @idx_is_id_act = true
    end
  }
end

#set_require_joinObject

Celltype# require 呼び口の結合を行う

STAGE: S セルタイプの require 呼び口について、結合を行う セルが生成されないかチェックを行う



1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
# File 'lib/tecsgen/core/componentobj.rb', line 1286

def set_require_join
  @require.each{|req|
    cp_name = req[0]
    cell_or_ct = req[1]
    port = req[2]
    @cell_list.each{|c|
      c.set_require_join(cp_name, cell_or_ct, port)
    }
  }
end

#set_specifier_list(spec_list) ⇒ Object

Celltype# celltype の指定子を設定



885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
# File 'lib/tecsgen/core/componentobj.rb', line 885

def set_specifier_list(spec_list)
  return if spec_list.nil?

  spec_list.each {|s|
    case s[0]
    when :SINGLETON
      @singleton = true
    when :IDX_IS_ID
      @idx_is_id = true
      @idx_is_id_act = true
    when :ACTIVE
      @active = true
    when :GENERATE
      if @generate
        cdl_error("S1014 generate specifier duplicate")
      end
      @generate = [s[1], s[2]] # [ PluginName, "option" ]
    else
      cdl_error("S1015 $1 cannot be specified for composite", s[0])
    end
  }
  if @singleton
    @idx_is_id_act = false
  end
end

#show_tree(indent) ⇒ Object



1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
# File 'lib/tecsgen/core/componentobj.rb', line 1312

def show_tree(indent)
  indent.times { print "  " }
  puts "Celltype: name=#{@name} global_name=#{@global_name}"
  (indent + 1).times { print "  " }
  puts "active=#{@active}, singleton=#{@singleton}, idx_is_id=#{@idx_is_id} plugin=#{@plugin.class} reuse=#{@b_reuse}"
  (indent + 1).times { print "  " }
  puts "namespace_path: #{@NamespacePath}"
  (indent + 1).times { print "  " }
  puts "port:"
  @port.each {|i| i.show_tree(indent + 2) }
  (indent + 1).times { print "  " }
  puts "attribute:"
  @attribute.each {|i| i.show_tree(indent + 2) }
  (indent + 1).times { print "  " }
  puts "var:"
  @var.each {|i| i.show_tree(indent + 2) }
#    (indent+1).times { print "  " }
#    puts "require:"   mikan
#    @require.each { |i| i.show_tree( indent + 2 ) }
  (indent + 1).times { print "  " }
  puts "factory:"
  @factory_list.each {|i| i.show_tree(indent + 2) }
  (indent + 1).times { print "  " }
  puts "@n_attribute_ro #{@n_attribute_ro}"
  (indent + 1).times { print "  " }
  puts "@n_attribute_rw #{@n_attribute_rw}"
# @n_attribute_omit : int >= 0  # of [omit] specified cells
# @n_var:: int >= 0
# @n_var_size_is:: int >= 0     # of [size_is] specified cells # mikan count_is
# @n_var_omit:: int >= 0        # of [omit] specified  cells # mikan var の omit は有?
# @n_call_port:: int >= 0
# @n_call_port_array:: int >= 0
# @n_call_port_omitted_in_CB:: int >= 0   最適化で省略される呼び口
# @n_entry_port:: int >= 0
# @n_entry_port_array:: int >= 0
  (indent + 1).times { print "  " }
  puts "@n_entry_port_inline #{@n_entry_port_inline}"
# @n_cell:: int >= 0  コード生成の頭で算出する.意味解析段階では参照不可
# @id_base:: Integer : cell の ID の最小値(最大値は @id_base + @n_cell)
end

#subst_name(str, name_array) ⇒ Object

$id$, $ct$, $cb$, $idx$ 置換

str に以下の置換を行う
  • $ct$ ⇒ セルタイプ名(ct)

  • $cell$ ⇒ セル名(cell) cell が nil ならば以下の置換は行われない

  • $cb$ ⇒ CB の C 言語名(cb)

  • $cbp$ ⇒ CB へのポインタ(cbp)

  • $cb_proto$ ⇒ CB の C 言語名プロトタイプ宣言用(cb_proto)

  • $id$ ⇒ $ct$_$cell_global$ # ct_cell before or same V1.5.2

  • $idx$ ⇒ idx

  • $ID$ ⇒ id (整数の番号)

  • $ct_global$ ⇒ セルタイプ名(ct)

  • $cell_global$ ⇒ セル名(cell)

  • $$ ⇒ $



5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
# File 'lib/tecsgen/core/generate.rb', line 5062

def subst_name(str, name_array)
  ct   = name_array[0]    # celltype name
  cell = name_array[1]    # cell name
  cb   = name_array[2]    # cell CB name
  cb_init = name_array[3] # cell CB INIT, これは置換に使われない
  cb_proto = name_array[4] # cell CB name for prototype
  id   = name_array[6]    # cell ID
  idx  = name_array[7]    # cell CB name for prototype
  cbp  = name_array[8]    # cell CB pointer
  ct_global = name_array[9] # cell CB pointer
  cell_global = name_array[10] # cell CB pointer

  str = str.gsub(/(^|[^\$])\$ct\$/, "\\1#{ct}")
  str = str.gsub(/(^|[^\$])\$ct_global\$/, "\\1#{ct_global}")
  if cell
    str = str.gsub(/(^|[^\$])\$cell\$/, "\\1#{cell}")
    str = str.gsub(/(^|[^\$])\$cb\$/, "\\1#{cb}")
    # str = str.gsub( /(^|[^\$])\$id\$/, "\\1#{ct}_#{cell}" )
    str = str.gsub(/(^|[^\$])\$id\$/, "\\1#{ct}_#{cell_global}")
    str = str.gsub(/(^|[^\$])\$cb_proto\$/, "\\1#{cb_proto}")
    str = str.gsub(/(^|[^\$])\$ID\$/, "\\1#{id}")
    str = str.gsub(/(^|[^\$])\$idx\$/, "\\1#{idx}")
    str = str.gsub(/(^|[^\$])\$cbp\$/, "\\1#{cbp}")
    str = str.gsub(/(^|[^\$])\$cell_global\$/, "\\1#{cell_global}")
  end
  str = str.gsub(/\$\$/, "\$") # $$ を $ に置換

  return str
end

#unjoin_pluginObject



161
162
163
164
165
# File 'lib/tecsgen/core/unjoin_plugin.rb', line 161

def unjoin_plugin
  @generate = nil
  @generate_list = []
  @plugin = nil
end