From fa51f89e55ceedbc230dbea5714a90920def7363 Mon Sep 17 00:00:00 2001 From: Niels <niels.bauquin@etu.univ-amu.fr> Date: Thu, 29 Feb 2024 22:03:08 +0100 Subject: [PATCH] BAHAHHAHAHAHAHAHAHHAHAHAHHAHAHAHHAHAHAHAHHAHAHAH --- src/Compiler.java | 3 +- src/c3a/Sa2c3a.java | 197 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 193 insertions(+), 7 deletions(-) diff --git a/src/Compiler.java b/src/Compiler.java index c59404d..4e182b3 100644 --- a/src/Compiler.java +++ b/src/Compiler.java @@ -38,9 +38,10 @@ public class Compiler System.out.println("[TYPE CHECKING]"); typeCheck(); -/* + System.out.println("[BUILD C3A] "); buildC3a(); +/* System.out.println("[BUILD PRE NASM] "); buildPreNasm(); System.out.println("[BUILD FLOW GRAPH] "); diff --git a/src/c3a/Sa2c3a.java b/src/c3a/Sa2c3a.java index 8e1a01f..03a00ee 100644 --- a/src/c3a/Sa2c3a.java +++ b/src/c3a/Sa2c3a.java @@ -19,16 +19,16 @@ public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> { public void defaultIn(SaNode node) { - //for(int i = 0; i < indentation; i++){System.out.print(" ");} - //indentation++; - //System.out.println("<" + node.getClass().getSimpleName() + ">"); + for(int i = 0; i < indentation; i++){System.out.print(" ");} + indentation++; + System.out.println("<" + node.getClass().getSimpleName() + ">"); } public void defaultOut(SaNode node) { - //indentation--; - // for(int i = 0; i < indentation; i++){System.out.print(" ");} - // System.out.println("</" + node.getClass().getSimpleName() + ">"); + indentation--; + for(int i = 0; i < indentation; i++){System.out.print(" ");} + System.out.println("</" + node.getClass().getSimpleName() + ">"); } @@ -45,5 +45,190 @@ public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> { return result; } + @Override + public C3aOperand visit(SaProg node) throws Exception { + return super.visit(node); + } + @Override + public C3aOperand visit(SaDecTab node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExp node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpInt node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpVrai node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpFaux node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpVar node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaInstEcriture node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaInstTantQue node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaLInst node) throws Exception { + 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")); + defaultOut(node); + return result; + } + + @Override + public C3aOperand visit(SaDecVar node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaInstAffect node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaLDecVar node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaLDecFonc node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaVarSimple node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaAppel node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpAppel node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpSub node) throws Exception { + defaultIn(node); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + C3aOperand result = c3a.newTemp(); + + c3a.ajouteInst(new C3aInstSub(op1, op2, result, "")); + defaultOut(node); + return result; + } + + @Override + public C3aOperand visit(SaExpMult node) throws Exception { + defaultIn(node); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + C3aOperand result = c3a.newTemp(); + + c3a.ajouteInst(new C3aInstMult(op1, op2, result, "")); + defaultOut(node); + return result; + } + + @Override + public C3aOperand visit(SaExpDiv node) throws Exception { + defaultIn(node); + C3aOperand op1 = node.getOp1().accept(this); + C3aOperand op2 = node.getOp2().accept(this); + C3aOperand result = c3a.newTemp(); + + c3a.ajouteInst(new C3aInstDiv(op1, op2, result, "")); + defaultOut(node); + return result; + } + + @Override + public C3aOperand visit(SaExpInf node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpEqual node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpAnd node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpOr node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpNot node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaExpLire node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaInstBloc node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaInstSi node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaInstRetour node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaLExp node) throws Exception { + return super.visit(node); + } + + @Override + public C3aOperand visit(SaVarIndicee node) throws Exception { + return super.visit(node); + } } -- GitLab