Skip to content
Snippets Groups Projects
Commit 6ef87e16 authored by Alexis Nasr's avatar Alexis Nasr
Browse files

ajout des fichiers pour l'évaluation 2024

parent a3c337bc
Branches
No related tags found
No related merge requests found
Showing
with 771 additions and 27 deletions
......@@ -30,12 +30,14 @@ saexpinf = 'SaExpInf';
saexpint = 'SaExpInt';
saexplire = 'SaExpLire';
saexpmult = 'SaExpMult';
saexpmodulo = 'SaExpModulo';
saexpnot = 'SaExpNot';
saexpor = 'SaExpOr';
saexpsub = 'SaExpSub';
saexpvar = 'SaExpVar';
saexpvrai = 'SaExpVrai';
sainstaffect = 'SaInstAffect';
saincr= 'SaIncr';
sainstbloc = 'SaInstBloc';
sainstecriture = 'SaInstEcriture';
sainstretour = 'SaInstRetour';
......@@ -73,6 +75,7 @@ exp = {add} po saexpadd [op1]:exp [op2]:exp pf
| {equal} po saexpequal [op1]:exp [op2]:exp pf
| {inf} po saexpinf [op1]:exp [op2]:exp pf
| {mult} po saexpmult [op1]:exp [op2]:exp pf
| {modulo} po saexpmodulo [op1]:exp [op2]:exp pf
| {or} po saexpor [op1]:exp [op2]:exp pf
| {sub} po saexpsub [op1]:exp [op2]:exp pf
| {not} po saexpnot exp pf
......@@ -85,6 +88,7 @@ exp = {add} po saexpadd [op1]:exp [op2]:exp pf
;
inst = {affect} po sainstaffect var exp pf
| {incr} po saincr var exp pf
| {bloc} po sainstbloc linst pf
| {ecriture} po sainstecriture exp pf
| {retour} po sainstretour exp pf
......
......@@ -159,6 +159,19 @@ public class LoadSa extends DepthFirstAdapter {
outAMultExp(node);
}
@Override
public void caseAModuloExp(AModuloExp node)
{
inAModuloExp(node);
node.getOp1().apply(this);
SaExp op1 = (SaExp) returnValue;
node.getOp2().apply(this);
SaExp op2 = (SaExp) returnValue;
returnValue = new SaExpModulo(op1,op2);
outAModuloExp(node);
}
// exp = {or} po saexpor [op1]:exp [op2]:exp pf
@Override
public void caseAOrExp(AOrExp node)
......@@ -267,6 +280,20 @@ public class LoadSa extends DepthFirstAdapter {
outAAffectInst(node);
}
@Override
public void caseAIncrInst(AIncrInst node)
{
inAIncrInst(node);
node.getVar().apply(this);
SaVar var = (SaVar) returnValue;
node.getExp().apply(this);
SaExp exp = (SaExp) returnValue;
returnValue = new SaIncr(var, exp);
outAIncrInst(node);
}
// inst = {bloc} po sainstbloc linst pf
@Override
public void caseABlocInst(ABlocInst node)
......
......@@ -187,6 +187,15 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{
return null;
}
public T visit(SaIncr node) throws Exception
{
defaultIn(node);
node.getLhs().accept(this);
node.getRhs().accept(this);
defaultOut(node);
return null;
}
// LDEC -> DEC LDEC
// LDEC -> null
/* public T visit(SaLDec node) throws Exception
......@@ -269,6 +278,15 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{
return null;
}
public T visit(SaExpModulo node) throws Exception
{
defaultIn(node);
node.getOp1().accept(this);
node.getOp2().accept(this);
defaultOut(node);
return null;
}
// EXP -> div EXP EXP
public T visit(SaExpDiv node) throws Exception
{
......@@ -340,10 +358,7 @@ public class SaDepthFirstVisitor <T> implements SaVisitor <T>{
public T visit(SaInstBloc node) throws Exception
{
defaultIn(node);
if ( node.getVal() != null )
{
node.getVal().accept(this);
}
defaultOut(node);
return null;
}
......
......@@ -23,9 +23,7 @@ public class SaEval extends SaDepthFirstVisitor <TypeVal> {
try{
appelMain.accept(this);
} catch(Exception e){
e.printStackTrace();
}
} catch(Exception e){}
}
public TypeVal getVar(SaVarSimple saVar){
......@@ -248,6 +246,21 @@ public class SaEval extends SaDepthFirstVisitor <TypeVal> {
defaultOut(node);
return null;
}
public TypeVal visit(SaIncr node) throws Exception
{
defaultIn(node);
TypeVal incr = node.getRhs().accept(this);
if(node.getLhs() instanceof SaVarIndicee){ // c'est une case de tableau, donc forcément globale
SaVarIndicee lhsIndicee = (SaVarIndicee) node.getLhs();
TypeVal indice = lhsIndicee.getIndice().accept(this);
setVarGlobIndicee(lhsIndicee, indice, new TypeVal(getVarGlobIndicee(lhsIndicee, indice).valInt + incr.valInt));
} else{
setVar((SaVarSimple) node.getLhs(), new TypeVal(getVar((SaVarSimple) node.getLhs()).valInt + incr.valInt));
}
defaultOut(node);
return null;
}
// LDEC -> DEC LDEC
// LDEC -> null
......@@ -344,6 +357,15 @@ public class SaEval extends SaDepthFirstVisitor <TypeVal> {
return new TypeVal(op1.valInt * op2.valInt);
}
public TypeVal visit(SaExpModulo node) throws Exception
{
defaultIn(node);
TypeVal op1 = node.getOp1().accept(this);
TypeVal op2 = node.getOp2().accept(this);
defaultOut(node);
return new TypeVal(op1.valInt % op2.valInt);
}
// EXP -> div EXP EXP
public TypeVal visit(SaExpDiv node) throws Exception
{
......
package sa;
import util.Type;
public class SaExpModulo implements SaExp{
private SaExp op1;
private SaExp op2;
public SaExpModulo(SaExp op1, SaExp op2){
this.op1 = op1;
this.op2 = op2;
}
public SaExp getOp1(){return this.op1;}
public SaExp getOp2(){return this.op2;}
public Type getType(){
return Type.ENTIER;
}
public <T> T accept(SaVisitor <T> visitor) throws Exception{
return visitor.visit(this);
}
@Override
public String toString() {
return "(" + this.getClass().getSimpleName() + " " + op1 + " " + op2 + ")";
}
}
package sa;
public class SaIncr implements SaInst{
private SaVar lhs;
private SaExp rhs;
public SaIncr(SaVar lhs, SaExp rhs){
this.lhs = lhs;
this.rhs = rhs;
}
public SaVar getLhs(){return this.lhs;}
public SaExp getRhs(){return this.rhs;}
public <T> T accept(SaVisitor <T> visitor) throws Exception{
return visitor.visit(this);
}
@Override
public String toString() {
return "(" + this.getClass().getSimpleName()+ " " + lhs + " " + rhs + ")";
}
}
......@@ -28,6 +28,7 @@ interface SaVisitor <T> {
public T visit(SaExpAdd node) throws Exception;
public T visit(SaExpSub node) throws Exception;
public T visit(SaExpMult node) throws Exception;
public T visit(SaExpModulo node) throws Exception;
public T visit(SaExpDiv node) throws Exception;
public T visit(SaExpInf node) throws Exception;
public T visit(SaExpEqual node) throws Exception;
......@@ -35,4 +36,6 @@ interface SaVisitor <T> {
public T visit(SaExpOr node) throws Exception;
public T visit(SaExpNot node) throws Exception;
public T visit(SaLExp node) throws Exception;
public T visit(SaIncr node) throws Exception;
}
@0 = call main
stop @0
main fbegin #entree fonction
a = 4
@1 = a + 1
a = @1
write a
fend
@0 = call main
stop @0
main fbegin #entree fonction
a = 4
@1 = a + 1
a = @1
write a
fend
@0 = call main
stop @0
main fbegin #entree fonction
t[1] = 100
@1 = t[1] + 10
t[1] = @1
write t[1]
fend
@0 = call main
stop @0
main fbegin #entree fonction
a = 4
@1 = 12 * 2
@2 = a + @1
@3 = a + @2
a = @3
write a
fend
@0 = call main
stop @0
main fbegin #entree fonction
t[1] = 2
t[2] = 3
t[3] = 1
@1 = t[1] * t[2]
@2 = t[3] + @1
t[3] = @2
write t[3]
fend
@0 = call main
stop @0
main fbegin #entree fonction
@1 = 5 / 3
@2 = 3 * @1
@3 = 5 - @2
write @3
fend
@0 = call main
stop @0
main fbegin #entree fonction
@1 = 12 / 7
@2 = 7 * @1
@3 = 12 - @2
@4 = @3 + 5
write @4
fend
@0 = call main
stop @0
main fbegin #entree fonction
@1 = 2 * 7
@2 = @1 / 5
@3 = 5 * @2
@4 = @1 - @3
@5 = @4 + 5
write @5
fend
@0 = call main
stop @0
main fbegin #entree fonction
a = 12
b = 5
@1 = a / b
@2 = b * @1
@3 = a - @2
write @3
fend
@0 = call main
stop @0
main fbegin #entree fonction
t[0] = 3164
t[1] = 152
@1 = t[0] / t[1]
@2 = t[1] * @1
@3 = t[0] - @2
t[2] = @3
write t[2]
fend
#! /usr/bin/python3 -u
import sys
import os
import subprocess
import inspect
import argparse
# code de sortie du compilateur
NOERROR_CODE = 0
ERR_TYPE_CODE = 3
ERR_SYMBOL_TABLE_CODE = 4
ERR_SYNTAX_CODE = 5
ERR_LEX_CODE = 6
# coefficients pour le calcul de la note finale
SC_COEFF = 4
SA_DIFF_COEFF = 0
TS_DIFF_COEFF = 0
SA_COEFF = 4
C3A_DIFF_COEFF = 0
C3A_COEFF = 4
PRE_NASM_DIFF = 0
PRE_NASM_COEFF = 4
NASM_DIFF_COEFF = 0
NASM_COEFF = 4
EXE_COEFF = 0
ERR_TS_COEFF = 0
ERR_TYPE_COEFF = 0
# Paths relative to this file (evaluate.py)
inputPath = "./input/"
errInputPathTs = "./input_err_ts/"
errInputPathType = "./input_err_type/"
refPath = "./"
srcPath = "../src/"
# Keep empty
classpath = ""
# Outputs files (don't change this, it's set in the main)
outErr = sys.stderr
outScore = sys.stdout
outVerbose = open(os.devnull,"w")
outputFilename = "result.txt"
################################################################################
def compileCompiler() :
global classpath
for file in ["Compiler.java", "SaVM.java", "C3aVM.java", "NasmVM.java"] :
if not os.path.isfile(srcPath+file) :
print("Skipping compilation of %s"%file, file=outVerbose)
continue
package = file.lower().split('.')[0].replace('vm', '')
if package in ["c3a", "nasm"] and not os.path.isdir(srcPath+package) :
print("Skipping compilation of %s"%file, file=outVerbose)
continue
print("Compiling %s..."%file, end="", file=outVerbose)
proc = subprocess.Popen("cd %s && javac %s %s %s"%(srcPath, "-cp " if len(classpath) > 0 else "", classpath, file), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errMess = proc.stderr.read().decode('utf8')
returnCode = proc.wait()
if returnCode == 0 :
print("Done", file=outVerbose)
else :
print("", file=outVerbose)
print("ERROR !", file=outErr)
print(errMess, file=outErr)
exit(1)
print("", file=outVerbose)
classpath = "../xerces-2_12_1/*:%s"%srcPath
classpath = ""
################################################################################
################################################################################
def deleteClasses() :
for root, subdirs, files in os.walk("%s.."%srcPath) :
if ".git" in root :
continue
for filename in files :
if os.path.splitext(filename)[1] == ".class" :
os.remove(root+"/"+filename)
return classpath
################################################################################
################################################################################
def findClasspath() :
global classpath
if len(classpath) > 0 :
return classpath
for root, subdirs, files in os.walk("%s.."%srcPath) :
if ".git" in root :
continue
for filename in files :
if os.path.splitext(filename)[1] in [".class", ".jar"] :
classpath += ("" if len(classpath) == 0 else ":") + root
break
classpath += ("" if len(classpath) == 0 else ":")+"../xerces-2_12_1/*"
return classpath
################################################################################
################################################################################
def compiler(verbose="-v 2") :
return "java -classpath %s Compiler %s"%(findClasspath(), verbose)
################################################################################
################################################################################
def green(string) :
return "\033[92m%s\033[0m"%string
################################################################################
################################################################################
def purple(string) :
return "\033[95m%s\033[0m"%string
################################################################################
################################################################################
def red(string) :
return "\033[91m%s\033[0m"%string
################################################################################
################################################################################
def changeExtension(filename, newExtension) :
return os.path.splitext(filename)[0] + newExtension
################################################################################
################################################################################
def findInputFiles(path) :
inputFiles = []
for filename in os.listdir(path) :
if os.path.splitext(filename)[1] == ".l" :
inputFiles.append(filename)
inputFiles.sort()
return inputFiles
################################################################################
################################################################################
def deleteCompilationOutputs() :
outputExtensions = [".exe", ".exeout", ".o", ".out", ".sa", ".saout", ".sc", ".ts", ".nasm", ".nasmout", ".pre-nasm", ".pre-nasmout", ".c3a", ".c3aout", ".fg", ".fgs", ".ig"]
for filename in os.listdir(inputPath) :
if os.path.splitext(filename)[1] in outputExtensions :
os.remove(inputPath+filename)
################################################################################
################################################################################
def compileInputFiles(inputFiles) :
evaluation = getNewEvaluationResult(ERR_SYNTAX_CODE)
for inputFile in inputFiles :
lightFilename = inputFile.split("/")[-1]
print("Compiling %s..."%inputFile, file=outVerbose, flush=True, end='')
returnCode = subprocess.Popen("{} {}{}".format(compiler(), inputPath, inputFile), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
if returnCode == NOERROR_CODE :
evaluation[1]["correct"].append(lightFilename)
print("Done", file=outVerbose)
else :
evaluation[1]["incorrect"].append(lightFilename)
print("ERROR !", file=outErr)
print("", file=outVerbose)
return evaluation
################################################################################
################################################################################
def getNewEvaluationResult(name) :
return [name, {"correct" : [], "incorrect" : [], "notfound" : []}]
################################################################################
################################################################################
def evaluateCompilationErrors(inputFiles, expectedCode, name) :
evaluation = getNewEvaluationResult(name)
print(file=outVerbose)
for inputFile in inputFiles :
if not os.path.isfile(inputFile) :
print("ERROR : could not find '%s'"%inputFile, file=outErr)
exit(1)
lightFilename = inputFile.split("/")[-1]
print("Compiling %s..."%lightFilename, end="", file=outVerbose)
returnCode = subprocess.Popen("{} {}".format(compiler(verbose=""), inputFile), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
print("Done (%d)"%returnCode, file=outVerbose)
if returnCode == expectedCode :
evaluation[1]["correct"].append(lightFilename)
else :
evaluation[1]["incorrect"].append(lightFilename)
print("", file=outVerbose)
return evaluation
################################################################################
################################################################################
def evaluateDiff(inputFiles, extension, extensionRef, path, name) :
evaluation = getNewEvaluationResult(name)
for filename in inputFiles :
producedFile = changeExtension(filename, extension)
if not os.path.isfile(inputPath+producedFile) :
evaluation[1]["notfound"].append(producedFile)
continue
ref = refPath+path+changeExtension(producedFile, extensionRef)
if not os.path.isfile(ref) :
print("ATTENTION : Fichier non trouvé : %s"%ref, file=sys.stderr)
continue
refContent = []
for line in open(ref, "r") :
line = line.strip()
if len(line) > 0 :
refContent.append(line)
producedContent = []
for line in open(inputPath+producedFile, "r") :
line = line.strip()
if len(line) > 0 :
producedContent.append(line)
if producedContent == refContent :
evaluation[1]["correct"].append(producedFile)
else :
evaluation[1]["incorrect"].append(producedFile)
return evaluation
################################################################################
################################################################################
def evaluateSa(inputFiles) :
errs = []
for filename in inputFiles :
saFilename = inputPath+changeExtension(filename, ".sa")
outFilename = inputPath+changeExtension(filename, ".saout")
if not os.path.isfile(saFilename) :
continue
command = "java -classpath %s SaVM -sa %s > %s"%(findClasspath(), saFilename, outFilename)
out = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read().decode()
if len(out) != 0 :
errs.append("ERROR %s for input %s : '%s'"%(inspect.stack()[0][3], filename, out))
return evaluateDiff(inputFiles, ".saout", ".out", "out-ref/", "Execution de sa"), errs
################################################################################
################################################################################
def evaluateC3a(inputFiles) :
errs = []
for filename in inputFiles :
c3aFilename = inputPath+changeExtension(filename, ".c3a")
tsFilename = inputPath+changeExtension(filename, ".ts")
outFilename = inputPath+changeExtension(filename, ".c3aout")
if not os.path.isfile(c3aFilename) or not os.path.isfile(tsFilename) :
continue
command = "java -classpath %s C3aVM -c3a %s -ts %s > %s"%(findClasspath(), c3aFilename, tsFilename, outFilename)
out = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read().decode()
if len(out) != 0 :
errs.append("ERROR %s for input %s : '%s'"%(inspect.stack()[0][3], filename, out))
return evaluateDiff(inputFiles, ".c3aout", ".out", "out-ref/", "Execution du c3a"), errs
################################################################################
################################################################################
def evaluatePreNasm(inputFiles) :
errs = []
for filename in inputFiles :
nasmFilename = inputPath+changeExtension(filename, ".pre-nasm")
outFilename = inputPath+changeExtension(filename, ".pre-nasmout")
if not os.path.isfile(nasmFilename) :
continue
command = "java -classpath %s NasmVM -nasm %s > %s"%(findClasspath(), nasmFilename, outFilename)
out = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read().decode()
if len(out) != 0 :
errs.append("ERROR %s for input %s : '%s'"%(inspect.stack()[0][3], filename, out))
return evaluateDiff(inputFiles, ".pre-nasmout", ".out", "out-ref/", "Execution du pre-nasm"), errs
################################################################################
################################################################################
def evaluateNasm(inputFiles) :
errs = []
for filename in inputFiles :
nasmFilename = inputPath+changeExtension(filename, ".nasm")
outFilename = inputPath+changeExtension(filename, ".nasmout")
if not os.path.isfile(nasmFilename) :
continue
command = "java -classpath %s NasmVM -nasm %s > %s"%(findClasspath(), nasmFilename, outFilename)
out = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read().decode()
if len(out) != 0 :
errs.append("ERROR %s for input %s : '%s'"%(inspect.stack()[0][3], filename, out))
return evaluateDiff(inputFiles, ".nasmout", ".out", "out-ref/", "Execution du nasm"), errs
################################################################################
################################################################################
def evaluateExecutable(inputFiles) :
errs = []
for filename in inputFiles :
nasmFilename = changeExtension(filename, ".nasm")
objectFilename = changeExtension(filename, ".o")
execFilename = changeExtension(filename, ".exe")
outFilename = changeExtension(filename, ".exeout")
if not os.path.isfile(inputPath+nasmFilename) :
continue
out = subprocess.Popen("cd {} && nasm -f elf -dwarf -g {}".format(inputPath+"..","input/"+nasmFilename), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read()
if not os.path.isfile(inputPath+objectFilename) :
errs.append("ERROR %s for input %s : '%s'"%(inspect.stack()[0][3], filename, out))
continue
out = subprocess.Popen("ld -m elf_i386 -o {}{} {}{}".format(inputPath,execFilename,inputPath,objectFilename), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read()
if not os.path.isfile(inputPath+execFilename) :
errs.append("ERROR %s for input %s : '%s'"%(inspect.stack()[0][3], filename, out))
continue
out = subprocess.Popen("{}{} > {}{}".format(inputPath,execFilename,inputPath,outFilename), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read()
if not os.path.isfile(inputPath+outFilename) :
errs.append("ERROR %s for input %s : '%s'"%(inspect.stack()[0][3], filename, out))
continue
return evaluateDiff(inputFiles, ".exeout", ".out", "out-ref/", "Execution du binaire"), errs
################################################################################
################################################################################
def printListElements(destination, elements, colorFunction, useColor, resultStr) :
if len(elements) == 0 :
return
maxColumnSize = len(max(elements, key=len))
for filename in elements :
if useColor :
print("\t{}".format(colorFunction(filename)), file=destination)
else :
print("\t{:{}} {}".format(filename, maxColumnSize+2, resultStr), file=destination)
################################################################################
################################################################################
def printEvaluationResult(destination, evaluationResult, useColor) :
name = evaluationResult[0]
correct = evaluationResult[1]["correct"]
incorrect = evaluationResult[1]["incorrect"]
notfound = evaluationResult[1]["notfound"]
nbCorrect = len(correct)
nbTotal = len(correct) + len(incorrect) + len(notfound)
score = 0.0
if nbTotal > 0 :
score = 100.0*nbCorrect/nbTotal
for dest, color in [(destination, useColor), (open(outputFilename, "a"), False)] :
print("Évaluation de %s :"%name, file=dest)
print("{}/{} correct ({:6.2f}%)".format(nbCorrect, nbTotal, score), file=dest)
if nbCorrect+len(incorrect) > 0 :
printListElements(dest, correct, green, color, "CORRECT")
printListElements(dest, incorrect, purple, color, "INCORRECT")
printListElements(dest, notfound, red, color, "NON-EXISTANT")
return score
################################################################################
################################################################################
if __name__ == "__main__" :
parser = argparse.ArgumentParser()
parser.add_argument("--verbose", "-v", default=False, action="store_true",
help="Verbose output (obsolete, verbose is default).")
parser.add_argument("--silent", "-s", default=False, action="store_true",
help="Less verbose output.")
parser.add_argument("--noColors", default=False, action="store_true",
help="Disable colors in output.")
parser.add_argument("--clean", "-c", default=False, action="store_true",
help="Clean input dir then exit.")
parser.add_argument("--number", "-n", default=None, type=int,
help="Restrict tests to n inputs.")
parser.add_argument("--files", "-f", default=[], nargs="*",
help="Specify input files.")
args = parser.parse_args()
args.verbose = not args.silent
if args.verbose :
outVerbose = outScore
if args.clean :
deleteCompilationOutputs()
exit(0)
with open(outputFilename, "w") as _ :
pass
inputFiles = args.files[:args.number]
if len(inputFiles) == 0 :
inputFiles = findInputFiles(inputPath)[:args.number]
errInputFilesTs = [errInputPathTs+"/"+f for f in findInputFiles(errInputPathTs)[:args.number]]
errInputFilesType = [errInputPathType+"/"+f for f in findInputFiles(errInputPathType)[:args.number]]
deleteCompilationOutputs()
compileCompiler()
scores = []
names = []
errors = []
names.append("SC ")
res = compileInputFiles(inputFiles)
scores.append(printEvaluationResult(outVerbose, res, not args.noColors))
msg = "Diff de %s"
dfSa = lambda files : (evaluateDiff(inputFiles, ".sa", ".sa", "sa-ref/", msg%"sa"), [])
dfTs = lambda files : (evaluateDiff(inputFiles, ".ts", ".ts", "ts-ref/", msg%"ts"), [])
dfC3a = lambda files : (evaluateDiff(inputFiles, ".c3a", ".c3a", "c3a-ref/", msg%"c3a"), [])
dfPreNasm = lambda files : (evaluateDiff(inputFiles, ".pre-nasm", ".pre-nasm", "pre-nasm-ref/", msg%"pre-nasm"), [])
dfNasm = lambda files : (evaluateDiff(inputFiles, ".nasm", ".nasm", "nasm-ref/", msg%"nasm"), [])
# Evaluation of normal (working) examples
for evalTarget in [
("SA-DIFF ", dfSa),
("TS-DIFF ", dfTs),
("SA ", evaluateSa),
("C3A-DIFF ", dfC3a),
("C3A ", evaluateC3a),
("PRE-NASM-DIFF", dfPreNasm),
("PRE-NASM ", evaluatePreNasm),
("NASM-DIFF ", dfNasm),
("NASM ", evaluateNasm),
("EXE ", evaluateExecutable),
] :
names.append(evalTarget[0])
res, err = evalTarget[1](inputFiles)
scores.append(printEvaluationResult(outVerbose, res, not args.noColors))
errors += err
# Evaluation of ill formed examples, that should trigger a compilation error
for evalTarget in [
("ERR_TS ", evaluateCompilationErrors, errInputFilesTs, ERR_SYMBOL_TABLE_CODE),
("ERR_TYPE ", evaluateCompilationErrors, errInputFilesType, ERR_TYPE_CODE),
] :
names.append(evalTarget[0])
res = evalTarget[1](evalTarget[2], evalTarget[3], evalTarget[0])
scores.append(printEvaluationResult(outVerbose, res, not args.noColors))
deleteClasses()
# The rest of the script will now print the results
if not args.noColors :
print("Légende : {} {} {}".format(green("CORRECT"), purple("INCORRECT"), red("NON-EXISTANT")), file=outVerbose)
errorsStr = ""
if len(errors) > 0 :
errorsStr = "%s\n%s"%((30*"-")+("EVALUATION ERRORS")+(30*"-"), "\n\n".join(errors))
print(errorsStr)
print(errorsStr, file=open(outputFilename, "a"))
for i in range(len(scores)):
print(names[i], "\t", scores[i])
print("Copy-pastable scores :", file=outScore)
print("\t".join(names), file=outScore)
print("\t".join(["%6.2f"%scores[i] for i in range(len(scores))]), file=outScore)
print("\nSauvegardé dans le fichier %s"%outputFilename)
# les coefficients associés à chaque partie pour le calcul de la note finale
coeffs = [SC_COEFF, SA_DIFF_COEFF, TS_DIFF_COEFF, SA_COEFF, C3A_DIFF_COEFF, C3A_COEFF, PRE_NASM_DIFF, PRE_NASM_COEFF, NASM_DIFF_COEFF, NASM_COEFF, EXE_COEFF, ERR_TS_COEFF, ERR_TYPE_COEFF]
# calcul de la note finale
note = 0
for i in range(len(scores)):
note += scores[i] / 100 * coeffs[i]
print ("note = ", note)
################################################################################
0 : ( 1 ) sub esp, 4 ;allocation mémoire pour la valeur de retour
1 : ( 2 ) call main
2 : ( 3 ) pop @0 ;récupération de la valeur de retour
3 : ( 4 ) mov ebx, 0 ; valeur de retour du programme
4 : ( 5 ) mov eax, 1 ; code de sortie
5 : ( 6 ) int 0x80
6 : ( 7 ) main : push ebp ;sauvegarde la valeur de ebp
7 : ( 8 ) mov ebp, esp ;nouvelle valeur de ebp
8 : ( 9 ) push eax ;sauvegarde de eax
9 : ( 10 ) push ebx ;sauvegarde de ebx
10 : ( 11 ) push ecx ;sauvegarde de ecx
11 : ( 12 ) push edx ;sauvegarde de edx
12 : ( 13 ) sub esp, 0 ;allocation des variables locales
13 : ( 14 ) mov dword [a], 4 ;Affect
14 : ( 15 ) mov @1, dword [a]
15 : ( 16 ) add @1, 1
16 : ( 17 ) mov dword [a], @1 ;Affect
17 : ( 18 ) mov eax, dword [a] ;Write 1
18 : ( 19 ) call iprintLF ;Write 2
19 : ( 20 ) add esp, 0 ;désallocation des variables locales
20 : ( 21 ) pop edx ;restaure edx
21 : ( 22 ) pop ecx ;restaure ecx
22 : ( 23 ) pop ebx ;restaure ebx
23 : ( 24 ) pop eax ;restaure eax
24 : ( 25 ) pop ebp ;restaure la valeur de ebp
25 : ( ) ret
0 : ( 1 ) sub esp, 4 ;allocation mémoire pour la valeur de retour
1 : ( 2 ) call main
2 : ( 3 ) pop @0 ;récupération de la valeur de retour
3 : ( 4 ) mov ebx, 0 ; valeur de retour du programme
4 : ( 5 ) mov eax, 1 ; code de sortie
5 : ( 6 ) int 0x80
6 : ( 7 ) main : push ebp ;sauvegarde la valeur de ebp
7 : ( 8 ) mov ebp, esp ;nouvelle valeur de ebp
8 : ( 9 ) push eax ;sauvegarde de eax
9 : ( 10 ) push ebx ;sauvegarde de ebx
10 : ( 11 ) push ecx ;sauvegarde de ecx
11 : ( 12 ) push edx ;sauvegarde de edx
12 : ( 13 ) sub esp, 4 ;allocation des variables locales
13 : ( 14 ) mov dword [ebp-4], 4 ;Affect
14 : ( 15 ) mov @1, dword [ebp-4]
15 : ( 16 ) add @1, 1
16 : ( 17 ) mov dword [ebp-4], @1 ;Affect
17 : ( 18 ) mov eax, dword [ebp-4] ;Write 1
18 : ( 19 ) call iprintLF ;Write 2
19 : ( 20 ) add esp, 4 ;désallocation des variables locales
20 : ( 21 ) pop edx ;restaure edx
21 : ( 22 ) pop ecx ;restaure ecx
22 : ( 23 ) pop ebx ;restaure ebx
23 : ( 24 ) pop eax ;restaure eax
24 : ( 25 ) pop ebp ;restaure la valeur de ebp
25 : ( ) ret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment