[388] | 1 | #!/usr/bin/env ruby
|
---|
| 2 | # -*- coding: utf-8 -*-
|
---|
| 3 | #
|
---|
| 4 | # TECS Generator
|
---|
| 5 | # Generator for TOPPERS Embedded Component System
|
---|
| 6 | #
|
---|
| 7 | # Copyright (C) 2008-2019 by TOPPERS Project
|
---|
| 8 | #--
|
---|
| 9 | # ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 11 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 12 | # å¤ã»åé
|
---|
| 13 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 14 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 15 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 16 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 17 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 18 | # ç¨ã§ããå½¢ã§åé
|
---|
| 19 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 20 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 21 | # è
|
---|
| 22 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 23 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 24 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 25 | # ç¨ã§ããªãå½¢ã§åé
|
---|
| 26 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 27 | # ã¨ï¼
|
---|
| 28 | # (a) åé
|
---|
| 29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 31 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 32 | # (b) åé
|
---|
| 33 | å¸ã®å½¢æ
|
---|
| 34 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 35 | # å ±åãããã¨ï¼
|
---|
| 36 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 37 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 38 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 39 | 責ãããã¨ï¼
|
---|
| 40 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 41 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 42 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 43 | # å
|
---|
| 44 | 責ãããã¨ï¼
|
---|
| 45 | #
|
---|
| 46 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 47 | ã
|
---|
| 48 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 49 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 50 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 51 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 52 | #
|
---|
| 53 | # $Id$
|
---|
| 54 | #++
|
---|
| 55 |
|
---|
| 56 | #= tecsgen : TECS ã®ã¸ã§ãã¬ã¼ã¿
|
---|
| 57 | #
|
---|
| 58 | #Authors:: ç³å·ãæä¹(HRP2Plugin)
|
---|
| 59 | #Authors:: åããæ(åççµåä»æ§)
|
---|
| 60 | #Authors:: æ²³ç°ãæºæ(NotifierPlugin)
|
---|
| 61 | #Authors:: é«ç°ãåºç« (ASP3 ã¸ã® TECS çµè¾¼ã¿)
|
---|
| 62 | #Authors:: é«æ¨ãä¿¡å°(ã©ã³ã¿ã¤ã ããã)
|
---|
| 63 | #Authors:: æç¬ãæç¾(TECS flow å®è£
|
---|
| 64 | )
|
---|
| 65 | #Authors:: éµé£¼ãæ¬å¹¸(ATK1Plugin)
|
---|
| 66 | #Authors:: 大山ãåå¸(ã¸ã§ãã¬ã¼ã¿å®è£
|
---|
| 67 | , RPCPlugin, TracePlugin, MrubyBridgePlugin)
|
---|
| 68 | #Authors:: å±±æ¬ãå°ä¹(ã¸ã§ãã¬ã¼ã¿åæãããã¿ã¤ãå®è£
|
---|
| 69 | )
|
---|
| 70 | #Authors:: å°åãéé(ãã¹ãã³ã¼ãã®ä¸é¨)
|
---|
| 71 | #Authors:: å®ç©ãåä¹(ASP+TECS, EV3RT+TECS, mruby on TECSçå®è£
|
---|
| 72 | )
|
---|
| 73 | # Authors list is in i-ro-ha order.
|
---|
| 74 | #Version:: see version.rb
|
---|
| 75 | $Copyright = "Copyright(c) 2008-2019, TOPPERS project. All rights reserved."
|
---|
| 76 | $License = "TOPPERS License"
|
---|
| 77 |
|
---|
| 78 | # This doesn't work as expected in exerb version (Ruby 1.8.7?)
|
---|
| 79 | $tecsgen_base_path = File.dirname( File.expand_path __FILE__ )
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | ###
|
---|
| 83 | #= Array initializer ã® '{', '}' ã§å²ã¾ããå ´å
|
---|
| 84 | # mikan AggregateInitializer ãªã©ãã¯ã©ã¹ãå¤æ´ãã¹ãã§ãã
|
---|
| 85 | class Array
|
---|
| 86 | #=== CDL ã®æååãçæãã
|
---|
| 87 | def to_CDL_str
|
---|
| 88 | str = '{ '
|
---|
| 89 | delim = ''
|
---|
| 90 | self.each{ |v|
|
---|
| 91 | str += delim + v.to_CDL_str
|
---|
| 92 | delim = ', '
|
---|
| 93 | }
|
---|
| 94 | str += ' }'
|
---|
| 95 | return str
|
---|
| 96 | end
|
---|
| 97 |
|
---|
| 98 | def show_tree( indent )
|
---|
| 99 | indent.times{ print " " }
|
---|
| 100 | print( "Array\n" )
|
---|
| 101 | self.each{ |m|
|
---|
| 102 | m.show_tree( indent+1 )
|
---|
| 103 | }
|
---|
| 104 | end
|
---|
| 105 | end
|
---|
| 106 |
|
---|
| 107 | #=== RUBY ã©ã¤ãã©ãªããã¼ããã
|
---|
| 108 | #
|
---|
| 109 | # -L, $RUBYLIB, ã·ã¹ãã (/usr/lib/rub..ãªã©) ã®é ã«ãµã¼ããè¡ããã
|
---|
| 110 | # exerb 対å¿ã®ãããä¸è¨ãã¹ã«ãã¡ã¤ã«ãè¦ã¤ãããªãå ´å require ãå®è¡ãã¦ã¿ã
|
---|
| 111 | #
|
---|
| 112 | # ãã©ã°ã¤ã³ã®å ´å㯠b_fatal = false ãæå®ããã¡ã¤ã«ããªãã¦ãã¨ã©ã¼åºåå¾ãå¦çç¶è¡
|
---|
| 113 | # b_fatal = false ã®å ´å tecslib/core ããµã¼ããã¹ã«è¿½å ããã
|
---|
| 114 | #RETURN::Bool : true=æåã false=失æ 失æããå ´åãGenerator.error ã¯å¼ã³å
|
---|
| 115 | ã§åºåãã
|
---|
| 116 | def require_tecsgen_lib( fname, b_fatal = true )
|
---|
| 117 | dbgPrint( "require_lib: #{fname}\n")
|
---|
| 118 | set_kcode $KCODE_TECSGEN
|
---|
| 119 | begin
|
---|
| 120 | b_require = false
|
---|
| 121 | b_exception = false
|
---|
| 122 |
|
---|
| 123 | # -L ã $RUBYLIB ã§æå®ããããã¹ããã³ã·ã¹ãã ã®ãã¹ãããµã¼ã
|
---|
| 124 | # exerb ã§ã¯ $LOAD_PATH 㯠["."] ã®ã¿å
|
---|
| 125 | ¥ã£ã¦ããããã
|
---|
| 126 | ($library_path+$LOAD_PATH).each{ |path|
|
---|
| 127 | [ "", "tecslib/plugin/" ].each { |lp|
|
---|
| 128 | lib = File.expand_path( path ) + '/' + lp + fname
|
---|
| 129 |
|
---|
| 130 | if File.exist? lib then # ãã¡ã¤ã«åå¦ã¨ä»ã®ã¨ã©ã¼ãåºå¥ããããåå¨ç¢ºèªããã
|
---|
| 131 | begin
|
---|
| 132 | require( lib )
|
---|
| 133 | b_require = true
|
---|
| 134 | rescue Exception => evar
|
---|
| 135 | b_exception = true
|
---|
| 136 | print_exception( evar )
|
---|
| 137 | end
|
---|
| 138 | break
|
---|
| 139 | end
|
---|
| 140 | }
|
---|
| 141 | if b_require then
|
---|
| 142 | break
|
---|
| 143 | end
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | if b_require == false && b_exception == false then
|
---|
| 147 | # exerb å¯¾å¿ "." ããµã¼ããã¹ã®æåã«å ãã
|
---|
| 148 | # "tecslib/" 㯠RPCPlugin.rb, TracePlugin.rb ã®ããã«ç¨æãã¦ãã
|
---|
| 149 | # RPCPlugin.rb, TracePlugin.rb ã tecslib ä¸ã§ãªããã°ä¸è¦ã«ãªããããã®ããã«ãã¦ãã
|
---|
| 150 | ["","tecslib/plugin/"].each{ |lp|
|
---|
| 151 | path = lp + fname
|
---|
| 152 | begin
|
---|
| 153 | require path
|
---|
| 154 | return true
|
---|
| 155 | rescue LoadError => e
|
---|
| 156 | # p "LoadError to load #{fname}"
|
---|
| 157 | # 2015.12.18 exerb çã§ãã©ã°ã¤ã³ã®ãã¼ãã§ã¨ã©ã¼ãåºãã®ã§ãç¡è¦ãã. ããããæããã¨ã©ã¼ã¯åºã¦ãã
|
---|
| 158 | # print_exception( e )
|
---|
| 159 | rescue Exception => e
|
---|
| 160 | b_exception = true
|
---|
| 161 | # ææ³ã¨ã©ã¼ãªã©ãçºç
|
---|
| 162 | print_exception( e )
|
---|
| 163 | break
|
---|
| 164 | end
|
---|
| 165 | }
|
---|
| 166 | end
|
---|
| 167 |
|
---|
| 168 | if b_require == false then
|
---|
| 169 | # è¦ã¤ãããªãã£ã
|
---|
| 170 | if b_exception == false then
|
---|
| 171 | STDERR << "tecsgen: Fail to load #{fname}. Check $RUBYLIB environment variable or -L option\n"
|
---|
| 172 | end
|
---|
| 173 | # tecsgen ãæ§æãããã¡ã¤ã«ã®å ´åã¯ä¸æ¢ãã
|
---|
| 174 | if b_fatal then
|
---|
| 175 | STDERR << "tecsgen: Exit because of unrecoverble error\n"
|
---|
| 176 | exit 1
|
---|
| 177 | end
|
---|
| 178 | return false
|
---|
| 179 | end
|
---|
| 180 | return true
|
---|
| 181 | ensure
|
---|
| 182 | # $KCODE ã CDL ã®æåã³ã¼ãã«æ»ãã¦ãã
|
---|
| 183 | set_kcode $KCODE_CDL
|
---|
| 184 | end
|
---|
| 185 | end
|
---|
| 186 |
|
---|
| 187 | #=== ä¾å¤ã®è¡¨ç¤º
|
---|
| 188 | #evar:: Exception
|
---|
| 189 | def print_exception( evar )
|
---|
| 190 | # ããã¹ã¿ãã¯ãã¬ã¼ã¹ãåºãã¾ã§ãæéãããããããªãã°ã次ãã³ã¡ã³ãã¢ã¦ããã¦ã¿ãã¹ã
|
---|
| 191 | print "*** Begin Ruby exception message ***\n"
|
---|
| 192 | puts( evar.to_s )
|
---|
| 193 |
|
---|
| 194 | if $debug then
|
---|
| 195 | puts "#### stack trace ####"
|
---|
| 196 | pp evar.backtrace
|
---|
| 197 | end
|
---|
| 198 | print "*** End Ruby exception message ***\n"
|
---|
| 199 | end
|
---|
| 200 |
|
---|
| 201 | def dbgPrint( str )
|
---|
| 202 | if $debug then
|
---|
| 203 | print str
|
---|
| 204 | end
|
---|
| 205 | end
|
---|
| 206 |
|
---|
| 207 | def dbgPrintf( *param )
|
---|
| 208 | if $debug then
|
---|
| 209 | printf *param
|
---|
| 210 | end
|
---|
| 211 | end
|
---|
| 212 |
|
---|
| 213 | #=== ã¨ã©ã¼ããã³è¦åã®ã¬ãã¼ã
|
---|
| 214 | def print_report
|
---|
| 215 | msg = nil
|
---|
| 216 |
|
---|
| 217 | if Generator.get_n_error != 0 then
|
---|
| 218 | msg = "#{Generator.get_n_error} error"
|
---|
| 219 | msg = "#{msg}s" if Generator.get_n_error >= 2
|
---|
| 220 | end
|
---|
| 221 |
|
---|
| 222 | if Generator.get_n_warning != 0 then
|
---|
| 223 | msg = "#{msg} " if msg
|
---|
| 224 | msg = "#{msg}#{Generator.get_n_warning} warning"
|
---|
| 225 | msg = "#{msg}s" if Generator.get_n_warning >= 2
|
---|
| 226 | end
|
---|
| 227 |
|
---|
| 228 | puts msg if msg
|
---|
| 229 | end
|
---|
| 230 |
|
---|
| 231 | #=== $KCODE ãè¨å®
|
---|
| 232 | def set_kcode kcode
|
---|
| 233 | if ! $b_no_kcode then
|
---|
| 234 | $KCODE = kcode
|
---|
| 235 | end
|
---|
| 236 | end
|
---|
| 237 | #----- class TECSGEN -------#
|
---|
| 238 | class TECSGEN
|
---|
| 239 |
|
---|
| 240 | @@current_tecsgen = nil
|
---|
| 241 |
|
---|
| 242 | def self.init( addtional_option_parser = nil )
|
---|
| 243 | initialize_global_var
|
---|
| 244 | analyze_option addtional_option_parser
|
---|
| 245 | load_modules
|
---|
| 246 | if ! $TECSFLOW then
|
---|
| 247 | setup
|
---|
| 248 | end
|
---|
| 249 |
|
---|
| 250 | dbgPrint "tecspath: #{$tecsgen_base_path}, __FILE__=#{__FILE__}\n"
|
---|
| 251 | dbgPrint "ARGV(remained): #{ARGV}, argments=#{$arguments}\n"
|
---|
| 252 | end
|
---|
| 253 |
|
---|
| 254 | #----- initialize -------#
|
---|
| 255 | def initialize
|
---|
| 256 | @cell_list = nil
|
---|
| 257 | @cell_list2 = nil
|
---|
| 258 | @celltype_list = nil
|
---|
| 259 | @root_namespace = nil
|
---|
| 260 |
|
---|
| 261 | #--- obsolete ---# replaced to TOOL_INFO
|
---|
| 262 | @cell_location_list = []
|
---|
| 263 | @join_location_list = []
|
---|
| 264 | end
|
---|
| 265 |
|
---|
| 266 | def run1
|
---|
| 267 | @@current_tecsgen = self
|
---|
| 268 |
|
---|
| 269 | syntax_analisys ARGV
|
---|
| 270 | semantics_analisys_1
|
---|
| 271 | semantics_analisys_2
|
---|
| 272 |
|
---|
| 273 | @celltype_list = Celltype.get_celltype_list
|
---|
| 274 | @cell_list = Cell.get_cell_list
|
---|
| 275 | @cell_list2 = Cell.get_cell_list2
|
---|
| 276 |
|
---|
| 277 | @@current_tecsgen = nil
|
---|
| 278 | end
|
---|
| 279 |
|
---|
| 280 | def run2
|
---|
| 281 | @@current_tecsgen = self
|
---|
| 282 |
|
---|
| 283 | optimize_and_generate
|
---|
| 284 | finalize
|
---|
| 285 |
|
---|
| 286 | @@current_tecsgen = nil
|
---|
| 287 | end
|
---|
| 288 |
|
---|
| 289 | #----- initialize_global_var -----#
|
---|
| 290 | def self.initialize_global_var
|
---|
| 291 |
|
---|
| 292 | require 'optparse'
|
---|
| 293 | #2.0 require 'runit/assert.rb'
|
---|
| 294 | require 'kconv'
|
---|
| 295 | $b_no_kcode = RUBY_VERSION >= "1.9.0" ? true : false
|
---|
| 296 | # Use Ruby 1.9 M17N code (use Ruby 1.8 code if false).
|
---|
| 297 | if ! $b_no_kcode then
|
---|
| 298 | require 'jcode'
|
---|
| 299 | end
|
---|
| 300 | require 'pp'
|
---|
| 301 | # include RUNIT::Assert
|
---|
| 302 |
|
---|
| 303 | ### ã°ãã¼ãã«å¤æ°å®ç¾© ###
|
---|
| 304 |
|
---|
| 305 | # ã³ãã³ãã©ã¤ã³å¼æ°ã (Makefile.templ ã¸åºå)
|
---|
| 306 | $arguments = ""
|
---|
| 307 | ARGV.each { |a| $arguments += " " + a }
|
---|
| 308 |
|
---|
| 309 | $unopt = false # bool: disable optimizing both call and entry port
|
---|
| 310 | $unopt_entry= false # bool: disable optimizing entry port
|
---|
| 311 | $gen_base = "gen" # string: folder path to place generated files
|
---|
| 312 | $gen = $gen_base # string: folder path to place generated files
|
---|
| 313 | $generate_all_template = false # bool: generarete template files for all celltypes (if non cell exist or system celltypes)
|
---|
| 314 | $generate_no_template = false # bool: generarete no template file (neither celltype code nor Makefile)
|
---|
| 315 | $idx_is_id = false # bool: all components are idx_is_id
|
---|
| 316 | $unique_id = false # bool: assign unique id to each cell (otherwise begin from 1 for each celltype)
|
---|
| 317 | $debug = false # bool: tecsgen debug message
|
---|
| 318 | $dryrun = false # bool: dryrun mode: syntax is checked, but not generate any files
|
---|
| 319 | $show_tree = false # bool: show parsing tree
|
---|
| 320 | $verbose = false # bool: verbose mode: show some messages
|
---|
| 321 | $yydebug = false # bool: yydebug: parser debug mode (need bnf-deb.tab.rb)
|
---|
| 322 | $run_dir = Dir.pwd # string: tecsgen/tecscde start up directory
|
---|
| 323 | $base_dir = { } # string=>bool: base dir for import_path (key:base_dir, val:actually used or specified directly)
|
---|
| 324 | $import_path = [ "." ] # string array : import/import_C path
|
---|
| 325 | $import_path_opt = [] # [String]
|
---|
| 326 | $library_path = [ $tecsgen_base_path ] # string array : path to dir where tecsgen.rb placed
|
---|
| 327 | $define = [ ] # string array : define
|
---|
| 328 | $ram_initializer = false # bool: generate ram initializer
|
---|
| 329 | $region_list = {} #string array : region path which is generated
|
---|
| 330 | $generating_region = nil # Region: Region to optimisze & generate code # ã³ãã³ãã©ã¤ã³ãªãã·ã§ã³ã§ã¯ãªã
|
---|
| 331 | # Cell#is_generate? ã«ã¦åç
|
---|
| 332 | §ããã
|
---|
| 333 | $unit_test = false # bool: unit test verification
|
---|
| 334 | $kcode = nil # nil | String: Kanji code type "euc"|"sjis"|"none"|"utf8"
|
---|
| 335 | $force_overwrite = false # bool: force overwrite all files if file contents not differ
|
---|
| 336 | $no_banner = false # bool: not print banner
|
---|
| 337 | $print_version = false # bool: print version
|
---|
| 338 | $target = "tecs" # String: target name, ARGV[0] ããåè¨å®ããï¼"tecs" ã¯ä»®ã®ã¿ã¼ã²ãã)
|
---|
| 339 | $no_default_import_path = false # bool: no default import path
|
---|
| 340 | $c_suffix = "c" # suffix for C progorams (for C++ source)
|
---|
| 341 | $h_suffix = "h" # suffix for C progoram headers (for C++ source)
|
---|
| 342 |
|
---|
| 343 | if ENV['TECSGEN_DEFAULT_RAM'] then
|
---|
| 344 | rom_ram_defalult = "ram"
|
---|
| 345 | else
|
---|
| 346 | rom_ram_defalult = "rom"
|
---|
| 347 | end
|
---|
| 348 | if rom_ram_defalult == "rom" then
|
---|
| 349 | $rom = true # bool: ROM support : generate CB separately
|
---|
| 350 | else
|
---|
| 351 | $rom = false # bool: ROM support : generate CB separately
|
---|
| 352 | end
|
---|
| 353 | $b_cpp_specified = false
|
---|
| 354 | if $cpp == nil then
|
---|
| 355 | $cpp = "gcc -E -DTECSGEN"
|
---|
| 356 | end
|
---|
| 357 | if ENV[ 'TECS_CPP' ]then
|
---|
| 358 | $cpp = ENV[ 'TECS_CPP' ]
|
---|
| 359 | $b_cpp_specified = true
|
---|
| 360 | end
|
---|
| 361 | if ENV[ 'TECSPATH' ] then
|
---|
| 362 | $tecspath = ENV[ 'TECSPATH' ]
|
---|
| 363 | else
|
---|
| 364 | $tecspath = "#{$tecsgen_base_path}/tecs"
|
---|
| 365 | end
|
---|
| 366 |
|
---|
| 367 | # # æåã³ã¼ãã®è¨å®
|
---|
| 368 | if $IN_EXERB then
|
---|
| 369 | # KCODE_CDL, $KCONV_CDL ãä»®ã«è¨å®ãã (tecs_lang.rb ã§ããã«åè¨å®ããã)
|
---|
| 370 | $KCODE_CDL = "SJIS" # string: "EUC" | "SJIS" | "NONE" | "UTF8"
|
---|
| 371 | $KCONV_CDL = Kconv::SJIS # const: NONE ã«ã¯ ASCII ã対å¿ããã
|
---|
| 372 | else
|
---|
| 373 | $KCODE_CDL = "EUC" # string: "EUC" | "SJIS" | "NONE" | "UTF8"
|
---|
| 374 | $KCONV_CDL = Kconv::EUC # const: NONE ã«ã¯ ASCII ã対å¿ããã
|
---|
| 375 | end
|
---|
| 376 | # $KCODE_TECSGEN, $KCONV_TECSGEN ãä»®ã«è¨å®ãã (tecs_lang.rb ã§ããã«åè¨å®ããã)
|
---|
| 377 | $KCODE_TECSGEN = "UTF8" # string: "EUC" ãã®ãã¡ã¤ã«ã®æåã³ã¼ãï¼ãªãã·ã§ã³ã§ã¯ãªãå®æ°ï¼
|
---|
| 378 | $KCONV_TECSGEN = Kconv::UTF8 # const:
|
---|
| 379 | set_kcode( $KCODE_TECSGEN ) # ãã®ãã¡ã¤ã«ã®æåã³ã¼ããè¨å®
|
---|
| 380 |
|
---|
| 381 | end # initialize_global_var
|
---|
| 382 |
|
---|
| 383 | def self.analyze_option( additional_option_parser )
|
---|
| 384 |
|
---|
| 385 | ### tecsgen ã³ãã³ããªãã·ã§ã³è§£æ ###
|
---|
| 386 | ARGV.options {|parser|
|
---|
| 387 | parser.banner = "Usage: tecsgen [options] files"
|
---|
| 388 | parser.on('-D', '--define=def', 'define cpp symbol for import_C') { |define|
|
---|
| 389 | $define << define
|
---|
| 390 | }
|
---|
| 391 | parser.on('-G', '--generate-region=path', 'generate region') { |path|
|
---|
| 392 | if path =~ /^::/ then
|
---|
| 393 | gen_path = path
|
---|
| 394 | else
|
---|
| 395 | gen_path = "::" + path
|
---|
| 396 | end
|
---|
| 397 | $region_list[ gen_path ] = true
|
---|
| 398 | }
|
---|
| 399 | parser.on('-I', '--import-path=path', 'imoprt/import_C path') { |path|
|
---|
| 400 | $import_path << path
|
---|
| 401 | $import_path_opt << path
|
---|
| 402 | }
|
---|
| 403 | parser.on('-L', '--library-path=path', 'path to dir where tecsgen.rb (obsolete, unnecessary to specify -L, those passes are gotten from tecsgen.rb') { |path|
|
---|
| 404 | $library_path << path
|
---|
| 405 | }
|
---|
| 406 | parser.on('-R', '--RAM-initializer', 'generate RAM initializer. INITIALIZE_TECS() must be called before running any TECS code.' ){
|
---|
| 407 | $ram_initializer = true
|
---|
| 408 | }
|
---|
| 409 | parser.on('-U', '--unoptimize', 'unoptimize') {
|
---|
| 410 | $unopt = true
|
---|
| 411 | }
|
---|
| 412 | parser.on('--unoptimize-entry', 'unoptimize entry port') {
|
---|
| 413 | $unopt_entry = true
|
---|
| 414 | }
|
---|
| 415 | parser.on('-c', '--cpp=cpp_cmd', 'C pre-processor command used import_C (default: gcc -E -DTECSGEN), you can also specify by environment variable TECS_CPP' ){
|
---|
| 416 | |arg|
|
---|
| 417 | $cpp = arg
|
---|
| 418 | $b_cpp_specified = true
|
---|
| 419 | }
|
---|
| 420 | parser.on('-d', '--dryrun', 'dryrun' ){
|
---|
| 421 | $dryrun = true
|
---|
| 422 | }
|
---|
| 423 | parser.on('-f', '--force-overwrite', 'force overwrite all files') {
|
---|
| 424 | $force_overwrite = true
|
---|
| 425 | }
|
---|
| 426 | parser.on('-g', '--gen=dir', 'generate dir') { |dir|
|
---|
| 427 | $gen = $gen_base = dir
|
---|
| 428 | }
|
---|
| 429 | parser.on('-i', '--idx_is_id', 'set idx_is_id to all celltypes') {
|
---|
| 430 | $idx_is_id = true
|
---|
| 431 | }
|
---|
| 432 | # parser.on('-k', '--kcode=code', 'set kanji code: euc|sjis|none|utf8, none is default') { |code|
|
---|
| 433 | parser.on('-k', '--kcode=code', "set kanji code: euc|sjis|none|utf8") { |code|
|
---|
| 434 | $kcode = code
|
---|
| 435 | }
|
---|
| 436 | # old_mode 㯠V1.0.C.22 ã§å»æ¢
|
---|
| 437 | # parser.on('-o', '--old-mode', 'old mode' ){
|
---|
| 438 | # $old_mode = true
|
---|
| 439 | # }
|
---|
| 440 | parser.on('-r', '--ram', 'RAM only' ){
|
---|
| 441 | $rom = false
|
---|
| 442 | }
|
---|
| 443 | parser.on('-s', '--show-tree', 'show parsing tree' ){
|
---|
| 444 | $show_tree = true
|
---|
| 445 | }
|
---|
| 446 | parser.on('-t', '--generator-debug', 'generator debug' ){
|
---|
| 447 | $debug = true
|
---|
| 448 | $verbose = true
|
---|
| 449 | }
|
---|
| 450 | parser.on('-u', '--unique-id', 'assign unique id for each cell' ){
|
---|
| 451 | $unique_id = true
|
---|
| 452 | }
|
---|
| 453 | parser.on('-v', '--verbose', 'verbose mode' ){
|
---|
| 454 | $verbose = true
|
---|
| 455 | }
|
---|
| 456 | parser.on('-y', '--yydebug', 'yydebug' ){
|
---|
| 457 | $yydebug = true
|
---|
| 458 | }
|
---|
| 459 | parser.on( '--no-banner', 'not display banner') {
|
---|
| 460 | $no_banner = true
|
---|
| 461 | }
|
---|
| 462 | parser.on( '--version', 'print version') {
|
---|
| 463 | $print_version = true
|
---|
| 464 | }
|
---|
| 465 | parser.on( '--unit-test', 'unit verification (test tecsgen itself)') {
|
---|
| 466 | $unit_test = true
|
---|
| 467 | }
|
---|
| 468 | parser.on( '--generate-all-template', 'generate all celltypes\' templates') {
|
---|
| 469 | $generate_all_template = true
|
---|
| 470 | }
|
---|
| 471 | parser.on( '--generate-no-template', 'generate no template') {
|
---|
| 472 | $generate_no_template = true
|
---|
| 473 | }
|
---|
| 474 | parser.on( '--no-default-import-path', 'no default import path' ){
|
---|
| 475 | $no_default_import_path = true
|
---|
| 476 | }
|
---|
| 477 | parser.on( '--c-suffix=c', 'C program suffix (default: c)' ){
|
---|
| 478 | | suffix |
|
---|
| 479 | $c_suffix = suffix
|
---|
| 480 | }
|
---|
| 481 | parser.on( '--h-suffix=h', 'C program header suffix (default: h)' ){
|
---|
| 482 | | suffix |
|
---|
| 483 | $h_suffix = suffix
|
---|
| 484 | }
|
---|
| 485 | # parser.on( '--include_path_opt_format', 'cpp include path option format, default: "-I %s"' ){
|
---|
| 486 | # }
|
---|
| 487 | parser.version = #{$version}
|
---|
| 488 | parser.release = nil
|
---|
| 489 | if additional_option_parser
|
---|
| 490 | additional_option_parser.call( parser )
|
---|
| 491 | end
|
---|
| 492 | parser.parse!
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | if ARGV.empty? && ! $print_version && ! $unit_test && ! $TECSFLOW
|
---|
| 496 | ARGV.options{|parser|
|
---|
| 497 | puts parser.help
|
---|
| 498 | exit 1
|
---|
| 499 | }
|
---|
| 500 | end
|
---|
| 501 |
|
---|
| 502 | end # analyze_option
|
---|
| 503 |
|
---|
| 504 | def self.load_modules
|
---|
| 505 | ### tecsgen ã¢ã¸ã¥ã¼ã«ã®ãã¼ã ####
|
---|
| 506 | # -L ã§ãã¹æå®å¯è½ã¨ããããããããããã¼ããéå§ãã
|
---|
| 507 |
|
---|
| 508 | # tecsgen ãã¼ã¸ã§ã³ãã¡ã¤ã«ã®ãã¼ã
|
---|
| 509 | # ãããå®è¡ããã¾ã§ tecsgen ã®ãã¼ã¸ã§ã³ã表示ã§ããªã
|
---|
| 510 | # ãã®ãã¡ã¤ã«ã誤ã£ã¦èªã¿è¾¼ãã¨ãç°ãªããã¼ã¸ã§ã³åã表示ãã¦ãã¾ã
|
---|
| 511 | require_tecsgen_lib 'tecslib/version.rb'
|
---|
| 512 | if $title then
|
---|
| 513 | STDERR << "#{$title} version #{$tool_version} (tecsgen version #{$version}) #{$Copyright}\n"
|
---|
| 514 | elsif ! $no_banner || $print_version
|
---|
| 515 | STDERR << "tecsgen version #{$version} #{$Copyright}\n"
|
---|
| 516 | end
|
---|
| 517 | if $verbose then
|
---|
| 518 | STDERR << "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]\n"
|
---|
| 519 | end
|
---|
| 520 | if $print_version && ARGV.empty? && ! $TECSFLOW
|
---|
| 521 | exit
|
---|
| 522 | end
|
---|
| 523 |
|
---|
| 524 | # æåã³ã¼ã決å®ã®ããæåã«èªã¿ãã
|
---|
| 525 | require_tecsgen_lib 'tecslib/core/tecs_lang.rb'
|
---|
| 526 |
|
---|
| 527 | unless $yydebug then
|
---|
| 528 | require_tecsgen_lib 'tecslib/core/bnf.tab.rb'
|
---|
| 529 | else
|
---|
| 530 | require_tecsgen_lib 'tecslib/core/bnf-deb.tab.rb'
|
---|
| 531 | end
|
---|
| 532 |
|
---|
| 533 | # syntaxobj.rb ã«ã¯ Node ãå®ç¾©ããã¦ããã®ã§ãæ©ã段é㧠require
|
---|
| 534 | require_tecsgen_lib 'tecslib/core/syntaxobj.rb'
|
---|
| 535 | require_tecsgen_lib 'tecslib/core/pluginModule.rb'
|
---|
| 536 | require_tecsgen_lib 'tecslib/core/plugin.rb'
|
---|
| 537 | require_tecsgen_lib 'tecslib/core/messages.rb'
|
---|
| 538 | require_tecsgen_lib 'tecslib/core/types.rb'
|
---|
| 539 | require_tecsgen_lib 'tecslib/core/value.rb'
|
---|
| 540 | require_tecsgen_lib 'tecslib/core/componentobj.rb'
|
---|
| 541 | require_tecsgen_lib 'tecslib/core/expression.rb'
|
---|
| 542 | require_tecsgen_lib 'tecslib/core/optimize.rb'
|
---|
| 543 | require_tecsgen_lib 'tecslib/core/tecsgen.rb'
|
---|
| 544 | require_tecsgen_lib 'tecslib/core/generate.rb'
|
---|
| 545 | require_tecsgen_lib 'tecslib/core/gen_xml.rb'
|
---|
| 546 | require_tecsgen_lib 'tecslib/core/tool_info.rb'
|
---|
| 547 | require_tecsgen_lib 'tecslib/core/tecsinfo.rb'
|
---|
| 548 | require_tecsgen_lib 'tecslib/core/unjoin_plugin.rb'
|
---|
| 549 | require_tecsgen_lib 'tecslib/plugin/CelltypePlugin.rb'
|
---|
| 550 | require_tecsgen_lib 'tecslib/plugin/CompositePlugin.rb'
|
---|
| 551 | require_tecsgen_lib 'tecslib/plugin/CellPlugin.rb'
|
---|
| 552 | require_tecsgen_lib 'tecslib/plugin/SignaturePlugin.rb'
|
---|
| 553 | require_tecsgen_lib 'tecslib/plugin/ThroughPlugin.rb'
|
---|
| 554 | require_tecsgen_lib 'tecslib/plugin/DomainPlugin.rb'
|
---|
| 555 | require_tecsgen_lib 'tecslib/plugin/MultiPlugin.rb'
|
---|
| 556 |
|
---|
| 557 | # C è¨èªãã¼ãµ
|
---|
| 558 | require_tecsgen_lib 'tecslib/core/C_parser.tab.rb'
|
---|
| 559 | require_tecsgen_lib 'tecslib/core/ctypes.rb'
|
---|
| 560 |
|
---|
| 561 | if $unit_test then
|
---|
| 562 | exit 1
|
---|
| 563 | end
|
---|
| 564 |
|
---|
| 565 | end # load_modules
|
---|
| 566 |
|
---|
| 567 | def self.setup
|
---|
| 568 | # $import_path, $tecspath ã調æ´
|
---|
| 569 | TECSGEN.adjust_exerb_path
|
---|
| 570 |
|
---|
| 571 | # $import_path ã«ç°å¢å¤æ° $TECSGEN ããã³ãã®ç´ä¸ã追å
|
---|
| 572 | if $no_default_import_path == false then
|
---|
| 573 | # $TECSGEN ããã³ããã®ç´ä¸ã®ãã£ã¬ã¯ããªããã¹ã«è¿½å
|
---|
| 574 | if $tecspath != "." then
|
---|
| 575 | TECSGEN.add_import_path $tecspath
|
---|
| 576 | dir = nil
|
---|
| 577 | begin
|
---|
| 578 | Dir.foreach( $tecspath ){ |f|
|
---|
| 579 | if f != "." && f != ".." && File.directory?( $tecspath + '/' + f ) then
|
---|
| 580 | TECSGEN.add_import_path( $tecspath + '/' + f )
|
---|
| 581 | end
|
---|
| 582 | }
|
---|
| 583 | rescue
|
---|
| 584 | # ç¡è¦
|
---|
| 585 | end
|
---|
| 586 | end
|
---|
| 587 | end
|
---|
| 588 |
|
---|
| 589 | # ããã©ã«ãè¨å®
|
---|
| 590 | TECSGEN.set_default_config
|
---|
| 591 |
|
---|
| 592 | # $target ã®è¨å®
|
---|
| 593 | $target = ARGV[0]
|
---|
| 594 | pos = $target.rindex( /[:\\\/]/ )
|
---|
| 595 | if pos then
|
---|
| 596 | $target = $target[pos+1..-1] # ãã£ã¬ã¯ããªåºåããé¤ããæåå
|
---|
| 597 | end
|
---|
| 598 | pos = $target.rindex( /\./ )
|
---|
| 599 | if pos then
|
---|
| 600 | $target = $target[0..pos-1] # æ¡å¼µåãåãé¤ããæåå
|
---|
| 601 | end
|
---|
| 602 |
|
---|
| 603 | # gen ãã£ã¬ã¯ããªã®ä½æ
|
---|
| 604 | begin
|
---|
| 605 | if ! File.directory?( $gen_base ) then
|
---|
| 606 | Dir.mkdir( $gen_base )
|
---|
| 607 | end
|
---|
| 608 | rescue
|
---|
| 609 | print( "Cannot mkdir #{$gen_base}. If the path has hierarchy, please create directory by manual.\n" )
|
---|
| 610 | exit 1
|
---|
| 611 | end
|
---|
| 612 | end # setup
|
---|
| 613 |
|
---|
| 614 | #=== TECSGEN#get_celltype_list
|
---|
| 615 | def get_celltype_list
|
---|
| 616 | @celltype_list
|
---|
| 617 | end
|
---|
| 618 |
|
---|
| 619 | #=== TECSGEN#get_cell_list
|
---|
| 620 | def get_cell_list
|
---|
| 621 | @cell_list
|
---|
| 622 | end
|
---|
| 623 |
|
---|
| 624 | def get_root_namespace
|
---|
| 625 | @root_namespace
|
---|
| 626 | end
|
---|
| 627 | end # TECSGEN
|
---|
| 628 |
|
---|
| 629 | # è¤æ°ã®ã¸ã§ãã¬ã¼ã¿ã¤ã³ã¹ã¿ã³ã¹ãçæãããã¨ã¯ãå¯è½ã ãã以ä¸ã®åé¡ããã
|
---|
| 630 | # ã¯ã©ã¹å¤æ°ã®ãªã»ããã確å®ã«è¡ãå¿
|
---|
| 631 | è¦ããã
|
---|
| 632 |
|
---|
| 633 | if $TECSCDE != true && $TECSFLOW != true then
|
---|
| 634 | begin
|
---|
| 635 | TECSGEN.init
|
---|
| 636 | tecsgen = TECSGEN.new
|
---|
| 637 | tecsgen.run1
|
---|
| 638 | tecsgen.run2
|
---|
| 639 | tecsgen.dump_tecsgen_rbdmp
|
---|
| 640 | rescue => evar
|
---|
| 641 | print_exception( evar )
|
---|
| 642 | STDERR << "tecsgen: exit because of unrecoverble error.\n"
|
---|
| 643 | STDERR << " please retry after resolve early error.\n"
|
---|
| 644 | STDERR << " if no error has occured, please report to TOPPERS TECS WG (users@toppers.jp or com-wg@toppers.jp).\n"
|
---|
| 645 | exit 1
|
---|
| 646 | end
|
---|
| 647 | end
|
---|