+55
-1
@@ -42,2 +42,5 @@ 'use strict'; | ||
| this.search(); | ||
| // Remove phis with no uses | ||
| this.reduce(); | ||
| }; | ||
@@ -146,3 +149,6 @@ | ||
| var undef = this.pipeline.create('ssa:undefined'); | ||
| block.add(undef); | ||
| if (block.getLastControl() === null) | ||
| block.add(undef); | ||
| else | ||
| block.insert(block.nodes.length - 1, undef); | ||
@@ -215,1 +221,49 @@ input = undef; | ||
| }; | ||
| SSA.prototype.reduce = function reduce() { | ||
| for (var i = 0; i < this.pipeline.blocks.length; i++) { | ||
| var block = this.pipeline.blocks[i]; | ||
| for (var j = block.nodes.length - 1; j >= 0; j--) { | ||
| var node = block.nodes[j]; | ||
| // Phis are inserted at the block start | ||
| if (node.opcode !== 'ssa:phi') | ||
| break; | ||
| if (node.uses.length !== 0) | ||
| continue; | ||
| block.remove(j); | ||
| this.pipeline.remove(node); | ||
| // Remove `ssa:undefined` in predecessor blocks | ||
| this.reduceUndefined(block, node); | ||
| } | ||
| } | ||
| }; | ||
| SSA.prototype.reduceUndefined = function reduceUndefined(block, phi) { | ||
| for (var i = 0; i < phi.inputs.length; i++) { | ||
| var input = phi.inputs[i]; | ||
| if (input.opcode !== 'ssa:undefined') | ||
| continue; | ||
| // Somehow this `ssa:undefined` is used elsewhere | ||
| if (input.uses.length !== 0) | ||
| continue; | ||
| // Input should come from right branch | ||
| var pred = block.predecessors[i]; | ||
| // `ssa:undefined` are inserted at the end of the block | ||
| for (var j = pred.nodes.length - 1; j >= 0; j--) { | ||
| var node = pred.nodes[j]; | ||
| if (node !== input) | ||
| continue; | ||
| pred.remove(j); | ||
| this.pipeline.remove(node); | ||
| break; | ||
| } | ||
| } | ||
| }; |
+2
-2
| { | ||
| "name": "ssa.js", | ||
| "version": "1.0.2", | ||
| "version": "1.1.0", | ||
| "description": "SSA Phi Insertion helper", | ||
@@ -28,3 +28,3 @@ "main": "lib/ssa.js", | ||
| "jshint": "^2.8.0", | ||
| "json-pipeline": "^1.4.1", | ||
| "json-pipeline": "^1.5.1", | ||
| "mocha": "~1.17.0" | ||
@@ -31,0 +31,0 @@ }, |
+87
-0
@@ -214,2 +214,89 @@ var fixtures = require('./fixtures'); | ||
| */}); | ||
| test('reduce phi in loop', function() {/* | ||
| pipeline { | ||
| b0 { | ||
| } | ||
| b0 -> b1 | ||
| b1 { | ||
| } | ||
| b1 -> b2, b3 | ||
| b2 { | ||
| i0 = literal 1 | ||
| i1 = ssa:store 0, i0 | ||
| i2 = ssa:load 0 | ||
| } | ||
| b2 -> b1 | ||
| b3 { | ||
| } | ||
| } | ||
| */}, function() {/* | ||
| pipeline { | ||
| b0 { | ||
| } | ||
| b0 -> b1 | ||
| b1 { | ||
| } | ||
| b1 -> b2, b3 | ||
| b2 { | ||
| i0 = literal 1 | ||
| } | ||
| b2 -> b1 | ||
| b3 { | ||
| } | ||
| } | ||
| */}); | ||
| test('insert `ssa:undefined` before control nodes', function() {/* | ||
| pipeline { | ||
| b0 { | ||
| i0 = if ^b0 | ||
| } | ||
| b0 -> b1, b2 | ||
| b1 { | ||
| i1 = jump ^b1 | ||
| } | ||
| b1 -> b3 | ||
| b2 { | ||
| i2 = literal 1 | ||
| i3 = ssa:store 0, i2 | ||
| i4 = jump ^b2 | ||
| } | ||
| b2 -> b3 | ||
| b3 { | ||
| i5 = ssa:load 0 | ||
| i6 = return ^b3, i2 | ||
| } | ||
| } | ||
| */}, function() {/* | ||
| pipeline { | ||
| b0 { | ||
| i0 = if ^b0 | ||
| } | ||
| b0 -> b1, b2 | ||
| b1 { | ||
| i3 = ssa:undefined | ||
| i1 = jump ^b1 | ||
| } | ||
| b1 -> b3 | ||
| b2 { | ||
| i2 = literal 1 | ||
| i4 = jump ^b2 | ||
| } | ||
| b2 -> b3 | ||
| b3 { | ||
| i5 = ssa:phi i3, i2 | ||
| i6 = return ^b3, i2 | ||
| } | ||
| } | ||
| */}); | ||
| }); |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
22069
13.22%495
31.65%2
100%