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

initialisation du dépôt

parents
Branches master
No related tags found
No related merge requests found
Showing
with 415 additions and 0 deletions
File added
File added
import java.io.*;
import sc.parser.*;
import sc.lexer.*;
import sc.node.*;
//import sa.*;
//import ts.*;
//import c3a.*;
//import nasm.*;
//import fg.*;
//import ig.*;
public class Compiler
{
public static void main(String[] args)
{
boolean outputArm = false;
boolean outputX86 = true;
boolean outputPython = false;
PushbackReader br = null;
String baseName = null;
String inputFileName = null;
int verboseLevel = 0;
for (int i = 0; i < args.length; i++) {
if(args[i].equals("-v")){
i++;
if (args[i].equals("0")){
verboseLevel = 0;
}
if (args[i].equals("1")){
verboseLevel = 1;
}
if (args[i].equals("2")){
verboseLevel = 2;
}
}
else if(args[i].equals("-f")){
i++;
if (args[i].equals("x86")){
}
else if (args[i].equals("arm")){
outputArm = true;
outputX86 = false;
}
else if (args[i].equals("python")){
outputPython = true;
outputX86 = false;
}
else{
System.out.println("output format file unknown");
System.exit(1);
}
}
else{
inputFileName = args[i];
// System.out.println(inputFileName);
}
}
if(inputFileName == null){
System.out.println("specify input file");
System.exit(1);
}
try {
br = new PushbackReader(new FileReader(inputFileName));
baseName = removeSuffix(inputFileName, ".l");
}
catch (IOException e) {
e.printStackTrace();
}
try {
// Create a Parser instance.
Parser p = new Parser(new Lexer(br));
// Parse the input.
System.out.println("[BUILD SC] ");
Start tree = p.parse();
if(verboseLevel > 1){
System.out.println("[PRINT SC]");
tree.apply(new Sc2Xml(baseName));
}
/* System.out.println("[BUILD SA] ");
Sc2sa sc2sa = new Sc2sa();
tree.apply(sc2sa);
SaNode saRoot = sc2sa.getRoot();
if(verboseLevel > 1){
System.out.println("[PRINT SA]");
new Sa2Xml(saRoot, baseName);
}
System.out.println("[BUILD TS] ");
Ts tableGlobale = new Sa2ts(saRoot).getTableGlobale();
if(verboseLevel > 1){
System.out.println("[PRINT TS]");
tableGlobale.afficheTout(baseName);
}
if(verboseLevel > 0){
System.out.println("[EXEC SA] ");
SaEval saEval = new SaEval(saRoot, tableGlobale);
if(verboseLevel > 1){
System.out.println("[PRINT SA]");
saEval.affiche(baseName);
}
}
System.out.println("[BUILD C3A] ");
C3a c3a = new Sa2c3a(saRoot, tableGlobale).getC3a();
if(verboseLevel > 1){
System.out.println("[PRINT C3A] ");
c3a.affiche(baseName);
}
if(verboseLevel > 0){
System.out.println("[EXEC C3A]");
C3aEval c3aEval = new C3aEval(c3a, tableGlobale);
c3aEval.affiche(baseName);
}
if(outputX86){
System.out.println("[BUILD PRE NASM] ");
Nasm nasm = new C3a2nasm(c3a, tableGlobale).getNasm();
if(verboseLevel > 1){
System.out.println("[PRINT PRE NASM] ");
nasm.affichePre(baseName);
}
System.out.println("[BUILD FG] ");
Fg fg = new Fg(nasm);
if(verboseLevel > 1){
System.out.println("[PRINT FG] ");
fg.affiche(baseName);
}
System.out.println("[SOLVE FG]");
FgSolution fgSolution = new FgSolution(nasm, fg);
if(verboseLevel > 1){
System.out.println("[PRINT FG SOLUTION] ");
fgSolution.affiche(baseName);
}
System.out.println("[BUILD IG] ");
Ig ig = new Ig(fgSolution);
if(verboseLevel > 1){
System.out.println("[PRINT IG] ");
ig.affiche(baseName);
}
System.out.println("[ALLOCATE REGISTERS]");
ig.allocateRegisters();
System.out.println("[PRINT NASM]");
nasm.affiche(baseName);
}
if(outputArm){
System.out.println("ARM output not implemented yet");
}
if(outputPython){
System.out.println("Python output not implemented yet");
}
*/
}
catch(Exception e){
System.out.println(e.getMessage());
System.exit(1);
}
}
public static String removeSuffix(final String s, final String suffix)
{
if (s != null && suffix != null && s.endsWith(suffix)){
return s.substring(0, s.length() - suffix.length());
}
return s;
}
}
#Compiler.jar : Compiler
# jar cmf Compiler.mf Compiler.jar *.class sc sa ts nasm util c3a fg ig
Compiler: Compiler.java #sa/*.java c3a/*.java ts/*.java nasm/*.java fg/*.java util/intset/*.java util/graph/*.java ig/*.java
# javac sa/*.java
# javac c3a/*.java
# javac ts/*.java
# javac nasm/*.java
# javac fg/*.java
# javac util/intset/*.java
# javac util/graph/*.java
# javac ig/*.java
javac Compiler.java
parser: grammaireL.sablecc
java -jar ../sablecc/sablecc.jar grammaireL.sablecc
clean:
-rm *.class
# -rm sa/*.class
# -rm c3a/*.class
# -rm ts/*.class
# -rm nasm/*.class
# -rm fg/*.class
# -rm ig/*.class
# -rm util/intset/*.class
# -rm util/graph/*.class
import java.io.*;
import sc.analysis.*;
import sc.node.*;
class Sc2Xml extends DepthFirstAdapter
{
private int indentation;
private String baseFileName;
private String fileName;
private PrintStream out;
public Sc2Xml(String baseFileName)
{
if (baseFileName == null){
this.out = System.out;
}
else{
try {
this.baseFileName = baseFileName;
this.fileName = baseFileName + ".sc";
this.out = new PrintStream(this.fileName);
}
catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
}
}
public void defaultIn(@SuppressWarnings("unused") Node node)
{
for(int i = 0; i < this.indentation; i++){this.out.print(" ");}
this.indentation++;
this.out.println("<" + node.getClass().getSimpleName() + ">");
}
public void defaultOut(@SuppressWarnings("unused") Node node)
{
this.indentation--;
for(int i = 0; i < this.indentation; i++){this.out.print(" ");}
this.out.println("</" + node.getClass().getSimpleName() + ">");
}
}
Package sc;
Helpers
lettre = [['a' .. 'z'] + ['A' .. 'Z']];
Tokens
test = 'test';
espaces = (' ' | 13 | 10)+;
commentaire= '#' [[0 .. 0xffff] - [10 + 13]]* (10 | 13 | 10 13);
Ignored Tokens
espaces, commentaire;
Productions
programme = test ;
FILES = add1 add2 sub1 sub2 sub3 mult1 mult2 mult3 div1 div2 div3 div4 and1 and2 and3 and4 and5 or1 or2 or3 or4 or5 not1 not2 not3 egal1 egal2 egal3 inf1 inf2 inf3 inf4 parenth1 parenth2 prio23-1 prio23-2 prio23-3 prio23-4 prio34-1 prio34-2 prio34-3 prio34-4 prio45-1 prio45-2 prio45-3 prio45-4 prio56-1 prio56-2 prio67-1 prio67-2 ecrire1 ecrire2 varglob1 varglob2 varglob3 varglob4 varloc1 varloc2 varloc3 varloc4 varloc5 appel1 appel2 appel3 appel-param1 appel-param2 appel-param3 appel-retour1 tab1 tab2 tab3 tab4 rec1 si1 si2 si3 si4 affect1 affect2 affect3 tantque1 tantque2 err1 err2 err3 err4
COMPILER = ../TP_JAVA/src/Compiler.jar
$(FILES): % : input/%.l
java -jar $(COMPILER) $<
- nasm -f elf -dwarf -g input/$@.nasm
- ld -m elf_i386 -o exec/$@ input/$@.o
- exec/$@ > out/$@.out
- exec/$@ > out-ref/$@.out
- diff out/$@.out out-ref/$@.out
clean:
-rm sc/*.sc
-rm sa/*.sa
-rm saout/*.saout
-rm ts/*.ts
-rm c3a/*.c3a
-rm c3aout/*.c3aout
-rm nasm/*.nasm
-rm fg/*.fg
-rm fgs/*.fgs
-rm ig/*.ig
-rm pre-nasm/*.pre-nasm
-rm exec/*
-rm out/*.out
-rm input/*.o
main fbegin #entree fonction
t0 = 3 + 10
write t0
fend
main fbegin #entree fonction
t0 = 2 + 4
t1 = t0 + 8
write t1
fend
main fbegin #entree fonction
a = 1
write a
fend
main fbegin #entree fonction
a = 1
write a
fend
f fbegin #entree fonction
a = 1
write a
fend
main fbegin #entree fonction
param 3
t0 = call f
fend
main fbegin #entree fonction
if 3 = 0 goto l1
if 1 = 0 goto l1
t0 = 1
goto l0
l1 t0 = 0
l0 write t0
fend
main fbegin #entree fonction
if 4 = 0 goto l1
if 0 = 0 goto l1
t0 = 1
goto l0
l1 t0 = 0
l0 write t0
fend
main fbegin #entree fonction
if 0 = 0 goto l1
if 1024 = 0 goto l1
t0 = 1
goto l0
l1 t0 = 0
l0 write t0
fend
main fbegin #entree fonction
if 0 = 0 goto l1
if 0 = 0 goto l1
t0 = 1
goto l0
l1 t0 = 0
l0 write t0
fend
main fbegin #entree fonction
if 1 = 0 goto l3
if 0 = 0 goto l3
t1 = 1
goto l2
l3 t1 = 0
l2 if t1 = 0 goto l1
if 1 = 0 goto l1
t0 = 1
goto l0
l1 t0 = 0
l0 write t0
fend
f fbegin #entree fonction
write a
fend
main fbegin #entree fonction
param 1
t0 = call f
fend
f fbegin #entree fonction
write a
write b
fend
main fbegin #entree fonction
param 1
param 456
t0 = call f
fend
f fbegin #entree fonction
write a
write b
write c
write d
write e
fend
main fbegin #entree fonction
param 1
param 2
param 3
param 4
param 5
t0 = call f
fend
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment