/** * Declare local variables * but first local variables in a set, so we reduce redundancy */ protected void handleLocalVariables() { Set <String> varNames = new HashSet<String> (); for (Variable var : graph.getLocalVariables()) { varNames.add(var.getName()); } for (String var : varNames) { appendIndentation(); FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var); graph.accept(fieldVisitor); code.append(fieldVisitor.giveDefinition(variableType)); code.append("\n"); } if (!graph.getLocalVariables().isEmpty()) { code.append("\n"); } }
/** * Updates the LocalVariable-set in a graph * @param graph The graph */ public static void updateVariableSets(ControlFlowGraph graph) { VariablesCollector collector = new VariablesCollector(); graph.accept(collector); LinkedList<Variable> vars = new LinkedList<Variable>(graph.getLocalVariables()); for (Variable v: vars) if (!collector.getVariables().contains(v.getName())) graph.removeLocalVariable(v); }
int bladeCount = graph.getAlgebraDefinitionFile().getBladeCount(); List<Variable> localVariables = sortVariables(graph.getLocalVariables()); if (standalone) { code.append("void calculate("); if (graph.getLocalVariables().size() > 0) { code.setLength(code.length() - 2); if (!graph.getLocalVariables().isEmpty()) { code.append("\n");
graph = node.getGraph(); List<Variable> localVariables = sortVariables(graph.getLocalVariables()); if (standalone) { code.append("void calculate("); if (graph.getLocalVariables().size() > 0) { code.setLength(code.length() - 2); if (!graph.getLocalVariables().isEmpty()) { code.append("\n");
@Override public void visit(StartNode startNode) { CluCalcFileHeader header = CluCalcFileHeader.get(startNode); if (header != null) { if (header.getNullSpace() != null) { switch (header.getNullSpace()) { case IPNS: code.append(":IPNS;\n"); break; case OPNS: code.append(":OPNS;\n"); break; } } code.append("\n"); } // TODO add "Generated by" header etc. // Generate the local variables for all local variables for (Variable localVariable : startNode.getGraph().getLocalVariables()) { code.append(localVariable.getName() + codeSuffix); code.append(" = List("); code.append(startNode.getGraph().getAlgebraDefinitionFile().getBladeCount()); code.append(");\n"); } code.append("\n"); startNode.getSuccessor().accept(this); }
/** * Updates the variable-sets in a graph * @param graph The graph */ public static void updateVariableSets(ControlFlowGraph graph) { UpdateLocalVariableSet visitor = new UpdateLocalVariableSet(); graph.accept(visitor); LinkedList<Variable> iVar = new LinkedList<Variable>(graph.getInputVariables()); LinkedList<Variable> lVar = new LinkedList<Variable>(graph.getLocalVariables()); //clear for (Variable inputVar: iVar) graph.removeInputVariable(inputVar); for (Variable defVar: lVar) graph.removeLocalVariable(defVar); //add for (String inputVar: visitor.inputVariables) graph.addInputVariable(new Variable(inputVar)); for (String defVar: visitor.defined) graph.addLocalVariable(new Variable(defVar)); }
/** * Searches the expression for variable references. If an undeclared reference is found, it is added to the input variables of * the graph. * * @param expression The expression to search in. */ private void findUndeclaredVariables(Expression expression) { UsedVariablesVisitor visitor = new UsedVariablesVisitor(); expression.accept(visitor); for (Variable usedVariable : visitor.getVariables()) { if (!graph.getLocalVariables().contains(usedVariable)) { // in case we have pragmas giving ranges for the variable, add them if (graph.getPragmaMinValue().containsKey(usedVariable.getName())) { usedVariable.setMinValue(graph.getPragmaMinValue().get(usedVariable.getName())); } if (graph.getPragmaMaxValue().containsKey(usedVariable.getName())) { usedVariable.setMaxValue(graph.getPragmaMaxValue().get(usedVariable.getName())); } graph.addInputVariable(usedVariable); } } }
/** * Searches the expression for variable references. If an undeclared reference is found, it is added to the * input variables of the graph. * * @param expression The expression to search in. * @param inMacro */ private void findUndeclaredVariables(Expression expression) { UsedVariablesVisitor visitor = new UsedVariablesVisitor(); expression.accept(visitor); for (Variable usedVariable : visitor.getVariables()) { checkIllegalVariable(usedVariable); if (!graph.getLocalVariables().contains(usedVariable)) { // in case we have pragmas giving ranges for the variable, add them if (graph.getPragmaMinValue().containsKey(usedVariable.getName())) { usedVariable.setMinValue(graph.getPragmaMinValue().get(usedVariable.getName())); } if (graph.getPragmaMaxValue().containsKey(usedVariable.getName())) { usedVariable.setMaxValue(graph.getPragmaMaxValue().get(usedVariable.getName())); } graph.addInputVariable(usedVariable); } } }
/** * Searches the expression for variable references. If an undeclared reference is found, it is added to the * input variables of the graph. * * @param expression The expression to search in. * @param inMacro */ private void findUndeclaredVariables(Expression expression) { UsedVariablesVisitor visitor = new UsedVariablesVisitor(); expression.accept(visitor); for (Variable usedVariable : visitor.getVariables()) { checkIllegalVariable(usedVariable); if (!graph.getLocalVariables().contains(usedVariable)) { // in case we have pragmas giving ranges for the variable, add them if (graph.getPragmaMinValue().containsKey(usedVariable.getName())) { usedVariable.setMinValue(graph.getPragmaMinValue().get(usedVariable.getName())); } if (graph.getPragmaMaxValue().containsKey(usedVariable.getName())) { usedVariable.setMaxValue(graph.getPragmaMaxValue().get(usedVariable.getName())); } graph.addInputVariable(usedVariable); } } }
protected void createVectorSet (FindStoreOutputNodes findOutput) { for (Variable var : graph.getInputVariables()) { FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var.getName()); graph.accept(fieldVisitor); vectorSet.add(fieldVisitor.getMultiVector()); } for (Variable var : graph.getLocalVariables()) { FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var.getName()); graph.accept(fieldVisitor); vectorSet.add(fieldVisitor.getMultiVector()); } for (StoreResultNode var : findOutput.getNodes()) { FieldsUsedVisitor fieldVisitor = new FieldsUsedVisitor(var.getValue().getName()); graph.accept(fieldVisitor); vectorSet.add(fieldVisitor.getMultiVector()); } }
graph.getInputVariables().contains(inputsVectorVar) || graph.getScalarVariables().contains(inputsVectorVar) || graph.getLocalVariables().contains(inputsVectorVar)