Select Git revision
Sa2c3a.java
Forked from
NASR Alexis / 2024_compilation
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Sa2c3a.java 5.24 KiB
package c3a;
import ts.*;
import sa.*;
public class Sa2c3a extends SaDepthFirstVisitor <C3aOperand> {
private C3a c3a;
int indentation;
public C3a getC3a(){return this.c3a;}
public Sa2c3a(SaNode root, Ts tableGlobale){
c3a = new C3a();
C3aTemp result = c3a.newTemp();
C3aFunction fct = new C3aFunction(tableGlobale.getFct("main"));
c3a.ajouteInst(new C3aInstCall(fct, result, ""));
c3a.ajouteInst(new C3aInstStop(result, ""));
indentation = 0;
}
public void defaultIn(SaNode node)
{
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() + ">");
}
// EXP -> op2 EXP EXP
public C3aOperand visit(SaExpAdd node) throws Exception
{
defaultIn(node);
C3aOperand op1 = node.getOp1().accept(this);
C3aOperand op2 = node.getOp2().accept(this);
C3aOperand result = c3a.newTemp();
c3a.ajouteInst(new C3aInstAdd(op1, op2, result, ""));
defaultOut(node);
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);