}
puts("");
}
+ else if (expr->code == IF)
+ {
+ printf(" br %%Bool ");
+ print_ident(p, &(expr->dest));
+ printf(", label %%L%ld, label %%L%ld\n",
+ expr->left.block->id,
+ expr->right.block->id
+ );
+ }
+ else if (expr->code == BRANCH)
+ {
+ printf(" br label %%L%ld\n", expr->left.block->id);
+ }
break;
case MODE_UNOP:
CALL,
LOAD,
STORE,
+
+ BRANCH,
ERROR = -2,
END_FILE = -1
} TokType;
SsaNode* ssa_if(Parser* p, SsaNode* cond, SsaBlock* br1, SsaBlock* br2);
SsaNode* ssa_return(Parser* p, SsaNode* expr);
+SsaNode* ssa_branch(Parser* p, SsaBlock* br);
SsaNode* ssa_call(SsaNode* func);
void ssa_call_add(SsaBlock* call, SsaNode* arg);
check_bool(p, cond);
expect(p, THEN);
SsaNode* if_node = ssa_if(p, cond, NULL, NULL);
-
SsaBlock* block = p->curr_block;
block->links[0] = statement_seq(p);
+ ssa_branch(p, p->curr_join);
block->links[0]->links[0] = p->curr_join;
ssa_reset_vars(p);
if (accept(p, ELSE))
{
block->links[1] = statement_seq(p);
+ ssa_branch(p, p->curr_join);
block->links[1]->links[0] = p->curr_join;
}
else
node->left.var = value->dest;
}
- node->dest.symver = phi_add(p, node->dest);
+ if (!symbol_getbyid(p, node->dest.symid)->global)
+ {
+ node->dest.symver = phi_add(p, node->dest);
+ }
ssa_block_add(p->curr_block, node);
node->loaded = 1;
return node;
return node;
}
+SsaNode* ssa_branch(Parser* p, SsaBlock* br)
+{
+ SsaNode* node = ssa_node(BRANCH, MODE_CTRL);
+ node->left.block = br;
+ ssa_block_add(p->curr_block, node);
+ node->loaded = 1;
+ return node;
+}
+
+
SsaNode* ssa_call(SsaNode* func);
void ssa_call_add(SsaBlock* call, SsaNode* arg);
vBool = vInt >= vInt;
end
-
procedure TestRealArithOps()
begin
vReal = vReal + 1.0;
vBool = vReal >= vReal;
end
+procedure TestIfStatements()
+begin
+ if vInt == 1 then
+ vInt = 42;
+ end
+
+ if vInt == 1 then
+ vInt = 42;
+ else
+ vInt = 24;
+ end
+end
+
#import
# Foo
# Bar3 = Bar2
##end
#
begin
-# # Integer Arithmetic ops
-# c = b + 1;
-# c = 1 + b;
-# c = b + b;
-#
-# c = b - 1;
-# c = 1 - b;
-# c = b - b;
-#
-# c = b * 1;
-# c = 1 * b;
-# c = b * b;
-#
-# c = b / 1;
-# c = 1 / b;
-# c = b / b;
-#
-# c = b % 1;
-# c = 1 % b;
-# c = b % b;
-#
-# # Integer Comparison ops
-# a = b == 1;
-# a = 1 == b;
-# a = b == b;
-#
-# a = b != 1;
-# a = 1 != b;
-# a = b != b;
-#
-# a = b < 1;
-# a = 1 < b;
-# a = b < b;
-#
-# a = b > 1;
-# a = 1 > b;
-# a = b > b;
-#
-# a = b <= 1;
-# a = 1 <= b;
-# a = b <= b;
-#
-# a = b >= 1;
-# a = 1 >= b;
-# a = b >= b;
-#
-# # Real Arithmetic ops
-# e = d + 1.0;
-# e = 1.0 + d;
-# e = d + d;
-#
-# e = d - 1.0;
-# e = 1.0 - d;
-# e = d - d;
-#
-# e = d * 1.0;
-# e = 1.0 * d;
-# e = d * d;
-#
-# e = d / 1.0;
-# e = 1.0 / d;
-# e = d / d;
-#
-# e = d % 1.0;
-# e = 1.0 % d;
-# e = d % d;
-#
-# # Real Comparison ops
-# a = d == 1.0;
-# a = 1.0 == d;
-# a = d == d;
-#
-# a = d != 1.0;
-# a = 1.0 != d;
-# a = d != d;
-#
-# a = d < 1.0;
-# a = 1.0 < d;
-# a = d < d;
-#
-# a = d > 1.0;
-# a = 1.0 > d;
-# a = d > d;
-#
-# a = d <= 1.0;
-# a = 1.0 <= d;
-# a = d <= d;
-#
-# a = d >= 1.0;
-# a = 1.0 >= d;
-# a = d >= d;
-#
-#
-#
## b = 1;
## if c == b then
## b = b - 1;