[374] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | #
|
---|
| 3 | # TECS Generator
|
---|
| 4 | # Generator for TOPPERS Embedded Component System
|
---|
| 5 | #
|
---|
| 6 | # Copyright (C) 2017-2018 by TOPPERS Project
|
---|
| 7 | #--
|
---|
| 8 | # 上記著作権者は,以下の(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 | #
|
---|
| 37 | # $Id$
|
---|
| 38 | #++
|
---|
| 39 |
|
---|
| 40 | #== CelltypePlugin for tTECSInfo
|
---|
| 41 | class TECSInfoPlugin < CelltypePlugin
|
---|
| 42 |
|
---|
| 43 | @@cell_list = []
|
---|
| 44 | #@celltype::Celltype
|
---|
| 45 | #@plugin_arg_str::String
|
---|
| 46 | #@plugin_arg_list::{argNameString=>argOptionString}
|
---|
| 47 | #@cell_list::[Cell]
|
---|
| 48 |
|
---|
| 49 | #celltype:: Celltype セルタイプ(インスタンス)
|
---|
| 50 | def initialize( celltype, option )
|
---|
| 51 | super
|
---|
| 52 | if $unopt_entry == false then
|
---|
| 53 | cdl_info( "TIF0001 forcely set --unoptimize-entry by TECSInfoPlugin (by importing TECSInfo.cdl)" )
|
---|
| 54 | $unopt_entry = true
|
---|
| 55 | end
|
---|
| 56 | end
|
---|
| 57 |
|
---|
| 58 | #=== 新しいセル
|
---|
| 59 | #cell:: Cell セル
|
---|
| 60 | #
|
---|
| 61 | # celltype プラグインを指定されたセルタイプのセルが生成された
|
---|
| 62 | # セルタイププラグインに対する新しいセルの報告
|
---|
| 63 | def new_cell( cell )
|
---|
| 64 | @@cell_list << cell
|
---|
| 65 |
|
---|
| 66 | # AppFile は、重ね書きようなので、やめる
|
---|
| 67 | # p "import: cell nTECSInfo::tTECSInfoSub #{cell.get_namespace_path.to_s} under #{cell.get_region.get_name}"
|
---|
| 68 | # cell.show_tree 0
|
---|
| 69 | # TECSInfoSub セルのプロトタイプ宣言
|
---|
| 70 | fn = "#{$gen}/tmp_#{cell.get_region.get_global_name}_TECSInfoSub.cdl"
|
---|
| 71 | File.open( fn, "w" ){ |f|
|
---|
| 72 | f.print "/* prototype declaration of TECSInfoSub */\n"
|
---|
| 73 | nest = cell.get_region.gen_region_str_pre f
|
---|
| 74 | indent = " " * nest
|
---|
| 75 | f.print <<EOT
|
---|
| 76 | #{indent}[in_through()]
|
---|
| 77 | #{indent}region rTECSInfo {
|
---|
| 78 | #{indent} cell nTECSInfo::tTECSInfoSub TECSInfoSub;
|
---|
| 79 | #{indent}}; /* rTECSInfo} */
|
---|
| 80 | EOT
|
---|
| 81 | cell.get_region.gen_region_str_post f
|
---|
| 82 | }
|
---|
| 83 | Import.new fn
|
---|
| 84 |
|
---|
| 85 | # セルに cTECSInfo の結合があるか?
|
---|
| 86 | if cell.get_join_list.get_item( :cTECSInfo ) == nil then
|
---|
| 87 | # cTECSInfo = rTECSInfo::TECSInfosub.eTECSInfo; の追加
|
---|
| 88 | nsp = NamespacePath.new( :rTECSInfo, false )
|
---|
| 89 | nsp.append! :TECSInfoSub
|
---|
| 90 | rhs = Expression.create_cell_join_expression nsp, nil, :eTECSInfo
|
---|
| 91 | join = Join.new :cTECSInfo, nil, rhs
|
---|
| 92 | cell.new_join join
|
---|
| 93 | end
|
---|
| 94 | end
|
---|
| 95 |
|
---|
| 96 | #=== tCelltype_factory.h に挿入するコードを生成する
|
---|
| 97 | # file 以外の他のファイルにファクトリコードを生成してもよい
|
---|
| 98 | # セルタイププラグインが指定されたセルタイプのみ呼び出される
|
---|
| 99 | def gen_factory file
|
---|
| 100 | File.open( "#{$gen}/include_all_signature_header.h", "w" ){ |f|
|
---|
| 101 | f.print <<EOT
|
---|
| 102 | #ifndef include_all_signature_header_h
|
---|
| 103 | #define include_all_signature_header_h
|
---|
| 104 |
|
---|
| 105 | EOT
|
---|
| 106 | Namespace.get_root.travers_all_signature{ |sig|
|
---|
| 107 | f.print "#include \"#{sig.get_global_name}_tecsgen.h\"\n"
|
---|
| 108 | }
|
---|
| 109 | f.print <<EOT
|
---|
| 110 |
|
---|
| 111 | #endif /* include_all_signature_header_h */
|
---|
| 112 | EOT
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | undefs2 = [ :INITIALIZE_CB, :FOREACH_CELL, :END_FOREACH_CELL ]
|
---|
| 116 | f = AppFile.open( "#{$gen}/nTECSInfo_tVarDeclInfo_factory.h" )
|
---|
| 117 | Namespace.get_root.print_struct_define f
|
---|
| 118 |
|
---|
| 119 | undefs = [ :VALID_IDX, :GET_CELLCB, :CELLCB, :CELLIDX,
|
---|
| 120 | :tVarDeclInfo_IDX, :ATTR_name, :ATTR_sizeIsExpr,
|
---|
| 121 | :ATTR_declType, :ATTR_offset ]
|
---|
| 122 |
|
---|
| 123 | f.print <<EOT
|
---|
| 124 |
|
---|
| 125 | /***** Offset of attr & var of celltype *****/
|
---|
| 126 | #define TOPPERS_CB_TYPE_ONLY
|
---|
| 127 |
|
---|
| 128 | /* In case a celltype has 'inline' entry,
|
---|
| 129 | * some macros are temporally defined
|
---|
| 130 | * even if TOPPERS_CB_TYPE_ONLY is defined.
|
---|
| 131 | * To avoid redefinition warning, undef these macros.
|
---|
| 132 | */
|
---|
| 133 | #{ str=""; undefs.each{|u| str += "#undef #{u}\n" }; str }
|
---|
| 134 | EOT
|
---|
| 135 | if $ram_initializer then
|
---|
| 136 | undefs2.each{|u|
|
---|
| 137 | f.print "#undef #{u}\n"
|
---|
| 138 | }
|
---|
| 139 | end
|
---|
| 140 | Namespace.get_root.print_celltype_define_offset f
|
---|
| 141 | f.print <<EOT
|
---|
| 142 |
|
---|
| 143 | /* redefine macros */
|
---|
| 144 | #define tVarDeclInfo_IDX nTECSInfo_tVarDeclInfo_IDX
|
---|
| 145 |
|
---|
| 146 | EOT
|
---|
| 147 | if $ram_initializer then
|
---|
| 148 | f.print <<EOT
|
---|
| 149 | #define FOREACH_CELL(i,p_cb) { (void)(i);
|
---|
| 150 | #define END_FOREACH_CELL }
|
---|
| 151 | #define INITIALIZE_CB(p_that) (void)(p_that);
|
---|
| 152 | #define SET_CB_INIB_POINTER(i,p_that)
|
---|
| 153 | EOT
|
---|
| 154 | end
|
---|
| 155 | f.close
|
---|
| 156 |
|
---|
| 157 | undefs = [ :N_CP_cEntryInfo, :NCP_cEntryInfo, :N_CP_cCallInfo, :NCP_cCallInfo,
|
---|
| 158 | :N_CP_cAttrInfo, :NCP_cAttrInfo, :N_CP_cVarInfo, :NCP_cVarInfo,
|
---|
| 159 | :VALID_IDX, :GET_CELLCB, :CELLCB, :CELLIDX, :ATTR_name, :ATTR_b_singleton,
|
---|
| 160 | :ATTR_b_IDX_is_ID_act, :ATTR_sizeOfCB, :ATTR_sizeOfINIB, :ATTR_n_cellInLinUnit,
|
---|
| 161 | :ATTR_n_cellInSystem, :cEntryInfo_getName, :cEntryInfo_getNameLength,
|
---|
| 162 | :cEntryInfo_getSignatureInfo, :cEntryInfo_getArraySize, :cEntryInfo_isInline,
|
---|
| 163 | :cCallInfo_getName, :cCallInfo_getNameLength, :cCallInfo_getSignatureInfo,
|
---|
| 164 | :cCallInfo_getArraySize, :cCallInfo_getSpecifierInfo, :cCallInfo_getInternalInfo,
|
---|
| 165 | :cCallInfo_getLocationInfo, :cCallInfo_getOptimizeInfo, :cAttrInfo_getName,
|
---|
| 166 | :cAttrInfo_getOffset, :cAttrInfo_getTypeInfo, :cAttrInfo_getSizeIsExpr,
|
---|
| 167 | :cAttrInfo_getSizeIs, :cVarInfo_getName, :cVarInfo_getOffset, :cVarInfo_getTypeInfo,
|
---|
| 168 | :cVarInfo_getSizeIsExpr, :cVarInfo_getSizeIs, :cEntryInfo_refer_to_descriptor,
|
---|
| 169 | :cEntryInfo_ref_desc, :cCallInfo_refer_to_descriptor, :cCallInfo_ref_desc,
|
---|
| 170 | :cAttrInfo_refer_to_descriptor, :cAttrInfo_ref_desc, :cVarInfo_refer_to_descriptor,
|
---|
| 171 | :cVarInfo_ref_desc, :is_cEntryInfo_joined, :is_cCallInfo_joined,
|
---|
| 172 | :is_cAttrInfo_joined, :is_cVarInfo_joined, :eCelltypeInfo_getName,
|
---|
| 173 | :eCelltypeInfo_getNameLength, :eCelltypeInfo_getNAttr, :eCelltypeInfo_getAttrInfo,
|
---|
| 174 | :eCelltypeInfo_getNVar, :eCelltypeInfo_getVarInfo, :eCelltypeInfo_getNCall,
|
---|
| 175 | :eCelltypeInfo_getCallInfo, :eCelltypeInfo_getNEntry, :eCelltypeInfo_getEntryInfo,
|
---|
| 176 | :eCelltypeInfo_isSingleton, :eCelltypeInfo_isIDX_is_ID, :eCelltypeInfo_hasCB,
|
---|
| 177 | :eCelltypeInfo_hasINIB, :FOREACH_CELL, :END_FOREACH_CELL ]
|
---|
| 178 |
|
---|
| 179 | f = AppFile.open( "#{$gen}/nTECSInfo_tCelltypeInfo_factory.h" )
|
---|
| 180 | undefs.each{ |u|
|
---|
| 181 | f.print "#undef #{u}\n"
|
---|
| 182 | }
|
---|
| 183 | f.print "#define TOPPERS_CB_TYPE_ONLY\n"
|
---|
| 184 | Namespace.get_root.print_celltype_define f
|
---|
| 185 | # FOREACH_CELL を出しなおす
|
---|
| 186 | ct = Namespace.find [ "::", :nTECSInfo, :tCelltypeInfo ]
|
---|
| 187 | ct.gen_ph_foreach_cell f
|
---|
| 188 | ct.gen_ph_cb_initialize_macro f
|
---|
| 189 | f.print "\n"
|
---|
| 190 | f.close
|
---|
| 191 |
|
---|
| 192 | undefs = [ :VALID_IDX, :GET_CELLCB, :CELLCB, :CELLIDX,
|
---|
| 193 | :tCallInfo_IDX, :ATTR_name, :ATTR_offset, :ATTR_b_inCB,
|
---|
| 194 | :ATTR_b_optional, :ATTR_b_omit, :ATTR_b_dynamic,
|
---|
| 195 | :ATTR_b_ref_desc, :ATTR_b_allocator_port,
|
---|
| 196 | :ATTR_b_require_port, :ATTR_b_VMT_useless,
|
---|
| 197 | :ATTR_b_skelton_useless, :ATTR_b_cell_unique,
|
---|
| 198 | :cSignatureInfo_getName, :cSignatureInfo_getNameLength,
|
---|
| 199 | :cSignatureInfo_getNFunction,
|
---|
| 200 | :cSignatureInfo_getFunctionInfo,
|
---|
| 201 | :cSignatureInfo_refer_to_descriptor,
|
---|
| 202 | :cSignatureInfo_ref_desc, :eCallInfo_getName,
|
---|
| 203 | :eCallInfo_getNameLength, :eCallInfo_getSignatureInfo,
|
---|
| 204 | :eCallInfo_getArraySize, :eCallInfo_isOptional,
|
---|
| 205 | :eCallInfo_isDynamic, :eCallInfo_isRefDesc,
|
---|
| 206 | :eCallInfo_isOmit ]
|
---|
| 207 |
|
---|
| 208 | f = AppFile.open( "#{$gen}/nTECSInfo_tCallInfo_factory.h" )
|
---|
| 209 | f.print <<EOT
|
---|
| 210 |
|
---|
| 211 | /***** Offset of attr & var of celltype *****/
|
---|
| 212 | #define TOPPERS_CB_TYPE_ONLY
|
---|
| 213 |
|
---|
| 214 | /* In case a celltype has 'inline' entry,
|
---|
| 215 | * some macros are temporally defined
|
---|
| 216 | * even if TOPPERS_CB_TYPE_ONLY is defined.
|
---|
| 217 | * To avoid redefinition warning, undef these macros.
|
---|
| 218 | */
|
---|
| 219 | #{ str=""; undefs.each{|u| str += "#undef #{u}\n" }; str }
|
---|
| 220 | EOT
|
---|
| 221 | if $ram_initializer then
|
---|
| 222 | undefs2.each{|u|
|
---|
| 223 | f.print "#undef #{u}\n"
|
---|
| 224 | }
|
---|
| 225 | end
|
---|
| 226 |
|
---|
| 227 | Namespace.get_root.print_call_define f
|
---|
| 228 | f.print <<EOT
|
---|
| 229 |
|
---|
| 230 | /* redefine macros */
|
---|
| 231 | #define tCallInfo_IDX nTECSInfo_tCallInfo_IDX
|
---|
| 232 |
|
---|
| 233 | EOT
|
---|
| 234 | if $ram_initializer then
|
---|
| 235 | f.print <<EOT
|
---|
| 236 | #define FOREACH_CELL(i,p_cb) { (void)(i);
|
---|
| 237 | #define END_FOREACH_CELL }
|
---|
| 238 | #define INITIALIZE_CB(p_that) (void)(p_that);
|
---|
| 239 | #define SET_CB_INIB_POINTER(i,p_that)
|
---|
| 240 |
|
---|
| 241 | EOT
|
---|
| 242 | end
|
---|
| 243 | f.close
|
---|
| 244 |
|
---|
| 245 | f = AppFile.open( "#{$gen}/nTECSInfo_tEntryInfo_factory.h" )
|
---|
| 246 | Namespace.get_root.print_entry_define f
|
---|
| 247 | f.close
|
---|
| 248 |
|
---|
| 249 | undefs = [ :GET_CELLCB, :CELLCB, :CELLIDX, :ATTR_name, :INITIALIZE_CB, :FOREACH_CELL ]
|
---|
| 250 | f = AppFile.open( "#{$gen}/nTECSInfo_tCellInfo_factory.h" )
|
---|
| 251 | undefs.each{ |u|
|
---|
| 252 | f.print "#undef #{u}\n"
|
---|
| 253 | }
|
---|
| 254 | Region.get_root.print_cell_define f
|
---|
| 255 | # FOREACH_CELL を出しなおす
|
---|
| 256 | ct = Namespace.find [ "::", :nTECSInfo, :tCellInfo ]
|
---|
| 257 | ct.gen_ph_foreach_cell f
|
---|
| 258 | ct.gen_ph_cb_initialize_macro f
|
---|
| 259 | f.close
|
---|
| 260 |
|
---|
| 261 | f = AppFile.open( "#{$gen}/nTECSInfo_tRawEntryDescriptorInfo_factory.h" )
|
---|
| 262 | Region.get_root.print_entry_descriptor_define f
|
---|
| 263 | f.close
|
---|
| 264 | end
|
---|
| 265 |
|
---|
| 266 | #=== 後ろの CDL コードを生成
|
---|
| 267 | #プラグインの後ろの CDL コードを生成
|
---|
| 268 | #file:: File:
|
---|
| 269 | def self.gen_post_code( file )
|
---|
| 270 | if Generator.get_n_error > 0 then
|
---|
| 271 | Generator.info( "I9999 TECSInfoPlugin does not generate TECSInfo code because of early error" )
|
---|
| 272 | return
|
---|
| 273 | end
|
---|
| 274 | # 複数のプラグインの post_code が一つのファイルに含まれるため、以下のような見出しをつけること
|
---|
| 275 | file.print <<EOT
|
---|
| 276 | /*------------ #{self.name} post code ------------*/
|
---|
| 277 | EOT
|
---|
| 278 | @@cell_list.each{|cell|
|
---|
| 279 | root = cell.get_region # .get_link_root
|
---|
| 280 | TECSInfo.print_info file, root
|
---|
| 281 | }
|
---|
| 282 | end
|
---|
| 283 | end
|
---|