@Override protected void verifyArgument() { //When call ArrayValue(ProgramBlock block, ArrayClass arrayCls, Parameterized... allocateDims) if(allocateDims != null){ for(KernelParam dim : allocateDims){ int order = IClassUtils.getPrimitiveAClass(dim.getResultType()).getCastOrder(); KernelProgramBlock block = getParent(); if(order > block.getType(int.class).getCastOrder() || order <= block.getType(boolean.class).getCastOrder()){ throw new RuntimeException("the allcate dim number must be byte, char, short or int type!"); } } } //When call other constructor final IClass rootComp = arrayCls.getRootComponentClass(); new EachValue(values){ @Override void process(KernelParam para) { if(!IClassUtils.checkAssignable(para.getResultType(), rootComp)) { throw new IllegalArgumentException("Type mismatch: cannot convert from " + para.getResultType() + " to " + rootComp + ""); } } }.process(); }
/** * @param comp * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public int numberCompare(Value comp) { if (!isNumber()) throw new ASMSupportException(this + " is not a number value."); if (!comp.isNumber()) throw new ASMSupportException(comp + " is not a number value."); int compOrder = cls.getCastOrder() - comp.cls.getCastOrder(); Object v1; Object v2; if (compOrder == 0) { v1 = value; v2 = comp.value; } else if (compOrder > 0) { v1 = value; v2 = comp.getConvert(cls).value; } else { v1 = getConvert(comp.cls).value; v2 = comp.value; } return ((Comparable) v1).compareTo(v2); }
private boolean checkExpression(IClass expCls1, IClass expCls2){ IClass expPrimCls1 = IClassUtils.getPrimitiveAClass(expCls1); IClass expPrimCls2 = IClassUtils.getPrimitiveAClass(expCls2); if(expPrimCls1.equals(expPrimCls2)){ resultClass = expPrimCls1; return true; }else if(expPrimCls1.isPrimitive() && expPrimCls2.isPrimitive()){ if(expPrimCls1.equals(getType(boolean.class)) || expPrimCls2.equals(getType(boolean.class))){ return false; }else{ if(expPrimCls1.getCastOrder() > expPrimCls2.getCastOrder()){ resultClass = expPrimCls1; }else{ resultClass = expPrimCls2; } return true; } }else if(expPrimCls1.isChildOrEqual(expPrimCls2)){ resultClass = expPrimCls2; return true; }else if(expPrimCls2.isChildOrEqual(expPrimCls1)){ resultClass = expPrimCls1; return true; } return false; }
private void pushFactorToStack(MethodExecuteContext context, KernelParam factor) { IClass factorCls = factor.getResultType(); Instructions instructions = context.getInstructions(); // factor to stack LOG.print("push the first arithmetic factor to stack"); factor.push(context); IClass factorPrimitiveAClass = factorCls; // unbox if needs if (!factorCls.isPrimitive()) { LOG.print("unbox " + factorCls); instructions.unbox(factorCls.getType()); factorPrimitiveAClass = IClassUtils.getPrimitiveAClass(factorCls); } // cast if needs if (factorPrimitiveAClass.getCastOrder() < targetClass.getCastOrder() && targetClass.getCastOrder() > getType(int.class).getCastOrder()) { LOG.print("cast factor from " + factorCls + " to " + targetClass); instructions.cast(factorPrimitiveAClass.getType(), targetClass.getType()); } }
@Override protected void initAdditionalProperties() { //replace Value object IClass leftPrimitiveType = IClassUtils.getPrimitiveAClass(leftFactor.getResultType()); IClass rightPrimitiveType = IClassUtils.getPrimitiveAClass(rightFactor.getResultType()); if(leftPrimitiveType.getCastOrder() > rightPrimitiveType.getCastOrder()){ targetClass = leftPrimitiveType; } else { targetClass = rightPrimitiveType; } if(leftFactor instanceof Value && ((Value) leftFactor).getValue() != null) ((Value)leftFactor).convert(targetClass); if(rightFactor instanceof Value && ((Value) rightFactor).getValue() != null) ((Value)rightFactor).convert(targetClass); }
/** * Defined a common method use in sub class * * @param factor the operand */ protected void pushFactorToStack(MethodExecuteContext context, KernelParam factor) { IClass factorCls = factor.getResultType(); Instructions instructions = context.getInstructions(); // factor to stack LOG.print("push the first arithmetic factor to stack"); factor.push(context); IClass factorPrimitiveAClass = factorCls; // unbox if needs if (!factorCls.isPrimitive()) { LOG.print("unbox " + factorCls); instructions.unbox(factorCls.getType()); factorPrimitiveAClass = IClassUtils.getPrimitiveAClass(factorCls); } // cast if needs if (factorPrimitiveAClass.getCastOrder() < targetClass.getCastOrder() && targetClass.getCastOrder() > getType(int.class).getCastOrder()) { LOG.print("cast factor from " + factorCls + " to " + targetClass); instructions.cast(factorPrimitiveAClass.getType(), targetClass.getType()); } }
boolean isNumerical = (targetClass.getCastOrder() >= getType(byte.class).getCastOrder() && targetClass.getCastOrder() <= getType(double.class).getCastOrder()); targetClass.getCastOrder() > getType(int.class).getCastOrder()){ LOG.print("cast from " + ftrCls1 + " to " + targetClass); instructions.cast(ftrCls1.getType(), targetClass.getType()); targetClass.getCastOrder() > getType(int.class).getCastOrder()){ LOG.print("cast from " + ftrCls2 + " to " + targetClass); instructions.cast(ftrCls2.getType(), targetClass.getType());
@Override public void doExecute(MethodExecuteContext context) { KernelProgramBlock block = getParent(); orginal.push(context); IClass from = orginal.getResultType(); if(to.equals(from)){ return; } if(from.isPrimitive() && to.isPrimitive()){ if(LOG.isPrintEnabled()) { LOG.print("checkcast from " + from + " to " + to ); } if(from.getCastOrder() > to.getCastOrder() || (from.equals(block.getType(char.class)) && to.equals(block.getType(short.class))) || (to.equals(block.getType(char.class)) && from.equals(block.getType(short.class)))){ context.getInstructions().cast(from.getType(), to.getType()); return; } } if(LOG.isPrintEnabled()) { LOG.print("checkcast from " + from + " to " + to ); } context.getInstructions().checkCast(to.getType()); }
@Override protected void initAdditionalProperties() { IClass ftrCls1 = leftFactor.getResultType(); IClass ftrCls2 = rightFactor.getResultType(); if(ftrCls2.getCastOrder() < ftrCls1.getCastOrder()){ targetClass = ftrCls1; }else{ targetClass = ftrCls2; } if(leftFactor instanceof Value) { ((Value)leftFactor).convert(targetClass); } if(rightFactor instanceof Value) { if(getOperatorSymbol().equals(Operator.SHIFT_LEFT) || getOperatorSymbol().equals(Operator.SHIFT_RIGHT) || getOperatorSymbol().equals(Operator.UNSIGNED_SHIFT_RIGHT) ){ ((Value)rightFactor).convert(getType(int.class)); } else { ((Value)rightFactor).convert(targetClass); } } }
if (!original.equals(getType(Boolean.class)) && !target.equals(getType(Boolean.class)) && original.getCastOrder() <= target.getCastOrder()) { instructions.cast(original.getType(), target.getType()); return;