@Test public void prepareStatementToDonateDiscardRemoved() throws Exception { final DonateLiveCodeTransformation dlc = getDummyTransformationObject(); DonationContext dc = new DonationContext(new DiscardStmt(), new HashMap<>(), new ArrayList<>(), null); Stmt donated = dlc.prepareStatementToDonate(null, dc, TransformationProbabilities.DEFAULT_PROBABILITIES, new RandomWrapper(0), ShadingLanguageVersion.ESSL_100); assertFalse(new CheckPredicateVisitor() { @Override public void visitDiscardStmt(DiscardStmt discardStmt) { predicateHolds(); } }.test(donated)); }
@Override Stmt prepareStatementToDonate(IInjectionPoint injectionPoint, DonationContext donationContext, TransformationProbabilities probabilities, IRandom generator, ShadingLanguageVersion shadingLanguageVersion) { List<Stmt> donatedStmts = new ArrayList<>(); for (Map.Entry<String, Type> vars : donationContext.getFreeVariables().entrySet()) { final Type type = vars.getValue(); final Type typeWithRestrictedQualifiers = dropQualifiersThatCannotBeUsedForLocalVariable(type); final Initializer initializer; if (isLoopLimiter(vars.getKey(), typeWithRestrictedQualifiers.getWithoutQualifiers())) { initializer = new Initializer(new IntConstantExpr("0")); } else { initializer = getInitializer(injectionPoint, donationContext, typeWithRestrictedQualifiers, true, generator, shadingLanguageVersion); } final ImmutablePair<Type, ArrayInfo> baseTypeAndArrayInfo = Typer.getBaseTypeArrayInfo(typeWithRestrictedQualifiers); donatedStmts.add(new DeclarationStmt( new VariablesDeclaration(baseTypeAndArrayInfo.left, new VariableDeclInfo(vars.getKey(), baseTypeAndArrayInfo.right, initializer)))); } donatedStmts.add(donationContext.getDonorFragment()); BlockStmt donatedStmt = new BlockStmt(donatedStmts, true); new RemoveImmediateBreakStatements(donatedStmt); new RemoveImmediateContinueStatements(donatedStmt); new RemoveImmediateCaseLabels(donatedStmt); new RemoveReturnStatements(donatedStmt); new RemoveDiscardStatements(donatedStmt); return donatedStmt; }
DonateLiveCodeTransformation extends DonateCodeTransformation { @Override Stmt prepareStatementToDonate(IInjectionPoint injectionPoint, DonationContext donationContext, TransformationProbabilities probabilities, IRandom generator, ShadingLanguageVersion shadingLanguageVersion) { List<Stmt> donatedStmts = new ArrayList<>(); for (Map.Entry<String, Type> vars : donationContext.getFreeVariables().entrySet()) { final Type type = vars.getValue(); final Type typeWithRestrictedQualifiers = dropQualifiersThatCannotBeUsedForLocalVariable(type); final Initializer initializer; if (isLoopLimiter(vars.getKey(), typeWithRestrictedQualifiers.getWithoutQualifiers())) { initializer = new Initializer(new IntConstantExpr("0")); } else { initializer = getInitializer(injectionPoint, donationContext, typeWithRestrictedQualifiers, true, generator, shadingLanguageVersion); } final ImmutablePair<Type, ArrayInfo> baseTypeAndArrayInfo = Typer.getBaseTypeArrayInfo(typeWithRestrictedQualifiers); donatedStmts.add(new DeclarationStmt( new VariablesDeclaration(baseTypeAndArrayInfo.left, new VariableDeclInfo(vars.getKey(), baseTypeAndArrayInfo.right, initializer)))); } donatedStmts.add(donationContext.getDonorFragment()); BlockStmt donatedStmt = new BlockStmt(donatedStmts, true); new RemoveImmediateBreakStatements(donatedStmt); new RemoveImmediateContinueStatements(donatedStmt); new RemoveImmediateCaseLabels(donatedStmt); new RemoveReturnStatements(donatedStmt); new RemoveDiscardStatements(donatedStmt); return donatedStmt; } }
DonateLiveCodeTransformation extends DonateCodeTransformation { @Override Stmt prepareStatementToDonate(IInjectionPoint injectionPoint, DonationContext donationContext, TransformationProbabilities probabilities, IRandom generator, ShadingLanguageVersion shadingLanguageVersion) { List<Stmt> donatedStmts = new ArrayList<>(); for (Map.Entry<String, Type> vars : donationContext.getFreeVariables().entrySet()) { final Type type = vars.getValue(); final Type typeWithRestrictedQualifiers = dropQualifiersThatCannotBeUsedForLocalVariable(type); final Initializer initializer; if (isLoopLimiter(vars.getKey(), typeWithRestrictedQualifiers.getWithoutQualifiers())) { initializer = new Initializer(new IntConstantExpr("0")); } else { initializer = getInitializer(injectionPoint, donationContext, typeWithRestrictedQualifiers, true, generator, shadingLanguageVersion); } final ImmutablePair<Type, ArrayInfo> baseTypeAndArrayInfo = Typer.getBaseTypeArrayInfo(typeWithRestrictedQualifiers); donatedStmts.add(new DeclarationStmt( new VariablesDeclaration(baseTypeAndArrayInfo.left, new VariableDeclInfo(vars.getKey(), baseTypeAndArrayInfo.right, initializer)))); } donatedStmts.add(donationContext.getDonorFragment()); BlockStmt donatedStmt = new BlockStmt(donatedStmts, true); new RemoveImmediateBreakStatements(donatedStmt); new RemoveImmediateContinueStatements(donatedStmt); new RemoveImmediateCaseLabels(donatedStmt); new RemoveReturnStatements(donatedStmt); new RemoveDiscardStatements(donatedStmt); return donatedStmt; } DonateLiveCodeTransformation(Function<IRandom, Boolean> probabilityOfDonation,
                                      File donorsDirectory,
                                      GenerationParams generationParams,
                                      boolean allowLongLoops); }
DonateLiveCodeTransformation extends DonateCodeTransformation { @Override Stmt prepareStatementToDonate(IInjectionPoint injectionPoint, DonationContext donationContext, TransformationProbabilities probabilities, IRandom generator, ShadingLanguageVersion shadingLanguageVersion) { List<Stmt> donatedStmts = new ArrayList<>(); for (Map.Entry<String, Type> vars : donationContext.getFreeVariables().entrySet()) { final Type type = vars.getValue(); final Type typeWithRestrictedQualifiers = dropQualifiersThatCannotBeUsedForLocalVariable(type); final Initializer initializer; if (isLoopLimiter(vars.getKey(), typeWithRestrictedQualifiers.getWithoutQualifiers())) { initializer = new Initializer(new IntConstantExpr("0")); } else { initializer = getInitializer(injectionPoint, donationContext, typeWithRestrictedQualifiers, true, generator, shadingLanguageVersion); } final ImmutablePair<Type, ArrayInfo> baseTypeAndArrayInfo = Typer.getBaseTypeArrayInfo(typeWithRestrictedQualifiers); donatedStmts.add(new DeclarationStmt( new VariablesDeclaration(baseTypeAndArrayInfo.left, new VariableDeclInfo(vars.getKey(), baseTypeAndArrayInfo.right, initializer)))); } donatedStmts.add(donationContext.getDonorFragment()); BlockStmt donatedStmt = new BlockStmt(donatedStmts, true); new RemoveImmediateBreakStatements(donatedStmt); new RemoveImmediateContinueStatements(donatedStmt); new RemoveImmediateCaseLabels(donatedStmt); new RemoveReturnStatements(donatedStmt); new RemoveDiscardStatements(donatedStmt); return donatedStmt; } DonateLiveCodeTransformation(Function<IRandom, Boolean> probabilityOfDonation,
                                      File donorsDirectory,
                                      GenerationParams generationParams,
                                      boolean allowLongLoops); @Override String getName(); }
DonateLiveCodeTransformation extends DonateCodeTransformation { @Override Stmt prepareStatementToDonate(IInjectionPoint injectionPoint, DonationContext donationContext, TransformationProbabilities probabilities, IRandom generator, ShadingLanguageVersion shadingLanguageVersion) { List<Stmt> donatedStmts = new ArrayList<>(); for (Map.Entry<String, Type> vars : donationContext.getFreeVariables().entrySet()) { final Type type = vars.getValue(); final Type typeWithRestrictedQualifiers = dropQualifiersThatCannotBeUsedForLocalVariable(type); final Initializer initializer; if (isLoopLimiter(vars.getKey(), typeWithRestrictedQualifiers.getWithoutQualifiers())) { initializer = new Initializer(new IntConstantExpr("0")); } else { initializer = getInitializer(injectionPoint, donationContext, typeWithRestrictedQualifiers, true, generator, shadingLanguageVersion); } final ImmutablePair<Type, ArrayInfo> baseTypeAndArrayInfo = Typer.getBaseTypeArrayInfo(typeWithRestrictedQualifiers); donatedStmts.add(new DeclarationStmt( new VariablesDeclaration(baseTypeAndArrayInfo.left, new VariableDeclInfo(vars.getKey(), baseTypeAndArrayInfo.right, initializer)))); } donatedStmts.add(donationContext.getDonorFragment()); BlockStmt donatedStmt = new BlockStmt(donatedStmts, true); new RemoveImmediateBreakStatements(donatedStmt); new RemoveImmediateContinueStatements(donatedStmt); new RemoveImmediateCaseLabels(donatedStmt); new RemoveReturnStatements(donatedStmt); new RemoveDiscardStatements(donatedStmt); return donatedStmt; } DonateLiveCodeTransformation(Function<IRandom, Boolean> probabilityOfDonation,
                                      File donorsDirectory,
                                      GenerationParams generationParams,
                                      boolean allowLongLoops); @Override String getName(); static final String NAME; }