[304] | 1 | #!/usr/bin/env ruby
|
---|
| 2 | # -*- coding: utf-8 -*-
|
---|
| 3 | #
|
---|
| 4 | # TOPPERS Software
|
---|
| 5 | # Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 6 | #
|
---|
| 7 | # Copyright (C) 2007-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: gentest.rb 578 2016-02-03 07:23:53Z ertl-hiro $
|
---|
| 55 | #
|
---|
| 56 |
|
---|
| 57 | #
|
---|
| 58 | # ãã¹ãããã°ã©ã çæãã¼ã«
|
---|
| 59 | #
|
---|
| 60 |
|
---|
| 61 | #
|
---|
| 62 | # çæåä½ã決ããããã®è¨å®
|
---|
| 63 | #
|
---|
| 64 | $parameterPosition = {
|
---|
| 65 | "get_tst" => 2,
|
---|
| 66 | "get_pri" => 2,
|
---|
| 67 | "get_inf" => 1,
|
---|
| 68 | "ref_tsk" => 2,
|
---|
| 69 | "ref_sem" => 2,
|
---|
| 70 | "ref_flg" => 2,
|
---|
| 71 | "ref_dtq" => 2,
|
---|
| 72 | "ref_pdq" => 2,
|
---|
| 73 | "ref_mtx" => 2,
|
---|
| 74 | "ref_mbf" => 2,
|
---|
| 75 | "ref_mpf" => 2,
|
---|
| 76 | "get_tim" => 1,
|
---|
| 77 | "ref_cyc" => 2,
|
---|
| 78 | "ref_alm" => 2,
|
---|
| 79 | "ref_ovr" => 2,
|
---|
| 80 | "get_tid" => 1,
|
---|
| 81 | "iget_tid" => 1,
|
---|
| 82 | "get_lod" => 2,
|
---|
| 83 | "get_nth" => 3,
|
---|
| 84 | "get_ipm" => 1,
|
---|
| 85 | "wai_flg" => 4,
|
---|
| 86 | "pol_flg" => 4,
|
---|
| 87 | "twai_flg" => 4,
|
---|
| 88 | "rcv_dtq" => 2,
|
---|
| 89 | "prcv_dtq" => 2,
|
---|
| 90 | "trcv_dtq" => 2,
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | $parameterType = {
|
---|
| 94 | "get_tst" => "STAT",
|
---|
| 95 | "get_pri" => "PRI",
|
---|
| 96 | "get_inf" => "intptr_t",
|
---|
| 97 | "ref_tsk" => "T_RTSK",
|
---|
| 98 | "ref_sem" => "T_RSEM",
|
---|
| 99 | "ref_flg" => "T_RFLG",
|
---|
| 100 | "ref_dtq" => "T_RDTQ",
|
---|
| 101 | "ref_pdq" => "T_RPDQ",
|
---|
| 102 | "ref_mtx" => "T_RMTX",
|
---|
| 103 | "ref_mbf" => "T_RMBF",
|
---|
| 104 | "ref_mpf" => "T_RMPF",
|
---|
| 105 | "get_tim" => "SYSTIM",
|
---|
| 106 | "ref_cyc" => "T_RCYC",
|
---|
| 107 | "ref_alm" => "T_RALM",
|
---|
| 108 | "ref_ovr" => "T_ROVR",
|
---|
| 109 | "get_tid" => "ID",
|
---|
| 110 | "iget_tid" => "ID",
|
---|
| 111 | "get_lod" => "uint_t",
|
---|
| 112 | "get_nth" => "ID",
|
---|
| 113 | "get_ipm" => "PRI",
|
---|
| 114 | "wai_flg" => "FLGPTN",
|
---|
| 115 | "pol_flg" => "FLGPTN",
|
---|
| 116 | "twai_flg" => "FLGPTN",
|
---|
| 117 | "rcv_dtq" => "intptr_t",
|
---|
| 118 | "prcv_dtq" => "intptr_t",
|
---|
| 119 | "trcv_dtq" => "intptr_t",
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | $functionParameters = {
|
---|
| 123 | "target_hrt_set_event" => "HRTCNT hrtcnt",
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | $functionValue = {
|
---|
| 127 | "target_hrt_get_current" => "HRTCNT",
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | $functionReturn = {
|
---|
| 131 | "target_hrt_get_current" => "0U",
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | $functionCheckParameter = {
|
---|
| 135 | "target_hrt_set_event" => "hrtcnt",
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | #
|
---|
| 139 | # å¦çåä½ã®ã³ã¼ããæ ¼ç´ããã¯ã©ã¹
|
---|
| 140 | #
|
---|
| 141 | class PUCode
|
---|
| 142 | # åæå
|
---|
| 143 | def initialize(puName)
|
---|
| 144 | @puName = puName # å¦çåä½ã®åå
|
---|
| 145 | @currentCount = "" # å¦çã«ã¦ã³ã
|
---|
| 146 | @countFlag = false # å¦çã«ã¦ã³ãã使ãããã
|
---|
| 147 | @code = Hash.new { |h,k| h[k] = [] } # å¦çåä½ã®ã³ã¼ã
|
---|
| 148 | @variableList = {} # å¦çåä½ã®å¤æ°
|
---|
| 149 | @silFlag = false # SILã使ãããã
|
---|
| 150 |
|
---|
| 151 | # å¦çã«ã¦ã³ãå¤æ°åã®çæ
|
---|
| 152 | case puName
|
---|
| 153 | when /^TASK([0-9]*)$/
|
---|
| 154 | @count_var = "task#{$1}_count"
|
---|
| 155 | when /^CYC([0-9]*)$/
|
---|
| 156 | @count_var = "cyclic#{$1}_count"
|
---|
| 157 | when /^ALM([0-9]*)$/
|
---|
| 158 | @count_var = "alarm#{$1}_count"
|
---|
| 159 | when /^OVR$/
|
---|
| 160 | @count_var = "overrun_count"
|
---|
| 161 | when /^CPUEXC([0-9]*)$/
|
---|
| 162 | @count_var = "cpuexc#{$1}_count"
|
---|
| 163 | when /^EXTSVC([0-9]*)$/
|
---|
| 164 | @count_var = "extsvc#{$1}_count"
|
---|
| 165 | else
|
---|
| 166 | @count_var = puName + "_count"
|
---|
| 167 | end
|
---|
| 168 | end
|
---|
| 169 |
|
---|
| 170 | # å¦çã«ã¦ã³ãã®è¨å®
|
---|
| 171 | def setCount(count)
|
---|
| 172 | @countFlag = true if count != ""
|
---|
| 173 | @currentCount = count
|
---|
| 174 | end
|
---|
| 175 |
|
---|
| 176 | # å¦çã«ã¦ã³ãã®ã¤ã³ã¯ãªã¡ã³ã
|
---|
| 177 | def incrementCount
|
---|
| 178 | if @currentCount != ""
|
---|
| 179 | @currentCount = (@currentCount.to_i + 1).to_s
|
---|
| 180 | end
|
---|
| 181 | end
|
---|
| 182 |
|
---|
| 183 | # ã³ã¼ãã®è¿½å
|
---|
| 184 | def append(*lines)
|
---|
| 185 | lines.each do |line|
|
---|
| 186 | @code[@currentCount].push(line)
|
---|
| 187 | end
|
---|
| 188 | end
|
---|
| 189 |
|
---|
| 190 | # å¤æ°ã®è¿½å
|
---|
| 191 | def addVariable(varName, typeName)
|
---|
| 192 | @variableList[varName] = typeName
|
---|
| 193 | end
|
---|
| 194 |
|
---|
| 195 | # SILã®ä½¿ç¨
|
---|
| 196 | def useSil
|
---|
| 197 | @silFlag = true
|
---|
| 198 | end
|
---|
| 199 |
|
---|
| 200 | # å¦çåä½ã®ã³ã¼ãã®åºå
|
---|
| 201 | def generateCode
|
---|
| 202 | # ä¸è¦ãªå¦çåä½ã®å¤å®
|
---|
| 203 | return if @code.length == 0
|
---|
| 204 |
|
---|
| 205 | # å¦çã«ã¦ã³ãå¤æ°ã®çæ
|
---|
| 206 | if @countFlag
|
---|
| 207 | print("\nstatic uint_t\t#{@count_var} = 0;\n")
|
---|
| 208 | end
|
---|
| 209 |
|
---|
| 210 | # é¢æ°ãããã®çæ
|
---|
| 211 | case @puName
|
---|
| 212 | when /^TASK([0-9]*)$/
|
---|
| 213 | print("\nvoid\n")
|
---|
| 214 | print("task#{$1}(intptr_t exinf)\n")
|
---|
| 215 | when /^CYC([0-9]*)$/
|
---|
| 216 | print("\nvoid\n")
|
---|
| 217 | print("cyclic#{$1}_handler(intptr_t exinf)\n")
|
---|
| 218 | when /^ALM([0-9]*)$/
|
---|
| 219 | print("\nvoid\n")
|
---|
| 220 | print("alarm#{$1}_handler(intptr_t exinf)\n")
|
---|
| 221 | when /^OVR$/
|
---|
| 222 | print("\nvoid\n")
|
---|
| 223 | print("overrun_handler(ID tskid, intptr_t exinf)\n")
|
---|
| 224 | when /^CPUEXC([0-9]*)$/
|
---|
| 225 | print("\nvoid\n")
|
---|
| 226 | print("cpuexc#{$1}_handler(void *p_excinf)\n")
|
---|
| 227 | when /^EXTSVC([0-9]*)$/
|
---|
| 228 | print("\nER_UINT\n")
|
---|
| 229 | print("extsvc#{$1}_routine")
|
---|
| 230 | print("(intptr_t par1, intptr_t par2, intptr_t par3,\n")
|
---|
| 231 | print("\t\t\t\t\t\t\t\tintptr_t par4, intptr_t par5, ID cdmid)\n")
|
---|
| 232 | else
|
---|
| 233 | if $functionValue[@puName]
|
---|
| 234 | print("\n#{$functionValue[@puName]}\n")
|
---|
| 235 | else
|
---|
| 236 | print("\nvoid\n")
|
---|
| 237 | end
|
---|
| 238 | print(@puName)
|
---|
| 239 | if $functionParameters[@puName]
|
---|
| 240 | print("(#{$functionParameters[@puName]})\n")
|
---|
| 241 | else
|
---|
| 242 | print("(void)\n")
|
---|
| 243 | end
|
---|
| 244 | end
|
---|
| 245 |
|
---|
| 246 | print("{\n")
|
---|
| 247 |
|
---|
| 248 | @variableList.keys.each do |varName|
|
---|
| 249 | print("\t#{@variableList[varName]}")
|
---|
| 250 | print(@variableList[varName].length < 4 ? "\t\t" : "\t")
|
---|
| 251 | print("#{varName};\n")
|
---|
| 252 | end
|
---|
| 253 | if @silFlag
|
---|
| 254 | print("\tSIL_PRE_LOC;\n")
|
---|
| 255 | end
|
---|
| 256 | print("\n")
|
---|
| 257 |
|
---|
| 258 | if @countFlag
|
---|
| 259 | print("\tswitch (++#{@count_var}) {\n")
|
---|
| 260 | @code.keys.sort_by { |c| c.to_i }.each do |count|
|
---|
| 261 | print("\tcase #{count}:\n")
|
---|
| 262 | @code[count].each do |line|
|
---|
| 263 | print("\t",line) if line != ""
|
---|
| 264 | print("\n")
|
---|
| 265 | end
|
---|
| 266 | print("\t\tcheck_point(0);\n\n")
|
---|
| 267 | end
|
---|
| 268 | print("\tdefault:\n")
|
---|
| 269 | print("\t\tcheck_point(0);\n")
|
---|
| 270 | print("\t}\n")
|
---|
| 271 | else
|
---|
| 272 | @code[""].each do |line|
|
---|
| 273 | print(line,"\n")
|
---|
| 274 | end
|
---|
| 275 | end
|
---|
| 276 |
|
---|
| 277 | print("\tcheck_point(0);\n")
|
---|
| 278 | if /^EXTSVC([0-9]*)$/ =~ @puName
|
---|
| 279 | print("\treturn(E_SYS);\n")
|
---|
| 280 | elsif $functionReturn[@pu_nama]
|
---|
| 281 | print("\treturn(#{$functionReturn[@puName]});\n")
|
---|
| 282 | end
|
---|
| 283 | print("}\n")
|
---|
| 284 | end
|
---|
| 285 | end
|
---|
| 286 |
|
---|
| 287 | #
|
---|
| 288 | # ãµã¼ãã¹ã³ã¼ã«å¼ã³åºãã®èªã¿è¾¼ã¿
|
---|
| 289 | #
|
---|
| 290 | def genServiceCall(pu, svc_call, error_code)
|
---|
| 291 | pu.addVariable("ercd", "ER_UINT")
|
---|
| 292 | pu.append("\tercd = #{svc_call};")
|
---|
| 293 |
|
---|
| 294 | if /^([a-z_]+)\((.*)\)$/ =~ svc_call
|
---|
| 295 | svcName = $1;
|
---|
| 296 | params = $2.split(/\s*,\s*/)
|
---|
| 297 |
|
---|
| 298 | if !$parameterPosition[svcName].nil? \
|
---|
| 299 | && params.size >= $parameterPosition[svcName]
|
---|
| 300 | varName = params[$parameterPosition[svcName] - 1].sub(/^\&/, "")
|
---|
| 301 | typeName = $parameterType[svcName]
|
---|
| 302 | pu.addVariable(varName, typeName)
|
---|
| 303 | end
|
---|
| 304 | end
|
---|
| 305 |
|
---|
| 306 | if !error_code
|
---|
| 307 | # E_OKãè¿ãå ´å
|
---|
| 308 | pu.append("\tcheck_ercd(ercd, E_OK);", "")
|
---|
| 309 | elsif error_code == "noreturn"
|
---|
| 310 | # ãªã¿ã¼ã³ããªãå ´å
|
---|
| 311 | pu.append("")
|
---|
| 312 | else
|
---|
| 313 | pu.append("\tcheck_ercd(ercd, #{error_code});", "")
|
---|
| 314 | end
|
---|
| 315 | end
|
---|
| 316 |
|
---|
| 317 | #
|
---|
| 318 | # ãã¹ãéå§ã³ã¼ãã®çæ
|
---|
| 319 | #
|
---|
| 320 | def testStartCode(pu)
|
---|
| 321 | # ãã¹ãéå§ã³ã¼ãã¯ä¸åº¦ã®ã¿åºåãã
|
---|
| 322 | if $startFlag == 0
|
---|
| 323 | pu.append("\ttest_start(__FILE__);", "")
|
---|
| 324 | $startFlag = 1
|
---|
| 325 | end
|
---|
| 326 | end
|
---|
| 327 |
|
---|
| 328 | #
|
---|
| 329 | # ã¿ã¼ã²ããä¾åé¨é¢æ°ã®æ¯ãèãã®èªã¿è¾¼ã¿
|
---|
| 330 | #
|
---|
| 331 | def targetFunction(line, checkNum)
|
---|
| 332 | if /^([a-zA-Z_]+)\s*(.*)$/ =~ line
|
---|
| 333 | functionName = $1
|
---|
| 334 | line = $2
|
---|
| 335 | if (pu = $puList[functionName]).nil?
|
---|
| 336 | # æ°ããå¦çåä½ã®çæ
|
---|
| 337 | pu = $puList[functionName] = PUCode.new(functionName)
|
---|
| 338 | pu.setCount("1")
|
---|
| 339 | testStartCode(pu)
|
---|
| 340 | end
|
---|
| 341 | end
|
---|
| 342 |
|
---|
| 343 | if /\-\>\s*([^\s]+)\s*(.*)$/ =~ line
|
---|
| 344 | retval = $1
|
---|
| 345 | line = $2
|
---|
| 346 | end
|
---|
| 347 | if /\<\-\s*([^\s]+)\s*(.*)$/ =~ line
|
---|
| 348 | param = $1
|
---|
| 349 | line = $2
|
---|
| 350 | end
|
---|
| 351 |
|
---|
| 352 | pu.append("\tcheck_point(#{checkNum});");
|
---|
| 353 | if param && $functionCheckParameter[functionName]
|
---|
| 354 | pu.append(sprintf("\tcheck_assert(%s == %s);",
|
---|
| 355 | $functionCheckParameter[functionName], param), "")
|
---|
| 356 | end
|
---|
| 357 | if retval
|
---|
| 358 | pu.append("\treturn(#{retval});", "")
|
---|
| 359 | else
|
---|
| 360 | pu.append("\treturn;", "")
|
---|
| 361 | end
|
---|
| 362 | pu.incrementCount()
|
---|
| 363 | end
|
---|
| 364 |
|
---|
| 365 | #
|
---|
| 366 | # ãã¹ãã¹ã¯ãªããã®èªã¿è¾¼ã¿
|
---|
| 367 | #
|
---|
| 368 | def parseLine(line)
|
---|
| 369 | if /^==\s*(([a-zA-Z_]+)[0-9]*)(.*)$/ =~ line
|
---|
| 370 | # å¦çåä½ã®éå§
|
---|
| 371 | $procFlag = 1
|
---|
| 372 | puName = $1
|
---|
| 373 | line2 = $3
|
---|
| 374 | if (pu = $puList[puName]).nil?
|
---|
| 375 | # æ°ããå¦çåä½ã®çæ
|
---|
| 376 | pu = $puList[puName] = PUCode.new(puName)
|
---|
| 377 | end
|
---|
| 378 | $currentPu = pu
|
---|
| 379 |
|
---|
| 380 | case line2
|
---|
| 381 | when /^\-([0-9]+)(.*)$/
|
---|
| 382 | pu.setCount($1)
|
---|
| 383 | when /^\-[nN](.*)$/
|
---|
| 384 | # do nothing.
|
---|
| 385 | else
|
---|
| 386 | pu.setCount("")
|
---|
| 387 | end
|
---|
| 388 | testStartCode(pu) if /^START/ !~ puName
|
---|
| 389 | elsif $procFlag != 0
|
---|
| 390 | pu = $currentPu
|
---|
| 391 | if /^([0-9]+\:)\s*(.*)$/ =~ line
|
---|
| 392 | # ãã§ãã¯ãã¤ã³ãçªå·ã®å¦ç
|
---|
| 393 | originalCheckNum = $1
|
---|
| 394 | line = $2
|
---|
| 395 | checkNum = ($lastCheckPoint += 1).to_s
|
---|
| 396 | $outputLine.sub!(/#{originalCheckNum}/, "#{checkNum}:")
|
---|
| 397 |
|
---|
| 398 | case line
|
---|
| 399 | when /^END$/
|
---|
| 400 | pu.append("\tcheck_finish(#{checkNum});")
|
---|
| 401 | $procFlag = 0
|
---|
| 402 | return
|
---|
| 403 | when /^HOOK\((.*)\)$/
|
---|
| 404 | pu.append(sprintf("\t#{$1};", checkNum))
|
---|
| 405 | return
|
---|
| 406 | when /^\[(.*)\]$/
|
---|
| 407 | targetFunction($1, checkNum)
|
---|
| 408 | return
|
---|
| 409 | else
|
---|
| 410 | pu.append("\tcheck_point(#{checkNum});")
|
---|
| 411 | end
|
---|
| 412 | end
|
---|
| 413 |
|
---|
| 414 | case line
|
---|
| 415 | when /^((assert|state|ipm)\(.*\))$/
|
---|
| 416 | pu.append("\tcheck_#{$1};", "")
|
---|
| 417 | when /^(call|DO)\((.*)\)$/
|
---|
| 418 | call_string = $2
|
---|
| 419 | pu.append("\t#{call_string};", "")
|
---|
| 420 | pu.useSil() if /^SIL_..._INT\(\)$/ =~ call_string
|
---|
| 421 | when /^RETURN((\(.*\))?)$/
|
---|
| 422 | pu.append("\treturn#{$1};", "")
|
---|
| 423 | pu.incrementCount()
|
---|
| 424 | when /^GOTO\((.*)\)$/
|
---|
| 425 | pu.append("\tgoto #{$1};", "")
|
---|
| 426 | when /^LABEL\((.*)\)$/
|
---|
| 427 | pu.append("#{$1}:", "")
|
---|
| 428 | when /^([a-z_]+\(.*\))\s*(\-\>\s*([A-Za-z0-9_]*))?\s*$/
|
---|
| 429 | genServiceCall(pu, $1, $3)
|
---|
| 430 | else
|
---|
| 431 | warn("Error: #{line}")
|
---|
| 432 | end
|
---|
| 433 | end
|
---|
| 434 | end
|
---|
| 435 |
|
---|
| 436 | #
|
---|
| 437 | # ã¨ã©ã¼ãã§ãã¯
|
---|
| 438 | #
|
---|
| 439 | if ARGV.length < 1
|
---|
| 440 | abort("Usage: ruby gentest.rb <test_program>")
|
---|
| 441 | end
|
---|
| 442 |
|
---|
| 443 | #
|
---|
| 444 | # åæå
|
---|
| 445 | #
|
---|
| 446 | inFileName = ARGV.shift
|
---|
| 447 |
|
---|
| 448 | #
|
---|
| 449 | # ã¹ã¯ãªãããã¡ã¤ã«èªã¿è¾¼ã¿å¦ç
|
---|
| 450 | #
|
---|
| 451 | $lastCheckPoint = 0 # æå¾ã®ãã§ãã¯ãã¤ã³ãçªå·
|
---|
| 452 | $procFlag = 0 # ã¹ã¯ãªããå¦çä¸ãã©ã°
|
---|
| 453 | $startFlag = 0 # ãã¹ãéå§ã³ã¼ãã®åºåãã©ã°
|
---|
| 454 | $currentPu = nil # èªã¿è¾¼ã¿ä¸ã®å¦çåä½
|
---|
| 455 | $puList = {} # å¦çåä½ã®ãªã¹ã
|
---|
| 456 |
|
---|
| 457 | begin
|
---|
| 458 | inFile = File.open(inFileName)
|
---|
| 459 | rescue Errno::ENOENT, Errno::EACCES => ex
|
---|
| 460 | abort(ex.message)
|
---|
| 461 | end
|
---|
| 462 |
|
---|
| 463 | while line = inFile.gets do
|
---|
| 464 | $outputLine = line.dup
|
---|
| 465 | line.chomp!
|
---|
| 466 | line.sub!(/^\s*\*\s*/, "")
|
---|
| 467 | line.sub!(/\s*\/\/.*$/, "")
|
---|
| 468 | line.sub!(/\s*\.\.\..*$/, "")
|
---|
| 469 |
|
---|
| 470 | while line.sub!(/\\$/, "") do
|
---|
| 471 | line1 = inFile.gets
|
---|
| 472 | $outputLine += line1.dup
|
---|
| 473 | line1.chomp!
|
---|
| 474 | line1.sub!(/^\s*\*\s*/, "")
|
---|
| 475 | line1.sub!(/\s*\/\/.*$/, "")
|
---|
| 476 | line1.sub!(/\s*\.\.\..*$/, "")
|
---|
| 477 | line += line1
|
---|
| 478 | end
|
---|
| 479 | parseLine(line) if line != ""
|
---|
| 480 | print($outputLine)
|
---|
| 481 | break if /DO NOT DELETE THIS LINE/ =~ $outputLine
|
---|
| 482 | end
|
---|
| 483 |
|
---|
| 484 | #
|
---|
| 485 | # ãã¹ãããã°ã©ã åºåå¦ç
|
---|
| 486 | #
|
---|
| 487 | $puList.keys.sort.each do |puName|
|
---|
| 488 | $puList[puName].generateCode()
|
---|
| 489 | end
|
---|