@Override public void visit(BinaryExpr expr) { try { output.writeByte(0); output.writeByte(expr.getOperation().ordinal()); output.writeByte(expr.getType() != null ? expr.getType().ordinal() + 1 : 0); writeExpr(expr.getFirstOperand()); writeExpr(expr.getSecondOperand()); } catch (IOException e) { throw new IOExceptionWrapper(e); } }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b, expr.getLocation()); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
private void generateBinary(WasmIntBinaryOperation intOp, BinaryExpr expr) { accept(expr.getFirstOperand()); WasmExpression first = result; accept(expr.getSecondOperand()); WasmExpression second = result; if (expr.getType() == OperationType.LONG) { switch (expr.getOperation()) { case LEFT_SHIFT: case RIGHT_SHIFT: case UNSIGNED_RIGHT_SHIFT: second = new WasmConversion(WasmType.INT32, WasmType.INT64, false, second); break; default: break; } } switch (expr.getType()) { case INT: result = new WasmIntBinary(WasmIntType.INT32, intOp, first, second); break; case LONG: result = new WasmIntBinary(WasmIntType.INT64, intOp, first, second); break; case FLOAT: case DOUBLE: throw new AssertionError("Can't translate operation " + intOp + " for type " + expr.getType()); } result.setLocation(expr.getLocation()); }
private Expr extractLongRightShiftedBy32(Expr expr) { if (!(expr instanceof BinaryExpr)) { return null; } BinaryExpr binary = (BinaryExpr) expr; if (binary.getOperation() != BinaryOperation.RIGHT_SHIFT && binary.getOperation() != BinaryOperation.UNSIGNED_RIGHT_SHIFT) { return null; } if (binary.getType() != OperationType.LONG) { return null; } if (!(binary.getSecondOperand() instanceof ConstantExpr)) { return null; } Object rightConstant = ((ConstantExpr) binary.getSecondOperand()).getValue(); if (rightConstant.equals(32) || rightConstant.equals(32L)) { return binary.getFirstOperand(); } return null; }
private void generateBinary(WasmIntBinaryOperation intOp, WasmFloatBinaryOperation floatOp, BinaryExpr expr) { accept(expr.getFirstOperand()); WasmExpression first = result; accept(expr.getSecondOperand()); WasmExpression second = result; if (expr.getType() == null) { result = new WasmIntBinary(WasmIntType.INT32, intOp, first, second); } else { switch (expr.getType()) { case INT: result = new WasmIntBinary(WasmIntType.INT32, intOp, first, second); break; case LONG: result = new WasmIntBinary(WasmIntType.INT64, intOp, first, second); break; case FLOAT: result = new WasmFloatBinary(WasmFloatType.FLOAT32, floatOp, first, second); break; case DOUBLE: result = new WasmFloatBinary(WasmFloatType.FLOAT64, floatOp, first, second); break; } } result.setLocation(expr.getLocation()); }
@Override public void visit(BinaryExpr expr) { super.visit(expr); switch (expr.getOperation()) { case COMPARE: consumer.consumeFunction("$rt_compare"); break; case MULTIPLY: if (expr.getType() == OperationType.INT && !RenderingUtil.isSmallInteger(expr.getFirstOperand()) && !RenderingUtil.isSmallInteger(expr.getSecondOperand())) { consumer.consumeFunction("$rt_imul"); } break; default: break; } }
@Override public void visit(BinaryExpr expr) { if (expr.getType() == OperationType.LONG) { longLibraryUsed = true; switch (expr.getOperation()) { switch (expr.getOperation()) { case ADD: visitBinary(expr, "+", expr.getType() == OperationType.INT); break; case SUBTRACT: visitBinary(expr, "-", expr.getType() == OperationType.INT); break; case MULTIPLY: if (expr.getType() != OperationType.INT || RenderingUtil.isSmallInteger(expr.getFirstOperand()) || RenderingUtil.isSmallInteger(expr.getSecondOperand())) { visitBinary(expr, "*", expr.getType() == OperationType.INT); } else { visitBinaryFunction(expr, naming.getNameForFunction("$rt_imul")); visitBinary(expr, "/", expr.getType() == OperationType.INT); break; case MODULO: visitBinary(expr, "%", expr.getType() == OperationType.INT); break; case EQUALS: if (expr.getType() == OperationType.INT) { visitBinary(expr, "==", false); } else {
break; case MODULO: { switch (expr.getType()) { case INT: case LONG: break; default: Class<?> type = convertType(expr.getType()); MethodReference method = new MethodReference(WasmRuntime.class, "remainder", type, type, type); WasmCall call = new WasmCall(context.names.forMethod(method), false); break; case COMPARE: { Class<?> type = convertType(expr.getType()); MethodReference method = new MethodReference(WasmRuntime.class, "compare", type, type, int.class); WasmCall call = new WasmCall(context.names.forMethod(method), false);
case COMPARE: writer.print("compare_"); switch (expr.getType()) { case INT: writer.print("i32"); return; case UNSIGNED_RIGHT_SHIFT: { String type = expr.getType() == OperationType.LONG ? "int64_t" : "int32_t"; writer.print("((" + type + ") ((u" + type + ") "); switch (expr.getType()) { case FLOAT: writer.print("fmodf(");
case GREATER_OR_EQUALS: { BinaryExpr comparison = (BinaryExpr) p; Expr result = BinaryExpr.binary(expr.getOperation(), comparison.getType(), comparison.getFirstOperand(), comparison.getSecondOperand()); result.setLocation(comparison.getLocation());
@Override public void visit(BinaryExpr expr) { try { output.writeByte(0); output.writeByte(expr.getOperation().ordinal()); output.writeByte(expr.getType() != null ? expr.getType().ordinal() + 1 : 0); writeExpr(expr.getFirstOperand()); writeExpr(expr.getSecondOperand()); } catch (IOException e) { throw new IOExceptionWrapper(e); } }
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
private Expr extractLongRightShiftedBy32(Expr expr) { if (!(expr instanceof BinaryExpr)) { return null; } BinaryExpr binary = (BinaryExpr) expr; if (binary.getOperation() != BinaryOperation.RIGHT_SHIFT && binary.getOperation() != BinaryOperation.UNSIGNED_RIGHT_SHIFT) { return null; } if (binary.getType() != OperationType.LONG) { return null; } if (!(binary.getSecondOperand() instanceof ConstantExpr)) { return null; } Object rightConstant = ((ConstantExpr) binary.getSecondOperand()).getValue(); if (rightConstant.equals(32) || rightConstant.equals(32L)) { return binary.getFirstOperand(); } return null; }
private void generateBinary(WasmIntBinaryOperation intOp, BinaryExpr expr) { accept(expr.getFirstOperand()); WasmExpression first = result; accept(expr.getSecondOperand()); WasmExpression second = result; if (expr.getType() == OperationType.LONG) { switch (expr.getOperation()) { case LEFT_SHIFT: case RIGHT_SHIFT: case UNSIGNED_RIGHT_SHIFT: second = new WasmConversion(WasmType.INT32, WasmType.INT64, false, second); break; default: break; } } switch (expr.getType()) { case INT: result = new WasmIntBinary(WasmIntType.INT32, intOp, first, second); break; case LONG: result = new WasmIntBinary(WasmIntType.INT64, intOp, first, second); break; case FLOAT: case DOUBLE: throw new AssertionError("Can't translate operation " + intOp + " for type " + expr.getType()); } result.setLocation(expr.getLocation()); }
private void generateBinary(WasmIntBinaryOperation intOp, WasmFloatBinaryOperation floatOp, BinaryExpr expr) { accept(expr.getFirstOperand()); WasmExpression first = result; accept(expr.getSecondOperand()); WasmExpression second = result; if (expr.getType() == null) { result = new WasmIntBinary(WasmIntType.INT32, intOp, first, second); } else { switch (expr.getType()) { case INT: result = new WasmIntBinary(WasmIntType.INT32, intOp, first, second); break; case LONG: result = new WasmIntBinary(WasmIntType.INT64, intOp, first, second); break; case FLOAT: result = new WasmFloatBinary(WasmFloatType.FLOAT32, floatOp, first, second); break; case DOUBLE: result = new WasmFloatBinary(WasmFloatType.FLOAT64, floatOp, first, second); break; } } result.setLocation(expr.getLocation()); }
@Override public void visit(BinaryExpr expr) { if (expr.getType() == OperationType.LONG) { switch (expr.getOperation()) { case ADD: switch (expr.getOperation()) { case ADD: visitBinary(expr, "+", expr.getType() == OperationType.INT); break; case SUBTRACT: visitBinary(expr, "-", expr.getType() == OperationType.INT); break; case MULTIPLY: visitBinary(expr, "*", expr.getType() == OperationType.INT); break; case DIVIDE: visitBinary(expr, "/", expr.getType() == OperationType.INT); break; case MODULO: visitBinary(expr, "%", expr.getType() == OperationType.INT); break; case EQUALS: if (expr.getType() == OperationType.INT) { visitBinary(expr, "==", false); } else { if (expr.getType() == OperationType.INT) { visitBinary(expr, "!=", false); } else {
break; case MODULO: { switch (expr.getType()) { case INT: case LONG: break; default: Class<?> type = convertType(expr.getType()); MethodReference method = new MethodReference(WasmRuntime.class, "remainder", type, type, type); WasmCall call = new WasmCall(WasmMangling.mangleMethod(method), false); break; case COMPARE: { Class<?> type = convertType(expr.getType()); MethodReference method = new MethodReference(WasmRuntime.class, "compare", type, type, int.class); WasmCall call = new WasmCall(WasmMangling.mangleMethod(method), false);
case GREATER_OR_EQUALS: { BinaryExpr comparison = (BinaryExpr) p; Expr result = BinaryExpr.binary(expr.getOperation(), comparison.getType(), comparison.getFirstOperand(), comparison.getSecondOperand()); result.setLocation(comparison.getLocation());