[374] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | #
|
---|
| 3 | # TECS Generator
|
---|
| 4 | # Generator for TOPPERS Embedded Component System
|
---|
| 5 | #
|
---|
| 6 | # Copyright (C) 2008-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 | #
|
---|
| 37 | # $Id$
|
---|
| 38 | #++
|
---|
| 39 |
|
---|
| 40 | #== celltype プラグインの共通の親クラス
|
---|
| 41 | class MrubyBridgeCellPlugin < CellPlugin
|
---|
| 42 |
|
---|
| 43 | # プラグイン引数名 => Proc
|
---|
| 44 | MrubyBridgePluginArgProc = {
|
---|
| 45 | "ignoreUnsigned" => Proc.new { |obj,rhs| obj.set_ignoreUnsigned rhs },
|
---|
| 46 | "exclude_port" => Proc.new { |obj,rhs| obj.set_exclude_port rhs },
|
---|
| 47 | "exclude_port_func" => Proc.new { |obj,rhs| obj.set_exclude_port_func rhs },
|
---|
| 48 | "auto_exclude" => Proc.new { |obj,rhs| obj.set_auto_exclude rhs },
|
---|
| 49 | }
|
---|
| 50 | @@b_gen_post_code_by_dependent = false # true if gen_post_code is called by MrubyBridgeCelltypePlugin
|
---|
| 51 | @@cell_list = {} # gen_cdl_file'ed list to avoid duplicate generation
|
---|
| 52 | @@signature_list = {}
|
---|
| 53 |
|
---|
| 54 | require_tecsgen_lib( "MrubyBridgeSignaturePlugin.rb" )
|
---|
| 55 |
|
---|
| 56 | #@exclude_port::[ String(port_name) ] :
|
---|
| 57 | #@exclude_port_func::{ [ String(port_name) ] => [ String(func_name) ] } :
|
---|
| 58 | #@port_list::{ String(port_name) => String(include/exclude=func_name) } : all included port and opt_string
|
---|
| 59 |
|
---|
| 60 | #=== CellPlugin# initialize
|
---|
| 61 | #cell:: Cell セル(インスタンス)
|
---|
| 62 | # このメソッドは、セルの構文解析が終わったところで呼び出される
|
---|
| 63 | # この段階では意味解析が終わっていない
|
---|
| 64 | def initialize( cell, option )
|
---|
| 65 | dbgPrint " #{self.class.name}: initialzie=#{cell.get_name} option=#{option}\n"
|
---|
| 66 | super
|
---|
| 67 | @cell = cell
|
---|
| 68 |
|
---|
| 69 | # option
|
---|
| 70 | @b_ignoreUnsigned = false
|
---|
| 71 | @exclude_port = []
|
---|
| 72 | @exclude_port_func = {}
|
---|
| 73 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
| 74 | MrubyBridgeSignaturePlugin.set_gen_post_code_by_dependent
|
---|
| 75 |
|
---|
| 76 | @plugin_arg_str = CDLString.remove_dquote option
|
---|
| 77 | # @plugin_arg_str = option.gsub( /\A"(.*)/, '\1' ) # 前後の "" を取り除く
|
---|
| 78 | # @plugin_arg_str.sub!( /(.*)"\z/, '\1' )
|
---|
| 79 | @plugin_arg_list = {}
|
---|
| 80 | dbgPrint "#{self.class.name}: initialzie: #{cell.get_name}\n"
|
---|
| 81 | @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc
|
---|
| 82 | parse_plugin_arg
|
---|
| 83 |
|
---|
| 84 | @port_list = {} # set @port_list before return
|
---|
| 85 | ct = @cell.get_celltype
|
---|
| 86 | return if ct == nil # error case
|
---|
| 87 |
|
---|
| 88 | port_list = ct.get_port_list
|
---|
| 89 | if @exclude_port.length > 0 then
|
---|
| 90 | # この実装では、存在しない port を指定されてもチェックできない
|
---|
| 91 | # print "MRBBridgeCellPlugin: exclude list\n"
|
---|
| 92 | port_list.each{ |port|
|
---|
| 93 | if ! @exclude_port.include?( port.get_name.to_s ) then
|
---|
| 94 | # print "MRBBridgeCellPlugin: #{port.get_name} included\n"
|
---|
| 95 | @port_list[ port ] = ""
|
---|
| 96 | else
|
---|
| 97 | # print "MRBBridgeCellPlugin: #{port.get_name} excluded\n"
|
---|
| 98 | end
|
---|
| 99 | }
|
---|
| 100 | else
|
---|
| 101 | port_list.each{ |port|
|
---|
| 102 | @port_list[ port ] = ""
|
---|
| 103 | }
|
---|
| 104 | end
|
---|
| 105 |
|
---|
| 106 | if @exclude_port_func.length > 0 then
|
---|
| 107 | @port_list.each{ |port, opt_str|
|
---|
| 108 | delim = ""
|
---|
| 109 | if @exclude_port_func.include?( port.get_name.to_s ) then
|
---|
| 110 | @exclude_port_func[ port.get_name.to_s ].each{ |func_name|
|
---|
| 111 | opt_str += delim + "exclude=" + func_name
|
---|
| 112 | delim = ","
|
---|
| 113 | }
|
---|
| 114 | end
|
---|
| 115 | @port_list[ port ] = opt_str
|
---|
| 116 | }
|
---|
| 117 | end
|
---|
| 118 | end
|
---|
| 119 |
|
---|
| 120 | def gen_cdl_file file
|
---|
| 121 | dbgPrint "#{self.class.name}: gen_cdl_file: #{@cell.get_name}\n"
|
---|
| 122 |
|
---|
| 123 | file.print <<EOT
|
---|
| 124 | /* MrubyBridgeCellPlugin: generate for cell=#{@cell.get_name} */
|
---|
| 125 | EOT
|
---|
| 126 |
|
---|
| 127 | if @@cell_list[ @cell ] then
|
---|
| 128 | file.print <<EOT
|
---|
| 129 |
|
---|
| 130 | /*
|
---|
| 131 | * generate for #{@cell.get_name} duplicate and ignored.
|
---|
| 132 | * This might comes from generate for celltype.
|
---|
| 133 | */
|
---|
| 134 | EOT
|
---|
| 135 | cdl_info( "MrubyBridgeCellPlugin: generate duplicate for cell '$1'", @cell.get_name )
|
---|
| 136 | return
|
---|
| 137 | end
|
---|
| 138 | @@cell_list[ @cell ] = @cell
|
---|
| 139 |
|
---|
| 140 | @port_list.each{ |port, opt_str|
|
---|
| 141 | next if port.get_signature == nil
|
---|
| 142 |
|
---|
| 143 | case port.get_signature.get_context
|
---|
| 144 | when "task", "any"
|
---|
| 145 | else
|
---|
| 146 | next
|
---|
| 147 | end
|
---|
| 148 |
|
---|
| 149 | if port.get_port_type == :ENTRY then
|
---|
| 150 | print " MrubyBridgeCellPlugin: [cell.port] #{@cell.get_name}.#{port.get_name} => [mruby instance] TECS::T#{port.get_signature.get_name}.new( '#{@cell.get_name}#{port.get_name}Bridge' ) \n"
|
---|
| 151 | if @@signature_list[ port.get_signature ] == nil then
|
---|
| 152 | opt_str = "ignoreUnsigned=#{@b_ignoreUnsigned}, auto_exclude=#{@b_auto_exclude}, " + opt_str
|
---|
| 153 | # p "opt_str=#{opt_str}"
|
---|
| 154 |
|
---|
| 155 | file.print <<EOT
|
---|
| 156 |
|
---|
| 157 | /* cell.port=#{@cell.get_name}.#{port.get_name} */
|
---|
| 158 | generate( MrubyBridgePlugin, #{port.get_signature.get_namespace_path}, "#{opt_str}" );
|
---|
| 159 | EOT
|
---|
| 160 | @@signature_list[ port.get_signature ] = true
|
---|
| 161 | end
|
---|
| 162 |
|
---|
| 163 | # mikan option
|
---|
| 164 | nest = @cell.get_region.gen_region_str_pre file
|
---|
| 165 | nest_str = " " * nest
|
---|
| 166 |
|
---|
| 167 | file.print <<EOT
|
---|
| 168 | #{nest_str}/* BridgeCell */
|
---|
| 169 | #{nest_str}cell nMruby::t#{port.get_signature.get_name} #{@cell.get_name}#{port.get_name}Bridge {
|
---|
| 170 | #{nest_str} cTECS = #{@cell.get_namespace_path}.#{port.get_name};
|
---|
| 171 | #{nest_str}};
|
---|
| 172 | EOT
|
---|
| 173 | @cell.get_region.gen_region_str_post file
|
---|
| 174 | end
|
---|
| 175 | }
|
---|
| 176 | end
|
---|
| 177 |
|
---|
| 178 | #=== 後ろの CDL コードを生成
|
---|
| 179 | #プラグインの後ろの CDL コードを生成
|
---|
| 180 | #file:: File:
|
---|
| 181 | def self.gen_post_code( file )
|
---|
| 182 | dbgPrint "#{self.name}: gen_post_code\n"
|
---|
| 183 | if ! @@b_gen_post_code_by_dependent then
|
---|
| 184 | gen_post_code_body file
|
---|
| 185 | end
|
---|
| 186 | end
|
---|
| 187 |
|
---|
| 188 | def self.set_gen_post_code_by_dependent # by MrubyBridgeCelltypePlugin
|
---|
| 189 | dbgPrint "#{self.name}: set_gen_post_code_by_dependent\n"
|
---|
| 190 | @@b_gen_post_code_by_dependent = true
|
---|
| 191 | MrubyBridgeSignaturePlugin.set_gen_post_code_by_dependent
|
---|
| 192 | end
|
---|
| 193 |
|
---|
| 194 | def self.gen_post_code_body file
|
---|
| 195 | # 複数のプラグインの post_code が一つのファイルに含まれるため、以下のような見出しをつけること
|
---|
| 196 | # file.print "/* '#{self.class.name}' post code */\n"
|
---|
| 197 | dbgPrint "#{self.name}: gen_post_code_body\n"
|
---|
| 198 | MrubyBridgeSignaturePlugin.gen_post_code_body file
|
---|
| 199 | end
|
---|
| 200 |
|
---|
| 201 | #=== プラグイン引数 ignoreUnsigned
|
---|
| 202 | def set_ignoreUnsigned rhs
|
---|
| 203 | if rhs == "true" || rhs == nil then
|
---|
| 204 | @b_ignoreUnsigned = true
|
---|
| 205 | end
|
---|
| 206 | end
|
---|
| 207 |
|
---|
| 208 | #=== プラグイン引数 exclude_port
|
---|
| 209 | def set_exclude_port rhs
|
---|
| 210 | ports = rhs.split ','
|
---|
| 211 | ct = @cell.get_celltype
|
---|
| 212 | return if ct == nil # error case
|
---|
| 213 | ports.each{ |rhs_port|
|
---|
| 214 | obj = ct.find( rhs_port.to_sym )
|
---|
| 215 | if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
|
---|
| 216 | cdl_error( "MRB9999 exclude_port '$1' not found or not entry in celltype '$2'", rhs_port, ct.get_name )
|
---|
| 217 | else
|
---|
| 218 | # print "MRBBridgeCellPlugin: exclude #{rhs_port}\n"
|
---|
| 219 | @exclude_port << rhs_port
|
---|
| 220 | end
|
---|
| 221 | }
|
---|
| 222 | end
|
---|
| 223 |
|
---|
| 224 | #=== プラグイン引数 exclude_port_func
|
---|
| 225 | def set_exclude_port_func rhs
|
---|
| 226 | port_funcs = rhs.split ','
|
---|
| 227 | ct = @cell.get_celltype
|
---|
| 228 | return if ct == nil # error case
|
---|
| 229 | port_funcs.each{ |rhs_port_func|
|
---|
| 230 | port_func = rhs_port_func.split '.'
|
---|
| 231 | if port_func.length != 2 then
|
---|
| 232 | cdl_error( "MRB9999 exclude_port_func: '$1' not in 'port.func' form", rhs_port_func )
|
---|
| 233 | end
|
---|
| 234 | obj = ct.find( port_func[0].to_sym )
|
---|
| 235 | if( ( ! obj.instance_of? Port ) || obj.get_port_type != :ENTRY ) then
|
---|
| 236 | cdl_error( "MRB9999 exclude_port_func: port '$1' not found in celltype '$2'", rhs_port, ct.get_name )
|
---|
| 237 | else
|
---|
| 238 | signature = obj.get_signature
|
---|
| 239 | next if signature == nil # error case
|
---|
| 240 | if signature.get_function_head port_func[1].to_sym
|
---|
| 241 | # print "MRBBridgeCellPlugin: #{port_func[0]}.#{port_func[1]} exclude\n"
|
---|
| 242 | if @exclude_port_func[ port_func[0] ] then
|
---|
| 243 | @exclude_port_func[ port_func[0] ] << port_func[1]
|
---|
| 244 | else
|
---|
| 245 | @exclude_port_func[ port_func[0] ] = [ port_func[1] ]
|
---|
| 246 | end
|
---|
| 247 | else
|
---|
| 248 | cdl_error( "MRB9999 exclude_port_func: func '$1' not found in port '$2' celltype $3",
|
---|
| 249 | port_func[1], port_func[0], ct.get_name )
|
---|
| 250 | end
|
---|
| 251 | end
|
---|
| 252 | }
|
---|
| 253 | end
|
---|
| 254 | #=== プラグイン引数 auto_exclude
|
---|
| 255 | def set_auto_exclude rhs
|
---|
| 256 | # print "MrubyBridgeCellPlugin: auto_exclude=#{rhs}\n"
|
---|
| 257 | if rhs == "false" then
|
---|
| 258 | @b_auto_exclude = false
|
---|
| 259 | elsif rhs == "true" then
|
---|
| 260 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
| 261 | else
|
---|
| 262 | cdl_warning( "MRB9999 auto_exclude: unknown rhs value ignored. specify true or false" )
|
---|
| 263 | end
|
---|
| 264 | end
|
---|
| 265 |
|
---|
| 266 | end
|
---|
| 267 |
|
---|