From 308ff7163f7442968976e17c1246218a56badbbe Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 13 Sep 2002 17:12:26 +0000 Subject: [PATCH] emit.c: 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 %) --- tools/qfcc/source/emit.c | 3 ++- tools/qfcc/source/expr.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/emit.c b/tools/qfcc/source/emit.c index e715bfa77..051f3a89b 100644 --- a/tools/qfcc/source/emit.c +++ b/tools/qfcc/source/emit.c @@ -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: diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index df92dc98e..2c2cf7bf2 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -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;