Ignore:
Timestamp:
Apr 5, 2019, 9:26:53 PM (5 years ago)
Author:
coas-nagasima
Message:

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_rx/trunk/asp3_dcre/tecsgen/tecslib/core/tecsinfo.rb

    r359 r374  
    44#      Generator for TOPPERS Embedded Component System
    55
    6 #   Copyright (C) 2017 by TOPPERS Project
     6#   Copyright (C) 2017-2018 by TOPPERS Project
    77#--
    88#   上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
     
    4949#{indent0}region rTECSInfo {
    5050EOT
    51     # mikan 全部生成するのではなく、region 下のセルのセルタイプと、そこから参照されるシグニチャ、セルタイプに限定して出力する.
     51    Type.reset_print_info
     52
     53    # mikan 全部生成するのではなく、region 下のセルのセルタイプと、そこから参照されるシグニチャ、セルタイプに限定して出力すべき
    5254    # しかし、意味解析後に出力するため、これは容易ではない.最適化とコード生成は、リンクルートごとに行われる.
    5355    Namespace.print_info f, indent
     
    149151                 "#{tag.get_ID_str}_#{decl.get_name}",
    150152                 "(uint32_t)(intptr_t)&(((#{tag.get_type_str}#{tag.get_type_str_post}*)0)->#{decl.get_name})"
     153        f.printf "#define PLACE_OF_%-30s  (%s)\n",
     154                 "#{tag.get_ID_str}_#{decl.get_name}",
     155                 "VARDECL_PLACE_STRUCT"
    151156      }
    152157    }
     
    191196    }
    192197  end
     198
     199  def print_entry_define f
     200    @celltype_list.each { |ct|
     201      if ct.get_cell_list.length > 0 then
     202        ct.print_entry_define f
     203      end
     204    }
     205    @namespace_list.each { |ns|
     206      if ns.instance_of? Namespace then   # region を含めない
     207        ns.print_entry_define f
     208      end
     209    }
     210  end
    193211end
    194212
     
    200218      name = @global_name
    201219    end
     220    # p "region:#{get_name}"
    202221    f.print "\n#{indent}/*** #{get_namespace_path} region information cell ***/\n"
    203222    f.print <<EOT
    204223#{indent}cell nTECSInfo::tRegionInfo #{name}RegionInfo{
    205224#{indent}    name = "#{@name}";
    206 #{indent}};
    207 EOT
     225EOT
     226    @cell_list.each{ |cell|
     227        # print "cell class="+cell.get_celltype.class.name+", " + cell.get_celltype.get_name.to_s + " 1\n"
     228      if ! cell.exclude_info? then
     229        # print "cell class="+cell.get_celltype.class.name+", " + cell.get_celltype.get_name.to_s + " 2\n"
     230        f.print "#{indent}    cCellInfo[] = #{cell.get_global_name}CellInfo.eCellInfo;\n"
     231      end
     232    }
     233    @namespace_list.each { |region|
     234      if region.instance_of? Region then
     235        f.print "#{indent}    cRegionInfo[] = #{region.get_global_name}RegionInfo.eRegionInfo;\n"
     236       end
     237    }
     238    f.print "#{indent}};\n"
     239    @cell_list.each{ |cell|
     240      if ! cell.exclude_info? then
     241        cell.print_info f, indent
     242      end
     243    }
    208244  end
    209245
     
    221257    self.print_info_region f, indent
    222258  end
     259
     260  def self.print_cell_define f
     261    region.get_link_root.print_cell_define f
     262    region.get_link_root.get_region{ |region|
     263      if region.instance_of? Region then
     264        region.print_cell_define_offset f
     265      end
     266
     267    }
     268  end
     269
     270  def print_cell_define f
     271    ct_list = {}
     272    @cell_list.each{ |cell|
     273      next if cell.exclude_info_factory?
     274      ct_list[ cell.get_celltype ] = true
     275    }
     276    f.print "#define TOPPERS_CB_TYPE_ONLY\n"
     277    ct_list.each{ |ct, val|
     278      f.print "#include \"#{ct.get_global_name}_tecsgen.h\"\n"
     279    }
     280    f.print "\n"
     281    @cell_list.each{ |cell|
     282      next if cell.exclude_info_factory?
     283      name_array = cell.get_celltype.get_name_array cell
     284      if cell.get_celltype.has_CB?
     285        cb = "(void*)#{name_array[8]}"
     286        cb_proto = "extern #{cell.get_celltype.get_global_name}_CB #{name_array[4]};\n"
     287      else
     288        cb = "0"
     289        cb_proto = ""
     290      end
     291      if cell.get_celltype.has_INIB?
     292        inib = "(void*)&#{name_array[5]}"
     293        inib_proto = "extern #{cell.get_celltype.get_global_name}_INIB #{name_array[11]};\n"
     294      else
     295        inib = "0"
     296        inib_proto = ""
     297      end
     298      if ! cell.exclude_info_factory? then
     299        f.print <<EOT
     300#{cb_proto}#define  #{cell.get_global_name}__CBP   #{cb}
     301#{inib_proto}#define  #{cell.get_global_name}__INIBP #{inib}
     302EOT
     303      end
     304    }
     305    @namespace_list.each { |region|
     306      if region.instance_of? Region then
     307        region.print_cell_define f
     308      end
     309    }
     310  end
     311
     312  def print_entry_descriptor_define f
     313    @cell_list.each{ |cell|
     314      next if cell.exclude_info_factory?
     315
     316      signatures = {}
     317      cell.get_celltype.get_port_list.each{ |port|
     318        next if port.get_port_type != :ENTRY
     319
     320        if signatures[ port.get_signature ] == nil then
     321          f.print "#include \"#{port.get_signature.get_global_name}_tecsgen.h\"\n"
     322        end
     323        if cell.get_celltype.get_global_name == :nTECSInfo_tRawEntryDescriptorInfo then
     324          f.print "const struct tag_#{cell.get_celltype.get_global_name}_#{port.get_name}_DES "
     325          f.print "#{cell.get_global_name}_#{port.get_name}_des;\n"
     326        else
     327          f.print "extern struct tag_#{port.get_signature.get_global_name}_VDES "
     328          f.print "#{cell.get_global_name}_#{port.get_name}_des;\n"
     329        end
     330      }
     331    }
     332    @namespace_list.each { |region|
     333      if region.instance_of? Region then
     334        region.print_entry_descriptor_define f
     335      end
     336    }
     337  end
    223338end
    224339
     
    227342    f.print <<EOT
    228343#{indent}cell nTECSInfo::tCelltypeInfo #{@global_name}CelltypeInfo {
    229 #{indent}    name            = "#{@name}";
    230 #{indent}    b_singleton     = #{@singleton};
    231 #{indent}    b_IDX_is_ID_act = C_EXP( "#{@global_name}__IDX_is_ID_act" );
    232 #{indent}    b_hasCB         = C_EXP( "#{@global_name}__hasCB" );
    233 #{indent}    b_hasINIB       = C_EXP( "#{@global_name}__hasINIB" );
    234 #{indent}    n_cellInLinUnit = C_EXP( "#{@global_name}__NCELLINLINKUNIT" );
    235 #{indent}    n_cellInSystem  = #{@cell_list.length};
     344#{indent}    name             = "#{@name}";
     345#{indent}    b_singleton      = #{@singleton};
     346#{indent}    b_IDX_is_ID_act  = C_EXP( "#{@global_name}__IDX_is_ID_act" );
     347#{indent}    sizeOfCB         = C_EXP( "#{@global_name}__sizeOfCB" );
     348#{indent}    sizeOfINIB       = C_EXP( "#{@global_name}__sizeOfINIB" );
     349#{indent}    n_cellInLinkUnit = C_EXP( "#{@global_name}__NCELLINLINKUNIT" );
     350#{indent}    n_cellInSystem   = #{@cell_list.length};
    236351EOT
    237352    @port.each{ |port|
     
    273388    }
    274389    @attribute.each{ |decl|
    275       decl.print_info f, @global_name, indent
     390      decl.print_info f, @global_name, indent, :DECLTYPE_ATTR
    276391    }
    277392    @var.each{ |decl|
    278       decl.print_info f, @global_name, indent
     393      decl.print_info f, @global_name, indent, :DECLTYPE_VAR
    279394    }
    280395  end
     
    295410        if ! decl.is_omit? then
    296411          offset = "(uint32_t)(intptr_t)&(((#{@global_name}_#{inib_cb}*)0)->#{decl.get_name})"
     412          place = inib_cb
    297413        else
    298414          offset = "0xffffffff"
     415          place = "NON"
    299416        end
    300417        f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", offset
     418        f.printf "#define PLACE_OF_%-30s  VARDECL_PLACE_%s\n", "#{@global_name}_#{decl.get_name}", place
    301419      }
    302420      @var.each{ |decl|
    303         if decl.get_size_is then
     421        if decl.get_size_is && has_INIB? then
    304422          inib_cb = "INIB"
    305423        else
    306424          inib_cb = "CB"
    307425        end
    308           f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", "(uint32_t)(intptr_t)&(((#{@global_name}_#{inib_cb}*)0)->#{decl.get_name})"
     426        place = inib_cb
     427        f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", "(uint32_t)(intptr_t)&(((#{@global_name}_#{inib_cb}*)0)->#{decl.get_name})"
     428        f.printf "#define PLACE_OF_%-30s  VARDECL_PLACE_%s\n", "#{@global_name}_#{decl.get_name}", place
    309429      }
    310430    else
     
    316436      @attribute.each{ |decl|
    317437        f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff"
     438        f.printf "#define PLACE_OF_%-30s   VARDECL_PLACE_NON\n", "#{@global_name}_#{decl.get_name}"
    318439      }
    319440      @var.each{ |decl|
    320441        f.printf "#define OFFSET_OF_%-30s  (%s)\n", "#{@global_name}_#{decl.get_name}", "0xffffffff"
     442        f.printf "#define PLACE_OF_%-30s   VARDECL_PLACE_NON\n", "#{@global_name}_#{decl.get_name}"
    321443      }
    322444    end
     
    324446
    325447  def print_celltype_define f
    326     f.printf "#define %-50s (#{@idx_is_id_act})\n",     "#{@global_name}__IDX_is_ID_act"
    327     f.printf "#define %-50s (#{has_CB?})\n",            "#{@global_name}__hasCB"
    328     f.printf "#define %-50s (#{has_INIB?})\n",          "#{@global_name}__hasINIB"
    329     f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen
     448    if has_INIB? then
     449      size_INIB = "(sizeof(#{@global_name}_INIB))"
     450    else
     451      size_INIB = "(0)"
     452    end
     453    if has_CB? then
     454      size_CB = "(sizeof(#{@global_name}_CB))"
     455    else
     456      size_CB   = "(0)"
     457    end
     458
     459    if @n_cell_gen > 0 then
     460      f.printf "\n#include \"#{@global_name}_tecsgen.h\"\n"
     461      f.printf "#define %-50s (#{@idx_is_id_act})\n",     "#{@global_name}__IDX_is_ID_act"
     462      f.printf "#define %-50s (#{size_CB})\n",            "#{@global_name}__sizeOfCB"
     463      f.printf "#define %-50s (#{size_INIB})\n",          "#{@global_name}__sizeOfINIB"
     464      f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen
     465    else
     466      f.printf "#define %-50s (false)\n",                 "#{@global_name}__IDX_is_ID_act"
     467      f.printf "#define %-50s (0)\n",                     "#{@global_name}__sizeOfCB"
     468      f.printf "#define %-50s (0)\n",                     "#{@global_name}__sizeOfINIB"
     469      f.printf "#define %-30s (%d)\n", "#{@global_name}__NCELLINLINKUNIT", @n_cell_gen
     470    end
    330471  end
    331472
     
    365506        end
    366507      end
    367       if ( port.is_VMT_useless? && port.is_cell_unique? ) || @n_cell_gen == 0 then
     508      if ( port.is_VMT_useless? && port.is_cell_unique? ) || port.is_omit? || @n_cell_gen == 0 then
    368509        offset = "0xffffffff"
    369510      else
     
    375516        offset = "(uint32_t)(intptr_t)&((#{@global_name}_#{cb_inib}*)0)->#{port.get_name}"
    376517      end
     518      array_size = port.get_array_size
     519      if array_size == "[]" then
     520        array_size = "0xffffffff"
     521      elsif array_size == nil then
     522        array_size = "0"
     523      end
     524
    377525      f.printf "#define %-50s (#{offset})\n",                   "#{@global_name}_#{port.get_name}__offset"
     526      f.printf "#define %-50s (#{array_size})\n",               "#{@global_name}_#{port.get_name}__array_size"
    378527      f.printf "#define %-50s (#{place})\n",                    "#{@global_name}_#{port.get_name}__place"
    379528      f.printf "#define %-50s (#{port.is_VMT_useless?})\n",     "#{@global_name}_#{port.get_name}__b_VMT_useless"
     
    382531    }
    383532  end
     533
     534  def print_entry_define f
     535    @port.each{ |port|
     536      next if port.get_port_type == :CALL
     537      array_size = port.get_array_size
     538      if array_size == "[]" then
     539        array_size = "0xffffffff"
     540      elsif array_size == nil then
     541        array_size = "0"
     542      end
     543
     544      f.printf "#define %-50s (#{array_size})\n",               "#{@global_name}_#{port.get_name}__array_size"
     545    }
     546  end
    384547end
    385548
     
    393556#{indent}    cSignatureInfo  = #{@signature.get_global_name}SignatureInfo.eSignatureInfo;
    394557#{indent}    b_inline        = #{@b_inline};
     558#{indent}    array_size      = C_EXP( "#{ct_global}_#{@name}__array_size" );
    395559#{indent}};
    396560EOT
     
    401565#{indent}    cSignatureInfo  = #{@signature.get_global_name}SignatureInfo.eSignatureInfo;
    402566#{indent}    offset            = C_EXP( "#{ct_global}_#{@name}__offset" );
     567#{indent}    array_size        = C_EXP( "#{ct_global}_#{@name}__array_size" );
    403568#{indent}    b_optional        = #{@b_optional};
    404569#{indent}    b_omit            = #{@b_omit};
     
    418583end
    419584
     585class Cell
     586  def print_info f, indent
     587    if exclude_info? then
     588      return
     589    end
     590    f.print <<EOT
     591
     592#{indent}/*** #{@global_name} cell information ****/
     593#{indent}cell nTECSInfo::tCellInfo #{@global_name}CellInfo {
     594#{indent}    name            = "#{@name}";
     595#{indent}    cbp             = C_EXP( \"#{@global_name}__CBP\" );
     596#{indent}    inibp           = C_EXP( \"#{@global_name}__INIBP\" );
     597#{indent}    cCelltypeInfo   = #{@celltype.get_global_name}CelltypeInfo.eCelltypeInfo;
     598EOT
     599    @celltype.get_port_list.each{ |port|
     600      next if port.get_port_type != :ENTRY
     601
     602      f.print <<EOT
     603#{indent}    cRawEntryDescriptor[] = #{@global_name}_#{port.get_name}RawEntryDescriptorInfo.eRawEntryDescriptor;
     604EOT
     605    }
     606    f.print "#{indent}};\n"
     607
     608    # RawEntryDescriptorInfo cells
     609    @celltype.get_port_list.each{ |port|
     610      next if port.get_port_type != :ENTRY
     611
     612      size = port.get_array_size
     613      if size == nil then
     614        size = 1
     615      elsif size == "[]" then
     616        size = @entry_array_max_subscript[ port ]
     617      end
     618      if ! port.is_omit? then
     619        red = "C_EXP( \"&#{@global_name}_#{port.get_name}_des\" )"
     620      else
     621        red = "(void *)0"
     622      end
     623      # mikan 受け口配列
     624      f.print <<EOT
     625#{indent}cell nTECSInfo::tRawEntryDescriptorInfo #{@global_name}_#{port.get_name}RawEntryDescriptorInfo {
     626#{indent}   size = #{size};
     627#{indent}   rawEntryDescriptor = { #{red} };
     628EOT
     629#  #{indent}   cEntryInfo = #{@celltype.get_global_name}_#{port.get_name}EntryInfo.eEntryInfo;
     630      f.print "#{indent}};\n"
     631    }
     632  end
     633
     634  def exclude_info?
     635    # print "exclude_info?: name=" + get_name.to_s
     636    if @celltype == nil ||
     637       is_of_composite? ||
     638       @celltype.get_global_name == :nTECSInfo_tTECSInfoSub ||
     639       post_code_generated? ||
     640       @b_defined == false then
     641      # print ": true celltype_is_of_composite=#{is_of_composite?} celltype_name=#{@celltype.get_global_name} celltype.need_generate=#{@celltype.need_generate?}\n"
     642      return true
     643    else
     644      # print ": false\n"
     645      return false
     646    end
     647  end
     648
     649  def exclude_info_factory?
     650    # print "exclude_info_factory?: name=" + get_name.to_s
     651    if @celltype == nil ||
     652       is_of_composite? ||
     653       @celltype.get_global_name == :nTECSInfo_tTECSInfoSub ||
     654       ! @celltype.need_generate? then
     655      # print ": true celltype_is_of_composite=#{is_of_composite?} celltype_name=#{@celltype.get_global_name} celltype.need_generate=#{@celltype.need_generate?}\n"
     656      return true
     657    else
     658      # print ": false\n"
     659      return false
     660    end
     661  end
     662end
     663
    420664class Signature
    421665  def print_info f, indent
     
    446690    f.print <<EOT
    447691#{indent}cell nTECSInfo::tFunctionInfo #{sig_name}_#{func_name}FunctionInfo {
    448 #{indent}    name            = "#{@owner.get_global_name}_#{@name}";
     692#{indent}    name            = "#{get_name}";
    449693#{indent}    bOneway         = #{is_oneway?};
    450694EOT
     
    502746
    503747class Decl
    504   def print_info f, parent_ID_str, indent
     748  def print_info f, parent_ID_str, indent, decl_type
    505749    if @size_is then
    506750      size = "\"mikan\"";
     
    512756#{indent}    name            = "#{get_name}";
    513757#{indent}    sizeIsExpr      = #{size};
    514 #{indent}    declType        = DECLTYPE_STMEMBER;
     758#{indent}    declType        = #{decl_type};
    515759#{indent}    offset          = C_EXP( "OFFSET_OF_#{parent_ID_str}_#{get_name}" );
     760#{indent}    place           = C_EXP( "PLACE_OF_#{parent_ID_str}_#{get_name}" );
    516761#{indent}    cTypeInfo       = #{get_type.get_ID_str}TypeInfo.eTypeInfo;
    517762#{indent}};
     
    523768class Type
    524769  @@typeinfo_printed = {}
     770
     771  def self.reset_print_info
     772    @@typeinfo_printed = {}
     773  end
     774
    525775  def print_info f, indent
    526776    # Type の info は、最後にまとめて出力するので、ここでは記録するだけ
     
    538788    elsif self.kind_of? StructType then
    539789      get_members_decl.get_items.each{ |decl|
    540         decl.get_type.print_info f, indent
     790        decl.print_info f, get_ID_str, indent, :DECLTYPE_STMEMBER
    541791      }
    542792    end
     
    550800
    551801  def print_info_post f, indent
    552     bit_size = get_bit_size
    553     if bit_size == 0 then
    554       bit_size = "C_EXP( \"sizeof(#{get_type_str}#{get_type_str_post})\" )"
    555     end
    556802    if self.class.superclass == Type then     # 親クラスが Type の場合 types.rb のクラス
    557803      type_name = self.class.name
     
    566812#{indent}    name           = "#{get_type_str}#{get_type_str_post}";
    567813#{indent}    typeKind       = TECSTypeKind_#{type_name};
    568 #{indent}    bitSize        = #{bit_size};
     814#{indent}    size           = C_EXP( "sizeof(#{get_type_str}#{get_type_str_post})" );
    569815#{indent}    b_const        = #{is_const?};
    570816#{indent}    b_volatile     = #{is_volatile?};
    571817EOT
    572818    if self.kind_of? PtrType then
    573       f.print "#{indent}    cTypeInfo      = #{get_referto.get_ID_str}TypeInfo.eTypeInfo;\n"
     819      f.print "#{indent}    cTypeInfo        = #{get_referto.get_ID_str}TypeInfo.eTypeInfo;\n"
    574820    elsif self.kind_of? ArrayType then
    575       f.print "#{indent}    cTypeInfo      = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
     821      f.print "#{indent}    cTypeInfo        = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
    576822    elsif self.kind_of? DefinedType then
    577       f.print "#{indent}    cTypeInfo      = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
     823      f.print "#{indent}    cTypeInfo        = #{get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
    578824    elsif self.kind_of? StructType then
    579825      get_members_decl.get_items.each{ |decl|
    580         f.print "#{indent}    cTypeInfo[]    = #{decl.get_type.get_ID_str}TypeInfo.eTypeInfo;\n"
     826        f.print "#{indent}    cVarDeclInfo[] = #{get_ID_str}_#{decl.get_name}VarDeclInfo.eVarDeclInfo;\n"
    581827      }
    582828    elsif self.kind_of? DescriptorType then
Note: See TracChangeset for help on using the changeset viewer.