@Override public TypeConstructorExpr clone() { return new TypeConstructorExpr(type, args.stream().map(x -> x.clone()).collect(Collectors.toList())); }
private Expr makeTypeConstructor(BasicType type, Supplier<ConstantExpr> supplier, int width) { List<Expr> args = new ArrayList<>(); for (int i = 0; i < width; i++) { args.add(supplier.get()); } return new TypeConstructorExpr(type.toString(), args); }
@Override public Expr generateExpr(IRandom generator, Expr... args) { assert args.length == getNumArguments(); return new TypeConstructorExpr(resultType.toString(), Arrays.asList(args)); }
public static Expr getBasicTypeLiteralExpr(BasicType baseType, List<Number> args) { List<Expr> argExprs; if (baseType.getElementType() == BasicType.FLOAT) { argExprs = args.stream().map(item -> new FloatConstantExpr(item.toString())) .collect(Collectors.toList()); } else if (baseType.getElementType() == BasicType.UINT) { argExprs = args.stream().map(item -> new UIntConstantExpr(item.toString() + "u")) .collect(Collectors.toList()); } else { argExprs = args.stream().map(item -> new IntConstantExpr(item.toString())) .collect(Collectors.toList()); } if (argExprs.size() == 1) { return argExprs.get(0); } return new TypeConstructorExpr(baseType.toString(), argExprs); }
public Expr makeOpaqueBoolean(boolean value, BasicType type, boolean constContext, final int depth, Fuzzer fuzzer) { assert type.isBoolean(); if (type == BasicType.BOOL) { return makeOpaqueBooleanScalar(value, constContext, depth, fuzzer); } List<Expr> args = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { args.add(makeOpaqueBoolean(value, BasicType.BOOL, constContext, depth, fuzzer)); } return new TypeConstructorExpr(type.toString(), args); }
private Expr makeInitializationExpr(StructDefinitionType structDefinitionType, Expr originalInitializer) { List<Expr> args = new ArrayList<>(); for (int i = 0; i < structDefinitionType.getNumFields(); i++) { if (structDefinitionType.getFieldName(i).startsWith(Constants.STRUCTIFICATION_FIELD_PREFIX)) { final Type fieldType = structDefinitionType.getFieldType(i); args.add(fieldType instanceof StructNameType ? makeInitializationExpr(tu.getStructDefinition((StructNameType) fieldType), originalInitializer) : fieldType.getCanonicalConstant()); } else { args.add(originalInitializer); } } return new TypeConstructorExpr(structDefinitionType.getStructNameType().getName(), args); }
private void findFoldFpScalarVectorBinaryOpportunities(IAstNode parent, Expr child, Expr lhs, Expr rhs, BinaryOperator<Float> op) { if (isFpConstant(lhs) && isFpVectorConstant(rhs)) { final TypeConstructorExpr typeConstructorExpr = (TypeConstructorExpr) rhs; addReplaceWithExpr(parent, child, new TypeConstructorExpr(typeConstructorExpr.getTypename(), typeConstructorExpr.getArgs() .stream() .map(item -> (FloatConstantExpr) item) .map(item -> new FloatConstantExpr(op.apply( Float.valueOf(((FloatConstantExpr) lhs).getValue()), Float.valueOf(item.getValue())).toString())) .collect(Collectors.toList()))); } if (isFpConstant(rhs) && isFpVectorConstant(lhs)) { final TypeConstructorExpr typeConstructorExpr = (TypeConstructorExpr) lhs; addReplaceWithExpr(parent, child, new TypeConstructorExpr(typeConstructorExpr.getTypename(), typeConstructorExpr.getArgs() .stream() .map(item -> (FloatConstantExpr) item) .map(item -> new FloatConstantExpr(op.apply( Float.valueOf(item.getValue()), Float.valueOf(((FloatConstantExpr) rhs).getValue())).toString())) .collect(Collectors.toList()))); } }
expr, new FunctionCallExpr("mix", new TypeConstructorExpr(type.toString(), xElements), new TypeConstructorExpr(type.toString(), yElements), new TypeConstructorExpr( BasicType.makeVectorType(BasicType.BOOL, type.getNumElements()) .toString(), aElements)));
return new TypeConstructorExpr(structName, sdt.getFieldTypes() .stream().map(item -> makeExpr(item, false, constContext, depth + 1)) .collect(Collectors.toList()));
@Override public Expr getCanonicalConstant() { if (this == FLOAT) { return new FloatConstantExpr("1.0"); } if (this == INT) { return new IntConstantExpr("1"); } if (this == UINT) { return new UIntConstantExpr("1u"); } if (this == BOOL) { return BoolConstantExpr.TRUE; } return new TypeConstructorExpr(toString().toString(), getElementType().getCanonicalConstant()); }
private Expr makeOpaqueZeroOrOneFromInjectionSwitch(boolean isZero, BasicType type) { assert generationParams.getInjectionSwitchIsAvailable(); if (type == BasicType.FLOAT) { if (isZero) { return zeroConstructor(injectionSwitch("x"), type); } return oneConstructor(injectionSwitch("y"), type); } List<Expr> args = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { // We use float for each argument, on the assumption that all the scalar and vector // constructors can take float arguments args.add(makeOpaqueZeroOrOneFromInjectionSwitch(isZero, BasicType.FLOAT)); } return new TypeConstructorExpr(type.toString(), args); }
private Expr makeRegularIntegerValuedLiteral(BasicType type, String integerPart) { assert type.getElementType() != BasicType.BOOL; if (type == BasicType.FLOAT) { return new FloatConstantExpr(integerPart + ".0"); } if (type == BasicType.INT) { return new IntConstantExpr(integerPart); } if (type == BasicType.UINT) { return new UIntConstantExpr(integerPart + "u"); } List<Expr> args = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { assert type.getElementType() != type; args.add(makeRegularIntegerValuedLiteral(type.getElementType(), integerPart)); } return new TypeConstructorExpr(type.toString(), args); }
getArrayInfo(header.array_specifier())), params); return new TypeConstructorExpr(getTypeConstructorName(header.function_identifier()), params); getArrayInfo(header.array_specifier())), params); return new TypeConstructorExpr(getTypeConstructorName(header.function_identifier()), params);