Skip to content

Commit

Permalink
Integrating SLIFO task in BuildzTranspilerFlowgraphTask, but it does …
Browse files Browse the repository at this point in the history
…not influence CFG building yet
  • Loading branch information
avishek-sen-gupta committed Nov 17, 2024
1 parent 62f5384 commit f891f00
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.smojol.common.transpiler;

import org.apache.commons.lang3.tuple.Pair;
import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultEdge;
import org.smojol.common.pseudocode.BasicBlock;

import java.util.List;
import java.util.Set;

public record TranspilerFlowgraph(Graph<BasicBlock<TranspilerInstruction>, DefaultEdge> basicBlockFlowgraph,
Graph<TranspilerInstruction, DefaultEdge> instructionFlowgraph,
TranspilerNode transpilerTree, List<TranspilerInstruction> instructions,
List<BasicBlock<TranspilerInstruction>> basicBlocks) {
List<BasicBlock<TranspilerInstruction>> basicBlocks,
Pair<Set<InvokingProcedureRange>, Set<InvokingProcedureRange>> categorisedRanges) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.smojol.toolkit.analysis.task.transpiler;

import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojo.woof.GraphSDK;
Expand All @@ -25,6 +26,7 @@
import org.smojol.toolkit.transpiler.TranspilerLoopUpdate;

import java.util.List;
import java.util.Set;

public class BuildTranspilerFlowgraphTask {
private final ParseTree rawAST;
Expand All @@ -51,13 +53,20 @@ public BuildTranspilerFlowgraphTask(ParseTree rawAST, CobolDataStructure dataStr

public TranspilerFlowgraph run() {
TranspilerNode transpilerTree = new BuildTranspilerASTTask(rawAST, dataStructures, symbolTable).run();
List<TranspilerInstruction> instructions = new BuildTranspilerInstructionsFromRawASTTask(rawAST, dataStructures, symbolTable).run();

// TranspilerNode mainNode = transpilerTree.findAllRecursive(t -> t instanceof LabelledTranspilerCodeBlockNode l && l.getName().equals("S-STEUERUNGS")).stream().findFirst().get();
List<TranspilerInstruction> instructions = new BuildTranspilerInstructionsFromIntermediateTreeTask(transpilerTree, new IncrementingIdProvider()).run();
Graph<TranspilerInstruction, DefaultEdge> implicitCFG = new BuildImplicitInstructionControlFlowgraphTask(instructions, ImmutableList.of()).run();
Set<InvokingProcedureRange> rangesWithChildren = new ProcedureBodyTask(transpilerTree, instructions, implicitCFG).run();
SLIFORangeCriterionTask task = new SLIFORangeCriterionTask(rangesWithChildren);
Pair<Set<InvokingProcedureRange>, Set<InvokingProcedureRange>> categorisedRanges = task.run();

Graph<TranspilerInstruction, DefaultEdge> instructionFlowgraph = new BuildInstructionFlowgraphTask(instructions, flowHints).run();
Pair<Graph<BasicBlock<TranspilerInstruction>, DefaultEdge>, List<BasicBlock<TranspilerInstruction>>> basicBlockModel = new BuildBasicBlocksTask(instructions, instructionFlowgraph, new BasicBlockFactory<>(new IncrementingIdProvider()), neo4JDriverBuilder).run();
Graph<BasicBlock<TranspilerInstruction>, DefaultEdge> basicBlockGraph = basicBlockModel.getLeft();
MermaidGraph<TranspilerInstruction, DefaultEdge> mermaid = new MermaidGraph<>();
String draw = mermaid.draw(instructionFlowgraph);
return new TranspilerFlowgraph(basicBlockGraph, instructionFlowgraph, transpilerTree, instructions, basicBlockModel.getRight());
return new TranspilerFlowgraph(basicBlockGraph, instructionFlowgraph, transpilerTree, instructions, basicBlockModel.getRight(), categorisedRanges);

// try {
// resourceOperations.createDirectories(transpilerModelOutputConfig.outputDir());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +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 {
Expand All @@ -37,15 +38,10 @@ public static void main(String[] args) throws IOException, InterruptedException
ImmutableList.of(new File("/Users/asgupta/code/smojol/smojol-test-code")),
"/Users/asgupta/code/smojol/che-che4z-lsp-for-cobol-integration/server/dialect-idms/target/dialect-idms.jar",
LanguageDialect.IDMS, new FullProgram(FlowchartOutputFormat.MERMAID, idProvider), idProvider, new OccursIgnoringFormat1DataStructureBuilder(), new ProgramSearch(), new LocalFilesystemOperations())
.runForPrograms(ImmutableList.of(BUILD_BASE_ANALYSIS, CommandLineAnalysisTask.BUILD_TRANSPILER_FLOWGRAPH), ImmutableList.of(programName));
.runForPrograms(ImmutableList.of(BUILD_BASE_ANALYSIS, BUILD_TRANSPILER_FLOWGRAPH), ImmutableList.of(programName));
List<AnalysisTaskResult> results = result.get(programName);
TranspilerFlowgraph transpilerFlowgraph = ((AnalysisTaskResultOK) results.get(1)).getDetail();
TranspilerNode tree = transpilerFlowgraph.transpilerTree();
List<TranspilerInstruction> instructions = new BuildTranspilerInstructionsFromIntermediateTreeTask(tree, new IncrementingIdProvider()).run();
Graph<TranspilerInstruction, DefaultEdge> implicitCFG = new BuildImplicitInstructionControlFlowgraphTask(instructions, ImmutableList.of()).run();
Set<InvokingProcedureRange> rangesWithChildren = new ProcedureBodyTask(tree, instructions, implicitCFG).run();
SLIFORangeCriterionTask task = new SLIFORangeCriterionTask(rangesWithChildren);
Pair<Set<InvokingProcedureRange>, Set<InvokingProcedureRange>> categorisedRanges = task.run();
Pair<Set<InvokingProcedureRange>, Set<InvokingProcedureRange>> categorisedRanges = transpilerFlowgraph.categorisedRanges();
categorisedRanges.getLeft().forEach(range -> System.out.println(range.range()));
categorisedRanges.getRight().forEach(range -> System.out.println(range.range()));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.smojol.toolkit.examples.qa;

import com.google.common.collect.ImmutableList;
import org.apache.commons.lang3.tuple.Pair;
import org.smojol.common.dialect.LanguageDialect;
import org.smojol.common.flowchart.FlowchartOutputFormat;
import org.smojol.common.id.UUIDProvider;
import org.smojol.common.resource.LocalFilesystemOperations;
import org.smojol.common.transpiler.InvokingProcedureRange;
import org.smojol.common.transpiler.TranspilerFlowgraph;
import org.smojol.toolkit.analysis.pipeline.ProgramSearch;
import org.smojol.toolkit.analysis.task.analysis.CodeTaskRunner;
import org.smojol.toolkit.interpreter.FullProgram;
import org.smojol.toolkit.interpreter.structure.OccursIgnoringFormat1DataStructureBuilder;
import org.smojol.toolkit.task.AnalysisTaskResult;
import org.smojol.toolkit.task.AnalysisTaskResultOK;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

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

public class SLIFORangeMainForQA {
public static void main(String[] args) throws IOException, InterruptedException {
String programName = "test-irreducible-simplified.cbl";
UUIDProvider idProvider = new UUIDProvider();
Map<String, List<AnalysisTaskResult>> result = new CodeTaskRunner("/Users/asgupta/code/qa-codebase/Missing Programs",
"/Users/asgupta/code/smojol/out/report",
ImmutableList.of(new File("/Users/asgupta/code/qa-codebase/Missing Programs")),
"/Users/asgupta/code/smojol/che-che4z-lsp-for-cobol-integration/server/dialect-idms/target/dialect-idms.jar",
LanguageDialect.COBOL, new FullProgram(FlowchartOutputFormat.MERMAID, idProvider), idProvider, new OccursIgnoringFormat1DataStructureBuilder(), new ProgramSearch(), new LocalFilesystemOperations())
.runForPrograms(ImmutableList.of(BUILD_BASE_ANALYSIS, BUILD_TRANSPILER_FLOWGRAPH), ImmutableList.of(programName));
List<AnalysisTaskResult> results = result.get(programName);
TranspilerFlowgraph transpilerFlowgraph = ((AnalysisTaskResultOK) results.get(1)).getDetail();
Pair<Set<InvokingProcedureRange>, Set<InvokingProcedureRange>> categorisedRanges = transpilerFlowgraph.categorisedRanges();
Set<InvokingProcedureRange> allSLIFORanges = categorisedRanges.getLeft();
System.out.println("SLIFO Ranges\n----------------------");
allSLIFORanges.forEach(range -> System.out.println(range.range()));
Set<InvokingProcedureRange> nonSLIFORanges = categorisedRanges.getRight();
System.out.println("Non-SLIFO Ranges\n----------------------");
nonSLIFORanges.forEach(range -> System.out.println(range.range()));
System.out.println("Total ranges = " + (categorisedRanges.getLeft().size() + categorisedRanges.getRight().size()));
System.out.println("SLIFO ranges = " + allSLIFORanges.size());
System.out.println("Non-SLIFO ranges = " + nonSLIFORanges.size());

System.out.println("DONE");
}
}

0 comments on commit f891f00

Please sign in to comment.