From d3e11e6364a5ff623b5b94313a47aaefb7e478fb Mon Sep 17 00:00:00 2001 From: Byakuren Hijiri Date: Mon, 29 Jul 2024 02:02:17 +0000 Subject: [PATCH] feat(ir): DOT dumper tests; simplify CFG construction --- .gitignore | 2 + cspell.json | 3 +- src/internals/ir.ts | 4 +- src/internals/tactIRBuilder.ts | 131 ++++++++-------------- test/contracts/conditional-1.cfg.dot | 15 +++ test/contracts/conditional-1.cfg.json | 64 +++++------ test/contracts/conditional-1.tact | 1 - test/contracts/conditional-2.cfg.dot | 16 +++ test/contracts/conditional-2.cfg.json | 88 +++++++++++++++ test/contracts/conditional-2.expected.out | 1 + test/contracts/conditional-2.tact | 10 ++ test/contracts/div-before-mul-1.cfg.dot | 15 +++ test/contracts/div-before-mul-1.cfg.json | 60 +++++----- test/contracts/div-before-mul-2.cfg.dot | 15 +++ test/contracts/div-before-mul-2.cfg.json | 60 +++++----- test/contracts/div-before-mul-3.cfg.dot | 17 +++ test/contracts/div-before-mul-3.cfg.json | 74 ++++++------ test/contracts/linear-flow-1.cfg.dot | 13 +++ test/contracts/linear-flow-1.cfg.json | 46 ++++---- test/contracts/loops-1.cfg.dot | 18 +++ test/contracts/loops-1.cfg.json | 89 +++++++-------- test/contracts/loops-2.cfg.dot | 18 +++ test/contracts/loops-2.cfg.json | 103 +++++++++++++++++ test/contracts/loops-2.expected.out | 1 + test/contracts/loops-2.tact | 9 ++ test/contracts/loops-3.cfg.dot | 18 +++ test/contracts/loops-3.cfg.json | 103 +++++++++++++++++ test/contracts/loops-3.expected.out | 1 + test/contracts/loops-3.tact | 10 ++ test/contracts/messages-1.cfg.dot | 13 +++ test/contracts/messages-1.cfg.json | 26 ++--- test/contracts/never-accessed-1.cfg.dot | 13 +++ test/contracts/never-accessed-1.cfg.json | 60 ++++------ test/contracts/never-accessed-2.cfg.dot | 11 ++ test/contracts/never-accessed-2.cfg.json | 10 +- test/contracts/never-accessed-3.cfg.dot | 7 ++ test/contracts/never-accessed-3.cfg.json | 6 +- test/contracts/never-accessed-4.cfg.dot | 7 ++ test/contracts/never-accessed-4.cfg.json | 4 +- test/contracts/readonly-1.cfg.dot | 17 +++ test/contracts/readonly-1.cfg.json | 88 ++++++--------- test/contracts/readonly-2.cfg.dot | 11 ++ test/contracts/readonly-2.cfg.json | 32 +++--- test/contracts/traits-1.cfg.dot | 7 ++ test/contracts/traits-1.cfg.json | 4 +- test/contracts/unbound-loop-1.cfg.dot | 12 ++ test/contracts/unbound-loop-1.cfg.json | 45 ++++---- test/contracts/unbound-loop-2.cfg.dot | 12 ++ test/contracts/unbound-loop-2.cfg.json | 45 ++++---- test/contracts/unbound-loop-3.cfg.dot | 14 +++ test/contracts/unbound-loop-3.cfg.json | 61 +++++----- test/contracts/unbound-loop-4.cfg.dot | 17 +++ test/contracts/unbound-loop-4.cfg.json | 61 +++++----- test/contracts/zero-address.cfg.dot | 7 ++ test/contracts/zero-address.cfg.json | 6 +- test/tactIR.spec.ts | 15 ++- 56 files changed, 1075 insertions(+), 541 deletions(-) create mode 100644 test/contracts/conditional-1.cfg.dot create mode 100644 test/contracts/conditional-2.cfg.dot create mode 100644 test/contracts/conditional-2.cfg.json create mode 100644 test/contracts/conditional-2.expected.out create mode 100644 test/contracts/conditional-2.tact create mode 100644 test/contracts/div-before-mul-1.cfg.dot create mode 100644 test/contracts/div-before-mul-2.cfg.dot create mode 100644 test/contracts/div-before-mul-3.cfg.dot create mode 100644 test/contracts/linear-flow-1.cfg.dot create mode 100644 test/contracts/loops-1.cfg.dot create mode 100644 test/contracts/loops-2.cfg.dot create mode 100644 test/contracts/loops-2.cfg.json create mode 100644 test/contracts/loops-2.expected.out create mode 100644 test/contracts/loops-2.tact create mode 100644 test/contracts/loops-3.cfg.dot create mode 100644 test/contracts/loops-3.cfg.json create mode 100644 test/contracts/loops-3.expected.out create mode 100644 test/contracts/loops-3.tact create mode 100644 test/contracts/messages-1.cfg.dot create mode 100644 test/contracts/never-accessed-1.cfg.dot create mode 100644 test/contracts/never-accessed-2.cfg.dot create mode 100644 test/contracts/never-accessed-3.cfg.dot create mode 100644 test/contracts/never-accessed-4.cfg.dot create mode 100644 test/contracts/readonly-1.cfg.dot create mode 100644 test/contracts/readonly-2.cfg.dot create mode 100644 test/contracts/traits-1.cfg.dot create mode 100644 test/contracts/unbound-loop-1.cfg.dot create mode 100644 test/contracts/unbound-loop-2.cfg.dot create mode 100644 test/contracts/unbound-loop-3.cfg.dot create mode 100644 test/contracts/unbound-loop-4.cfg.dot create mode 100644 test/contracts/zero-address.cfg.dot diff --git a/.gitignore b/.gitignore index 009d24d0..dec79310 100644 --- a/.gitignore +++ b/.gitignore @@ -134,5 +134,7 @@ docs # Generated test artifacts test/contracts/*.config.json test/contracts/*.json +test/contracts/*.dot test/contracts/*.actual.out !test/contracts/*.cfg.json +!test/contracts/*.cfg.dot diff --git a/cspell.json b/cspell.json index 93cf1f0f..724af844 100644 --- a/cspell.json +++ b/cspell.json @@ -88,7 +88,8 @@ "привет", "PUSHREF", "PUSHSLICE", - "SETINDEXVARQ" + "SETINDEXVARQ", + "Idxes" ], "flagWords": [], "ignorePaths": [ diff --git a/src/internals/ir.ts b/src/internals/ir.ts index da9e64b5..187555b1 100644 --- a/src/internals/ir.ts +++ b/src/internals/ir.ts @@ -600,7 +600,7 @@ export class CFG { * @param astStore The store containing the AST nodes. * @param callback The function to apply to each node. */ - forEachNode( + public forEachNode( astStore: TactASTStore, callback: (stmt: AstStatement, cfgNode: Node) => void, ) { @@ -620,7 +620,7 @@ export class CFG { * Iterates over all edges in a CFG, applying a callback to each edge. * @param callback The function to apply to each edge. */ - forEachEdge(callback: (cfgEdge: Edge) => void) { + public forEachEdge(callback: (cfgEdge: Edge) => void) { this.edges.forEach((cfgEdge) => { callback(cfgEdge); }); diff --git a/src/internals/tactIRBuilder.ts b/src/internals/tactIRBuilder.ts index e5a94484..bdcfabb9 100644 --- a/src/internals/tactIRBuilder.ts +++ b/src/internals/tactIRBuilder.ts @@ -567,104 +567,61 @@ export class TactIRBuilder { * @param statements The array of AstStatement objects. * @param nodes An optional array of Node objects to which new nodes will be added. * @param edges An optional array of Edge objects to which new edges will be added. - * @param parentNodeIdx An optional NodeIdx representing the index of the node from which control flow enters the current sequence of statements. + * @param lastNodeIdxes An optional NodeIdx representing the index of the node from which control flow enters the current sequence of statements. * @returns A tuple containing the arrays of Node and Edge objects representing the CFG derived from the statements. */ processStatements( statements: AstStatement[], nodes: Node[] = [], edges: Edge[] = [], - parentNodeIdx?: NodeIdx, + lastNodeIdxes: NodeIdx[] = [], ): [Node[], Edge[]] { - let lastNodeIdx: NodeIdx | undefined = parentNodeIdx; - - statements.forEach((stmt, index) => { + statements.forEach((stmt, _index) => { const newNode = new Node(stmt.id, this.getNodeKind(stmt)); nodes.push(newNode); - - // For the first node, if there's a parent node, connect this node to the parent - if (index === 0 && parentNodeIdx !== undefined) { - const edgeToParent = new Edge(parentNodeIdx, newNode.idx); - edges.push(edgeToParent); - nodes - .find((node) => node.idx === parentNodeIdx) - ?.dstEdges.add(edgeToParent.idx); - newNode.srcEdges.add(edgeToParent.idx); - } else if (lastNodeIdx !== undefined) { - // Connect this node to the last node if it's not the first or has a specific parent node - const newEdge = new Edge(lastNodeIdx, newNode.idx); - edges.push(newEdge); - nodes - .find((node) => node.idx === lastNodeIdx) - ?.dstEdges.add(newEdge.idx); - newNode.srcEdges.add(newEdge.idx); + // If there's a parent node, connect this node to the parent + if (lastNodeIdxes !== undefined) { + lastNodeIdxes.forEach((idx) => { + const src = this.getParent(nodes, idx); + edges.push(this.addEdge(src, newNode)); + }); } - // Update the lastNodeIdx to the current node's index - lastNodeIdx = newNode.idx; - if ( stmt.kind == "statement_let" || stmt.kind == "statement_expression" || stmt.kind == "statement_assign" || stmt.kind == "statement_augmentedassign" ) { - // Logic for linear flow statements + // Update the lastNodeIdx to the current node's index + lastNodeIdxes = [newNode.idx]; } else if (stmt.kind === "statement_condition") { // Branching logic for trueStatements const [trueNodes, trueEdges] = this.processStatements( stmt.trueStatements, nodes, edges, - newNode.idx, + [newNode.idx], ); nodes = trueNodes; edges = trueEdges; - const trueEndNode = trueNodes[trueNodes.length - 1]; - if (stmt.falseStatements) { + if (stmt.falseStatements !== null && stmt.falseStatements.length > 0) { // Branching logic for falseStatements const [falseNodes, falseEdges] = this.processStatements( stmt.falseStatements, nodes, edges, - newNode.idx, + [newNode.idx], ); nodes = falseNodes; edges = falseEdges; - const falseEndNode = falseNodes[falseNodes.length - 1]; - - const nextStmt = statements[index + 1]; - if (nextStmt) { - const nextNode = new Node(nextStmt.id, this.getNodeKind(nextStmt)); - nodes.push(nextNode); - - const edgeToNextFromTrue = new Edge(trueEndNode.idx, nextNode.idx); - edges.push(edgeToNextFromTrue); - trueEndNode.dstEdges.add(edgeToNextFromTrue.idx); - nextNode.srcEdges.add(edgeToNextFromTrue.idx); - - const edgeToNextFromFalse = new Edge( - falseEndNode.idx, - nextNode.idx, - ); - edges.push(edgeToNextFromFalse); - falseEndNode.dstEdges.add(edgeToNextFromFalse.idx); - nextNode.srcEdges.add(edgeToNextFromFalse.idx); - } + lastNodeIdxes = [trueEndNode.idx, falseEndNode.idx]; } else { - const nextStmt = statements[index + 1]; - if (nextStmt) { - const nextNode = new Node(nextStmt.id, this.getNodeKind(nextStmt)); - nodes.push(nextNode); - - const edgeToNextFromTrue = new Edge(trueEndNode.idx, nextNode.idx); - edges.push(edgeToNextFromTrue); - trueEndNode.dstEdges.add(edgeToNextFromTrue.idx); - nextNode.srcEdges.add(edgeToNextFromTrue.idx); - } + // Connect the end of the true branch to the next statement + lastNodeIdxes = [trueEndNode.idx]; } } else if ( stmt.kind == "statement_while" || @@ -678,40 +635,23 @@ export class TactIRBuilder { // Process the statements within the loop body. const [loopNodes, loopEdges] = this.processStatements( stmt.statements, - [], - [], - newNode.idx, // Pass the loop condition node as the parent node to link back to. + nodes, + edges, + [newNode.idx], ); - - // Concatenate the loop nodes and edges with the main lists. - nodes = nodes.concat(loopNodes); - edges = edges.concat(loopEdges); + nodes = loopNodes; + edges = loopEdges; // Create an edge from the last node in the loop back to the condition to represent the loop's cycle. if (loopNodes.length > 0) { - const backEdge = new Edge( - loopNodes[loopNodes.length - 1].idx, - newNode.idx, - ); - edges.push(backEdge); - loopNodes[loopNodes.length - 1].dstEdges.add(backEdge.idx); - newNode.srcEdges.add(backEdge.idx); + const lastNode = loopNodes[loopNodes.length - 1]; + edges.push(this.addEdge(lastNode, newNode)); } - - const nextStmt = statements[index + 1]; - if (nextStmt) { - const nextNode = new Node(nextStmt.id, this.getNodeKind(nextStmt)); - nodes.push(nextNode); - const exitEdge = new Edge(newNode.idx, nextNode.idx); - edges.push(exitEdge); - newNode.dstEdges.add(exitEdge.idx); - nextNode.srcEdges.add(exitEdge.idx); - } - - lastNodeIdx = undefined; + // Connect condition with the statement after loop. + lastNodeIdxes = [newNode.idx]; } else if (stmt.kind === "statement_return") { // No need to connect return statements to subsequent nodes - lastNodeIdx = undefined; // This effectively ends the current flow + lastNodeIdxes = []; } else { throw InternalException.make("Unsupported statement", { node: stmt }); } @@ -719,6 +659,23 @@ export class TactIRBuilder { return [nodes, edges]; } + + private getParent(nodes: Node[], idx: NodeIdx): Node { + const node = nodes.find((node) => node.idx === idx); + if (node === undefined) { + throw InternalException.make( + `Cannot find node with index=${idx}. Available nodes: ${nodes.map((n) => n.idx)}`, + ); + } + return node; + } + + private addEdge(src: Node, dst: Node): Edge { + const edge = new Edge(src.idx, dst.idx); + src.dstEdges.add(edge.idx); + dst.srcEdges.add(edge.idx); + return edge; + } } class TactConfigManager { diff --git a/test/contracts/conditional-1.cfg.dot b/test/contracts/conditional-1.cfg.dot new file mode 100644 index 00000000..6726e022 --- /dev/null +++ b/test/contracts/conditional-1.cfg.dot @@ -0,0 +1,15 @@ +digraph "conditional-1" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="if (a > 42)"]; + "test_144" [label="a = 23"]; + "test_146" [label="let b: Int = a + 1"]; + "test_148" [label="return b"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + } +} diff --git a/test/contracts/conditional-1.cfg.json b/test/contracts/conditional-1.cfg.json index a9315635..8577b91b 100644 --- a/test/contracts/conditional-1.cfg.json +++ b/test/contracts/conditional-1.cfg.json @@ -6,86 +6,72 @@ "cfg": { "nodes": [ { - "id": 150, + "id": 141, "stmtID": 1531, "srcEdges": [], "dstEdges": [ - 152 + 143 ] }, { - "id": 151, + "id": 142, "stmtID": 1538, "srcEdges": [ - 152 + 143 ], "dstEdges": [ - 154, - 158 + 145 ] }, { - "id": 153, + "id": 144, "stmtID": 1537, "srcEdges": [ - 154 + 145 ], "dstEdges": [ - 156 + 147 ] }, { - "id": 155, + "id": 146, "stmtID": 1544, "srcEdges": [ - 156 - ], - "dstEdges": [] - }, - { - "id": 157, - "stmtID": 1544, - "srcEdges": [ - 158 + 147 ], "dstEdges": [ - 160 + 149 ] }, { - "id": 159, + "id": 148, "stmtID": 1546, "srcEdges": [ - 160 + 149 ], "dstEdges": [] } ], "edges": [ { - "id": 152, - "src": 150, - "dst": 151 - }, - { - "id": 154, - "src": 151, - "dst": 153 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 156, - "src": 153, - "dst": 155 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 158, - "src": 151, - "dst": 157 + "id": 147, + "src": 144, + "dst": 146 }, { - "id": 160, - "src": 157, - "dst": 159 + "id": 149, + "src": 146, + "dst": 148 } ] } diff --git a/test/contracts/conditional-1.tact b/test/contracts/conditional-1.tact index 1575ca0a..931378fe 100644 --- a/test/contracts/conditional-1.tact +++ b/test/contracts/conditional-1.tact @@ -6,4 +6,3 @@ fun test(): Int { let b: Int = a + 1; return b; } - diff --git a/test/contracts/conditional-2.cfg.dot b/test/contracts/conditional-2.cfg.dot new file mode 100644 index 00000000..c0ea57f3 --- /dev/null +++ b/test/contracts/conditional-2.cfg.dot @@ -0,0 +1,16 @@ +digraph "conditional-2" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="if (a > 42)"]; + "test_144" [label="a = 23"]; + "test_146" [label="a = 22"]; + "test_148" [label="return a"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_142" -> "test_146"; + "test_144" -> "test_148"; + "test_146" -> "test_148"; + } +} diff --git a/test/contracts/conditional-2.cfg.json b/test/contracts/conditional-2.cfg.json new file mode 100644 index 00000000..b7834ffc --- /dev/null +++ b/test/contracts/conditional-2.cfg.json @@ -0,0 +1,88 @@ +{ + "projectName": "conditional-2", + "functions": [ + { + "name": "test", + "cfg": { + "nodes": [ + { + "id": 141, + "stmtID": 4627, + "srcEdges": [], + "dstEdges": [ + 143 + ] + }, + { + "id": 142, + "stmtID": 4637, + "srcEdges": [ + 143 + ], + "dstEdges": [ + 145, + 147 + ] + }, + { + "id": 144, + "stmtID": 4633, + "srcEdges": [ + 145 + ], + "dstEdges": [ + 149 + ] + }, + { + "id": 146, + "stmtID": 4636, + "srcEdges": [ + 147 + ], + "dstEdges": [ + 150 + ] + }, + { + "id": 148, + "stmtID": 4639, + "srcEdges": [ + 149, + 150 + ], + "dstEdges": [] + } + ], + "edges": [ + { + "id": 143, + "src": 141, + "dst": 142 + }, + { + "id": 145, + "src": 142, + "dst": 144 + }, + { + "id": 147, + "src": 142, + "dst": 146 + }, + { + "id": 149, + "src": 144, + "dst": 148 + }, + { + "id": 150, + "src": 146, + "dst": 148 + } + ] + } + } + ], + "contracts": [] +} \ No newline at end of file diff --git a/test/contracts/conditional-2.expected.out b/test/contracts/conditional-2.expected.out new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/contracts/conditional-2.expected.out @@ -0,0 +1 @@ + diff --git a/test/contracts/conditional-2.tact b/test/contracts/conditional-2.tact new file mode 100644 index 00000000..812386c4 --- /dev/null +++ b/test/contracts/conditional-2.tact @@ -0,0 +1,10 @@ +fun test(): Int { + let a: Int = 20; + if (a > 42) { + a = 23; + } else { + a = 22 + } + return a; +} + diff --git a/test/contracts/div-before-mul-1.cfg.dot b/test/contracts/div-before-mul-1.cfg.dot new file mode 100644 index 00000000..2ed28411 --- /dev/null +++ b/test/contracts/div-before-mul-1.cfg.dot @@ -0,0 +1,15 @@ +digraph "div-before-mul-1" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 10"]; + "test_142" [label="let b: Int = 3"]; + "test_144" [label="let c: Int = 2"]; + "test_146" [label="let result: Int = a / b * c"]; + "test_148" [label="return result"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + } +} diff --git a/test/contracts/div-before-mul-1.cfg.json b/test/contracts/div-before-mul-1.cfg.json index f683e9b0..37a747ba 100644 --- a/test/contracts/div-before-mul-1.cfg.json +++ b/test/contracts/div-before-mul-1.cfg.json @@ -6,72 +6,72 @@ "cfg": { "nodes": [ { - "id": 310, - "stmtID": 3079, + "id": 141, + "stmtID": 7717, "srcEdges": [], "dstEdges": [ - 312 + 143 ] }, { - "id": 311, - "stmtID": 3083, + "id": 142, + "stmtID": 7721, "srcEdges": [ - 312 + 143 ], "dstEdges": [ - 314 + 145 ] }, { - "id": 313, - "stmtID": 3087, + "id": 144, + "stmtID": 7725, "srcEdges": [ - 314 + 145 ], "dstEdges": [ - 316 + 147 ] }, { - "id": 315, - "stmtID": 3095, + "id": 146, + "stmtID": 7733, "srcEdges": [ - 316 + 147 ], "dstEdges": [ - 318 + 149 ] }, { - "id": 317, - "stmtID": 3097, + "id": 148, + "stmtID": 7735, "srcEdges": [ - 318 + 149 ], "dstEdges": [] } ], "edges": [ { - "id": 312, - "src": 310, - "dst": 311 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 314, - "src": 311, - "dst": 313 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 316, - "src": 313, - "dst": 315 + "id": 147, + "src": 144, + "dst": 146 }, { - "id": 318, - "src": 315, - "dst": 317 + "id": 149, + "src": 146, + "dst": 148 } ] } diff --git a/test/contracts/div-before-mul-2.cfg.dot b/test/contracts/div-before-mul-2.cfg.dot new file mode 100644 index 00000000..9b5b53ed --- /dev/null +++ b/test/contracts/div-before-mul-2.cfg.dot @@ -0,0 +1,15 @@ +digraph "div-before-mul-2" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 10"]; + "test_142" [label="let b: Int = 3"]; + "test_144" [label="let c: Int = 2"]; + "test_146" [label="let result: Int = a * c / b"]; + "test_148" [label="return result"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + } +} diff --git a/test/contracts/div-before-mul-2.cfg.json b/test/contracts/div-before-mul-2.cfg.json index c15fd847..13e4dfbf 100644 --- a/test/contracts/div-before-mul-2.cfg.json +++ b/test/contracts/div-before-mul-2.cfg.json @@ -6,72 +6,72 @@ "cfg": { "nodes": [ { - "id": 468, - "stmtID": 4630, + "id": 141, + "stmtID": 10819, "srcEdges": [], "dstEdges": [ - 470 + 143 ] }, { - "id": 469, - "stmtID": 4634, + "id": 142, + "stmtID": 10823, "srcEdges": [ - 470 + 143 ], "dstEdges": [ - 472 + 145 ] }, { - "id": 471, - "stmtID": 4638, + "id": 144, + "stmtID": 10827, "srcEdges": [ - 472 + 145 ], "dstEdges": [ - 474 + 147 ] }, { - "id": 473, - "stmtID": 4646, + "id": 146, + "stmtID": 10835, "srcEdges": [ - 474 + 147 ], "dstEdges": [ - 476 + 149 ] }, { - "id": 475, - "stmtID": 4648, + "id": 148, + "stmtID": 10837, "srcEdges": [ - 476 + 149 ], "dstEdges": [] } ], "edges": [ { - "id": 470, - "src": 468, - "dst": 469 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 472, - "src": 469, - "dst": 471 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 474, - "src": 471, - "dst": 473 + "id": 147, + "src": 144, + "dst": 146 }, { - "id": 476, - "src": 473, - "dst": 475 + "id": 149, + "src": 146, + "dst": 148 } ] } diff --git a/test/contracts/div-before-mul-3.cfg.dot b/test/contracts/div-before-mul-3.cfg.dot new file mode 100644 index 00000000..05dd1673 --- /dev/null +++ b/test/contracts/div-before-mul-3.cfg.dot @@ -0,0 +1,17 @@ +digraph "div-before-mul-3" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 10 / 3"]; + "test_142" [label="let c: Int = 2"]; + "test_144" [label="let taintedWithA1: Int = 2 - a"]; + "test_146" [label="let taintedWithA2: Int = 55 + taintedWithA1"]; + "test_148" [label="let result: Int = taintedWithA2 * c"]; + "test_150" [label="return result"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + "test_148" -> "test_150"; + } +} diff --git a/test/contracts/div-before-mul-3.cfg.json b/test/contracts/div-before-mul-3.cfg.json index 28603c79..c4173465 100644 --- a/test/contracts/div-before-mul-3.cfg.json +++ b/test/contracts/div-before-mul-3.cfg.json @@ -6,87 +6,87 @@ "cfg": { "nodes": [ { - "id": 626, - "stmtID": 6183, + "id": 141, + "stmtID": 13923, "srcEdges": [], "dstEdges": [ - 628 + 143 ] }, { - "id": 627, - "stmtID": 6187, + "id": 142, + "stmtID": 13927, "srcEdges": [ - 628 + 143 ], "dstEdges": [ - 630 + 145 ] }, { - "id": 629, - "stmtID": 6193, + "id": 144, + "stmtID": 13933, "srcEdges": [ - 630 + 145 ], "dstEdges": [ - 632 + 147 ] }, { - "id": 631, - "stmtID": 6199, + "id": 146, + "stmtID": 13939, "srcEdges": [ - 632 + 147 ], "dstEdges": [ - 634 + 149 ] }, { - "id": 633, - "stmtID": 6205, + "id": 148, + "stmtID": 13945, "srcEdges": [ - 634 + 149 ], "dstEdges": [ - 636 + 151 ] }, { - "id": 635, - "stmtID": 6207, + "id": 150, + "stmtID": 13947, "srcEdges": [ - 636 + 151 ], "dstEdges": [] } ], "edges": [ { - "id": 628, - "src": 626, - "dst": 627 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 630, - "src": 627, - "dst": 629 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 632, - "src": 629, - "dst": 631 + "id": 147, + "src": 144, + "dst": 146 }, { - "id": 634, - "src": 631, - "dst": 633 + "id": 149, + "src": 146, + "dst": 148 }, { - "id": 636, - "src": 633, - "dst": 635 + "id": 151, + "src": 148, + "dst": 150 } ] } diff --git a/test/contracts/linear-flow-1.cfg.dot b/test/contracts/linear-flow-1.cfg.dot new file mode 100644 index 00000000..27916767 --- /dev/null +++ b/test/contracts/linear-flow-1.cfg.dot @@ -0,0 +1,13 @@ +digraph "linear-flow-1" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="let b: Int = 22"]; + "test_144" [label="let c: Int = a + b"]; + "test_146" [label="return c"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + } +} diff --git a/test/contracts/linear-flow-1.cfg.json b/test/contracts/linear-flow-1.cfg.json index 2b2d2e7b..01f6a26f 100644 --- a/test/contracts/linear-flow-1.cfg.json +++ b/test/contracts/linear-flow-1.cfg.json @@ -6,57 +6,57 @@ "cfg": { "nodes": [ { - "id": 786, - "stmtID": 7740, + "id": 141, + "stmtID": 17039, "srcEdges": [], "dstEdges": [ - 788 + 143 ] }, { - "id": 787, - "stmtID": 7744, + "id": 142, + "stmtID": 17043, "srcEdges": [ - 788 + 143 ], "dstEdges": [ - 790 + 145 ] }, { - "id": 789, - "stmtID": 7750, + "id": 144, + "stmtID": 17049, "srcEdges": [ - 790 + 145 ], "dstEdges": [ - 792 + 147 ] }, { - "id": 791, - "stmtID": 7752, + "id": 146, + "stmtID": 17051, "srcEdges": [ - 792 + 147 ], "dstEdges": [] } ], "edges": [ { - "id": 788, - "src": 786, - "dst": 787 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 790, - "src": 787, - "dst": 789 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 792, - "src": 789, - "dst": 791 + "id": 147, + "src": 144, + "dst": 146 } ] } diff --git a/test/contracts/loops-1.cfg.dot b/test/contracts/loops-1.cfg.dot new file mode 100644 index 00000000..b1d0dc07 --- /dev/null +++ b/test/contracts/loops-1.cfg.dot @@ -0,0 +1,18 @@ +digraph "loops-1" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let sum: Int = 0"]; + "test_142" [label="let i: Int = 0"]; + "test_144" [label="while (i < 10)"]; + "test_146" [label="i = i + 1"]; + "test_148" [label="sum = sum + i"]; + "test_151" [label="return sum"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + "test_148" -> "test_144"; + "test_144" -> "test_151"; + } +} diff --git a/test/contracts/loops-1.cfg.json b/test/contracts/loops-1.cfg.json index 6eb23419..1d3a57b1 100644 --- a/test/contracts/loops-1.cfg.json +++ b/test/contracts/loops-1.cfg.json @@ -6,99 +6,94 @@ "cfg": { "nodes": [ { - "id": 942, - "stmtID": 9285, + "id": 141, + "stmtID": 20129, "srcEdges": [], "dstEdges": [ - 944 + 143 ] }, { - "id": 943, - "stmtID": 9289, + "id": 142, + "stmtID": 20133, "srcEdges": [ - 944 + 143 ], "dstEdges": [ - 946 + 145 ] }, { - "id": 945, - "stmtID": 9303, + "id": 144, + "stmtID": 20147, "srcEdges": [ - 946, - 951 + 145, + 150 ], "dstEdges": [ - 953 + 147, + 152 ] }, { - "id": 947, - "stmtID": 9297, + "id": 146, + "stmtID": 20141, "srcEdges": [ - 948 + 147 ], "dstEdges": [ - 950 + 149 ] }, { - "id": 949, - "stmtID": 9302, + "id": 148, + "stmtID": 20146, "srcEdges": [ - 950 + 149 ], "dstEdges": [ - 951 + 150 ] }, { - "id": 952, - "stmtID": 9305, + "id": 151, + "stmtID": 20149, "srcEdges": [ - 953 + 152 ], "dstEdges": [] - }, - { - "id": 954, - "stmtID": 9305, - "srcEdges": [], - "dstEdges": [] } ], "edges": [ { - "id": 944, - "src": 942, - "dst": 943 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 946, - "src": 943, - "dst": 945 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 948, - "src": 945, - "dst": 947 + "id": 147, + "src": 144, + "dst": 146 }, { - "id": 950, - "src": 947, - "dst": 949 + "id": 149, + "src": 146, + "dst": 148 }, { - "id": 951, - "src": 949, - "dst": 945 + "id": 150, + "src": 148, + "dst": 144 }, { - "id": 953, - "src": 945, - "dst": 952 + "id": 152, + "src": 144, + "dst": 151 } ] } diff --git a/test/contracts/loops-2.cfg.dot b/test/contracts/loops-2.cfg.dot new file mode 100644 index 00000000..6207a671 --- /dev/null +++ b/test/contracts/loops-2.cfg.dot @@ -0,0 +1,18 @@ +digraph "loops-2" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let sum: Int = 0"]; + "test_142" [label="let i: Int = 0"]; + "test_144" [label="until (i < 10)"]; + "test_146" [label="i = i + 1"]; + "test_148" [label="sum = sum + i"]; + "test_151" [label="return sum"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + "test_148" -> "test_144"; + "test_144" -> "test_151"; + } +} diff --git a/test/contracts/loops-2.cfg.json b/test/contracts/loops-2.cfg.json new file mode 100644 index 00000000..26a19d2b --- /dev/null +++ b/test/contracts/loops-2.cfg.json @@ -0,0 +1,103 @@ +{ + "projectName": "loops-2", + "functions": [ + { + "name": "test", + "cfg": { + "nodes": [ + { + "id": 141, + "stmtID": 23235, + "srcEdges": [], + "dstEdges": [ + 143 + ] + }, + { + "id": 142, + "stmtID": 23239, + "srcEdges": [ + 143 + ], + "dstEdges": [ + 145 + ] + }, + { + "id": 144, + "stmtID": 23253, + "srcEdges": [ + 145, + 150 + ], + "dstEdges": [ + 147, + 152 + ] + }, + { + "id": 146, + "stmtID": 23247, + "srcEdges": [ + 147 + ], + "dstEdges": [ + 149 + ] + }, + { + "id": 148, + "stmtID": 23252, + "srcEdges": [ + 149 + ], + "dstEdges": [ + 150 + ] + }, + { + "id": 151, + "stmtID": 23255, + "srcEdges": [ + 152 + ], + "dstEdges": [] + } + ], + "edges": [ + { + "id": 143, + "src": 141, + "dst": 142 + }, + { + "id": 145, + "src": 142, + "dst": 144 + }, + { + "id": 147, + "src": 144, + "dst": 146 + }, + { + "id": 149, + "src": 146, + "dst": 148 + }, + { + "id": 150, + "src": 148, + "dst": 144 + }, + { + "id": 152, + "src": 144, + "dst": 151 + } + ] + } + } + ], + "contracts": [] +} \ No newline at end of file diff --git a/test/contracts/loops-2.expected.out b/test/contracts/loops-2.expected.out new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/contracts/loops-2.expected.out @@ -0,0 +1 @@ + diff --git a/test/contracts/loops-2.tact b/test/contracts/loops-2.tact new file mode 100644 index 00000000..767e34d7 --- /dev/null +++ b/test/contracts/loops-2.tact @@ -0,0 +1,9 @@ +fun test(): Int { + let sum: Int = 0; + let i: Int = 0; + do { + i = i + 1; + sum = sum + i; + } until (i < 10); + return sum; +} diff --git a/test/contracts/loops-3.cfg.dot b/test/contracts/loops-3.cfg.dot new file mode 100644 index 00000000..a9390a88 --- /dev/null +++ b/test/contracts/loops-3.cfg.dot @@ -0,0 +1,18 @@ +digraph "loops-3" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let sum: Int = 0"]; + "test_142" [label="let i: Int = 0"]; + "test_144" [label="repeat (10)"]; + "test_146" [label="i = i + 1"]; + "test_148" [label="sum = sum + i"]; + "test_151" [label="return sum"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + "test_148" -> "test_144"; + "test_144" -> "test_151"; + } +} diff --git a/test/contracts/loops-3.cfg.json b/test/contracts/loops-3.cfg.json new file mode 100644 index 00000000..17b2c71c --- /dev/null +++ b/test/contracts/loops-3.cfg.json @@ -0,0 +1,103 @@ +{ + "projectName": "loops-3", + "functions": [ + { + "name": "test", + "cfg": { + "nodes": [ + { + "id": 141, + "stmtID": 26341, + "srcEdges": [], + "dstEdges": [ + 143 + ] + }, + { + "id": 142, + "stmtID": 26345, + "srcEdges": [ + 143 + ], + "dstEdges": [ + 145 + ] + }, + { + "id": 144, + "stmtID": 26357, + "srcEdges": [ + 145, + 150 + ], + "dstEdges": [ + 147, + 152 + ] + }, + { + "id": 146, + "stmtID": 26351, + "srcEdges": [ + 147 + ], + "dstEdges": [ + 149 + ] + }, + { + "id": 148, + "stmtID": 26356, + "srcEdges": [ + 149 + ], + "dstEdges": [ + 150 + ] + }, + { + "id": 151, + "stmtID": 26359, + "srcEdges": [ + 152 + ], + "dstEdges": [] + } + ], + "edges": [ + { + "id": 143, + "src": 141, + "dst": 142 + }, + { + "id": 145, + "src": 142, + "dst": 144 + }, + { + "id": 147, + "src": 144, + "dst": 146 + }, + { + "id": 149, + "src": 146, + "dst": 148 + }, + { + "id": 150, + "src": 148, + "dst": 144 + }, + { + "id": 152, + "src": 144, + "dst": 151 + } + ] + } + } + ], + "contracts": [] +} \ No newline at end of file diff --git a/test/contracts/loops-3.expected.out b/test/contracts/loops-3.expected.out new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/contracts/loops-3.expected.out @@ -0,0 +1 @@ + diff --git a/test/contracts/loops-3.tact b/test/contracts/loops-3.tact new file mode 100644 index 00000000..9fcdc45c --- /dev/null +++ b/test/contracts/loops-3.tact @@ -0,0 +1,10 @@ +fun test(): Int { + let sum: Int = 0; + let i: Int = 0; + repeat (10) { + i = i + 1; + sum = sum + i; + } + return sum; +} + diff --git a/test/contracts/messages-1.cfg.dot b/test/contracts/messages-1.cfg.dot new file mode 100644 index 00000000..8728dc8f --- /dev/null +++ b/test/contracts/messages-1.cfg.dot @@ -0,0 +1,13 @@ +digraph "messages-1" { + node [shape=box]; + subgraph "cluster_A__receive_internal_comment_31172_increment" { + label="A__receive_internal_comment_31172_increment"; + "A__receive_internal_comment_31172_increment_142" [label="self.val = self.val + 1"]; + "A__receive_internal_comment_31172_increment_143" [label="self.reply(M{value: self.val}.toCell())"]; + "A__receive_internal_comment_31172_increment_142" -> "A__receive_internal_comment_31172_increment_143"; + } + subgraph "cluster_A__receive_internal_comment_31187_query" { + label="A__receive_internal_comment_31187_query"; + "A__receive_internal_comment_31187_query_145" [label="self.reply(M{value: self.val}.toCell())"]; + } +} diff --git a/test/contracts/messages-1.cfg.json b/test/contracts/messages-1.cfg.json index e557ebbe..08c0fa11 100644 --- a/test/contracts/messages-1.cfg.json +++ b/test/contracts/messages-1.cfg.json @@ -6,42 +6,42 @@ "name": "A", "methods": [ { - "name": "A.receive_internal_comment_10868_increment", + "name": "A.receive_internal_comment_29473_increment", "cfg": { "nodes": [ { - "id": 1105, - "stmtID": 10854, + "id": 142, + "stmtID": 29459, "srcEdges": [], "dstEdges": [ - 1107 + 144 ] }, { - "id": 1106, - "stmtID": 10867, + "id": 143, + "stmtID": 29472, "srcEdges": [ - 1107 + 144 ], "dstEdges": [] } ], "edges": [ { - "id": 1107, - "src": 1105, - "dst": 1106 + "id": 144, + "src": 142, + "dst": 143 } ] } }, { - "name": "A.receive_internal_comment_10883_query", + "name": "A.receive_internal_comment_29488_query", "cfg": { "nodes": [ { - "id": 1108, - "stmtID": 10882, + "id": 145, + "stmtID": 29487, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/never-accessed-1.cfg.dot b/test/contracts/never-accessed-1.cfg.dot new file mode 100644 index 00000000..d87578aa --- /dev/null +++ b/test/contracts/never-accessed-1.cfg.dot @@ -0,0 +1,13 @@ +digraph "never-accessed-1" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="if (true)"]; + "test_144" [label="a = 42"]; + "test_146" [label="return 42"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + } +} diff --git a/test/contracts/never-accessed-1.cfg.json b/test/contracts/never-accessed-1.cfg.json index ced893a6..6d6339f0 100644 --- a/test/contracts/never-accessed-1.cfg.json +++ b/test/contracts/never-accessed-1.cfg.json @@ -6,71 +6,57 @@ "cfg": { "nodes": [ { - "id": 1259, - "stmtID": 12537, + "id": 141, + "stmtID": 32841, "srcEdges": [], "dstEdges": [ - 1261 + 143 ] }, { - "id": 1260, - "stmtID": 12542, + "id": 142, + "stmtID": 32846, "srcEdges": [ - 1261 + 143 ], "dstEdges": [ - 1263, - 1267 + 145 ] }, { - "id": 1262, - "stmtID": 12541, + "id": 144, + "stmtID": 32845, "srcEdges": [ - 1263 + 145 ], "dstEdges": [ - 1265 + 147 ] }, { - "id": 1264, - "stmtID": 12544, + "id": 146, + "stmtID": 32848, "srcEdges": [ - 1265 - ], - "dstEdges": [] - }, - { - "id": 1266, - "stmtID": 12544, - "srcEdges": [ - 1267 + 147 ], "dstEdges": [] } ], "edges": [ { - "id": 1261, - "src": 1259, - "dst": 1260 - }, - { - "id": 1263, - "src": 1260, - "dst": 1262 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 1265, - "src": 1262, - "dst": 1264 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 1267, - "src": 1260, - "dst": 1266 + "id": 147, + "src": 144, + "dst": 146 } ] } diff --git a/test/contracts/never-accessed-2.cfg.dot b/test/contracts/never-accessed-2.cfg.dot new file mode 100644 index 00000000..b42d1eda --- /dev/null +++ b/test/contracts/never-accessed-2.cfg.dot @@ -0,0 +1,11 @@ +digraph "never-accessed-2" { + node [shape=box]; + subgraph "cluster_FieldTest__init_37609" { + label="FieldTest__init_37609"; + "FieldTest__init_37609_142" [label="self.f1 = sender()"]; + } + subgraph "cluster_FieldTest__use_f1" { + label="FieldTest__use_f1"; + "FieldTest__use_f1_143" [label="return self.f1"]; + } +} diff --git a/test/contracts/never-accessed-2.cfg.json b/test/contracts/never-accessed-2.cfg.json index a5bc56a7..067b58c6 100644 --- a/test/contracts/never-accessed-2.cfg.json +++ b/test/contracts/never-accessed-2.cfg.json @@ -6,12 +6,12 @@ "name": "FieldTest", "methods": [ { - "name": "FieldTest.init_14095", + "name": "FieldTest.init_35939", "cfg": { "nodes": [ { - "id": 1418, - "stmtID": 14086, + "id": 142, + "stmtID": 35930, "srcEdges": [], "dstEdges": [] } @@ -24,8 +24,8 @@ "cfg": { "nodes": [ { - "id": 1419, - "stmtID": 14093, + "id": 143, + "stmtID": 35937, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/never-accessed-3.cfg.dot b/test/contracts/never-accessed-3.cfg.dot new file mode 100644 index 00000000..381c212f --- /dev/null +++ b/test/contracts/never-accessed-3.cfg.dot @@ -0,0 +1,7 @@ +digraph "never-accessed-3" { + node [shape=box]; + subgraph "cluster_FieldTest__init_40925" { + label="FieldTest__init_40925"; + "FieldTest__init_40925_141" [label="self.f1 = sender()"]; + } +} diff --git a/test/contracts/never-accessed-3.cfg.json b/test/contracts/never-accessed-3.cfg.json index 3209d5ad..cc1de1c5 100644 --- a/test/contracts/never-accessed-3.cfg.json +++ b/test/contracts/never-accessed-3.cfg.json @@ -6,12 +6,12 @@ "name": "FieldTest", "methods": [ { - "name": "FieldTest.init_15753", + "name": "FieldTest.init_39267", "cfg": { "nodes": [ { - "id": 1570, - "stmtID": 15751, + "id": 141, + "stmtID": 39265, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/never-accessed-4.cfg.dot b/test/contracts/never-accessed-4.cfg.dot new file mode 100644 index 00000000..5cbb6b1b --- /dev/null +++ b/test/contracts/never-accessed-4.cfg.dot @@ -0,0 +1,7 @@ +digraph "never-accessed-4" { + node [shape=box]; + subgraph "cluster_ConstantFieldTest__test" { + label="ConstantFieldTest__test"; + "ConstantFieldTest__test_141" [label="send(SendParameters{to: sender(), bounce: true, value: self.val, mode: SendRemainingValue + SendIgnoreErrors})"]; + } +} diff --git a/test/contracts/never-accessed-4.cfg.json b/test/contracts/never-accessed-4.cfg.json index 7fd2222b..d9cdedcc 100644 --- a/test/contracts/never-accessed-4.cfg.json +++ b/test/contracts/never-accessed-4.cfg.json @@ -10,8 +10,8 @@ "cfg": { "nodes": [ { - "id": 1721, - "stmtID": 17429, + "id": 141, + "stmtID": 42601, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/readonly-1.cfg.dot b/test/contracts/readonly-1.cfg.dot new file mode 100644 index 00000000..396d8237 --- /dev/null +++ b/test/contracts/readonly-1.cfg.dot @@ -0,0 +1,17 @@ +digraph "readonly-1" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="let b: Int = 22"]; + "test_144" [label="let c: Int = 24"]; + "test_146" [label="if (true)"]; + "test_148" [label="c = a + b"]; + "test_150" [label="return c"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_146"; + "test_146" -> "test_148"; + "test_148" -> "test_150"; + } +} diff --git a/test/contracts/readonly-1.cfg.json b/test/contracts/readonly-1.cfg.json index 4586b8de..370d6526 100644 --- a/test/contracts/readonly-1.cfg.json +++ b/test/contracts/readonly-1.cfg.json @@ -6,101 +6,87 @@ "cfg": { "nodes": [ { - "id": 1872, - "stmtID": 19084, + "id": 141, + "stmtID": 45935, "srcEdges": [], "dstEdges": [ - 1874 + 143 ] }, { - "id": 1873, - "stmtID": 19088, + "id": 142, + "stmtID": 45939, "srcEdges": [ - 1874 + 143 ], "dstEdges": [ - 1876 + 145 ] }, { - "id": 1875, - "stmtID": 19092, + "id": 144, + "stmtID": 45943, "srcEdges": [ - 1876 + 145 ], "dstEdges": [ - 1878 + 147 ] }, { - "id": 1877, - "stmtID": 19099, + "id": 146, + "stmtID": 45950, "srcEdges": [ - 1878 + 147 ], "dstEdges": [ - 1880, - 1884 + 149 ] }, { - "id": 1879, - "stmtID": 19098, + "id": 148, + "stmtID": 45949, "srcEdges": [ - 1880 + 149 ], "dstEdges": [ - 1882 + 151 ] }, { - "id": 1881, - "stmtID": 19101, + "id": 150, + "stmtID": 45952, "srcEdges": [ - 1882 - ], - "dstEdges": [] - }, - { - "id": 1883, - "stmtID": 19101, - "srcEdges": [ - 1884 + 151 ], "dstEdges": [] } ], "edges": [ { - "id": 1874, - "src": 1872, - "dst": 1873 - }, - { - "id": 1876, - "src": 1873, - "dst": 1875 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 1878, - "src": 1875, - "dst": 1877 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 1880, - "src": 1877, - "dst": 1879 + "id": 147, + "src": 144, + "dst": 146 }, { - "id": 1882, - "src": 1879, - "dst": 1881 + "id": 149, + "src": 146, + "dst": 148 }, { - "id": 1884, - "src": 1877, - "dst": 1883 + "id": 151, + "src": 148, + "dst": 150 } ] } diff --git a/test/contracts/readonly-2.cfg.dot b/test/contracts/readonly-2.cfg.dot new file mode 100644 index 00000000..4e252bf6 --- /dev/null +++ b/test/contracts/readonly-2.cfg.dot @@ -0,0 +1,11 @@ +digraph "readonly-2" { + node [shape=box]; + subgraph "cluster_test1" { + label="test1"; + "test1_141" [label="let a: Int = 20"]; + "test1_142" [label="let b: Int = 22"]; + "test1_144" [label="return b"]; + "test1_141" -> "test1_142"; + "test1_142" -> "test1_144"; + } +} diff --git a/test/contracts/readonly-2.cfg.json b/test/contracts/readonly-2.cfg.json index 854423f6..f17e6ef0 100644 --- a/test/contracts/readonly-2.cfg.json +++ b/test/contracts/readonly-2.cfg.json @@ -6,42 +6,42 @@ "cfg": { "nodes": [ { - "id": 2034, - "stmtID": 20634, + "id": 141, + "stmtID": 49035, "srcEdges": [], "dstEdges": [ - 2036 + 143 ] }, { - "id": 2035, - "stmtID": 20638, + "id": 142, + "stmtID": 49039, "srcEdges": [ - 2036 + 143 ], "dstEdges": [ - 2038 + 145 ] }, { - "id": 2037, - "stmtID": 20640, + "id": 144, + "stmtID": 49041, "srcEdges": [ - 2038 + 145 ], "dstEdges": [] } ], "edges": [ { - "id": 2036, - "src": 2034, - "dst": 2035 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 2038, - "src": 2035, - "dst": 2037 + "id": 145, + "src": 142, + "dst": 144 } ] } diff --git a/test/contracts/traits-1.cfg.dot b/test/contracts/traits-1.cfg.dot new file mode 100644 index 00000000..73c0b3fb --- /dev/null +++ b/test/contracts/traits-1.cfg.dot @@ -0,0 +1,7 @@ +digraph "traits-1" { + node [shape=box]; + subgraph "cluster_TestContract__getter" { + label="TestContract__getter"; + "TestContract__getter_141" [label="return 0"]; + } +} diff --git a/test/contracts/traits-1.cfg.json b/test/contracts/traits-1.cfg.json index 75f8ee4f..d01a3e46 100644 --- a/test/contracts/traits-1.cfg.json +++ b/test/contracts/traits-1.cfg.json @@ -10,8 +10,8 @@ "cfg": { "nodes": [ { - "id": 2188, - "stmtID": 22180, + "id": 141, + "stmtID": 52120, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/unbound-loop-1.cfg.dot b/test/contracts/unbound-loop-1.cfg.dot new file mode 100644 index 00000000..0ae5274e --- /dev/null +++ b/test/contracts/unbound-loop-1.cfg.dot @@ -0,0 +1,12 @@ +digraph "unbound-loop-1" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="while (a > 10)"]; + "test_145" [label="return a"]; + "test_141" -> "test_142"; + "test_142" -> "test_142"; + "test_142" -> "test_145"; + } +} diff --git a/test/contracts/unbound-loop-1.cfg.json b/test/contracts/unbound-loop-1.cfg.json index 7e3a9048..8b4fba6f 100644 --- a/test/contracts/unbound-loop-1.cfg.json +++ b/test/contracts/unbound-loop-1.cfg.json @@ -6,48 +6,49 @@ "cfg": { "nodes": [ { - "id": 2339, - "stmtID": 23960, + "id": 141, + "stmtID": 55687, "srcEdges": [], "dstEdges": [ - 2341 + 143 ] }, { - "id": 2340, - "stmtID": 23964, + "id": 142, + "stmtID": 55691, "srcEdges": [ - 2341 + 143, + 144 ], "dstEdges": [ - 2343 + 144, + 146 ] }, { - "id": 2342, - "stmtID": 23966, + "id": 145, + "stmtID": 55693, "srcEdges": [ - 2343 + 146 ], "dstEdges": [] - }, - { - "id": 2344, - "stmtID": 23966, - "srcEdges": [], - "dstEdges": [] } ], "edges": [ { - "id": 2341, - "src": 2339, - "dst": 2340 + "id": 143, + "src": 141, + "dst": 142 + }, + { + "id": 144, + "src": 142, + "dst": 142 }, { - "id": 2343, - "src": 2340, - "dst": 2342 + "id": 146, + "src": 142, + "dst": 145 } ] } diff --git a/test/contracts/unbound-loop-2.cfg.dot b/test/contracts/unbound-loop-2.cfg.dot new file mode 100644 index 00000000..6b086bb9 --- /dev/null +++ b/test/contracts/unbound-loop-2.cfg.dot @@ -0,0 +1,12 @@ +digraph "unbound-loop-2" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="until (a > 10)"]; + "test_145" [label="return a"]; + "test_141" -> "test_142"; + "test_142" -> "test_142"; + "test_142" -> "test_145"; + } +} diff --git a/test/contracts/unbound-loop-2.cfg.json b/test/contracts/unbound-loop-2.cfg.json index 85b8483f..82f3e172 100644 --- a/test/contracts/unbound-loop-2.cfg.json +++ b/test/contracts/unbound-loop-2.cfg.json @@ -6,48 +6,49 @@ "cfg": { "nodes": [ { - "id": 2494, - "stmtID": 25499, + "id": 141, + "stmtID": 58765, "srcEdges": [], "dstEdges": [ - 2496 + 143 ] }, { - "id": 2495, - "stmtID": 25503, + "id": 142, + "stmtID": 58769, "srcEdges": [ - 2496 + 143, + 144 ], "dstEdges": [ - 2498 + 144, + 146 ] }, { - "id": 2497, - "stmtID": 25505, + "id": 145, + "stmtID": 58771, "srcEdges": [ - 2498 + 146 ], "dstEdges": [] - }, - { - "id": 2499, - "stmtID": 25505, - "srcEdges": [], - "dstEdges": [] } ], "edges": [ { - "id": 2496, - "src": 2494, - "dst": 2495 + "id": 143, + "src": 141, + "dst": 142 + }, + { + "id": 144, + "src": 142, + "dst": 142 }, { - "id": 2498, - "src": 2495, - "dst": 2497 + "id": 146, + "src": 142, + "dst": 145 } ] } diff --git a/test/contracts/unbound-loop-3.cfg.dot b/test/contracts/unbound-loop-3.cfg.dot new file mode 100644 index 00000000..6eb3e166 --- /dev/null +++ b/test/contracts/unbound-loop-3.cfg.dot @@ -0,0 +1,14 @@ +digraph "unbound-loop-3" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let a: Int = 20"]; + "test_142" [label="while (a > 10)"]; + "test_144" [label="a += 1"]; + "test_147" [label="return a"]; + "test_141" -> "test_142"; + "test_142" -> "test_144"; + "test_144" -> "test_142"; + "test_142" -> "test_147"; + } +} diff --git a/test/contracts/unbound-loop-3.cfg.json b/test/contracts/unbound-loop-3.cfg.json index 2f7707c2..dbd4c361 100644 --- a/test/contracts/unbound-loop-3.cfg.json +++ b/test/contracts/unbound-loop-3.cfg.json @@ -6,69 +6,64 @@ "cfg": { "nodes": [ { - "id": 2649, - "stmtID": 27038, + "id": 141, + "stmtID": 61843, "srcEdges": [], "dstEdges": [ - 2651 + 143 ] }, { - "id": 2650, - "stmtID": 27045, + "id": 142, + "stmtID": 61850, "srcEdges": [ - 2651, - 2654 + 143, + 146 ], "dstEdges": [ - 2656 + 145, + 148 ] }, { - "id": 2652, - "stmtID": 27044, + "id": 144, + "stmtID": 61849, "srcEdges": [ - 2653 + 145 ], "dstEdges": [ - 2654 + 146 ] }, { - "id": 2655, - "stmtID": 27047, + "id": 147, + "stmtID": 61852, "srcEdges": [ - 2656 + 148 ], "dstEdges": [] - }, - { - "id": 2657, - "stmtID": 27047, - "srcEdges": [], - "dstEdges": [] } ], "edges": [ { - "id": 2651, - "src": 2649, - "dst": 2650 + "id": 143, + "src": 141, + "dst": 142 }, { - "id": 2653, - "src": 2650, - "dst": 2652 + "id": 145, + "src": 142, + "dst": 144 }, { - "id": 2654, - "src": 2652, - "dst": 2650 + "id": 146, + "src": 144, + "dst": 142 }, { - "id": 2656, - "src": 2650, - "dst": 2655 + "id": 148, + "src": 142, + "dst": 147 } ] } diff --git a/test/contracts/unbound-loop-4.cfg.dot b/test/contracts/unbound-loop-4.cfg.dot new file mode 100644 index 00000000..81ce9775 --- /dev/null +++ b/test/contracts/unbound-loop-4.cfg.dot @@ -0,0 +1,17 @@ +digraph "unbound-loop-4" { + node [shape=box]; + subgraph "cluster_fn" { + label="fn"; + } + subgraph "cluster_test" { + label="test"; + "test_142" [label="let a: Int = 20"]; + "test_143" [label="while (a > 10)"]; + "test_145" [label="fn(a)"]; + "test_148" [label="return a"]; + "test_142" -> "test_143"; + "test_143" -> "test_145"; + "test_145" -> "test_143"; + "test_143" -> "test_148"; + } +} diff --git a/test/contracts/unbound-loop-4.cfg.json b/test/contracts/unbound-loop-4.cfg.json index e6d1799b..5fb7186b 100644 --- a/test/contracts/unbound-loop-4.cfg.json +++ b/test/contracts/unbound-loop-4.cfg.json @@ -13,69 +13,64 @@ "cfg": { "nodes": [ { - "id": 2808, - "stmtID": 28585, + "id": 142, + "stmtID": 64932, "srcEdges": [], "dstEdges": [ - 2810 + 144 ] }, { - "id": 2809, - "stmtID": 28593, + "id": 143, + "stmtID": 64940, "srcEdges": [ - 2810, - 2813 + 144, + 147 ], "dstEdges": [ - 2815 + 146, + 149 ] }, { - "id": 2811, - "stmtID": 28592, + "id": 145, + "stmtID": 64939, "srcEdges": [ - 2812 + 146 ], "dstEdges": [ - 2813 + 147 ] }, { - "id": 2814, - "stmtID": 28595, + "id": 148, + "stmtID": 64942, "srcEdges": [ - 2815 + 149 ], "dstEdges": [] - }, - { - "id": 2816, - "stmtID": 28595, - "srcEdges": [], - "dstEdges": [] } ], "edges": [ { - "id": 2810, - "src": 2808, - "dst": 2809 + "id": 144, + "src": 142, + "dst": 143 }, { - "id": 2812, - "src": 2809, - "dst": 2811 + "id": 146, + "src": 143, + "dst": 145 }, { - "id": 2813, - "src": 2811, - "dst": 2809 + "id": 147, + "src": 145, + "dst": 143 }, { - "id": 2815, - "src": 2809, - "dst": 2814 + "id": 149, + "src": 143, + "dst": 148 } ] } diff --git a/test/contracts/zero-address.cfg.dot b/test/contracts/zero-address.cfg.dot new file mode 100644 index 00000000..7a3291db --- /dev/null +++ b/test/contracts/zero-address.cfg.dot @@ -0,0 +1,7 @@ +digraph "zero-address" { + node [shape=box]; + subgraph "cluster_SampleContract__init_69679" { + label="SampleContract__init_69679"; + "SampleContract__init_69679_141" [label="newAddress(1, 0)"]; + } +} diff --git a/test/contracts/zero-address.cfg.json b/test/contracts/zero-address.cfg.json index 0cd2f736..fdbf4a1e 100644 --- a/test/contracts/zero-address.cfg.json +++ b/test/contracts/zero-address.cfg.json @@ -6,12 +6,12 @@ "name": "SampleContract", "methods": [ { - "name": "SampleContract.init_30130", + "name": "SampleContract.init_68025", "cfg": { "nodes": [ { - "id": 2966, - "stmtID": 30128, + "id": 141, + "stmtID": 68023, "srcEdges": [], "dstEdges": [] } diff --git a/test/tactIR.spec.ts b/test/tactIR.spec.ts index 1200c542..790538e4 100644 --- a/test/tactIR.spec.ts +++ b/test/tactIR.spec.ts @@ -1,12 +1,13 @@ import { run } from "../src/driver"; -import { describe, it } from "@jest/globals"; +import { IdxGenerator } from "../src/internals/ir"; import { TAP, processTactFiles, CONTRACTS_DIR } from "./testUtil"; import path from "path"; processTactFiles(CONTRACTS_DIR, (file) => { const contractName = file.replace(".tact", ""); describe(`Testing CFG dump for ${contractName}`, () => { - it(`should produce the correct CFG JSON output for ${contractName}`, async () => { + it(`should produce correct CFG JSON output for ${contractName}`, async () => { + IdxGenerator.__reset(); await run(path.join(CONTRACTS_DIR, file), { dumpCfg: "json", dumpCfgStdlib: false, @@ -15,5 +16,15 @@ processTactFiles(CONTRACTS_DIR, (file) => { }); await TAP.from(contractName, "json", "cfg.json").run(); }); + it(`should produce correct CFG DOT output for ${contractName}`, async () => { + IdxGenerator.__reset(); + await run(path.join(CONTRACTS_DIR, file), { + dumpCfg: "dot", + dumpCfgStdlib: false, + dumpCfgOutput: CONTRACTS_DIR, + quiet: true, + }); + await TAP.from(contractName, "dot", "cfg.dot").run(); + }); }); });