Skip to content
Snippets Groups Projects
Commit 59cd6dbd authored by BAUQUIN Niels's avatar BAUQUIN Niels
Browse files

BAHAHHAHAHAHAHAHAHHAHAHAHHAHAHAHHAHAHAHAHHAHAHAH

parent fa51f89e
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@ package c3a;
import ts.*;
import sa.*;
import java.util.List;
public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> {
private C3a c3a;
......@@ -45,100 +47,185 @@ public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> {
return result;
}
@Override
public C3aOperand visit(SaProg node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaDecTab node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaExp node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaExpInt node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand op = new C3aConstant(node.getVal());
defaultOut(node);
return op;
}
@Override
public C3aOperand visit(SaExpVrai node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand op = new C3aConstant(1);
defaultOut(node);
return op;
}
@Override
public C3aOperand visit(SaExpFaux node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand op = new C3aConstant(0);
defaultOut(node);
return op;
}
@Override
public C3aOperand visit(SaExpVar node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand var = node.getVar().accept(this);
defaultOut(node);
return var;
}
@Override
public C3aOperand visit(SaInstEcriture node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand op = node.getArg().accept(this);
c3a.ajouteInst(new C3aInstWrite(op,""));
defaultOut(node);
return op;
}
@Override
public C3aOperand visit(SaInstTantQue node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aLabel labelDebut = c3a.newAutoLabel();
C3aLabel labelFin = c3a.newAutoLabel();
c3a.addLabelToNextInst(labelDebut);
C3aOperand temp = node.getTest().accept(this);
c3a.ajouteInst(new C3aInstJumpIfEqual(temp, new C3aConstant(0), labelFin, ""));
node.getFaire().accept(this);
c3a.ajouteInst(new C3aInstJump(labelDebut, ""));
c3a.addLabelToNextInst(labelFin);
defaultOut(node);
return temp;
}
@Override
public C3aOperand visit(SaLInst node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaDecFonc node) throws Exception {
defaultIn(node);
C3aOperand result = c3a.newAutoLabel();
c3a.ajouteInst(new C3aInstFBegin(node.tsItem, "begin"));
node.getCorps().accept(this);
c3a.ajouteInst(new C3aInstFEnd("end"));
c3a.ajouteInst(new C3aInstFBegin(node.tsItem, "entree fonction"));
C3aOperand op = node.getCorps().accept(this);
c3a.ajouteInst(new C3aInstFEnd(""));
defaultOut(node);
return result;
return op;
}
@Override
public C3aOperand visit(SaDecVar node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaInstAffect node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand var = node.getLhs().accept(this);
C3aOperand exp = node.getRhs().accept(this);
c3a.ajouteInst(new C3aInstAffect(exp, var, ""));
defaultOut(node);
return var;
}
@Override
public C3aOperand visit(SaLDecVar node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaLDecFonc node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaVarSimple node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand var = new C3aVar(node.tsItem, null);
defaultOut(node);
return var;
}
@Override
public C3aOperand visit(SaAppel node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand temp = c3a.newTemp();
if (node.getArguments() != null) {
SaLExp args = node.getArguments();
for (int i = 0; i < node.getArguments().length(); i++) {
C3aOperand param = args.getTete().accept(this);
c3a.ajouteInst(new C3aInstParam(param,""));
if (args.getQueue() == null) {
break;
}
args = args.getQueue();
}
}
c3a.ajouteInst(new C3aInstCall(new C3aFunction(node.tsItem), temp, ""));
defaultOut(node);
return temp;
}
@Override
public C3aOperand visit(SaExpAppel node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand op = node.getVal().accept(this);
defaultOut(node);
return op;
}
@Override
......@@ -179,56 +266,199 @@ public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> {
@Override
public C3aOperand visit(SaExpInf node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aLabel label = c3a.newAutoLabel();
C3aOperand temp = c3a.newTemp();
C3aOperand op1 = node.getOp1().accept(this);
C3aOperand op2 = node.getOp2().accept(this);
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(1), temp, ""));
c3a.ajouteInst(new C3aInstJumpIfLess(op1, op2, label, ""));
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(0), temp, ""));
c3a.addLabelToNextInst(label);
defaultOut(node);
return temp;
}
@Override
public C3aOperand visit(SaExpEqual node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand result = c3a.newTemp();
C3aLabel label = c3a.newAutoLabel();
C3aOperand op1 = node.getOp1().accept(this);
C3aOperand op2 = node.getOp2().accept(this);
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(1), result, ""));
c3a.ajouteInst(new C3aInstJumpIfEqual(op1, op2, label,""));
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(0), result, ""));
c3a.addLabelToNextInst(label);
defaultOut(node);
return result;
}
@Override
public C3aOperand visit(SaExpAnd node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand result = c3a.newTemp();
C3aLabel label1 = c3a.newAutoLabel();
C3aLabel label2 = c3a.newAutoLabel();
C3aOperand op1 = node.getOp1().accept(this);
C3aOperand op2 = node.getOp2().accept(this);
c3a.ajouteInst(new C3aInstJumpIfEqual(op1, new C3aConstant(0), label2,""));
c3a.ajouteInst(new C3aInstJumpIfEqual(op2, new C3aConstant(0), label2,""));
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(1), result, ""));
c3a.ajouteInst(new C3aInstJump(label1,""));
c3a.addLabelToNextInst(label2);
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(0), result, ""));
c3a.addLabelToNextInst(label1);
defaultOut(node);
return result;
}
@Override
public C3aOperand visit(SaExpOr node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand result = c3a.newTemp();
System.out.println(node);
C3aLabel label1 = c3a.newAutoLabel();
C3aLabel label2 = c3a.newAutoLabel();
C3aOperand op1 = node.getOp1().accept(this);
C3aOperand op2 = node.getOp2().accept(this);
c3a.ajouteInst(new C3aInstJumpIfNotEqual(op1, new C3aConstant(0), label2,""));
c3a.ajouteInst(new C3aInstJumpIfNotEqual(op2, new C3aConstant(0), label2,""));
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(0), result, ""));
c3a.ajouteInst(new C3aInstJump(label1,""));
c3a.addLabelToNextInst(label2);
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(1), result, ""));
c3a.addLabelToNextInst(label1);
defaultOut(node);
return result;
}
@Override
public C3aOperand visit(SaExpNot node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand result = c3a.newTemp();
C3aLabel label = c3a.newAutoLabel();
C3aOperand op = node.getOp1().accept(this);
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(1), result, ""));
c3a.ajouteInst(new C3aInstJumpIfEqual(op, new C3aConstant(0), label,""));
c3a.ajouteInst(new C3aInstAffect(new C3aConstant(0), result, ""));
c3a.addLabelToNextInst(label);
defaultOut(node);
return result;
}
@Override
public C3aOperand visit(SaExpLire node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaInstBloc node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaInstSi node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aLabel label1 = c3a.newAutoLabel();
C3aLabel label2 = c3a.newAutoLabel();
C3aOperand test = node.getTest().accept(this);
C3aOperand op = null;
if (node.getAlors() != null) {
if (node.getSinon() == null) {
c3a.ajouteInst(new C3aInstJumpIfEqual(test, new C3aConstant(0),label2,""));
op = node.getAlors().accept(this);
c3a.addLabelToNextInst(label2);
}
else {
c3a.ajouteInst(new C3aInstJumpIfEqual(test, new C3aConstant(0),label1,""));
op = node.getAlors().accept(this);
c3a.ajouteInst(new C3aInstJump(label2,""));
c3a.addLabelToNextInst(label1);
op = node.getSinon().accept(this);
c3a.addLabelToNextInst(label2);
}
;
}
defaultOut(node);
return op;
}
@Override
public C3aOperand visit(SaInstRetour node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand op = node.getVal().accept(this);
c3a.ajouteInst(new C3aInstReturn(op, ""));
c3a.ajouteInst(new C3aInstFEnd(""));
defaultOut(node);
return op;
}
@Override
public C3aOperand visit(SaLExp node) throws Exception {
defaultIn(node);
defaultOut(node);
return super.visit(node);
}
@Override
public C3aOperand visit(SaVarIndicee node) throws Exception {
return super.visit(node);
defaultIn(node);
C3aOperand var = new C3aVar(node.getTsItem(), node.getIndice().accept(this));
defaultOut(node);
return var;
}
}
......@@ -28,7 +28,6 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
String idTab = node.getNom();
Type typeTab = node.getType();
int tailleTab = node.getTaille();
System.out.println(node);
if (context == Context.GLOBAL) {
if (tableGlobale.getVar(idTab) != null) {
throw new ErrorException(Error.TS, "Le tableau " + idTab + " est déjà défini.");
......@@ -167,12 +166,12 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
public void defaultIn(SaNode node)
{
System.out.println("<" + node.getClass().getSimpleName() + ">");
//System.out.println("<" + node.getClass().getSimpleName() + ">");
}
public void defaultOut(SaNode node)
{
System.out.println("</" + node.getClass().getSimpleName() + ">");
//System.out.println("</" + node.getClass().getSimpleName() + ">");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment