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 | # ä¸è¨èä½æ¨©è
|
---|
9 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
10 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
11 | # å¤ã»åé
|
---|
12 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
13 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
14 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
15 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
16 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
17 | # ç¨ã§ããå½¢ã§åé
|
---|
18 | å¸ããå ´åã«ã¯ï¼åé
|
---|
19 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
20 | # è
|
---|
21 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
22 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
23 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
24 | # ç¨ã§ããªãå½¢ã§åé
|
---|
25 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
26 | # ã¨ï¼
|
---|
27 | # (a) åé
|
---|
28 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
29 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
30 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
31 | # (b) åé
|
---|
32 | å¸ã®å½¢æ
|
---|
33 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
34 | # å ±åãããã¨ï¼
|
---|
35 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
36 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
37 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
38 | 責ãããã¨ï¼
|
---|
39 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
40 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
42 | # å
|
---|
43 | 責ãããã¨ï¼
|
---|
44 | #
|
---|
45 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
46 | ã
|
---|
47 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
48 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
49 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
50 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
51 | #
|
---|
52 | # $Id$
|
---|
53 | #++
|
---|
54 |
|
---|
55 | #== celltype ãã©ã°ã¤ã³ã®å
|
---|
56 | ±éã®è¦ªã¯ã©ã¹
|
---|
57 | class MrubyBridgeCellPlugin < CellPlugin
|
---|
58 |
|
---|
59 | # ãã©ã°ã¤ã³å¼æ°å => Proc
|
---|
60 | MrubyBridgePluginArgProc = {
|
---|
61 | "ignoreUnsigned" => Proc.new { |obj,rhs| obj.set_ignoreUnsigned rhs },
|
---|
62 | "exclude_port" => Proc.new { |obj,rhs| obj.set_exclude_port rhs },
|
---|
63 | "exclude_port_func" => Proc.new { |obj,rhs| obj.set_exclude_port_func rhs },
|
---|
64 | "auto_exclude" => Proc.new { |obj,rhs| obj.set_auto_exclude rhs },
|
---|
65 | }
|
---|
66 | @@b_gen_post_code_by_dependent = false # true if gen_post_code is called by MrubyBridgeCelltypePlugin
|
---|
67 | @@cell_list = {} # gen_cdl_file'ed list to avoid duplicate generation
|
---|
68 | @@signature_list = {}
|
---|
69 |
|
---|
70 | require_tecsgen_lib( "MrubyBridgeSignaturePlugin.rb" )
|
---|
71 |
|
---|
72 | #@exclude_port::[ String(port_name) ] :
|
---|
73 | #@exclude_port_func::{ [ String(port_name) ] => [ String(func_name) ] } :
|
---|
74 | #@port_list::{ String(port_name) => String(include/exclude=func_name) } : all included port and opt_string
|
---|
75 |
|
---|
76 | #=== CellPlugin# initialize
|
---|
77 | #cell:: Cell ã»ã«ï¼ã¤ã³ã¹ã¿ã³ã¹ï¼
|
---|
78 | # ãã®ã¡ã½ããã¯ãã»ã«ã®æ§æ解æãçµãã£ãã¨ããã§å¼ã³åºããã
|
---|
79 | # ãã®æ®µéã§ã¯æå³è§£æãçµãã£ã¦ããªã
|
---|
80 | def initialize( cell, option )
|
---|
81 | dbgPrint " #{self.class.name}: initialzie=#{cell.get_name} option=#{option}\n"
|
---|
82 | super
|
---|
83 | @cell = cell
|
---|
84 |
|
---|
85 | # option
|
---|
86 | @b_ignoreUnsigned = false
|
---|
87 | @exclude_port = []
|
---|
88 | @exclude_port_func = {}
|
---|
89 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
90 | MrubyBridgeSignaturePlugin.set_gen_post_code_by_dependent
|
---|
91 |
|
---|
92 | @plugin_arg_str = CDLString.remove_dquote option
|
---|
93 | # @plugin_arg_str = option.gsub( /\A"(.*)/, '\1' ) # åå¾ã® "" ãåãé¤ã
|
---|
94 | # @plugin_arg_str.sub!( /(.*)"\z/, '\1' )
|
---|
95 | @plugin_arg_list = {}
|
---|
96 | dbgPrint "#{self.class.name}: initialzie: #{cell.get_name}\n"
|
---|
97 | @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc
|
---|
98 | parse_plugin_arg
|
---|
99 |
|
---|
100 | @port_list = {} # set @port_list before return
|
---|
101 | ct = @cell.get_celltype
|
---|
102 | return if ct == nil # error case
|
---|
103 |
|
---|
104 | port_list = ct.get_port_list
|
---|
105 | if @exclude_port.length > 0 then
|
---|
106 | # ãã®å®è£
|
---|
107 | ã§ã¯ãåå¨ããªã port ãæå®ããã¦ããã§ãã¯ã§ããªã
|
---|
108 | # print "MRBBridgeCellPlugin: exclude list\n"
|
---|
109 | port_list.each{ |port|
|
---|
110 | if ! @exclude_port.include?( port.get_name.to_s ) then
|
---|
111 | # print "MRBBridgeCellPlugin: #{port.get_name} included\n"
|
---|
112 | @port_list[ port ] = ""
|
---|
113 | else
|
---|
114 | # print "MRBBridgeCellPlugin: #{port.get_name} excluded\n"
|
---|
115 | end
|
---|
116 | }
|
---|
117 | else
|
---|
118 | port_list.each{ |port|
|
---|
119 | @port_list[ port ] = ""
|
---|
120 | }
|
---|
121 | end
|
---|
122 |
|
---|
123 | if @exclude_port_func.length > 0 then
|
---|
124 | @port_list.each{ |port, opt_str|
|
---|
125 | delim = ""
|
---|
126 | if @exclude_port_func.include?( port.get_name.to_s ) then
|
---|
127 | @exclude_port_func[ port.get_name.to_s ].each{ |func_name|
|
---|
128 | opt_str += delim + "exclude=" + func_name
|
---|
129 | delim = ","
|
---|
130 | }
|
---|
131 | end
|
---|
132 | @port_list[ port ] = opt_str
|
---|
133 | }
|
---|
134 | end
|
---|
135 | end
|
---|
136 |
|
---|
137 | def gen_cdl_file file
|
---|
138 | dbgPrint "#{self.class.name}: gen_cdl_file: #{@cell.get_name}\n"
|
---|
139 |
|
---|
140 | file.print <<EOT
|
---|
141 | /* MrubyBridgeCellPlugin: generate for cell=#{@cell.get_name} */
|
---|
142 | EOT
|
---|
143 |
|
---|
144 | if @@cell_list[ @cell ] then
|
---|
145 | file.print <<EOT
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * generate for #{@cell.get_name} duplicate and ignored.
|
---|
149 | * This might comes from generate for celltype.
|
---|
150 | */
|
---|
151 | EOT
|
---|
152 | cdl_info( "MrubyBridgeCellPlugin: generate duplicate for cell '$1'", @cell.get_name )
|
---|
153 | return
|
---|
154 | end
|
---|
155 | @@cell_list[ @cell ] = @cell
|
---|
156 |
|
---|
157 | @port_list.each{ |port, opt_str|
|
---|
158 | next if port.get_signature == nil
|
---|
159 |
|
---|
160 | case port.get_signature.get_context
|
---|
161 | when "task", "any"
|
---|
162 | else
|
---|
163 | next
|
---|
164 | end
|
---|
165 |
|
---|
166 | if port.get_port_type == :ENTRY then
|
---|
167 | 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"
|
---|
168 | if @@signature_list[ port.get_signature ] == nil then
|
---|
169 | opt_str = "ignoreUnsigned=#{@b_ignoreUnsigned}, auto_exclude=#{@b_auto_exclude}, " + opt_str
|
---|
170 | # p "opt_str=#{opt_str}"
|
---|
171 |
|
---|
172 | file.print <<EOT
|
---|
173 |
|
---|
174 | /* cell.port=#{@cell.get_name}.#{port.get_name} */
|
---|
175 | generate( MrubyBridgePlugin, #{port.get_signature.get_namespace_path}, "#{opt_str}" );
|
---|
176 | EOT
|
---|
177 | @@signature_list[ port.get_signature ] = true
|
---|
178 | end
|
---|
179 |
|
---|
180 | # mikan option
|
---|
181 | nest = @cell.get_region.gen_region_str_pre file
|
---|
182 | nest_str = " " * nest
|
---|
183 |
|
---|
184 | file.print <<EOT
|
---|
185 | #{nest_str}/* BridgeCell */
|
---|
186 | #{nest_str}cell nMruby::t#{port.get_signature.get_name} #{@cell.get_name}#{port.get_name}Bridge {
|
---|
187 | #{nest_str} cTECS = #{@cell.get_namespace_path}.#{port.get_name};
|
---|
188 | #{nest_str}};
|
---|
189 | EOT
|
---|
190 | @cell.get_region.gen_region_str_post file
|
---|
191 | end
|
---|
192 | }
|
---|
193 | end
|
---|
194 |
|
---|
195 | #=== å¾ãã® CDL ã³ã¼ããçæ
|
---|
196 | #ãã©ã°ã¤ã³ã®å¾ãã® CDL ã³ã¼ããçæ
|
---|
197 | #file:: File:
|
---|
198 | def self.gen_post_code( file )
|
---|
199 | dbgPrint "#{self.name}: gen_post_code\n"
|
---|
200 | if ! @@b_gen_post_code_by_dependent then
|
---|
201 | gen_post_code_body file
|
---|
202 | end
|
---|
203 | end
|
---|
204 |
|
---|
205 | def self.set_gen_post_code_by_dependent # by MrubyBridgeCelltypePlugin
|
---|
206 | dbgPrint "#{self.name}: set_gen_post_code_by_dependent\n"
|
---|
207 | @@b_gen_post_code_by_dependent = true
|
---|
208 | MrubyBridgeSignaturePlugin.set_gen_post_code_by_dependent
|
---|
209 | end
|
---|
210 |
|
---|
211 | def self.gen_post_code_body file
|
---|
212 | # è¤æ°ã®ãã©ã°ã¤ã³ã® post_code ãä¸ã¤ã®ãã¡ã¤ã«ã«å«ã¾ããããã以ä¸ã®ãããªè¦åºããã¤ãããã¨
|
---|
213 | # file.print "/* '#{self.class.name}' post code */\n"
|
---|
214 | dbgPrint "#{self.name}: gen_post_code_body\n"
|
---|
215 | MrubyBridgeSignaturePlugin.gen_post_code_body file
|
---|
216 | end
|
---|
217 |
|
---|
218 | #=== ãã©ã°ã¤ã³å¼æ° ignoreUnsigned
|
---|
219 | def set_ignoreUnsigned rhs
|
---|
220 | if rhs == "true" || rhs == nil then
|
---|
221 | @b_ignoreUnsigned = true
|
---|
222 | end
|
---|
223 | end
|
---|
224 |
|
---|
225 | #=== ãã©ã°ã¤ã³å¼æ° exclude_port
|
---|
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 = @cell.get_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, 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 exclude_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 | #=== ãã©ã°ã¤ã³å¼æ° auto_exclude
|
---|
272 | def set_auto_exclude rhs
|
---|
273 | # print "MrubyBridgeCellPlugin: auto_exclude=#{rhs}\n"
|
---|
274 | if rhs == "false" then
|
---|
275 | @b_auto_exclude = false
|
---|
276 | elsif rhs == "true" then
|
---|
277 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
278 | else
|
---|
279 | cdl_warning( "MRB9999 auto_exclude: unknown rhs value ignored. specify true or false" )
|
---|
280 | end
|
---|
281 | end
|
---|
282 |
|
---|
283 | end
|
---|
284 |
|
---|