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