1 | #!/usr/bin/env ruby
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | #
|
---|
4 | # TOPPERS Configurator by Ruby
|
---|
5 | #
|
---|
6 | # Copyright (C) 2015 by FUJI SOFT INCORPORATED, JAPAN
|
---|
7 | # Copyright (C) 2015,2016 by Embedded and Real-Time Systems Laboratory
|
---|
8 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
9 | #
|
---|
10 | # ä¸è¨èä½æ¨©è
|
---|
11 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
12 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
13 | # å¤ã»åé
|
---|
14 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | # ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | # è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | # ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
28 | # ã¨ï¼
|
---|
29 | # (a) åé
|
---|
30 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
31 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
32 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
33 | # (b) åé
|
---|
34 | å¸ã®å½¢æ
|
---|
35 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
36 | # å ±åãããã¨ï¼
|
---|
37 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
38 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
39 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
40 | 責ãããã¨ï¼
|
---|
41 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
42 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
43 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
44 | # å
|
---|
45 | 責ãããã¨ï¼
|
---|
46 | #
|
---|
47 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
48 | ã
|
---|
49 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
50 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
51 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
52 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
53 | #
|
---|
54 | # $Id: cfg.rb 111 2016-03-16 23:50:27Z ertl-hiro $
|
---|
55 | #
|
---|
56 |
|
---|
57 | if $0 == __FILE__
|
---|
58 | TOOL_ROOT = File.expand_path(File.dirname(__FILE__)) + "/"
|
---|
59 | $LOAD_PATH.unshift(TOOL_ROOT)
|
---|
60 | end
|
---|
61 |
|
---|
62 | require "pp"
|
---|
63 | require "csv"
|
---|
64 | require "optparse"
|
---|
65 | require "pstore"
|
---|
66 | require "GenFile.rb"
|
---|
67 | require "SRecord.rb"
|
---|
68 |
|
---|
69 | #
|
---|
70 | # å®æ°å®ç¾©
|
---|
71 | #
|
---|
72 | # å
|
---|
73 | ±é
|
---|
74 | VERSION = "1.2.2"
|
---|
75 |
|
---|
76 | # cfg1_outé¢ä¿
|
---|
77 | CFG1_PREFIX = "TOPPERS_cfg_"
|
---|
78 | CFG1_MAGIC_NUM = "TOPPERS_magic_number"
|
---|
79 | CFG1_SIZEOF_SIGNED = "TOPPERS_sizeof_signed_t"
|
---|
80 | CFG1_OUT_C = "cfg1_out.c"
|
---|
81 | CFG1_OUT_DB = "cfg1_out.db"
|
---|
82 | CFG1_OUT_SREC = "cfg1_out.srec"
|
---|
83 | CFG1_OUT_SYMS = "cfg1_out.syms"
|
---|
84 | CFG1_OUT_TIMESTAMP = "cfg1_out.timestamp"
|
---|
85 | CFG1_OUT_TARGET_H = "target_cfg1_out.h"
|
---|
86 |
|
---|
87 | # cfg2_outé¢ä¿
|
---|
88 | CFG2_OUT_DB = "cfg2_out.db"
|
---|
89 |
|
---|
90 | # cfg3_outé¢ä¿
|
---|
91 | CFG3_OUT_DB = "cfg3_out.db"
|
---|
92 |
|
---|
93 | #
|
---|
94 | # ã¨ã©ã¼çºçæç¡ãã©ã°
|
---|
95 | #
|
---|
96 | $errorFlag = false
|
---|
97 |
|
---|
98 | #
|
---|
99 | # ã¨ã©ã¼ï¼è¦å表示é¢æ°
|
---|
100 | #
|
---|
101 | # ä¸è¬çãªã¨ã©ã¼è¡¨ç¤ºï¼å¦çãä¸æï¼
|
---|
102 | def error_exit(message, location = "")
|
---|
103 | location += " " if location != ""
|
---|
104 | abort("#{location}error: #{message}")
|
---|
105 | end
|
---|
106 |
|
---|
107 | # ä¸è¬çãªã¨ã©ã¼è¡¨ç¤ºï¼å¦çãç¶ç¶ï¼
|
---|
108 | def error(message, location = "")
|
---|
109 | location += " " if location != ""
|
---|
110 | STDERR.puts("#{location}error: #{message}")
|
---|
111 | $errorFlag = true
|
---|
112 | end
|
---|
113 |
|
---|
114 | # ä¸è¬çãªè¦å表示
|
---|
115 | def warning(message, location = "")
|
---|
116 | location += " " if location != ""
|
---|
117 | STDERR.puts("#{location}warning: #{message}")
|
---|
118 | end
|
---|
119 |
|
---|
120 | # ã·ã¹ãã ã³ã³ãã£ã®ã¥ã¬ã¼ã·ã§ã³ãã¡ã¤ã«ã®æ§æ解ææã®ã¨ã©ã¼
|
---|
121 | $noParseError = 0
|
---|
122 | def parse_error(cfgFile, message)
|
---|
123 | error(message, "#{cfgFile.getFileName()}:#{cfgFile.getLineNo}:")
|
---|
124 | if ($noParseError += 1) >= 10
|
---|
125 | abort("too many errors emitted, stopping now")
|
---|
126 | end
|
---|
127 | end
|
---|
128 |
|
---|
129 | # ã·ã¹ãã ã³ã³ãã£ã®ã¥ã¬ã¼ã·ã§ã³ãã¡ã¤ã«ã®æ§æ解ææã®è¦å
|
---|
130 | def parse_warning(cfgFile, message)
|
---|
131 | warning(message, "#{cfgFile.getFileName()}:#{cfgFile.getLineNo}:")
|
---|
132 | end
|
---|
133 |
|
---|
134 | #
|
---|
135 | # éçAPIå¦çæã®ã¨ã©ã¼ï¼è¦å表示é¢æ°
|
---|
136 | #
|
---|
137 | # éçAPIå¦çæã®ã¨ã©ã¼ï¼è¦åãçãè¨è¿°ã§ããããã«ï¼ã¡ãã»ã¼ã¸ä¸ã®%ã¾
|
---|
138 | # ãã¯%%ã§å§ã¾ãè¨è¿°ã以ä¸ã®ããã«å±éããï¼
|
---|
139 | # %label â #{params[:label]}
|
---|
140 | # %%label â label `#{params[:label]}'
|
---|
141 | #
|
---|
142 | # ã¨ã©ã¼ï¼è¦åã¡ãã»ã¼ã¸ã®å±é
|
---|
143 | def expand_message(message, params)
|
---|
144 | result = message.dup
|
---|
145 | while /%%(\w+)\b/ =~ result
|
---|
146 | param = $1
|
---|
147 | paramVal = params[param.to_sym].to_s
|
---|
148 | result.sub!(/%%#{param}\b/, "#{param} `#{paramVal}'")
|
---|
149 | end
|
---|
150 | while /%(\w+)\b/ =~ result
|
---|
151 | param = $1
|
---|
152 | paramVal = params[param.to_sym].to_s
|
---|
153 | result.sub!(/%#{param}\b/, paramVal)
|
---|
154 | end
|
---|
155 | return(result)
|
---|
156 | end
|
---|
157 |
|
---|
158 | # éçAPIå¦çæã®ã¨ã©ã¼
|
---|
159 | def error_api(params, message)
|
---|
160 | error(expand_message(message, params), \
|
---|
161 | "#{params[:_file_]}:#{params[:_line_]}:")
|
---|
162 | end
|
---|
163 |
|
---|
164 | # éçAPIå¦çæã®è¦å
|
---|
165 | def warning_api(params, message)
|
---|
166 | warning(expand_message(message, params), \
|
---|
167 | "#{params[:_file_]}:#{params[:_line_]}:")
|
---|
168 | end
|
---|
169 |
|
---|
170 | # éçAPIå¦çæã®ã¨ã©ã¼ï¼ã¨ã©ã¼ã³ã¼ãä»ãï¼
|
---|
171 | def error_ercd(errorCode, params, message)
|
---|
172 | error_api(params, "#{errorCode}: #{message}")
|
---|
173 | end
|
---|
174 |
|
---|
175 | # éçAPIå¦çæã®è¦åï¼ã¨ã©ã¼ã³ã¼ãä»ãï¼
|
---|
176 | def warning_ercd(errorCode, params, message)
|
---|
177 | warning_api(params, "#{errorCode}: #{message}")
|
---|
178 | end
|
---|
179 |
|
---|
180 | # ãã©ã¡ã¼ã¿ã®ã¨ã©ã¼
|
---|
181 | def error_wrong(errorCode, params, symbol, wrong)
|
---|
182 | error_ercd(errorCode, params, "%%#{symbol} is #{wrong} in %apiname")
|
---|
183 | end
|
---|
184 |
|
---|
185 | def error_wrong_id(errorCode, params, symbol, objid, wrong)
|
---|
186 | error_ercd(errorCode, params, "%%#{symbol} is #{wrong} " \
|
---|
187 | "in %apiname of %#{objid}")
|
---|
188 | end
|
---|
189 |
|
---|
190 | def error_wrong_sym(errorCode, params, symbol, symbol2, wrong)
|
---|
191 | error_ercd(errorCode, params, "%%#{symbol} is #{wrong} " \
|
---|
192 | "in %apiname of %%#{symbol2}")
|
---|
193 | end
|
---|
194 |
|
---|
195 | # ãã©ã¡ã¼ã¿ä¸æ£ã®ã¨ã©ã¼
|
---|
196 | def error_illegal(errorCode, params, symbol)
|
---|
197 | error_ercd(errorCode, params, "illegal %%#{symbol} in %apiname")
|
---|
198 | end
|
---|
199 |
|
---|
200 | def error_illegal_id(errorCode, params, symbol, objid)
|
---|
201 | error_ercd(errorCode, params, "illegal %%#{symbol} " \
|
---|
202 | "in %apiname of %#{objid}")
|
---|
203 | end
|
---|
204 |
|
---|
205 | def error_illegal_sym(errorCode, params, symbol, symbol2)
|
---|
206 | error_ercd(errorCode, params, "illegal %%#{symbol} " \
|
---|
207 | "in %apiname of %%#{symbol2}")
|
---|
208 | end
|
---|
209 |
|
---|
210 | #
|
---|
211 | # Stringã¯ã©ã¹ã®æ¡å¼µï¼äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®ä½æï¼å±éï¼
|
---|
212 | #
|
---|
213 | class String
|
---|
214 | #
|
---|
215 | # äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®ä½æ
|
---|
216 | #
|
---|
217 | def quote
|
---|
218 | result = ""
|
---|
219 | self.chars do |c|
|
---|
220 | case c
|
---|
221 | when "'"
|
---|
222 | result += "\\\'"
|
---|
223 | when "\""
|
---|
224 | result += "\\\""
|
---|
225 | when "\0"
|
---|
226 | result += "\\0"
|
---|
227 | when "\a"
|
---|
228 | result += "\\a"
|
---|
229 | when "\b"
|
---|
230 | result += "\\b"
|
---|
231 | when "\f"
|
---|
232 | result += "\\f"
|
---|
233 | when "\n"
|
---|
234 | result += "\\n"
|
---|
235 | when "\r"
|
---|
236 | result += "\\r"
|
---|
237 | when "\t"
|
---|
238 | result += "\\t"
|
---|
239 | when "\v"
|
---|
240 | result += "\\v"
|
---|
241 | when "\\"
|
---|
242 | result += "\\\\"
|
---|
243 | else
|
---|
244 | result += c
|
---|
245 | end
|
---|
246 | end
|
---|
247 | return("\"" + result + "\"")
|
---|
248 | end
|
---|
249 |
|
---|
250 | #
|
---|
251 | # äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®å±é
|
---|
252 | #
|
---|
253 | def unquote
|
---|
254 | if /^\"(.*)\"$/m =~ self
|
---|
255 | str = $1
|
---|
256 | result = ""
|
---|
257 | while (/^(.*)\\(.*)$/m =~ str)
|
---|
258 | result += $1
|
---|
259 | str = $2
|
---|
260 | case str
|
---|
261 | when /^[aA](.*)$/m
|
---|
262 | result += "\a"
|
---|
263 | str = $1
|
---|
264 | when /^[bB](.*)$/m
|
---|
265 | result += "\b"
|
---|
266 | str = $1
|
---|
267 | when /^[fF](.*)$/m
|
---|
268 | result += "\f"
|
---|
269 | str = $1
|
---|
270 | when /^[nN](.*)$/m
|
---|
271 | result += "\n"
|
---|
272 | str = $1
|
---|
273 | when /^[rR](.*)$/m
|
---|
274 | result += "\r"
|
---|
275 | str = $1
|
---|
276 | when /^[tT](.*)$/m
|
---|
277 | result += "\t"
|
---|
278 | str = $1
|
---|
279 | when /^[vV](.*)$/m
|
---|
280 | result += "\v"
|
---|
281 | str = $1
|
---|
282 | when /^[xX]([0-9a-fA-F][0-9a-fA-F]?)(.*)$/m
|
---|
283 | result += $1.hex
|
---|
284 | str = $2
|
---|
285 | when /^([0-7][0-7]?[0-7]?)(.*)$/m
|
---|
286 | result += $1.oct
|
---|
287 | str = $2
|
---|
288 | when /^\\(.*)$/m
|
---|
289 | result += "\\"
|
---|
290 | str = $1
|
---|
291 | end
|
---|
292 | end
|
---|
293 | return(result + str)
|
---|
294 | else
|
---|
295 | return(self.dup)
|
---|
296 | end
|
---|
297 | end
|
---|
298 | end
|
---|
299 |
|
---|
300 | #
|
---|
301 | # NumStrã¯ã©ã¹ï¼æ°å¤ã«æååãä»å ãããã®ï¼ã®å®ç¾©
|
---|
302 | #
|
---|
303 | class NumStr
|
---|
304 | def initialize(val, str = val.to_s)
|
---|
305 | @val = val
|
---|
306 | @str = str
|
---|
307 | end
|
---|
308 |
|
---|
309 | # æ°å¤æ
|
---|
310 | å ±ãè¿ã
|
---|
311 | def val
|
---|
312 | return @val
|
---|
313 | end
|
---|
314 | alias_method :to_i, :val
|
---|
315 |
|
---|
316 | # æååæ
|
---|
317 | å ±ãè¿ã
|
---|
318 | def str
|
---|
319 | return @str
|
---|
320 | end
|
---|
321 | alias_method :to_s, :str
|
---|
322 |
|
---|
323 | # æ¯è¼ã¯æ°å¤æ
|
---|
324 | å ±ã§è¡ã
|
---|
325 | def ==(other)
|
---|
326 | @val == other
|
---|
327 | end
|
---|
328 | def !=(other)
|
---|
329 | @val != other
|
---|
330 | end
|
---|
331 | def <=>(other)
|
---|
332 | @val <=> other
|
---|
333 | end
|
---|
334 |
|
---|
335 | # ããã·ã¥ã®ãã¼ã¨ãã¦ä½¿ãæã®æ¯è¼ãæ°å¤æ
|
---|
336 | å ±ã§è¡ã
|
---|
337 | def eql?(other)
|
---|
338 | @val == other.val
|
---|
339 | end
|
---|
340 |
|
---|
341 | # ããã·ã¥å¤ã®å®ç¾©ãä¸æ¸ããã
|
---|
342 | def hash
|
---|
343 | return @val.hash
|
---|
344 | end
|
---|
345 |
|
---|
346 | # æ°å¤ã¯ã©ã¹ã¨æ¼ç®ã§ããããã«ãã
|
---|
347 | def coerce(other)
|
---|
348 | if other.kind_of?(Numeric)
|
---|
349 | return other, @val
|
---|
350 | else
|
---|
351 | raise
|
---|
352 | end
|
---|
353 | end
|
---|
354 |
|
---|
355 | # äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®ä½æ
|
---|
356 | def quote
|
---|
357 | str.quote
|
---|
358 | end
|
---|
359 |
|
---|
360 | # äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®å±é
|
---|
361 | def unquote
|
---|
362 | str.unquote
|
---|
363 | end
|
---|
364 |
|
---|
365 | # ppæã®è¡¨ç¤º
|
---|
366 | def pretty_print(q)
|
---|
367 | q.text("[#{@val}(=0x#{@val.to_s(16)}),")
|
---|
368 | @str.pretty_print(q)
|
---|
369 | q.text("]")
|
---|
370 | end
|
---|
371 |
|
---|
372 | # æªå®ç¾©ã®ã¡ã½ããã¯@valã«éã
|
---|
373 | def method_missing(*method)
|
---|
374 | @val.send(*method)
|
---|
375 | end
|
---|
376 | end
|
---|
377 |
|
---|
378 | #
|
---|
379 | # ã·ã³ãã«ãã¡ã¤ã«ã®èªã¿è¾¼ã¿
|
---|
380 | #
|
---|
381 | # 以ä¸ã®ã¡ã½ããã¯ï¼GNUã®nmãçæããã·ã³ãã«ãã¡ã¤ã«ã«å¯¾å¿ãã¦ããï¼
|
---|
382 | # å¥ã®ãã¼ã«ã«å¯¾å¿ããå ´åã«ã¯ï¼ãã®ã¡ã½ãããæ¸ãæããã°ããï¼
|
---|
383 | #
|
---|
384 | def ReadSymbolFile(symbolFileName)
|
---|
385 | begin
|
---|
386 | symbolFile = File.open(symbolFileName)
|
---|
387 | rescue Errno::ENOENT, Errno::EACCES => ex
|
---|
388 | abort(ex.message)
|
---|
389 | end
|
---|
390 |
|
---|
391 | symbolAddress = {}
|
---|
392 | symbolFile.each do |line|
|
---|
393 | # ã¹ãã¼ã¹åºåãã§å解
|
---|
394 | fields = line.split(/\s+/)
|
---|
395 |
|
---|
396 | # 3åã«ãªã£ã¦ããªãè¡ã¯é¤å¤
|
---|
397 | if fields.size == 3
|
---|
398 | symbolAddress[fields[2]] = fields[0].hex
|
---|
399 | end
|
---|
400 | end
|
---|
401 | symbolFile.close
|
---|
402 | return(symbolAddress)
|
---|
403 | end
|
---|
404 |
|
---|
405 | #
|
---|
406 | # å¤åå¾ã·ã³ãã«ãã°ãã¼ãã«å¤æ°ã¨ãã¦å®ç¾©ãã
|
---|
407 | #
|
---|
408 | def DefineSymbolValue
|
---|
409 | $symbolValueTable.each do |symbolName, symbolData|
|
---|
410 | if symbolData.has_key?(:VALUE)
|
---|
411 | eval("$#{symbolName} = #{symbolData[:VALUE]}")
|
---|
412 | end
|
---|
413 | end
|
---|
414 | end
|
---|
415 |
|
---|
416 | #
|
---|
417 | # ã¤ã³ã¯ã«ã¼ããã¹ãããã¡ã¤ã«ãæ¢ã
|
---|
418 | #
|
---|
419 | def SearchFilePath(fileName)
|
---|
420 | if File.exist?(fileName)
|
---|
421 | # æå®ãããã¡ã¤ã«ãã¹ã«åå¨ãã
|
---|
422 | return fileName
|
---|
423 | elsif /^\./ =~ fileName
|
---|
424 | # ç¸å¯¾ãã¹ãæå®ãã¦ãã¦è¦ã¤ãããªãã£ãå ´åï¼åå¨ããªããã®ã¨ãã
|
---|
425 | #ï¼æå³ããªããã¡ã¤ã«ã対象ã¨ãªããã¨ãé²æ¢ï¼
|
---|
426 | return nil
|
---|
427 | else
|
---|
428 | # åã¤ã³ã¯ã«ã¼ããã¹ãããã¡ã¤ã«åå¨ãã§ãã¯
|
---|
429 | $includeDirectories.each do |includeDirectory|
|
---|
430 | path = includeDirectory + "/" + fileName
|
---|
431 | # è¦ã¤ãã£ããç¸å¯¾ãã¹ãè¿ã
|
---|
432 | if File.exist?(path)
|
---|
433 | return path
|
---|
434 | end
|
---|
435 | end
|
---|
436 | return nil
|
---|
437 | end
|
---|
438 | end
|
---|
439 |
|
---|
440 | #
|
---|
441 | # æå®ããçæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼ãæ¤ç´¢ãã¦loadãã
|
---|
442 | #
|
---|
443 | def IncludeTrb(fileName)
|
---|
444 | filePath = SearchFilePath(fileName)
|
---|
445 | if filePath.nil?
|
---|
446 | error_exit("`#{fileName}' not found")
|
---|
447 | else
|
---|
448 | load(filePath)
|
---|
449 | end
|
---|
450 | end
|
---|
451 |
|
---|
452 | #
|
---|
453 | # ãã¹3ã®å¦ç
|
---|
454 | #
|
---|
455 | def Pass3
|
---|
456 | #
|
---|
457 | # ãã¹2ããå¼ã渡ãããæ
|
---|
458 | å ±ããã¡ã¤ã«ããèªã¿è¾¼ã
|
---|
459 | #
|
---|
460 | db = PStore.new(CFG2_OUT_DB)
|
---|
461 | db.transaction(true) do
|
---|
462 | $apiDefinition = db[:apiDefinition]
|
---|
463 | $symbolValueTable = db[:symbolValueTable]
|
---|
464 | $cfgFileInfo = db[:cfgFileInfo]
|
---|
465 | $includeFiles = db[:includeFiles]
|
---|
466 | $cfgData = db[:cfgData]
|
---|
467 | $asmLabel = db[:asmLabel]
|
---|
468 | $endianLittle = db[:endianLittle]
|
---|
469 | $cfg2Data = db[:cfg2Data]
|
---|
470 | end
|
---|
471 | $cfg3Data = {}
|
---|
472 |
|
---|
473 | #
|
---|
474 | # å¤åå¾ã·ã³ãã«ãã°ãã¼ãã«å¤æ°ã¨ãã¦å®ç¾©ãã
|
---|
475 | #
|
---|
476 | DefineSymbolValue()
|
---|
477 |
|
---|
478 | #
|
---|
479 | # çæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼ãå®è¡ãã
|
---|
480 | #
|
---|
481 | $trbFileNames.each do |trbFileName|
|
---|
482 | IncludeTrb(trbFileName)
|
---|
483 | end
|
---|
484 |
|
---|
485 | #
|
---|
486 | # ãã¹4ã«å¼ã渡ãæ
|
---|
487 | å ±ããã¡ã¤ã«ã«çæ
|
---|
488 | #
|
---|
489 | if $omitOutputDb.nil?
|
---|
490 | db = PStore.new(CFG3_OUT_DB)
|
---|
491 | db.transaction do
|
---|
492 | db[:apiDefinition] = $apiDefinition
|
---|
493 | db[:symbolValueTable] = $symbolValueTable
|
---|
494 | db[:cfgFileInfo] = $cfgFileInfo
|
---|
495 | db[:includeFiles] = $includeFiles
|
---|
496 | db[:cfgData] = $cfgData
|
---|
497 | db[:asmLabel] = $asmLabel
|
---|
498 | db[:endianLittle] = $endianLittle
|
---|
499 | db[:cfg3Data] = $cfg3Data
|
---|
500 | end
|
---|
501 | end
|
---|
502 | end
|
---|
503 |
|
---|
504 | #
|
---|
505 | # ãã¹4ã®å¦ç
|
---|
506 | #
|
---|
507 | def Pass4
|
---|
508 | #
|
---|
509 | # ãã¹3ããå¼ã渡ãããæ
|
---|
510 | å ±ããã¡ã¤ã«ããèªã¿è¾¼ã
|
---|
511 | #
|
---|
512 | db = PStore.new(CFG3_OUT_DB)
|
---|
513 | db.transaction(true) do
|
---|
514 | $apiDefinition = db[:apiDefinition]
|
---|
515 | $symbolValueTable = db[:symbolValueTable]
|
---|
516 | $cfgFileInfo = db[:cfgFileInfo]
|
---|
517 | $includeFiles = db[:includeFiles]
|
---|
518 | $cfgData = db[:cfgData]
|
---|
519 | $asmLabel = db[:asmLabel]
|
---|
520 | $endianLittle = db[:endianLittle]
|
---|
521 | $cfg3Data = db[:cfg3Data] || db[:cfg2Data]
|
---|
522 | end
|
---|
523 |
|
---|
524 | #
|
---|
525 | # å¤åå¾ã·ã³ãã«ãã°ãã¼ãã«å¤æ°ã¨ãã¦å®ç¾©ãã
|
---|
526 | #
|
---|
527 | DefineSymbolValue()
|
---|
528 |
|
---|
529 | #
|
---|
530 | # çæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼ãå®è¡ãã
|
---|
531 | #
|
---|
532 | $trbFileNames.each do |trbFileName|
|
---|
533 | IncludeTrb(trbFileName)
|
---|
534 | end
|
---|
535 | end
|
---|
536 |
|
---|
537 | #
|
---|
538 | # çæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼åãã®é¢æ°
|
---|
539 | #
|
---|
540 | def SYMBOL(symbol)
|
---|
541 | if !$romSymbol.nil? && $romSymbol.has_key?($asmLabel + symbol)
|
---|
542 | return $romSymbol[$asmLabel + symbol]
|
---|
543 | else
|
---|
544 | return nil
|
---|
545 | end
|
---|
546 | end
|
---|
547 |
|
---|
548 | def BCOPY(fromAddress, toAddress, size)
|
---|
549 | if !$romImage.nil?
|
---|
550 | copyData = $romImage.get_data(fromAddress, size)
|
---|
551 | if !copyData.nil?
|
---|
552 | $romImage.set_data(toAddress, copyData)
|
---|
553 | end
|
---|
554 | end
|
---|
555 | end
|
---|
556 |
|
---|
557 | def BZERO(address, size)
|
---|
558 | if !$romImage.nil?
|
---|
559 | $romImage.set_data(address, "00" * size)
|
---|
560 | end
|
---|
561 | end
|
---|
562 |
|
---|
563 | def PEEK(address, size, signed=false)
|
---|
564 | if !$romImage.nil?
|
---|
565 | return $romImage.get_value(address, size, signed)
|
---|
566 | else
|
---|
567 | return nil
|
---|
568 | end
|
---|
569 | end
|
---|
570 |
|
---|
571 | #
|
---|
572 | # ã°ãã¼ãã«å¤æ°ã®åæå
|
---|
573 | #
|
---|
574 | $kernel = nil
|
---|
575 | $pass = nil
|
---|
576 | $includeDirectories = []
|
---|
577 | $trbFileNames = []
|
---|
578 | $apiTableFileNames = []
|
---|
579 | $symvalTableFileNames = []
|
---|
580 | $romImageFileName = nil
|
---|
581 | $romSymbolFileName = nil
|
---|
582 | $dependencyFileName = nil
|
---|
583 | $idInputFileName = nil
|
---|
584 | $idOutputFileName = nil
|
---|
585 |
|
---|
586 | #
|
---|
587 | # ãªãã·ã§ã³ã®å¦ç
|
---|
588 | #
|
---|
589 | OptionParser.new(banner="Usage: cfg.rb [options] CONFIG-FILE", 40) do |opt|
|
---|
590 | opt.version = VERSION
|
---|
591 | opt.on("-k KERNEL", "--kernel KERNEL", "kernel profile name") do |val|
|
---|
592 | $kernel = val
|
---|
593 | end
|
---|
594 | opt.on("-p NUM", "--pass NUM", "processing pass number") do |val|
|
---|
595 | $pass = val
|
---|
596 | end
|
---|
597 | opt.on("-I DIRECTORY", "--include-directory DIRECTORY",
|
---|
598 | "include directory") do |val|
|
---|
599 | $includeDirectories.push(val)
|
---|
600 | end
|
---|
601 | opt.on("-T TRB-FILE", "--trb-file TRB-FILE",
|
---|
602 | "generation script (trb file)") do |val|
|
---|
603 | $trbFileNames.push(val)
|
---|
604 | end
|
---|
605 | opt.on("--api-table API-TABLE-FILE", "static API table file") do |val|
|
---|
606 | $apiTableFileNames.push(val)
|
---|
607 | end
|
---|
608 | opt.on("--symval-table SYMVAL-TABLE-FILE", "symbol-value table file") do |val|
|
---|
609 | $symvalTableFileNames.push(val)
|
---|
610 | end
|
---|
611 | opt.on("--rom-image SREC-FILE", "rom image file (s-record)") do |val|
|
---|
612 | $romImageFileName = val
|
---|
613 | end
|
---|
614 | opt.on("--rom-symbol SYMS-FILE", "rom symbol table file (nm)") do |val|
|
---|
615 | $romSymbolFileName = val
|
---|
616 | end
|
---|
617 | opt.on("--id-input-file ID-FILE", "ID input file") do |val|
|
---|
618 | $idInputFileName = val
|
---|
619 | end
|
---|
620 | opt.on("--id-output-file ID-FILE", "ID output file") do |val|
|
---|
621 | $idOutputFileName = val
|
---|
622 | end
|
---|
623 | opt.on("-M [DEPEND-FILE]", "--print-dependencies [DEPEND-FILE]",
|
---|
624 | "dependency file") do |val|
|
---|
625 | $dependencyFileName = val.nil? ? "" : val
|
---|
626 | end
|
---|
627 | opt.on("-O", "--omit-output-db", "omit DB file output") do
|
---|
628 | $omitOutputDb = true
|
---|
629 | end
|
---|
630 | opt.on("-v", "--version", "show version number") do
|
---|
631 | abort(opt.ver)
|
---|
632 | end
|
---|
633 | opt.on("-h", "--help", "show help (this)") do
|
---|
634 | abort(opt.help)
|
---|
635 | end
|
---|
636 | opt.parse!(ARGV)
|
---|
637 | end
|
---|
638 | $configFileNames = ARGV
|
---|
639 |
|
---|
640 | #
|
---|
641 | # ãªãã·ã§ã³ã®ãã§ãã¯
|
---|
642 | #
|
---|
643 | if $pass.nil?
|
---|
644 | # ãã¹ã®æå®ã¯å¿
|
---|
645 | é
|
---|
646 | abort("`--pass' option is mandatory")
|
---|
647 | elsif /^[1234]$/ !~ $pass
|
---|
648 | abort("pass number `#{$pass}' is not valid")
|
---|
649 | end
|
---|
650 |
|
---|
651 | # ãã¹1ã§ã¯ï¼éçAPIãã¼ãã«ã¯å¿
|
---|
652 | é
|
---|
653 | if ($pass == "1" && $apiTableFileNames.empty?)
|
---|
654 | abort("`--api-table' option must be specified in pass 1")
|
---|
655 | end
|
---|
656 |
|
---|
657 | # ãã¹1以å¤ã§ã¯ï¼çæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼ãå¿
|
---|
658 | é
|
---|
659 | if ($pass != "1" && $trbFileNames.empty?)
|
---|
660 | abort("`--trb-file' must be specified except in pass 1")
|
---|
661 | end
|
---|
662 |
|
---|
663 | #
|
---|
664 | # ã«ã¼ãã«ãªãã·ã§ã³ã®å¦ç
|
---|
665 | #
|
---|
666 | case $kernel
|
---|
667 | when /^hrp/
|
---|
668 | $supportDomain = true
|
---|
669 | when /^fmp/
|
---|
670 | $supportClass = true
|
---|
671 | end
|
---|
672 |
|
---|
673 | #
|
---|
674 | # IDçªå·å
|
---|
675 | ¥åãã¡ã¤ã«ã®åãè¾¼ã¿
|
---|
676 | #
|
---|
677 | $inputObjid = {}
|
---|
678 | if !$idInputFileName.nil?
|
---|
679 | begin
|
---|
680 | idInputFile = File.open($idInputFileName)
|
---|
681 | rescue Errno::ENOENT, Errno::EACCES => ex
|
---|
682 | abort(ex.message)
|
---|
683 | end
|
---|
684 |
|
---|
685 | idInputFile.each do |line|
|
---|
686 | ( objName, objidNumber ) = line.split(/\s+/)
|
---|
687 | $inputObjid[objName] = objidNumber.to_i
|
---|
688 | end
|
---|
689 |
|
---|
690 | idInputFile.close
|
---|
691 | end
|
---|
692 |
|
---|
693 | #
|
---|
694 | # æå®ãããã·ã³ãã«ãã¡ã¤ã«ã®èªã¿è¾¼ã¿
|
---|
695 | #
|
---|
696 | if !$romSymbolFileName.nil?
|
---|
697 | if File.exist?($romSymbolFileName)
|
---|
698 | $romSymbol = ReadSymbolFile($romSymbolFileName)
|
---|
699 | else
|
---|
700 | error_exit("`#{$romSymbolFileName}' not found")
|
---|
701 | end
|
---|
702 | end
|
---|
703 |
|
---|
704 | #
|
---|
705 | # æå®ãããSã¬ã³ã¼ããã¡ã¤ã«ã®èªã¿è¾¼ã¿
|
---|
706 | #
|
---|
707 | if !$romImageFileName.nil?
|
---|
708 | if File.exist?($romImageFileName)
|
---|
709 | $romImage = SRecord.new($romImageFileName)
|
---|
710 | else
|
---|
711 | error_exit("`#{$romImageFileName}' not found")
|
---|
712 | end
|
---|
713 | end
|
---|
714 |
|
---|
715 | #
|
---|
716 | # ãã¹ã«å¾ã£ã¦åå¦çãå®è¡
|
---|
717 | #
|
---|
718 | case $pass
|
---|
719 | when "1"
|
---|
720 | load("pass1.rb")
|
---|
721 | Pass1()
|
---|
722 | when "2"
|
---|
723 | load("pass2.rb")
|
---|
724 | Pass2()
|
---|
725 | when "3"
|
---|
726 | Pass3()
|
---|
727 | when "4"
|
---|
728 | Pass4()
|
---|
729 | else
|
---|
730 | error_exit("invalid pass: #{$pass}")
|
---|
731 | end
|
---|
732 |
|
---|
733 | # ã¨ã©ã¼çºçæã¯abortãã
|
---|
734 | if $errorFlag
|
---|
735 | if ($0 == __FILE__)
|
---|
736 | abort()
|
---|
737 | else
|
---|
738 | # simplecov対å¿
|
---|
739 | raise()
|
---|
740 | end
|
---|
741 | end
|
---|
742 |
|
---|
743 | #
|
---|
744 | # ä½æãããã¹ã¦ã®ãã¡ã¤ã«ãåºåãã
|
---|
745 | #
|
---|
746 | GenFile.output
|
---|
747 |
|
---|
748 | #
|
---|
749 | # ã¿ã¤ã ã¹ã¿ã³ããã¡ã¤ã«ã®çæ
|
---|
750 | #
|
---|
751 | if !$timeStampFileName.nil?
|
---|
752 | File.open($timeStampFileName, "w").close
|
---|
753 | end
|
---|