This uses "conditional rules" for EXPR_CONVERSION in order to catch the
right terminals (both produced and kids) without cluttering HIR with new
FLOAT_TO_INT_CONVERSION and INT_TO_FLOAT_CONVERSION.

Signed-off-by: Arthur Huillet <arthur.huil...@free.fr>
---
 arch/x86/insn-selector_32.brg |   71 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg
index 027976c..ea4e3fc 100644
--- a/arch/x86/insn-selector_32.brg
+++ b/arch/x86/insn-selector_32.brg
@@ -1169,16 +1169,77 @@ reg:    EXPR_CONVERSION(reg)
                state->reg1 = get_var(s->b_parent);
 
                select_insn(s, tree, reg_reg_insn(INSN_MOVSX_REG_REG, 
state->left->reg1, state->reg1));
-       } else if (src->vm_type == J_INT && expr->vm_type == J_FLOAT) {
-               NOT_IMPLEMENTED;
-               state->reg1 = get_var(s->b_parent);
-       } else if (src->vm_type == J_FLOAT && expr->vm_type == J_INT) {
-               NOT_IMPLEMENTED;
+       } else {
+               printf("%d to %d\n", src->vm_type, expr->vm_type);
+               assert(!"conversion not implemented");
+       }
+} cost {
+       int c = 1;
+       struct expression *expr, *src;
+
+       expr = to_expr(state->tree);
+       src = to_expr(expr->from_expression);
+
+       if (expr->vm_type == J_FLOAT || src->vm_type == J_FLOAT)
+               c = MB_DISCARD_RULE;
+
+       return c;
+}
+
+freg:  EXPR_CONVERSION(reg)
+{
+       struct expression *expr, *src;
+
+       expr = to_expr(tree);
+       src = to_expr(expr->from_expression);
+
+       if (src->vm_type == J_INT && expr->vm_type == J_FLOAT) {
+               state->reg1 = get_fpu_var(s->b_parent);
+
+               select_insn(s, tree, reg_reg_insn(INSN_CONV_GPR_TO_FPU, 
state->left->reg1, state->reg1));
+       } else {
+               printf("%d to %d\n", src->vm_type, expr->vm_type);
+               assert(!"conversion not implemented");
+       }
+} cost {
+       int c = 1;
+       struct expression *expr, *src;
+
+       expr = to_expr(state->tree);
+       src = to_expr(expr->from_expression);
+
+       if (expr->vm_type != J_FLOAT)
+               c = MB_DISCARD_RULE;
+
+       return c;
+}
+
+reg:   EXPR_CONVERSION(freg)
+{
+       struct expression *expr, *src;
+
+       expr = to_expr(tree);
+       src = to_expr(expr->from_expression);
+
+       if (src->vm_type == J_FLOAT && expr->vm_type == J_INT) {
                state->reg1 = get_var(s->b_parent);
+               
+               select_insn(s, tree, reg_reg_insn(INSN_CONV_FPU_TO_GPR, 
state->left->reg1, state->reg1));
        } else {
                printf("%d to %d\n", src->vm_type, expr->vm_type);
                assert(!"conversion not implemented");
        }
+} cost {
+       int c = 1;
+       struct expression *expr, *src;
+
+       expr = to_expr(state->tree);
+       src = to_expr(expr->from_expression);
+
+       if (src->vm_type != J_FLOAT)
+               c = MB_DISCARD_RULE;
+
+       return c;
 }
 
 arg:   EXPR_NO_ARGS
-- 
1.6.3.3



------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to