Skip to content
Snippets Groups Projects
Commit 36793e61 authored by Xun Yang's avatar Xun Yang
Browse files

output .s files to individual folders for each test cases

parent 55b8f097
No related branches found
No related tags found
No related merge requests found
......@@ -3,3 +3,4 @@ __pycache__/
ErrorTest.py
Test.py
*.zip
output/
......@@ -57,7 +57,7 @@ def reachabilityChecking(ASTs):
t[1].reachCheck()
####################################################
def codeGen(ASTs):
def codeGen(ASTs, output="output"):
for t in ASTs:
t[1].codeGen()
# Outputting the generated code into className.s
......@@ -65,22 +65,22 @@ def codeGen(ASTs):
for t in ASTs:
classInterNode = t[1].typeDcl
if classInterNode and classInterNode.__class__.__name__ == "ClassNode":
fileName = "output/" + classInterNode.name + ".s"
fileName = output + "/" + classInterNode.name + ".s"
f = open(fileName, "w")
f.write(classInterNode.code)
f.close()
# ASTs[0][1].codeGen()
startGen(ASTs[0][1]) # pass in the first AST that contains the test method
startGen(ASTs[0][1], output) # pass in the first AST that contains the test method
# reset lables for running multiple testCases
used_labels = set()
local_labels = 0
def startGen(ast):
def startGen(ast, output):
className = ast.typeDcl.name
method_label = "M_" + className + "_test_None"
f = open("output/RunTest.s","w")
f = open( output + "/RunTest.s","w")
result = " global _start\n_start:\n" \
+ p("extern", method_label, None, None) \
......
import sys
import time
from os import listdir, scandir, walk
from os.path import isfile, join
from os import listdir, scandir, walk, makedirs
from os.path import isfile, join, exists
from shutil import rmtree, copyfile
import traceback
from Scanning import scan
......@@ -45,7 +46,13 @@ def a2Multiple():
testFiles = [join(dp, f) for dp, dn, filenames in walk(c) for f in filenames] + testFiles
ret = run(testFiles)
testOutput = "output/" + c.split("/")[-1]
if exists(testOutput):
rmtree(testOutput)
makedirs(testOutput)
copyfile('stdlib/5.0/runtime.s', testOutput + "/runtime.s")
ret = run(testFiles, testOutput)
total += 1
if ret == "":
......@@ -67,7 +74,7 @@ def a2Multiple():
print("\nTime Elapsed: {}".format(time.strftime('%H:%M:%S', time.gmtime(end - start))))
print("SCORE: {} / {} -> {:.3g}%".format(correct, total, (correct/total)*100))
def run(testFiles):
def run(testFiles, testOutput):
parseTrees = []
for f in testFiles:
......@@ -140,7 +147,7 @@ def run(testFiles):
except Exception as e:
return "reachabilityChecking: " + e.args[0]
try:
codeGen(ASTs)
codeGen(ASTs, testOutput)
except Exception as e:
return "code generation: " + e.args[0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment