use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project incubator-systemml by apache.
the class DMLProgram method createRuntimeProgramBlock.
public ProgramBlock createRuntimeProgramBlock(Program prog, StatementBlock sb, DMLConfig config) throws IOException, LopsException, DMLRuntimeException {
Dag<Lop> dag = null;
Dag<Lop> pred_dag = null;
ArrayList<Instruction> instruct;
ArrayList<Instruction> pred_instruct = null;
ProgramBlock retPB = null;
// process While Statement - add runtime program blocks to program
if (sb instanceof WhileStatementBlock) {
// create DAG for loop predicates
pred_dag = new Dag<Lop>();
((WhileStatementBlock) sb).get_predicateLops().addToDag(pred_dag);
// create instructions for loop predicates
pred_instruct = new ArrayList<Instruction>();
ArrayList<Instruction> pInst = pred_dag.getJobs(null, config);
for (Instruction i : pInst) {
pred_instruct.add(i);
}
// create while program block
WhileProgramBlock rtpb = new WhileProgramBlock(prog, pred_instruct);
if (rtpb.getPredicateResultVar() == null) {
// e.g case : WHILE(continue)
if (((WhileStatementBlock) sb).get_predicateLops().getExecLocation() == LopProperties.ExecLocation.Data) {
String resultVar = ((WhileStatementBlock) sb).get_predicateLops().getOutputParameters().getLabel();
rtpb.setPredicateResultVar(resultVar);
} else {
LOG.error(sb.printBlockErrorLocation() + "Error in translating the WHILE predicate.");
throw new LopsException(sb.printBlockErrorLocation() + "Error in translating the WHILE predicate.");
}
}
//// process the body of the while statement block ////
WhileStatementBlock wsb = (WhileStatementBlock) sb;
if (wsb.getNumStatements() > 1) {
LOG.error(wsb.printBlockErrorLocation() + "WhileStatementBlock should only have 1 statement");
throw new LopsException(wsb.printBlockErrorLocation() + "WhileStatementBlock should only have 1 statement");
}
WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
for (StatementBlock sblock : wstmt.getBody()) {
// process the body
ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
rtpb.addProgramBlock(childBlock);
}
// check there are actually Lops in to process (loop stmt body will not have any)
if (wsb.getLops() != null && !wsb.getLops().isEmpty()) {
LOG.error(wsb.printBlockErrorLocation() + "WhileStatementBlock should have no Lops");
throw new LopsException(wsb.printBlockErrorLocation() + "WhileStatementBlock should have no Lops");
}
retPB = rtpb;
//post processing for generating missing instructions
//retPB = verifyAndCorrectProgramBlock(sb.liveIn(), sb.liveOut(), sb._kill, retPB);
// add statement block
retPB.setStatementBlock(sb);
// add location information
retPB.setAllPositions(sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
} else // process If Statement - add runtime program blocks to program
if (sb instanceof IfStatementBlock) {
// create DAG for loop predicates
pred_dag = new Dag<Lop>();
((IfStatementBlock) sb).get_predicateLops().addToDag(pred_dag);
// create instructions for loop predicates
pred_instruct = new ArrayList<Instruction>();
ArrayList<Instruction> pInst = pred_dag.getJobs(null, config);
for (Instruction i : pInst) {
pred_instruct.add(i);
}
// create if program block
IfProgramBlock rtpb = new IfProgramBlock(prog, pred_instruct);
if (rtpb.getPredicateResultVar() == null) {
// e.g case : If(continue)
if (((IfStatementBlock) sb).get_predicateLops().getExecLocation() == LopProperties.ExecLocation.Data) {
String resultVar = ((IfStatementBlock) sb).get_predicateLops().getOutputParameters().getLabel();
rtpb.setPredicateResultVar(resultVar);
} else {
LOG.error(sb.printBlockErrorLocation() + "Error in translating the IF predicate.");
throw new LopsException(sb.printBlockErrorLocation() + "Error in translating the IF predicate.");
}
}
// process the body of the if statement block
IfStatementBlock isb = (IfStatementBlock) sb;
if (isb.getNumStatements() > 1) {
LOG.error(isb.printBlockErrorLocation() + "IfStatementBlock should have only 1 statement");
throw new LopsException(isb.printBlockErrorLocation() + "IfStatementBlock should have only 1 statement");
}
IfStatement istmt = (IfStatement) isb.getStatement(0);
// process the if body
for (StatementBlock sblock : istmt.getIfBody()) {
ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
rtpb.addProgramBlockIfBody(childBlock);
}
// process the else body
for (StatementBlock sblock : istmt.getElseBody()) {
ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
rtpb.addProgramBlockElseBody(childBlock);
}
// check there are actually Lops in to process (loop stmt body will not have any)
if (isb.getLops() != null && !isb.getLops().isEmpty()) {
LOG.error(isb.printBlockErrorLocation() + "IfStatementBlock should have no Lops");
throw new LopsException(isb.printBlockErrorLocation() + "IfStatementBlock should have no Lops");
}
retPB = rtpb;
//post processing for generating missing instructions
//retPB = verifyAndCorrectProgramBlock(sb.liveIn(), sb.liveOut(), sb._kill, retPB);
// add statement block
retPB.setStatementBlock(sb);
// add location information
retPB.setAllPositions(sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
} else // NOTE: applies to ForStatementBlock and ParForStatementBlock
if (sb instanceof ForStatementBlock) {
ForStatementBlock fsb = (ForStatementBlock) sb;
// create DAGs for loop predicates
Dag<Lop> fromDag = new Dag<Lop>();
Dag<Lop> toDag = new Dag<Lop>();
Dag<Lop> incrementDag = new Dag<Lop>();
if (fsb.getFromHops() != null)
fsb.getFromLops().addToDag(fromDag);
if (fsb.getToHops() != null)
fsb.getToLops().addToDag(toDag);
if (fsb.getIncrementHops() != null)
fsb.getIncrementLops().addToDag(incrementDag);
// create instructions for loop predicates
ArrayList<Instruction> fromInstructions = fromDag.getJobs(null, config);
ArrayList<Instruction> toInstructions = toDag.getJobs(null, config);
ArrayList<Instruction> incrementInstructions = incrementDag.getJobs(null, config);
// create for program block
String sbName = null;
ForProgramBlock rtpb = null;
IterablePredicate iterPred = fsb.getIterPredicate();
String[] iterPredData = IterablePredicate.createIterablePredicateVariables(iterPred.getIterVar().getName(), fsb.getFromLops(), fsb.getToLops(), fsb.getIncrementLops());
if (sb instanceof ParForStatementBlock) {
sbName = "ParForStatementBlock";
rtpb = new ParForProgramBlock(prog, iterPredData, iterPred.getParForParams());
ParForProgramBlock pfrtpb = (ParForProgramBlock) rtpb;
pfrtpb.setResultVariables(((ParForStatementBlock) sb).getResultVariables());
//used for optimization and creating unscoped variables
pfrtpb.setStatementBlock((ParForStatementBlock) sb);
} else //ForStatementBlock
{
sbName = "ForStatementBlock";
rtpb = new ForProgramBlock(prog, iterPredData);
}
rtpb.setFromInstructions(fromInstructions);
rtpb.setToInstructions(toInstructions);
rtpb.setIncrementInstructions(incrementInstructions);
rtpb.setIterablePredicateVars(iterPredData);
// process the body of the for statement block
if (fsb.getNumStatements() > 1) {
LOG.error(fsb.printBlockErrorLocation() + " " + sbName + " should have 1 statement");
throw new LopsException(fsb.printBlockErrorLocation() + " " + sbName + " should have 1 statement");
}
ForStatement fs = (ForStatement) fsb.getStatement(0);
for (StatementBlock sblock : fs.getBody()) {
ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
rtpb.addProgramBlock(childBlock);
}
// check there are actually Lops in to process (loop stmt body will not have any)
if (fsb.getLops() != null && !fsb.getLops().isEmpty()) {
LOG.error(fsb.printBlockErrorLocation() + sbName + " should have no Lops");
throw new LopsException(fsb.printBlockErrorLocation() + sbName + " should have no Lops");
}
retPB = rtpb;
//post processing for generating missing instructions
//retPB = verifyAndCorrectProgramBlock(sb.liveIn(), sb.liveOut(), sb._kill, retPB);
// add statement block
retPB.setStatementBlock(sb);
// add location information
retPB.setAllPositions(sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
} else // process function statement block - add runtime program blocks to program
if (sb instanceof FunctionStatementBlock) {
FunctionStatementBlock fsb = (FunctionStatementBlock) sb;
if (fsb.getNumStatements() > 1) {
LOG.error(fsb.printBlockErrorLocation() + "FunctionStatementBlock should only have 1 statement");
throw new LopsException(fsb.printBlockErrorLocation() + "FunctionStatementBlock should only have 1 statement");
}
FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
FunctionProgramBlock rtpb = null;
if (fstmt instanceof ExternalFunctionStatement) {
// create external function program block
String execType = ((ExternalFunctionStatement) fstmt).getOtherParams().get(ExternalFunctionStatement.EXEC_TYPE);
boolean isCP = (execType.equals(ExternalFunctionStatement.IN_MEMORY)) ? true : false;
String scratchSpaceLoc = null;
try {
scratchSpaceLoc = config.getTextValue(DMLConfig.SCRATCH_SPACE);
} catch (Exception e) {
LOG.error(fsb.printBlockErrorLocation() + "could not retrieve parameter " + DMLConfig.SCRATCH_SPACE + " from DMLConfig");
}
StringBuilder buff = new StringBuilder();
buff.append(scratchSpaceLoc);
buff.append(Lop.FILE_SEPARATOR);
buff.append(Lop.PROCESS_PREFIX);
buff.append(DMLScript.getUUID());
buff.append(Lop.FILE_SEPARATOR);
buff.append(ProgramConverter.CP_ROOT_THREAD_ID);
buff.append(Lop.FILE_SEPARATOR);
buff.append("PackageSupport");
buff.append(Lop.FILE_SEPARATOR);
String basedir = buff.toString();
if (isCP) {
rtpb = new ExternalFunctionProgramBlockCP(prog, fstmt.getInputParams(), fstmt.getOutputParams(), ((ExternalFunctionStatement) fstmt).getOtherParams(), basedir);
} else {
rtpb = new ExternalFunctionProgramBlock(prog, fstmt.getInputParams(), fstmt.getOutputParams(), ((ExternalFunctionStatement) fstmt).getOtherParams(), basedir);
}
if (!fstmt.getBody().isEmpty()) {
LOG.error(fstmt.printErrorLocation() + "ExternalFunctionStatementBlock should have no statement blocks in body");
throw new LopsException(fstmt.printErrorLocation() + "ExternalFunctionStatementBlock should have no statement blocks in body");
}
} else {
// create function program block
rtpb = new FunctionProgramBlock(prog, fstmt.getInputParams(), fstmt.getOutputParams());
// process the function statement body
for (StatementBlock sblock : fstmt.getBody()) {
// process the body
ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
rtpb.addProgramBlock(childBlock);
}
}
// check there are actually Lops in to process (loop stmt body will not have any)
if (fsb.getLops() != null && !fsb.getLops().isEmpty()) {
LOG.error(fsb.printBlockErrorLocation() + "FunctionStatementBlock should have no Lops");
throw new LopsException(fsb.printBlockErrorLocation() + "FunctionStatementBlock should have no Lops");
}
retPB = rtpb;
// add location information
retPB.setAllPositions(sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
} else {
// handle general case
ProgramBlock rtpb = new ProgramBlock(prog);
// DAGs for Lops
dag = new Dag<Lop>();
// check there are actually Lops in to process (loop stmt body will not have any)
if (sb.getLops() != null && !sb.getLops().isEmpty()) {
for (Lop l : sb.getLops()) {
l.addToDag(dag);
}
// Instructions for Lobs DAGs
instruct = dag.getJobs(sb, config);
rtpb.addInstructions(instruct);
}
/*// TODO: check with Doug
// add instruction for a function call
if (sb.getFunctionCallInst() != null){
rtpb.addInstruction(sb.getFunctionCallInst());
}*/
retPB = rtpb;
//post processing for generating missing instructions
//retPB = verifyAndCorrectProgramBlock(sb.liveIn(), sb.liveOut(), sb._kill, retPB);
// add statement block
retPB.setStatementBlock(sb);
// add location information
retPB.setAllPositions(sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
}
return retPB;
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project incubator-systemml by apache.
the class DMLProgram method getRuntimeProgram.
public Program getRuntimeProgram(DMLConfig config) throws IOException, LanguageException, DMLRuntimeException, LopsException {
// constructor resets the set of registered functions
Program rtprog = new Program();
// for all namespaces, translate function statement blocks into function program blocks
for (String namespace : _namespaces.keySet()) {
for (String fname : getFunctionStatementBlocks(namespace).keySet()) {
// add program block to program
FunctionStatementBlock fsb = getFunctionStatementBlocks(namespace).get(fname);
FunctionProgramBlock rtpb = (FunctionProgramBlock) createRuntimeProgramBlock(rtprog, fsb, config);
rtprog.addFunctionProgramBlock(namespace, fname, rtpb);
rtpb.setRecompileOnce(fsb.isRecompileOnce());
}
}
// for each top-level block
for (StatementBlock sb : _blocks) {
// add program block to program
ProgramBlock rtpb = createRuntimeProgramBlock(rtprog, sb, config);
rtprog.addProgramBlock(rtpb);
}
return rtprog;
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rParseFunctionProgramBlock.
private static FunctionProgramBlock rParseFunctionProgramBlock(String in, Program prog, int id) throws DMLRuntimeException {
String lin = in.substring(PARFOR_PB_FC.length(), in.length() - PARFOR_PB_END.length());
HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
//LocalVariableMap vars = parseVariables(st.nextToken());
//inputs and outputs
ArrayList<DataIdentifier> dat1 = parseDataIdentifiers(st.nextToken());
ArrayList<DataIdentifier> dat2 = parseDataIdentifiers(st.nextToken());
//instructions
ArrayList<Instruction> inst = parseInstructions(st.nextToken(), id);
//program blocks
ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
ArrayList<DataIdentifier> tmp1 = new ArrayList<DataIdentifier>(dat1);
ArrayList<DataIdentifier> tmp2 = new ArrayList<DataIdentifier>(dat2);
FunctionProgramBlock fpb = new FunctionProgramBlock(prog, tmp1, tmp2);
fpb.setInstructions(inst);
fpb.setChildBlocks(pbs);
return fpb;
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rSerializeProgramBlock.
private static String rSerializeProgramBlock(ProgramBlock pb, HashMap<String, byte[]> clsMap) throws DMLRuntimeException {
StringBuilder sb = new StringBuilder();
//handle header
if (pb instanceof WhileProgramBlock)
sb.append(PARFOR_PB_WHILE);
else if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock))
sb.append(PARFOR_PB_FOR);
else if (pb instanceof ParForProgramBlock)
sb.append(PARFOR_PB_PARFOR);
else if (pb instanceof IfProgramBlock)
sb.append(PARFOR_PB_IF);
else if (pb instanceof FunctionProgramBlock && !(pb instanceof ExternalFunctionProgramBlock))
sb.append(PARFOR_PB_FC);
else if (pb instanceof ExternalFunctionProgramBlock)
sb.append(PARFOR_PB_EFC);
else
//all generic program blocks
sb.append(PARFOR_PB_BEGIN);
//handle body
if (pb instanceof WhileProgramBlock) {
WhileProgramBlock wpb = (WhileProgramBlock) pb;
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(wpb.getPredicate(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(wpb.getPredicateResultVar());
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(wpb.getExitInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_PBS_BEGIN);
sb.append(rSerializeProgramBlocks(wpb.getChildBlocks(), clsMap));
sb.append(PARFOR_PBS_END);
} else if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)) {
ForProgramBlock fpb = (ForProgramBlock) pb;
sb.append(serializeStringArray(fpb.getIterablePredicateVars()));
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(fpb.getFromInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(fpb.getToInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(fpb.getIncrementInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(fpb.getExitInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_PBS_BEGIN);
sb.append(rSerializeProgramBlocks(fpb.getChildBlocks(), clsMap));
sb.append(PARFOR_PBS_END);
} else if (pb instanceof ParForProgramBlock) {
ParForProgramBlock pfpb = (ParForProgramBlock) pb;
//check for nested remote ParFOR
if (PExecMode.valueOf(pfpb.getParForParams().get(ParForStatementBlock.EXEC_MODE)) == PExecMode.REMOTE_MR)
throw new DMLRuntimeException(NOT_SUPPORTED_MR_PARFOR);
sb.append(serializeStringArray(pfpb.getIterablePredicateVars()));
sb.append(COMPONENTS_DELIM);
sb.append(serializeStringArrayList(pfpb.getResultVariables()));
sb.append(COMPONENTS_DELIM);
//parameters of nested parfor
sb.append(serializeStringHashMap(pfpb.getParForParams()));
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(pfpb.getFromInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(pfpb.getToInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(pfpb.getIncrementInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(pfpb.getExitInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_PBS_BEGIN);
sb.append(rSerializeProgramBlocks(pfpb.getChildBlocks(), clsMap));
sb.append(PARFOR_PBS_END);
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock ipb = (IfProgramBlock) pb;
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(ipb.getPredicate(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(ipb.getPredicateResultVar());
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(ipb.getExitInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_PBS_BEGIN);
sb.append(rSerializeProgramBlocks(ipb.getChildBlocksIfBody(), clsMap));
sb.append(PARFOR_PBS_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_PBS_BEGIN);
sb.append(rSerializeProgramBlocks(ipb.getChildBlocksElseBody(), clsMap));
sb.append(PARFOR_PBS_END);
} else if (pb instanceof FunctionProgramBlock && !(pb instanceof ExternalFunctionProgramBlock)) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
sb.append(serializeDataIdentifiers(fpb.getInputParams()));
sb.append(COMPONENTS_DELIM);
sb.append(serializeDataIdentifiers(fpb.getOutputParams()));
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(fpb.getInstructions(), clsMap));
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_PBS_BEGIN);
sb.append(rSerializeProgramBlocks(fpb.getChildBlocks(), clsMap));
sb.append(PARFOR_PBS_END);
sb.append(COMPONENTS_DELIM);
} else if (pb instanceof ExternalFunctionProgramBlock) {
if (!(pb instanceof ExternalFunctionProgramBlockCP)) {
throw new DMLRuntimeException(NOT_SUPPORTED_EXTERNALFUNCTION_PB);
}
ExternalFunctionProgramBlockCP fpb = (ExternalFunctionProgramBlockCP) pb;
sb.append(serializeDataIdentifiers(fpb.getInputParams()));
sb.append(COMPONENTS_DELIM);
sb.append(serializeDataIdentifiers(fpb.getOutputParams()));
sb.append(COMPONENTS_DELIM);
sb.append(serializeStringHashMap(fpb.getOtherParams()));
sb.append(COMPONENTS_DELIM);
sb.append(fpb.getBaseDir());
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_INST_BEGIN);
//create on construction anyway
sb.append(PARFOR_INST_END);
sb.append(COMPONENTS_DELIM);
sb.append(PARFOR_PBS_BEGIN);
sb.append(rSerializeProgramBlocks(fpb.getChildBlocks(), clsMap));
sb.append(PARFOR_PBS_END);
} else //all generic program blocks
{
sb.append(PARFOR_INST_BEGIN);
sb.append(serializeInstructions(pb.getInstructions(), clsMap));
sb.append(PARFOR_INST_END);
}
//handle end
sb.append(PARFOR_PB_END);
return sb.toString();
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rFindSerializationCandidates.
private static void rFindSerializationCandidates(ArrayList<ProgramBlock> pbs, HashSet<String> cand) throws DMLRuntimeException {
for (ProgramBlock pb : pbs) {
if (pb instanceof WhileProgramBlock) {
WhileProgramBlock wpb = (WhileProgramBlock) pb;
rFindSerializationCandidates(wpb.getChildBlocks(), cand);
} else if (pb instanceof ForProgramBlock || pb instanceof ParForProgramBlock) {
ForProgramBlock fpb = (ForProgramBlock) pb;
rFindSerializationCandidates(fpb.getChildBlocks(), cand);
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock ipb = (IfProgramBlock) pb;
rFindSerializationCandidates(ipb.getChildBlocksIfBody(), cand);
if (ipb.getChildBlocksElseBody() != null)
rFindSerializationCandidates(ipb.getChildBlocksElseBody(), cand);
} else //all generic program blocks
{
for (Instruction inst : pb.getInstructions()) if (inst instanceof FunctionCallCPInstruction) {
FunctionCallCPInstruction fci = (FunctionCallCPInstruction) inst;
String fkey = DMLProgram.constructFunctionKey(fci.getNamespace(), fci.getFunctionName());
if (//memoization for multiple calls, recursion
!cand.contains(fkey)) {
//add to candidates
cand.add(fkey);
//investigate chains of function calls
FunctionProgramBlock fpb = pb.getProgram().getFunctionProgramBlock(fci.getNamespace(), fci.getFunctionName());
rFindSerializationCandidates(fpb.getChildBlocks(), cand);
}
}
}
}
}
Aggregations