Skip to content

Commit

Permalink
Added some IMC
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanja-S committed May 25, 2023
1 parent 66c410f commit 53d5b01
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"request": "launch",
"mainClass": "Main",
"projectName": "PINSCompiler_aaffa8a2",
"args": "PINS --exec FRM --dump FRM test.pns"
"args": "PINS --exec IMC --dump IMC test.pns"
},
{
"type": "java",
Expand Down
20 changes: 17 additions & 3 deletions src/compiler/ir/IRCodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,24 @@ public void visit(Binary binary) {
var leftExpr = getIRExpr(binary.left);
var rightExpr = getIRExpr(binary.right);

var operator = BinopExpr.Operator.valueOf(binary.operator.name());
var binaryExpr = new BinopExpr(leftExpr, rightExpr, operator);
BinopExpr.Operator operator;
if (binary.operator.isAndOr() || binary.operator.isArithmetic() || binary.operator.isComparison()) {
operator = BinopExpr.Operator.valueOf(binary.operator.toString());
imcCode.store(new BinopExpr(leftExpr, rightExpr, operator), binary);
} else if(binary.operator == Binary.Operator.ASSIGN) {
imcCode.store( new EseqExpr(new MoveStmt(leftExpr, rightExpr), leftExpr), binary);
} else if(binary.operator == Binary.Operator.ARR) {
var type = types.valueFor(binary.left).get();
var elementType = ((Type.Array) type).type;

operator = BinopExpr.Operator.MUL;
BinopExpr index = new BinopExpr(rightExpr, new ConstantExpr(elementType.sizeInBytes()), operator);
operator = BinopExpr.Operator.ADD;
BinopExpr offset = new BinopExpr(leftExpr, index, operator);

imcCode.store(types.valueFor(), binary)
}

imcCode.store(binaryExpr, binary);
}

@Override
Expand Down
24 changes: 12 additions & 12 deletions test.pns
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
fun main(x: integer) : integer = (
{i = 2},
print_int(i),
{str = 'hello'},
print_str(str),
{bol = true},
print_log(bol),
seed(2),
print_int(rand_int(1,2)),
print_int(rand_int(1,100)),
print_int(rand_int(1,100)),
fun main(x : integer) : integer = (
{for i = 0, 12, 1: (
{ar[i] = i}
)},
{for i = 0, 12, 1: (
{if i % 2 == 0 then (
print_int(g(ar[i]))
)}
)},
0
) {where var i: integer; var str : string; var bol : logical}
) {where var i: integer; var ar : arr[12] integer};

fun g(y:integer) : integer = y

0 comments on commit 53d5b01

Please sign in to comment.