private void generateOr(BinaryExpr expr) { WasmBlock block = new WasmBlock(false); block.setType(WasmType.INT32); accept(expr.getFirstOperand()); WasmBranch branch = new WasmBranch(result, block); branch.setResult(new WasmInt32Constant(1)); branch.setLocation(expr.getLocation()); branch.getResult().setLocation(expr.getLocation()); block.getBody().add(new WasmDrop(branch)); accept(expr.getSecondOperand()); block.getBody().add(result); block.setLocation(expr.getLocation()); result = block; }
private void generateAnd(BinaryExpr expr) { WasmBlock block = new WasmBlock(false); block.setType(WasmType.INT32); accept(expr.getFirstOperand()); WasmBranch branch = new WasmBranch(negate(result), block); branch.setResult(new WasmInt32Constant(0)); branch.setLocation(expr.getLocation()); branch.getResult().setLocation(expr.getLocation()); block.getBody().add(new WasmDrop(branch)); accept(expr.getSecondOperand()); block.getBody().add(result); block.setLocation(expr.getLocation()); result = block; }
private void visitBinary(BinaryExpr expr, String op, boolean guarded) { if (expr.getLocation() != null) { pushLocation(expr.getLocation()); } if (guarded) { visitBinary(BinaryOperation.OR, "|", () -> visitBinary(expr, op, false), () -> { try { writer.append("0"); } catch (IOException e) { throw new RenderingException("IO error occurred", e); } }); } else { visitBinary(expr.getOperation(), op, () -> expr.getFirstOperand().acceptVisitor(this), () -> expr.getSecondOperand().acceptVisitor(this)); } if (expr.getLocation() != null) { popLocation(); } }
private void visitBinaryFunction(BinaryExpr expr, String function) { try { if (expr.getLocation() != null) { pushLocation(expr.getLocation()); } writer.append(function); writer.append('('); precedence = Precedence.min(); expr.getFirstOperand().acceptVisitor(this); writer.append(",").ws(); precedence = Precedence.min(); expr.getSecondOperand().acceptVisitor(this); writer.append(')'); if (expr.getLocation() != null) { popLocation(); } } catch (IOException e) { throw new RenderingException("IO error occured", e); } }
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()); }
call.getArguments().add(result); call.setLocation(expr.getLocation()); result = call; break; call.getArguments().add(result); call.setLocation(expr.getLocation()); result = call; break;
@Override public void visit(BinaryExpr expr) { pushLocation(expr.getLocation()); try { switch (expr.getOperation()) { Expr result = BinaryExpr.binary(expr.getOperation(), comparison.getType(), comparison.getFirstOperand(), comparison.getSecondOperand()); result.setLocation(comparison.getLocation()); if (invert) { result = ExprOptimizer.invert(result);
private void generateOr(BinaryExpr expr) { WasmBlock block = new WasmBlock(false); block.setType(WasmType.INT32); accept(expr.getFirstOperand()); WasmBranch branch = new WasmBranch(result, block); branch.setResult(new WasmInt32Constant(1)); branch.setLocation(expr.getLocation()); branch.getResult().setLocation(expr.getLocation()); block.getBody().add(new WasmDrop(branch)); accept(expr.getSecondOperand()); block.getBody().add(result); block.setLocation(expr.getLocation()); result = block; }
private void generateAnd(BinaryExpr expr) { WasmBlock block = new WasmBlock(false); block.setType(WasmType.INT32); accept(expr.getFirstOperand()); WasmBranch branch = new WasmBranch(negate(result), block); branch.setResult(new WasmInt32Constant(0)); branch.setLocation(expr.getLocation()); branch.getResult().setLocation(expr.getLocation()); block.getBody().add(new WasmDrop(branch)); accept(expr.getSecondOperand()); block.getBody().add(result); block.setLocation(expr.getLocation()); result = block; }
private void visitBinary(BinaryExpr expr, String op, boolean guarded) { if (expr.getLocation() != null) { pushLocation(expr.getLocation()); } if (guarded) { visitBinary(BinaryOperation.OR, "|", () -> visitBinary(expr, op, false), () -> { try { writer.append("0"); } catch (IOException e) { throw new RenderingException("IO error occurred", e); } }); } else { visitBinary(expr.getOperation(), op, () -> expr.getFirstOperand().acceptVisitor(this), () -> expr.getSecondOperand().acceptVisitor(this)); } if (expr.getLocation() != null) { popLocation(); } }
private void visitBinaryFunction(BinaryExpr expr, String function) { try { if (expr.getLocation() != null) { pushLocation(expr.getLocation()); } writer.append(function); writer.append('('); precedence = Precedence.min(); expr.getFirstOperand().acceptVisitor(this); writer.append(",").ws(); precedence = Precedence.min(); expr.getSecondOperand().acceptVisitor(this); writer.append(')'); if (expr.getLocation() != null) { popLocation(); } } catch (IOException e) { throw new RenderingException("IO error occured", e); } }
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) { pushLocation(expr.getLocation()); try { switch (expr.getOperation()) { Expr result = BinaryExpr.binary(expr.getOperation(), comparison.getType(), comparison.getFirstOperand(), comparison.getSecondOperand()); result.setLocation(comparison.getLocation()); if (invert) { result = ExprOptimizer.invert(result);
call.getArguments().add(result); call.setLocation(expr.getLocation()); result = call; break; call.getArguments().add(result); call.setLocation(expr.getLocation()); result = call; break;