Changeset 429 for EcnlProtoTool/trunk/asp3_dcre/utils/gentest.rb
- Timestamp:
- Jul 3, 2020, 7:19:17 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/utils/gentest.rb
r331 r429 5 5 # Toyohashi Open Platform for Embedded Real-Time Systems 6 6 # 7 # Copyright (C) 2007-201 6by Embedded and Real-Time Systems Laboratory7 # Copyright (C) 2007-2019 by Embedded and Real-Time Systems Laboratory 8 8 # Graduate School of Information Science, Nagoya Univ., JAPAN 9 9 # … … 44 44 # 45 45 46 Encoding.default_external = 'utf-8' 47 require "pp" 48 require "fileutils" 49 46 50 # 47 51 # 生成動作を決めるための設定 … … 67 71 "ref_mtx" => { 2 => "T_RMTX" }, 68 72 "ref_mbf" => { 2 => "T_RMBF" }, 73 "ref_spn" => { 2 => "T_RSPN" }, 69 74 "get_mpf" => { 2 => "void *" }, 70 75 "pget_mpf" => { 2 => "void *" }, … … 77 82 "get_tid" => { 1 => "ID" }, 78 83 "get_did" => { 1 => "ID" }, 84 "get_pid" => { 1 => "ID" }, 79 85 "get_lod" => { 2 => "uint_t" }, 80 86 "mget_lod" => { 3 => "uint_t" }, 81 87 "get_nth" => { 3 => "ID" }, 82 88 "mget_nth" => { 4 => "ID" }, 89 "ref_mem" => { 2 => "T_RMEM" }, 83 90 "get_ipm" => { 1 => "PRI" }, 84 91 "get_som" => { 1 => "ID" } … … 86 93 87 94 $functionParameters = { 88 "target_hrt_set_event" => "HRTCNT hrtcnt" 95 "target_hrt_set_event" => "HRTCNT hrtcnt", 96 "hook_hrt_set_event" => "HRTCNT hrtcnt" 89 97 } 90 98 … … 98 106 99 107 $functionCheckParameter = { 100 "target_hrt_set_event" => "hrtcnt" 108 "target_hrt_set_event" => "hrtcnt", 109 "hook_hrt_set_event" => "hrtcnt" 101 110 } 102 111 … … 154 163 lines.each do |line| 155 164 @code[@currentCount].push(line) 156 165 end 157 166 end 158 167 … … 174 183 # 処理カウント変数の生成 175 184 if @countFlag 176 print("\nstatic uint_t\t#{@count_var} = 0;\n")185 $outFile.print("\nstatic uint_t\t#{@count_var} = 0;\n") 177 186 end 178 187 … … 180 189 case @puName 181 190 when /^TASK([0-9]*)$/ 182 print("\nvoid\n")183 print("task#{$1}(intptr_t exinf)\n")191 $outFile.print("\nvoid\n") 192 $outFile.print("task#{$1}(intptr_t exinf)\n") 184 193 when /^CYC([0-9]*)$/ 185 print("\nvoid\n")186 print("cyclic#{$1}_handler(intptr_t exinf)\n")194 $outFile.print("\nvoid\n") 195 $outFile.print("cyclic#{$1}_handler(intptr_t exinf)\n") 187 196 when /^ALM([0-9]*)$/ 188 print("\nvoid\n")189 print("alarm#{$1}_handler(intptr_t exinf)\n")197 $outFile.print("\nvoid\n") 198 $outFile.print("alarm#{$1}_handler(intptr_t exinf)\n") 190 199 when /^OVR$/ 191 print("\nvoid\n")192 print("overrun_handler(ID tskid, intptr_t exinf)\n")200 $outFile.print("\nvoid\n") 201 $outFile.print("overrun_handler(ID tskid, intptr_t exinf)\n") 193 202 when /^ISR([0-9]*)$/ 194 print("\nvoid\n")195 print("isr#{$1}(intptr_t exinf)\n")203 $outFile.print("\nvoid\n") 204 $outFile.print("isr#{$1}(intptr_t exinf)\n") 196 205 when /^INTHDR([0-9]*)$/ 197 print("\nvoid\n")198 print("inthdr#{$1}_handler(void)\n")206 $outFile.print("\nvoid\n") 207 $outFile.print("inthdr#{$1}_handler(void)\n") 199 208 when /^CPUEXC([0-9]*)$/ 200 print("\nvoid\n")201 print("cpuexc#{$1}_handler(void *p_excinf)\n")209 $outFile.print("\nvoid\n") 210 $outFile.print("cpuexc#{$1}_handler(void *p_excinf)\n") 202 211 when /^EXTSVC([0-9]*)$/ 203 print("\nER_UINT\n")204 print("extsvc#{$1}_routine")205 print("(intptr_t par1, intptr_t par2, intptr_t par3,\n")206 print("\t\t\t\t\t\t\t\tintptr_t par4, intptr_t par5, ID cdmid)\n")212 $outFile.print("\nER_UINT\n") 213 $outFile.print("extsvc#{$1}_routine") 214 $outFile.print("(intptr_t par1, intptr_t par2, intptr_t par3,\n") 215 $outFile.print("\t\t\t\t\t\t\t\tintptr_t par4, intptr_t par5, ID cdmid)\n") 207 216 else 208 217 if $functionValue[@puName] 209 print("\n#{$functionValue[@puName]}\n")218 $outFile.print("\n#{$functionValue[@puName]}\n") 210 219 else 211 print("\nvoid\n")212 end 213 print(@puName)220 $outFile.print("\nvoid\n") 221 end 222 $outFile.print(@puName) 214 223 if $functionParameters[@puName] 215 print("(#{$functionParameters[@puName]})\n")224 $outFile.print("(#{$functionParameters[@puName]})\n") 216 225 else 217 print("(void)\n")218 end 219 end 220 221 print("{\n")226 $outFile.print("(void)\n") 227 end 228 end 229 230 $outFile.print("{\n") 222 231 223 232 @variableList.each do |varName, varType| 224 233 if /^(.+)\w*\*$/ =~ varType 225 234 varBaseType = $1 226 print("\t#{varBaseType}")227 print(varBaseType.length < 4 ? "\t\t*" : "\t*")235 $outFile.print("\t#{varBaseType}") 236 $outFile.print(varBaseType.length < 4 ? "\t\t*" : "\t*") 228 237 else 229 print("\t#{varType}")230 print(varType.length < 4 ? "\t\t" : "\t")231 end 232 print("#{varName};\n")238 $outFile.print("\t#{varType}") 239 $outFile.print(varType.length < 4 ? "\t\t" : "\t") 240 end 241 $outFile.print("#{varName};\n") 233 242 end 234 243 if @silFlag 235 print("\tSIL_PRE_LOC;\n")236 end 237 print("\n")244 $outFile.print("\tSIL_PRE_LOC;\n") 245 end 246 $outFile.print("\n") 238 247 239 248 if @countFlag 240 print("\tswitch (++#{@count_var}) {\n")249 $outFile.print("\tswitch (++#{@count_var}) {\n") 241 250 @code.keys.sort_by { |c| c.to_i }.each do |count| 242 print("\tcase #{count}:\n")251 $outFile.print("\tcase #{count}:\n") 243 252 @code[count].each do |line| 244 print("\t",line) if line != ""245 print("\n")253 $outFile.print("\t",line) if line != "" 254 $outFile.print("\n") 246 255 end 247 print("\t\tcheck_point(0);\n\n")248 end 249 print("\tdefault:\n")250 print("\t\tcheck_point(0);\n")251 print("\t}\n")256 $outFile.print("\t\tcheck_assert(false);\n\n") 257 end 258 $outFile.print("\tdefault:\n") 259 $outFile.print("\t\tcheck_assert(false);\n") 260 $outFile.print("\t}\n") 252 261 else 253 262 @code[""].each do |line| 254 print(line,"\n")255 end 256 end 257 258 print("\tcheck_point(0);\n")263 $outFile.print(line,"\n") 264 end 265 end 266 267 $outFile.print("\tcheck_assert(false);\n") 259 268 if /^EXTSVC([0-9]*)$/ =~ @puName 260 print("\treturn(E_SYS);\n")269 $outFile.print("\treturn(E_SYS);\n") 261 270 elsif $functionReturn[@pu_nama] 262 print("\treturn(#{$functionReturn[@puName]});\n")263 end 264 print("}\n")271 $outFile.print("\treturn(#{$functionReturn[@puName]});\n") 272 end 273 $outFile.print("}\n") 265 274 end 266 275 end … … 303 312 def testStartCode(pu) 304 313 # テスト開始コードは一度のみ出力する 305 if $startFlag == 0314 if !$startFlag 306 315 pu.append("\ttest_start(__FILE__);", "") 307 $startFlag = 1316 $startFlag = true 308 317 end 309 318 end … … 312 321 # ターゲット依存部関数の振る舞いの読み込み 313 322 # 314 def targetFunction(line, checkNum )323 def targetFunction(line, checkNum, prcid) 315 324 if /^([a-zA-Z_]+)\s*(.*)$/ =~ line 316 325 functionName = $1 … … 333 342 end 334 343 335 pu.append("\tcheck_point (#{checkNum});");344 pu.append("\tcheck_point#{$cpSuffix[prcid]}(#{checkNum});"); 336 345 if param && $functionCheckParameter[functionName] 337 346 pu.append(sprintf("\tcheck_assert(%s == %s);", … … 347 356 348 357 # 358 # チェックポイント番号の処理 359 # 360 def procCheckPoint(prcid, originalCheckNum, oline_list) 361 checkNum = ($lastCheckPoint[prcid] += 1).to_s 362 oline_list.each do |oline| 363 oline.sub!(/#{originalCheckNum}/, "#{checkNum}:") 364 end 365 return(checkNum) 366 end 367 368 # 349 369 # テストスクリプトの読み込み 350 370 # 351 def parseLine(line) 352 if /^==\s*(([a-zA-Z_]+)[0-9]*)(.*)$/ =~ line 371 def parseLine(line, prcid, oline_list) 372 if /^==\s*START(_[a-zA-Z0-9]+)?(.*)$/ =~ line 373 $procFlag = true unless $procFlagEnd 374 $cpSuffix[prcid] = $1 375 elsif /^==\s*(([a-zA-Z_]+)[0-9]*)(.*)$/ =~ line 353 376 # 処理単位の開始 354 $procFlag = 1377 $procFlag = true unless $procFlagEnd 355 378 puName = $1 356 379 line2 = $3 … … 359 382 pu = $puList[puName] = PUCode.new(puName) 360 383 end 361 $currentPu = pu384 $currentPu[prcid] = pu 362 385 363 386 case line2 … … 369 392 pu.setCount("") 370 393 end 371 testStartCode(pu) if /^START/ !~ puName372 elsif $procFlag != 0373 pu = $currentPu 394 testStartCode(pu) 395 elsif $procFlag 396 pu = $currentPu[prcid] 374 397 if /^([0-9]+\:)\s*(.*)$/ =~ line 375 398 # チェックポイント番号の処理 376 originalCheckNum = $1377 399 line = $2 378 checkNum = ($lastCheckPoint += 1).to_s 379 $outputLine.sub!(/#{originalCheckNum}/, "#{checkNum}:") 400 checkNum = procCheckPoint(prcid, $1, oline_list) 380 401 381 402 case line 382 403 when /^END$/ 383 pu.append("\tcheck_finish (#{checkNum});")384 $procFlag = 0404 pu.append("\tcheck_finish#{$cpSuffix[prcid]}(#{checkNum});") 405 $procFlagEnd = true 385 406 return 386 407 when /^HOOK\((.*)\)$/ … … 388 409 return 389 410 when /^\[(.*)\]$/ 390 targetFunction($1, checkNum )411 targetFunction($1, checkNum, prcid) 391 412 return 392 413 else 393 pu.append("\tcheck_point (#{checkNum});")414 pu.append("\tcheck_point#{$cpSuffix[prcid]}(#{checkNum});") 394 415 end 395 416 end … … 402 423 pu.append("\t#{call_string};", "") 403 424 pu.useSil() if /^SIL_..._INT\(\)$/ =~ call_string 425 when /^VAR\(\s*(.*)\s+(.*)\s*\)$/ 426 pu.addVariable($2, $1) 404 427 when /^RETURN((\(.*\))?)$/ 405 428 pu.append("\treturn#{$1};", "") … … 409 432 when /^LABEL\((.*)\)$/ 410 433 pu.append("#{$1}:", "") 434 when /^BARRIER\((.*)\)$/ 435 pu.append("\ttest_barrier(#{$1});", "") 436 when /^((SET|RESET|WAIT|WAIT_WO_RESET|WAIT_RESET)\(.*\))$/ 437 pu.append("\t#{$1};", "") 411 438 when /^([a-z_]+\(.*\))\s*(\-\>\s*([A-Za-z0-9_]*))?\s*$/ 412 439 genServiceCall(pu, $1, $3) … … 428 455 # 429 456 inFileName = ARGV.shift 457 outFileName = inFileName + ".new" 430 458 431 459 # 432 460 # スクリプトファイル読み込み処理 433 461 # 434 $lastCheckPoint = 0 # 最後のチェックポイント番号 435 $procFlag = 0 # スクリプト処理中フラグ 436 $startFlag = 0 # テスト開始コードの出力フラグ 437 $currentPu = nil # 読み込み中の処理単位 438 $puList = {} # 処理単位のリスト 462 $procFlag = false # スクリプト処理中フラグ 463 $procFlagEnd = false # スクリプト処理終了フラグ 464 $startFlag = false # テスト開始コードの出力フラグ 465 $currentPu = {} # 読み込み中の処理単位 466 $puList = {} # 処理単位のリスト 467 $outputLines = [] # 出力すべき行のリストのリスト 468 $cpSuffix = Hash.new("") # チェックポイント関数のサフィックス 469 $lastCheckPoint = Hash.new(0) # 最後のチェックポイント番号 439 470 440 471 begin 441 472 inFile = File.open(inFileName) 473 $outFile = File.open(outFileName, "w") 442 474 rescue Errno::ENOENT, Errno::EACCES => ex 443 475 abort(ex.message) 444 476 end 445 477 478 statements = Hash.new("") 479 oline_lists = Hash.new([]) 446 480 while line = inFile.gets do 447 $outputLine = line.dup 448 line.chomp! 449 line.sub!(/^\s*\*\s*/, "") 450 line.sub!(/\s*\/\/.*$/, "") 451 line.sub!(/\s*\.\.\..*$/, "") 452 453 while line.sub!(/\\$/, "") do 454 line1 = inFile.gets 455 $outputLine += line1.dup 456 line1.chomp! 457 line1.sub!(/^\s*\*\s*/, "") 458 line1.sub!(/\s*\/\/.*$/, "") 459 line1.sub!(/\s*\.\.\..*$/, "") 460 line += line1 461 end 462 parseLine(line) if line != "" 463 print($outputLine) 464 break if /DO NOT DELETE THIS LINE/ =~ $outputLine 481 line.chomp! # 末尾の改行の削除 482 if /DO NOT DELETE THIS LINE/ =~ line 483 $outputLines.push([ line ]) 484 break 485 elsif line =~ /^(\s*\*)(.*)$/ # 行頭のスペースと "*" の削除 486 outputLine = [ $1.dup ] 487 $2.split(/|/, -1).each_with_index do |sline, index| 488 outLine = sline.dup 489 outputLine.push(outLine) 490 sline.sub!(/^\s*/, "") # 先頭のスペースの削除 491 sline.sub!(/\/\/.*$/, "") # // コメントの削除 492 sline.sub!(/\.\.\..*$/, "") # ... コメントの削除 493 494 prcid = index + 1 495 statements[prcid] += sline 496 oline_lists[prcid].push(outLine) 497 next if statements[prcid].sub!(/\\\s*$/, "") # 継続行の場合 498 499 statements[prcid].sub!(/\s*$/, "") # 末尾のスペースの削除 500 if sline !~ /^\s*$/ 501 parseLine(statements[prcid], prcid, oline_lists[prcid]) 502 end 503 statements[prcid] = "" 504 oline_lists[prcid] = [] 505 end 506 $outputLines.push(outputLine) 507 $procFlag = false if $procFlagEnd 508 else 509 $outputLines.push([ line ]) 510 end 511 end 512 $outputLines.each do |outputLine| 513 outputLine.each_with_index do |sline, index| 514 $outFile.print("|") if index > 1 515 $outFile.print(sline); 516 end 517 $outFile.print("\n"); 465 518 end 466 519 … … 471 524 $puList[puName].generateCode() 472 525 end 526 527 # 528 # ファイルの置き換え 529 # 530 FileUtils.move(inFileName, inFileName + ".bak") 531 FileUtils.move(outFileName, inFileName)
Note:
See TracChangeset
for help on using the changeset viewer.