Skip to content

Commit

Permalink
Can take in main section as input to include as part of range
Browse files Browse the repository at this point in the history
  • Loading branch information
avishek-sen-gupta committed Nov 17, 2024
1 parent 1ed9b4e commit 5f47e16
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public Set<ProcedureRange> rangesTerminatingIn(ProcedureRange range) {
Set<TranspilerInstruction> bodyVertices = range.body().vertexSet();
Set<TranspilerInstruction> selfExit = bodyVertices.stream().filter(v -> v == range.exit()).collect(Collectors.toUnmodifiableSet());
Set<TranspilerInstruction> body = Sets.difference(bodyVertices, selfExit);
// Set<TranspilerInstruction> body = bodyVertices;
Set<ProcedureRange> rangesTerminatingInCurrentRangeIncludingSelf = procedureRanges.stream()
.filter(bbr -> body.contains(bbr.exit()))
.collect(Collectors.toUnmodifiableSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,27 @@
public class CallRangesTask {
private final TranspilerNode tree;
private final List<TranspilerInstruction> instructions;
private final TranspilerNode mainNode;

public CallRangesTask(TranspilerNode tree, List<TranspilerInstruction> instructions) {
public CallRangesTask(TranspilerNode tree, List<TranspilerInstruction> instructions, TranspilerNode mainNode) {
this.tree = tree;
this.instructions = instructions;
this.mainNode = mainNode;
}

public CallRangesTask(TranspilerCodeBlockNode program, List<TranspilerInstruction> instructions) {
this(program, instructions, new NullTranspilerNode());
}

public Set<Pair<TranspilerInstruction, TranspilerInstruction>> run() {
Set<TranspilerNode> allCalls = findAllRecursive(tree, n -> n instanceof JumpTranspilerNode l && l.getEnd() != LocationNode.NULL).stream().collect(Collectors.toUnmodifiableSet());
List<TranspilerNode> allBlocks = findAllRecursiveOrdered(tree, n -> n instanceof LabelledTranspilerCodeBlockNode).stream().toList();
Pair<TranspilerInstruction, TranspilerInstruction> programLevelRange = ImmutablePair.of(
entryOrExitVertex(allBlocks.getFirst(), CodeSentinelType.ENTER),
entryOrExitVertex(allBlocks.getLast(), CodeSentinelType.EXIT));
Stream<Pair<TranspilerInstruction, TranspilerInstruction>> programLevelRange = mainNode instanceof NullTranspilerNode
? Stream.empty()
: Stream.of(ImmutablePair.of(
entryOrExitVertex(mainNode, CodeSentinelType.ENTER),
entryOrExitVertex(mainNode, CodeSentinelType.EXIT)));

return Stream.concat(Stream.of(programLevelRange),
return Stream.concat(programLevelRange,
allCalls.stream().map(call -> {
TranspilerNode entryBlock = labelledBlock(((JumpTranspilerNode) call).getStart());
TranspilerNode exitBlock = labelledBlock(((JumpTranspilerNode) call).getEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ public class ProcedureBodyTask {
private final TranspilerNode program;
private final List<TranspilerInstruction> instructions;
private final Graph<TranspilerInstruction, DefaultEdge> instructionFlowgraph;
private final TranspilerNode mainNode;

public ProcedureBodyTask(TranspilerNode program, List<TranspilerInstruction> instructions, Graph<TranspilerInstruction, DefaultEdge> instructionFlowgraph) {
public ProcedureBodyTask(TranspilerNode program, List<TranspilerInstruction> instructions, Graph<TranspilerInstruction, DefaultEdge> instructionFlowgraph, TranspilerNode mainNode) {
this.program = program;
this.instructions = instructions;
this.instructionFlowgraph = instructionFlowgraph;
this.mainNode = mainNode;
}

public ProcedureBodyTask(TranspilerNode program, List<TranspilerInstruction> instructions, Graph<TranspilerInstruction, DefaultEdge> implicitCFG) {
this(program, instructions, implicitCFG, new NullTranspilerNode());
}

public Set<Pair<ProcedureRange, Set<ProcedureRange>>> run() {
Set<ProcedureRange> bodiesWithoutChildren = new CallRangesTask(program, instructions).run().stream().map(range -> new RangeBodyTask(instructionFlowgraph).run(range)).collect(Collectors.toUnmodifiableSet());
Set<ProcedureRange> bodiesWithoutChildren = new CallRangesTask(program, instructions, mainNode).run().stream().map(range -> new RangeBodyTask(instructionFlowgraph).run(range)).collect(Collectors.toUnmodifiableSet());
return rangesWithChildren(bodiesWithoutChildren);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.smojol.common.flowchart.FlowchartOutputFormat;
import org.smojol.common.id.IncrementingIdProvider;
import org.smojol.common.id.UUIDProvider;
import org.smojol.common.pseudocode.BasicBlock;
import org.smojol.common.resource.LocalFilesystemOperations;
import org.smojol.common.transpiler.*;
import org.smojol.toolkit.analysis.pipeline.ProgramSearch;
Expand All @@ -27,7 +26,7 @@
import java.util.Map;
import java.util.Set;

import static org.smojol.toolkit.task.CommandLineAnalysisTask.*;
import static org.smojol.toolkit.task.CommandLineAnalysisTask.BUILD_BASE_ANALYSIS;

public class SLIFORangeMain {
public static void main(String[] args) throws IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.smojol.common.transpiler.*;
import org.smojol.toolkit.analysis.task.transpiler.BuildTranspilerInstructionsFromIntermediateTreeTask;
import org.smojol.toolkit.analysis.task.transpiler.ProcedureBodyTask;
import org.smojol.toolkit.analysis.task.transpiler.RangeBodyTask;

import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -89,9 +88,9 @@ public void canDetermineSLIFORangesInductively() {
Graph<TranspilerInstruction, DefaultEdge> implicitCFG = new BuildImplicitInstructionControlFlowgraphTask(instructions, ImmutableList.of()).run();
Set<Pair<ProcedureRange, Set<ProcedureRange>>> rangesWithChildren = new ProcedureBodyTask(program, instructions, implicitCFG).run();
SLIFORangeCriterionTask task = new SLIFORangeCriterionTask(rangesWithChildren);
assertEquals(3, rangesWithChildren.size());
assertEquals(2, rangesWithChildren.size());
Set<Pair<ProcedureRange, Set<ProcedureRange>>> allSLIFORanges = task.allSLIFORanges(rangesWithChildren);
assertEquals(3, allSLIFORanges.size());
assertEquals(2, allSLIFORanges.size());
}

private static PrintTranspilerNode p() {
Expand Down

0 comments on commit 5f47e16

Please sign in to comment.