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 | #= TOOL_INFO class
|
---|
56 | # The syntax of the contents of __tool_info__ is same as JSON.
|
---|
57 | # Home made schema is used to validate the contents of __tool_info__.
|
---|
58 | # the schema is not defiened well. see saveload.rb for example of the schema.
|
---|
59 | #
|
---|
60 | class TOOL_INFO
|
---|
61 |
|
---|
62 | # tool_info
|
---|
63 | @@tool_info = { }
|
---|
64 |
|
---|
65 | # tool_info schema for tecsgen
|
---|
66 | @@TECSGEN_schema = {
|
---|
67 | :tecsgen => { # require
|
---|
68 | :base_dir => [ :string ], # dir where the cde created initially
|
---|
69 | :direct_import => [ :string ], # .cdl (sometimes .cde) specified in argments
|
---|
70 | :import_path => [ :string ], # -I of tecsgen
|
---|
71 | :define_macro => [ :string ], # -D of tecsgen
|
---|
72 | :tecscde_version=> :string, # TECSCDE version
|
---|
73 | :cde_format_version=> :string, # CDE format version
|
---|
74 | :save_date => :string, # last save date & time
|
---|
75 | },
|
---|
76 | :__tecsgen => { # optioanl
|
---|
77 | :cpp => :string # -c or TECS_CPP environment variable
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | def initialize( name, val )
|
---|
82 | @@tool_info[name] = val
|
---|
83 |
|
---|
84 | # __tool_info__( "tecsgen" ): validate & reflect immediately
|
---|
85 | p "tool_info: tecsgen #{name}"
|
---|
86 | if name == :tecsgen then
|
---|
87 | set_tecsgen_tool_info
|
---|
88 | end
|
---|
89 | end
|
---|
90 |
|
---|
91 | def self.get_tool_info name
|
---|
92 | @@tool_info[ name ]
|
---|
93 | end
|
---|
94 |
|
---|
95 | #=== TOOL_INFO#set_tecsgen_tool_info
|
---|
96 | # __tool_info__( "tecsgen" )
|
---|
97 | def set_tecsgen_tool_info
|
---|
98 | validator = TOOL_INFO::VALIDATOR.new( :tecsgen, @@TECSGEN_schema )
|
---|
99 | if validator.validate || $b_force_apply_tool_info
|
---|
100 | info = TOOL_INFO.get_tool_info( :tecsgen )
|
---|
101 | (info[ :base_dir ]).each{ |bd|
|
---|
102 | if ! $base_dir.include? bd
|
---|
103 | $base_dir[ bd ] = true
|
---|
104 | end
|
---|
105 | }
|
---|
106 |
|
---|
107 | info[ :import_path ].each{ |path|
|
---|
108 | if ! $import_path.include?( path )
|
---|
109 | $import_path << path
|
---|
110 | end
|
---|
111 | }
|
---|
112 |
|
---|
113 | info[ :define_macro ].each{ |define|
|
---|
114 | if ! $define.include?( define )
|
---|
115 | $define << define
|
---|
116 | end
|
---|
117 | }
|
---|
118 | if info[ :cpp ]
|
---|
119 | if ! $b_cpp_specified
|
---|
120 | $cpp = info[ :cpp ]
|
---|
121 | $b_cpp_specified = true
|
---|
122 | end
|
---|
123 | end
|
---|
124 |
|
---|
125 | info[ :direct_import ] && info[ :direct_import ].each{ |import|
|
---|
126 | Import.new( import, false, false )
|
---|
127 | }
|
---|
128 | end
|
---|
129 | end
|
---|
130 |
|
---|
131 | #== simple JSON validator
|
---|
132 | # this validator use simple schema.
|
---|
133 | # array length cannot be checked.
|
---|
134 | # you have to check array length in your code, if necessary.
|
---|
135 | class VALIDATOR
|
---|
136 |
|
---|
137 | #@b_ok::Bool
|
---|
138 |
|
---|
139 | def error( msg )
|
---|
140 | STDERR.print( "__tool_info__: " + msg )
|
---|
141 | @b_ok = false
|
---|
142 | end
|
---|
143 |
|
---|
144 | def initialize name, schema
|
---|
145 | @name = name
|
---|
146 | @schema = schema
|
---|
147 | @b_ok = true
|
---|
148 | end
|
---|
149 |
|
---|
150 | #=== VALIDATOR#validate
|
---|
151 | def validate
|
---|
152 | info = TOOL_INFO.get_tool_info @name
|
---|
153 | if info == nil
|
---|
154 | error( "\"#{@name}\" not found\n" )
|
---|
155 | return @b_ok
|
---|
156 | end
|
---|
157 | validate_object info, @name, @name
|
---|
158 | return @b_ok
|
---|
159 | end
|
---|
160 |
|
---|
161 | def validate_object( object, require_type, path )
|
---|
162 | obj_type = @schema[ require_type ]
|
---|
163 | dbgPrint "validate_object: #{path} object=#{obj_type[ :type ]} required=#{object[:type]}\n"
|
---|
164 |
|
---|
165 | obj_type.each{ |name, val_type|
|
---|
166 | val = object[name]
|
---|
167 | path2 = path.to_s + "." + name.to_s
|
---|
168 | if val == nil
|
---|
169 | error( "#{path}: required property not found '#{name}'\n" )
|
---|
170 | next
|
---|
171 | end
|
---|
172 | if val_type.kind_of? Array
|
---|
173 | validate_array_member val, val_type, path2
|
---|
174 | else
|
---|
175 | validate_types val, val_type, path2
|
---|
176 | end
|
---|
177 | }
|
---|
178 |
|
---|
179 | optional = @schema[ ("__" + require_type.to_s).to_sym ]
|
---|
180 | if optional
|
---|
181 | dbgPrint "#{require_type.to_s} has optional\n"
|
---|
182 |
|
---|
183 | optional.each{ |name, val_type|
|
---|
184 | val = object[name]
|
---|
185 | path2 = path.to_s + "." + name.to_s
|
---|
186 | if val == nil
|
---|
187 | # no need to occur error
|
---|
188 | # error( "#{path}: required property not found '#{name}'\n" )
|
---|
189 | next
|
---|
190 | end
|
---|
191 | if val_type.kind_of? Array
|
---|
192 | validate_array_member val, val_type, path2
|
---|
193 | else
|
---|
194 | validate_types val, val_type, path2
|
---|
195 | end
|
---|
196 | }
|
---|
197 | end
|
---|
198 |
|
---|
199 | end
|
---|
200 |
|
---|
201 | def validate_array_member array, val_types, path
|
---|
202 | if ! array.kind_of? Array
|
---|
203 | error( "#{path2}: array required as value\n" )
|
---|
204 | return
|
---|
205 | end
|
---|
206 | index=0
|
---|
207 | array.each{ |member|
|
---|
208 | type = get_object_type member
|
---|
209 | i = val_types.find_index type
|
---|
210 | if i == nil
|
---|
211 | if type == :integer
|
---|
212 | i = val_types.find_index :number
|
---|
213 | end
|
---|
214 | end
|
---|
215 | if i == nil
|
---|
216 | error( "#{path}: array member type mismatch, #{type} for #{val_types}\n" )
|
---|
217 | next
|
---|
218 | end
|
---|
219 | val_type = val_types[ i ]
|
---|
220 | validate_types member, val_type, (path.to_s + '[' + index.to_s + '].')
|
---|
221 | index += 1
|
---|
222 | }
|
---|
223 | end
|
---|
224 |
|
---|
225 | #=== TOOL_INFO::VALIDATOR#validate_types
|
---|
226 | #obj::Object (Integer, Floating, String, Hash)
|
---|
227 | #val_type::Symbol : required object type
|
---|
228 | def validate_types obj, val_type, path
|
---|
229 | type = get_object_type obj
|
---|
230 | case val_type
|
---|
231 | when :integer
|
---|
232 | if type == :integer
|
---|
233 | return
|
---|
234 | end
|
---|
235 | when :number
|
---|
236 | if type == :integer || type == :number
|
---|
237 | return
|
---|
238 | end
|
---|
239 | when :string
|
---|
240 | if type == :string
|
---|
241 | return
|
---|
242 | end
|
---|
243 | # when :nil # mikan
|
---|
244 | # when :bool # mikan
|
---|
245 | else # object or fixed string
|
---|
246 | if val_type.kind_of? String
|
---|
247 | # val is specified by String
|
---|
248 | if type == :string
|
---|
249 | if obj == val_type
|
---|
250 | return
|
---|
251 | end
|
---|
252 | end
|
---|
253 | else
|
---|
254 | if type.to_sym == val_type
|
---|
255 | validate_object( obj, val_type, path + val_type.to_s )
|
---|
256 | return
|
---|
257 | end
|
---|
258 | end
|
---|
259 | end
|
---|
260 | error( "#{path}: type mismatch, #{type} for #{val_type}\n" )
|
---|
261 | end
|
---|
262 |
|
---|
263 | def get_object_type obj
|
---|
264 | # p "#{obj.class} #{obj.to_s}"
|
---|
265 | if obj.kind_of? Integer
|
---|
266 | return :integer
|
---|
267 | elsif obj.kind_of? Float
|
---|
268 | return :number
|
---|
269 | elsif obj.kind_of? String
|
---|
270 | return :string
|
---|
271 | elsif obj.kind_of? Hash
|
---|
272 | return obj[ :type ].to_sym
|
---|
273 | end
|
---|
274 | return nil
|
---|
275 | end
|
---|
276 | end
|
---|
277 |
|
---|
278 | end
|
---|
279 |
|
---|
280 |
|
---|
281 | #---------- obsolete -------#
|
---|
282 |
|
---|
283 | #--- TOOL_INFO replaced location information ---#
|
---|
284 |
|
---|
285 | class TECSGEN
|
---|
286 |
|
---|
287 | #------ manupulate location information --------#
|
---|
288 | def self.new_cell_location cell_location
|
---|
289 | @@current_tecsgen.new_cell_location cell_location
|
---|
290 | end
|
---|
291 | def new_cell_location cell_location
|
---|
292 | @cell_location_list << cell_location
|
---|
293 | end
|
---|
294 | def get_cell_location_list
|
---|
295 | @cell_location_list
|
---|
296 | end
|
---|
297 |
|
---|
298 | def self.new_join_location join_location
|
---|
299 | @@current_tecsgen.new_join_location join_location
|
---|
300 | end
|
---|
301 | def new_join_location join_location
|
---|
302 | @join_location_list << join_location
|
---|
303 | end
|
---|
304 | def get_join_location_list
|
---|
305 | @join_location_list
|
---|
306 | end
|
---|
307 |
|
---|
308 | #== Cell_location
|
---|
309 | # tecscde ã®ä½ç½®æ
|
---|
310 | å ±
|
---|
311 | class Cell_location
|
---|
312 |
|
---|
313 | #=== Join_location#initialize
|
---|
314 | #cell_nspath::NamespacePath
|
---|
315 | #x,y,w,h::Expression
|
---|
316 | #port_location_list::[ [Symbol(ep_or_cp_name), Symbol(edge_name), Expression(offset)], ... ]
|
---|
317 | #ep_name::Symbol
|
---|
318 | def initialize( cell_nspath, x, y, w, h, port_location_list )
|
---|
319 | # p "Cell_location: #{cell_nspath}, #{x}, #{y}, #{w}, #{h}, #{port_location_list}"
|
---|
320 | @cell_nspath = cell_nspath
|
---|
321 | @x = x.eval_const nil
|
---|
322 | @y = y.eval_const nil
|
---|
323 | @w = w.eval_const nil
|
---|
324 | @h = h.eval_const nil
|
---|
325 | @port_location_list = port_location_list
|
---|
326 |
|
---|
327 | TECSGEN.new_cell_location self
|
---|
328 | end
|
---|
329 |
|
---|
330 | def get_location
|
---|
331 | [ @cell_nspath, @x, @y, @w, @h, @port_location_list ]
|
---|
332 | end
|
---|
333 |
|
---|
334 | end # Cell_location
|
---|
335 |
|
---|
336 | #== Join_location
|
---|
337 | # tecscde ã®ä½ç½®æ
|
---|
338 | å ±
|
---|
339 | class Join_location
|
---|
340 | @@join_location_list = []
|
---|
341 |
|
---|
342 | #=== Join_location#initialize
|
---|
343 | #cp_cell_nspath::NamespacePath
|
---|
344 | #cp_name::Symbol
|
---|
345 | #ep_cell_nspath::NamespacePath
|
---|
346 | #ep_name::Symbol
|
---|
347 | #bar_list::[[Symbol (VBar or HBar), Expression(position mm)], ....]
|
---|
348 | def initialize( cp_cell_nspath, cp_name, ep_cell_path, ep_name, bar_list )
|
---|
349 | # p "Join_location #{cp_cell_nspath}, #{cp_name}, #{ep_cell_path}, #{ep_name} #{bar_list}"
|
---|
350 | @cp_cell_nspath = cp_cell_nspath
|
---|
351 | @cp_name = cp_name
|
---|
352 | @ep_cell_path = ep_cell_path
|
---|
353 | @ep_name = ep_name
|
---|
354 | @bar_list = bar_list
|
---|
355 |
|
---|
356 | TECSGEN.new_join_location self
|
---|
357 | end
|
---|
358 |
|
---|
359 | def get_location
|
---|
360 | [@cp_cell_nspath, @cp_name, @ep_cell_path, @ep_name, @bar_list]
|
---|
361 | end
|
---|
362 |
|
---|
363 | end # Join_location
|
---|
364 |
|
---|
365 | end # TECSGEN
|
---|