[374] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | #
|
---|
| 3 | # TECS Generator
|
---|
| 4 | # Generator for TOPPERS Embedded Component System
|
---|
| 5 | #
|
---|
| 6 | # Copyright (C) 2008-2011 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 | #== celltype プラグインの共通の親クラス
|
---|
| 41 | module MrubyBridgeCelltypePluginModule
|
---|
| 42 |
|
---|
| 43 | # プラグイン引数名 => Proc
|
---|
| 44 | MrubyBridgePluginArgProc = {
|
---|
| 45 | "ignoreUnsigned" => Proc.new { |obj,rhs| obj.set_ignoreUnsigned rhs },
|
---|
| 46 | "include_inner_cell" => Proc.new { |obj,rhs| obj.set_include_inner_cell rhs },
|
---|
| 47 | "exclude_cell" => Proc.new { |obj,rhs| obj.set_exclude_cell rhs },
|
---|
| 48 | "exclude_port" => Proc.new { |obj,rhs| obj.set_exclude_port rhs },
|
---|
| 49 | "exclude_port_func" => Proc.new { |obj,rhs| obj.set_exclude_port_func rhs },
|
---|
| 50 | "auto_exclude" => Proc.new { |obj,rhs| obj.set_auto_exclude rhs },
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | require_tecsgen_lib( "MrubyBridgeCellPlugin.rb" )
|
---|
| 54 | @@plugin_list = []
|
---|
| 55 | @@count = 1
|
---|
| 56 |
|
---|
| 57 | #celltype:: Celltype セルタイプ(インスタンス)
|
---|
| 58 | def initialize( celltype, option )
|
---|
| 59 | dbgPrint "#{self.class.name}: initialzie: #{celltype.get_name}\n"
|
---|
| 60 |
|
---|
| 61 | super
|
---|
| 62 | @celltype = celltype
|
---|
| 63 | @cell_list = []
|
---|
| 64 | @include_inner_cell = false
|
---|
| 65 | @exclude_cells = []
|
---|
| 66 | @exclude_port = []
|
---|
| 67 | @exclude_port_func = {}
|
---|
| 68 | @b_ignoreUnsigned = false
|
---|
| 69 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
| 70 | @@plugin_list << self
|
---|
| 71 |
|
---|
| 72 | @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc
|
---|
| 73 | @plugin_arg_str = CDLString.remove_dquote option
|
---|
| 74 | parse_plugin_arg
|
---|
| 75 |
|
---|
| 76 | MrubyBridgeCellPlugin.set_gen_post_code_by_dependent
|
---|
| 77 | end
|
---|
| 78 |
|
---|
| 79 | #=== 新しいセル
|
---|
| 80 | #cell:: Cell セル
|
---|
| 81 | #
|
---|
| 82 | # celltype プラグインを指定されたセルタイプのセルが生成された
|
---|
| 83 | # セルタイププラグインに対する新しいセルの報告
|
---|
| 84 | # generate 文により呼び出された場合、それまでに定義された cell については、initialize のタイミングで呼び出される
|
---|
| 85 | def new_cell( cell )
|
---|
| 86 | dbgPrint "MrubyBridgeCelltypePluginModule: new_cell: #{cell.get_name}\n"
|
---|
| 87 |
|
---|
| 88 | return if @cell_list.include? cell # この行は、本来不要のはず
|
---|
| 89 | if TECSGEN.post_coded? # post_code 以降のセルは対象から外す
|
---|
| 90 | cdl_info( "I9999 MrubyBridgeCelltypePlugin: $1 is excluded because cell generated after post_coded", cell.get_name )
|
---|
| 91 | return
|
---|
| 92 | end
|
---|
| 93 |
|
---|
| 94 | # include_inner_cell option
|
---|
| 95 | if cell.is_cloned? && @include_inner_cell == false then
|
---|
| 96 | # p "#{cell.get_name} excluded"
|
---|
| 97 | cdl_info( "I9999 MrubyBridgeCelltypePlugin: inner cell $1 is excluded", cell.get_name )
|
---|
| 98 | return
|
---|
| 99 | # else
|
---|
| 100 | # p "#{cell.get_name} included"
|
---|
| 101 | end
|
---|
| 102 |
|
---|
| 103 | # exclude_cell option
|
---|
| 104 | if @exclude_cells.include?( cell.get_name ) then
|
---|
| 105 | return
|
---|
| 106 | end
|
---|
| 107 |
|
---|
| 108 | opt_str = "ignoreUnsigned=#{@b_ignoreUnsigned}, auto_exclude=#{@b_auto_exclude}"
|
---|
| 109 | @exclude_port.each{ |port|
|
---|
| 110 | opt_str += ",exclude_port=#{port}"
|
---|
| 111 | }
|
---|
| 112 | @exclude_port_func.each{ |port, funcs|
|
---|
| 113 | funcs.each{ |func|
|
---|
| 114 | opt_str += ",exclude_port_func=#{port}.#{func}"
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | # p "MrubyBridgeCelltypePlugin: opt_str=#{opt_str}"
|
---|
| 119 |
|
---|
| 120 | fn2 = "#{$gen}/tmp_MrubyBridgeCelltypePluginModule_#{@celltype.get_name}_#{@@count}.cdl"
|
---|
| 121 | f2 = File.open( fn2, "w" )
|
---|
| 122 | f2.print <<EOT
|
---|
| 123 | /* MrubyBridgeCelltypePluginModule: celltype=#{@celltype.get_name} */
|
---|
| 124 | generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "#{opt_str}" );
|
---|
| 125 | EOT
|
---|
| 126 | f2.close
|
---|
| 127 | dbgPrint "MrubyBridgeCelltypePluginModule new_cell: Import #{fn2}\n"
|
---|
| 128 | Import.new "#{fn2}"
|
---|
| 129 | @@count += 1
|
---|
| 130 | end
|
---|
| 131 |
|
---|
| 132 | ### 意味解析段階で呼び出されるメソッド ###
|
---|
| 133 | #=== CDL ファイルの生成
|
---|
| 134 | # typedef, signature, celltype, cell のコードを生成
|
---|
| 135 | # 重複して生成してはならない
|
---|
| 136 | # すでに生成されている場合は出力しないこと。
|
---|
| 137 | # もしくは同名の import により、重複を避けること。
|
---|
| 138 | #file:: FILE 生成するファイル
|
---|
| 139 | def gen_cdl_file file
|
---|
| 140 | # この段階で呼びだすと generate 文が呼び出される前のセルのみの出力となる
|
---|
| 141 |
|
---|
| 142 | # dbgPrint "MrubyBridgeCelltypePlugin: gen_cdl_file: #{@celltype.get_name}\n"
|
---|
| 143 | # file.print <<EOT
|
---|
| 144 | #/* MrubyBridgeCelltypePlugin: celltype=#{@celltype.get_name}
|
---|
| 145 | # *
|
---|
| 146 | # * cell's generate before celltype's generate
|
---|
| 147 | # */
|
---|
| 148 | #
|
---|
| 149 | #EOT
|
---|
| 150 | # @celltype.get_cell_list.each { |cell|
|
---|
| 151 | # @cell_list << cell
|
---|
| 152 | # # mikan option, region
|
---|
| 153 | # dbgPrint "MrubyBridgeCelltypePlugin: cell=#{cell.get_name}\n"
|
---|
| 154 | # file.print <<EOT
|
---|
| 155 | #generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "" );
|
---|
| 156 | #EOT
|
---|
| 157 | # }
|
---|
| 158 |
|
---|
| 159 | end
|
---|
| 160 |
|
---|
| 161 | #=== tCelltype_factory.h に挿入するコードを生成する
|
---|
| 162 | # file 以外の他のファイルにファクトリコードを生成してもよい
|
---|
| 163 | # セルタイププラグインが指定されたセルタイプのみ呼び出される
|
---|
| 164 | def gen_factory file
|
---|
| 165 | end
|
---|
| 166 |
|
---|
| 167 | def get_celltype
|
---|
| 168 | @celltype
|
---|
| 169 | end
|
---|
| 170 |
|
---|
| 171 | @@b_gen_post_code_called = false
|
---|
| 172 | #=== 後ろの CDL コードを生成
|
---|
| 173 | #プラグインの後ろの CDL コードを生成
|
---|
| 174 | #file:: File:
|
---|
| 175 | def self.gen_post_code( file )
|
---|
| 176 | dbgPrint "#{self.name}: gen_post_code_body\n"
|
---|
| 177 |
|
---|
| 178 | if @@b_gen_post_code_called == false then
|
---|
| 179 | @@b_gen_post_code_called = true
|
---|
| 180 | MrubyBridgeCellPlugin.gen_post_code_body file
|
---|
| 181 | end
|
---|
| 182 |
|
---|
| 183 | # この段階で生成すると、同じポストコードで出力される mruby の初期化コードに反映されない
|
---|
| 184 |
|
---|
| 185 | # # MrubyBridgeCelltypePlugin の生成する generate 文は、
|
---|
| 186 | # fn2 = "#{$gen}/tmp_MrubyBridgeCelltypePlugin_post.cdl"
|
---|
| 187 | # f2 = File.open( fn2, "w" )
|
---|
| 188 | # # 複数のプラグインの post_code が一つのファイルに含まれるため、以下のような見出しをつけること
|
---|
| 189 | # dbgPrint "MrubyBridgeCelltypePlugin: gen_post_code\n"
|
---|
| 190 | # f2.print "/* '#{self.name}' post code */\n"
|
---|
| 191 | # @@plugin_list.each{ |plugin|
|
---|
| 192 | # plugin.get_celltype.get_cell_list.each{ |cell|
|
---|
| 193 | # # mikan option, region
|
---|
| 194 | # f2.print <<EOT
|
---|
| 195 | #generate( MrubyBridgeCellPlugin, #{cell.get_namespace_path}, "" );
|
---|
| 196 | #EOT
|
---|
| 197 | # }
|
---|
| 198 | # }
|
---|
| 199 | # f2.close
|
---|
| 200 | # p Import
|
---|
| 201 | # Import.new "#{fn2}"
|
---|
| 202 | end
|
---|
| 203 |
|
---|
| 204 | #=== プラグイン引数
|
---|
| 205 |
|
---|
| 206 | #=== プラグイン引数 ignoreUnsigned
|
---|
| 207 | def set_ignoreUnsigned rhs
|
---|
| 208 | if rhs == "true" || rhs == nil then
|
---|
| 209 | @b_ignoreUnsigned = true
|
---|
| 210 | end
|
---|
| 211 | end
|
---|
| 212 |
|
---|
| 213 | def set_include_inner_cell rhs
|
---|
| 214 | if rhs == "true" || rhs == nil then
|
---|
| 215 | @include_inner_cell = true
|
---|
| 216 | end
|
---|
| 217 | end
|
---|
| 218 |
|
---|
| 219 | def set_exclude_cell rhs
|
---|
| 220 | cells = rhs.split ','
|
---|
| 221 | cells.each{ |rhs_cell|
|
---|
| 222 | rhs_cell.gsub!( /\s/, "" )
|
---|
| 223 | @exclude_cells << rhs_cell.to_sym
|
---|
| 224 | }
|
---|
| 225 | end
|
---|
| 226 | def set_exclude_port rhs
|
---|
| 227 | ports = rhs.split ','
|
---|
| 228 | ct = @cell.get_celltype
|
---|
| 229 | return if ct == nil # error case
|
---|
| 230 | ports.each{ |rhs_port|
|
---|
| 231 | obj = ct.find( rhs_port.to_sym )
|
---|
| 232 | if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
|
---|
| 233 | cdl_error( "MRB9999 exclude_port '$1' not found or not entry in celltype '$2'", rhs_port, ct.get_name )
|
---|
| 234 | else
|
---|
| 235 | # print "MRBBridgeCellPlugin: exclude #{rhs_port}\n"
|
---|
| 236 | @exclude_port << rhs_port
|
---|
| 237 | end
|
---|
| 238 | }
|
---|
| 239 | end
|
---|
| 240 |
|
---|
| 241 | #=== プラグイン引数 exclude_port_func
|
---|
| 242 | def set_exclude_port_func rhs
|
---|
| 243 | port_funcs = rhs.split ','
|
---|
| 244 | ct = @celltype
|
---|
| 245 | return if ct == nil # error case
|
---|
| 246 | port_funcs.each{ |rhs_port_func|
|
---|
| 247 | port_func = rhs_port_func.split( '.' )
|
---|
| 248 | if port_func.length != 2 then
|
---|
| 249 | cdl_error( "MRB9999 exclude_port_func: '$1' not in 'port.func' form", rhs_port_func )
|
---|
| 250 | end
|
---|
| 251 | obj = ct.find( port_func[0].to_sym )
|
---|
| 252 | if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
|
---|
| 253 | cdl_error( "MRB9999 exclude_port_func: port '$1' not found in celltype '$2'", rhs_port_func, ct.get_name )
|
---|
| 254 | else
|
---|
| 255 | signature = obj.get_signature
|
---|
| 256 | next if signature == nil # error case
|
---|
| 257 | if signature.get_function_head port_func[1].to_sym
|
---|
| 258 | # print "MRBBridgeCellPlugin: #{port_func[0]}.#{port_func[1]} exclude\n"
|
---|
| 259 | if @exclude_port_func[ port_func[0] ] then
|
---|
| 260 | @exclude_port_func[ port_func[0] ] << port_func[1]
|
---|
| 261 | else
|
---|
| 262 | @exclude_port_func[ port_func[0] ] = [ port_func[1] ]
|
---|
| 263 | end
|
---|
| 264 | else
|
---|
| 265 | cdl_error( "MRB9999 include_port_func: func '$1' not found in port '$2' celltype $3",
|
---|
| 266 | port_func[1], port_func[0], ct.get_name )
|
---|
| 267 | end
|
---|
| 268 | end
|
---|
| 269 | }
|
---|
| 270 | end
|
---|
| 271 |
|
---|
| 272 | #=== プラグイン引数 auto_exclude
|
---|
| 273 | def set_auto_exclude rhs
|
---|
| 274 | # print "MrubyBridgeCellPlugin: auto_exclude=#{rhs}\n"
|
---|
| 275 | if rhs == "false" then
|
---|
| 276 | @b_auto_exclude = false
|
---|
| 277 | elsif rhs == "true" then
|
---|
| 278 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
| 279 | else
|
---|
| 280 | cdl_warning( "MRB9999 auto_exclude: unknown rhs value ignored. specify true or false" )
|
---|
| 281 | end
|
---|
| 282 | end
|
---|
| 283 | end
|
---|
| 284 |
|
---|