git ingnore, modification de toString
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ build
|
||||
bin
|
||||
*.ll
|
||||
*.DS_Store
|
||||
**/.antlr/
|
||||
@@ -22,12 +22,23 @@ public class LLVM {
|
||||
sealed interface ListInstr{
|
||||
String toString(String string);}
|
||||
sealed interface Par{}
|
||||
sealed interface Expression{}
|
||||
sealed interface Expression{
|
||||
Type getType();
|
||||
}
|
||||
sealed static interface Op{}
|
||||
sealed interface Var extends Expression{
|
||||
};
|
||||
sealed interface Val extends Expression{
|
||||
};
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Expression exp1 = new Add(new Add(new Val(0),new Val(1)),new Val(2));
|
||||
Add ADD = new Add();
|
||||
Modulo MODULO = new Modulo();
|
||||
|
||||
Expression exp1 = new BinOp(ADD,new BinOp(ADD,new ValInt(0),new ValInt(1)),new ValInt(2));
|
||||
ListPar param = new ListParImpl(new ArrayList<>());
|
||||
ArrayList<Instr> l = new ArrayList<>();
|
||||
l.add(new Return(exp1));
|
||||
@@ -39,8 +50,9 @@ public class LLVM {
|
||||
|
||||
System.out.println("\n");
|
||||
|
||||
Var a = new Var("a");
|
||||
Var b = new Var("b");
|
||||
|
||||
Var a = new VarInt("a");
|
||||
Var b = new VarInt("b");
|
||||
Prog p2 = new ProgImpl(List.of(
|
||||
f,
|
||||
new FonctionImpl(new INT(),"maFonction",new ListParImpl(List.of(new ParImpl(new INT(),a),new ParImpl(new INT(),b) )),List.of(
|
||||
@@ -50,9 +62,9 @@ public class LLVM {
|
||||
new Print(List.of("b = ",b))
|
||||
)),
|
||||
new While(b, List.of(
|
||||
new Aff(b, new Modulo(b,new Val(2)))
|
||||
new Aff(b, new BinOp(MODULO,b,new ValInt(2)))
|
||||
)),
|
||||
new Return(new Add(a,b))
|
||||
new Return(new BinOp(ADD,a,b))
|
||||
))
|
||||
|
||||
|
||||
@@ -125,15 +137,12 @@ public class LLVM {
|
||||
}
|
||||
}
|
||||
|
||||
record Read(List<Object> items) implements Instr{ //TODO pas bon
|
||||
record Read(List<Var> items) implements Instr{ //TODO pas bon
|
||||
public String toString(String indent){
|
||||
String str = indent + "READ";
|
||||
for(int i = 0; i<items.size(); i++){
|
||||
if(items.get(i) instanceof Exception || items.get(i) instanceof String){
|
||||
str += items.get(i).toString();
|
||||
if(i<items.size()-1) str += ", ";
|
||||
}
|
||||
else System.err.println("Item de mauvais type, READ");
|
||||
str += items.get(i).toString();
|
||||
if(i<items.size()-1) str += ", ";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@@ -190,7 +199,7 @@ public class LLVM {
|
||||
}
|
||||
}
|
||||
|
||||
record ListDeclImpl(Type type, List<String> vars) implements ListDecl{
|
||||
record ListDeclImpl(Type type, List<String> vars) implements ListDecl{ //erreur
|
||||
public String toString(String indent){
|
||||
String str = indent + type.toString() + " ";
|
||||
for(int i = 0; i<vars.size(); i++){
|
||||
@@ -231,47 +240,64 @@ public class LLVM {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
record Add(Expression e1, Expression e2) implements Expression{
|
||||
record BinOp(Op op,Expression e1, Expression e2) implements Expression{
|
||||
public String toString(){
|
||||
return "("+ e1 + " + " + e2 + ")";
|
||||
return "("+ e1 + " " + op.toString() + " " + e2 + ")";
|
||||
}
|
||||
public Type getType(){
|
||||
Type t1 = e1.getType();
|
||||
Type t2 = e2.getType();
|
||||
if(t1 == t2) return t1;
|
||||
else return null;
|
||||
}
|
||||
}
|
||||
|
||||
record Sub(Expression e1, Expression e2) implements Expression{
|
||||
record Add() implements Op{
|
||||
public String toString(){
|
||||
return "("+ e1 + " - " + e2 + ")";
|
||||
return "+";
|
||||
}
|
||||
}
|
||||
|
||||
record Modulo(Expression e1, Expression e2) implements Expression{
|
||||
record Sub() implements Op{
|
||||
public String toString(){
|
||||
return "("+ e1 + " % " + e2 + ")";
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
|
||||
record Mult(Expression e1, Expression e2) implements Expression{
|
||||
record Modulo() implements Op{
|
||||
public String toString(){
|
||||
return "("+ e1 + " * " + e2 + ")";
|
||||
return "%";
|
||||
}
|
||||
}
|
||||
|
||||
record Div(Expression e1, Expression e2) implements Expression{
|
||||
record Mult() implements Op{
|
||||
public String toString(){
|
||||
return "("+ e1 + " / " + e2 + ")";
|
||||
return "*";
|
||||
}
|
||||
}
|
||||
|
||||
record Val(int val) implements Expression{
|
||||
record Div() implements Op{
|
||||
public String toString(){
|
||||
return "/";
|
||||
}
|
||||
}
|
||||
|
||||
record ValInt(int val) implements Val{
|
||||
public String toString(){
|
||||
return val+"";
|
||||
}
|
||||
public Type getType(){
|
||||
return new INT();
|
||||
}
|
||||
}
|
||||
|
||||
record Var(String nom) implements Expression{
|
||||
record VarInt(String nom) implements Var{
|
||||
public String toString(){
|
||||
return nom;
|
||||
}
|
||||
public Type getType(){
|
||||
return new INT();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user