implement % for v6 code. hacky, but it works :) (Closes: #29)
expr.c:
	emit the body of a block expresion before emitting its result (needed
	for v6 %)
This commit is contained in:
Bill Currie 2002-09-13 17:12:26 +00:00
parent 1e5402a30a
commit 308ff7163f
2 changed files with 24 additions and 1 deletions

View file

@ -384,9 +384,10 @@ emit_sub_expr (expr_t *e, def_t *dest)
switch (e->type) {
case ex_block:
if (e->e.block.result) {
d = emit_sub_expr (e->e.block.result, dest);
expr_t *res = e->e.block.result;
for (e = e->e.block.head; e; e = e->next)
emit_expr (e);
d = emit_sub_expr (res, dest);
break;
}
case ex_name:

View file

@ -1439,6 +1439,28 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if (!type)
error (e1, "internal error");
if (options.code.progsversion == PROG_ID_VERSION) {
switch (op) {
case '%':
{
expr_t *tmp1, *tmp2;
e = new_block_expr ();
tmp1 = new_temp_def_expr (&type_float);
tmp2 = new_temp_def_expr (&type_float);
e2 = binary_expr ('&', e2, new_float_expr (-1.0));
e1 = binary_expr ('&', e1, new_float_expr (-1.0));
append_expr (e, assign_expr (tmp1, e2));
append_expr (e, assign_expr (tmp2,
binary_expr ('/', e1, tmp1)));
e2 = binary_expr ('&', tmp2, new_float_expr (-1.0));
e->e.block.result = binary_expr ('-', tmp2, e2);
e2 = e;
e1 = tmp1;
op = '*';
}
break;
}
}
e = new_binary_expr (op, e1, e2);
e->e.expr.type = type;
return e;