aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/remove__label__s.diff
blob: 683829cd42261f3f38cfdd6e5b4c32c11422545c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
diff --git a/src/analyzer.js b/src/analyzer.js
index d0c3cb7..bbeceed 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -768,18 +768,19 @@ function analyzer(data) {
     }
 
     operateOnLabels(line, function process(item, id) {
+dprint('zz consider replacing: ' + [item[id], ' ^^^^ ', wildcardParts]);
       if (item[id] in labelIds || (wildcard && wildcardCheck(item[id]))) {
         ret.push(item[id]);
-        dprint('relooping', 'zz ' + id + ' replace ' + item[id] + ' with ' + toLabelId);
         if (toLabelId) {
           // replace wildcards in new value with old parts
           var oldParts = item[id].split('|');
           var newParts = toLabelId.split('|');
-          for (var i = 1; i < 3; i++) {
+          for (var i = 0; i < 3; i++) {
             if (newParts[i] === '*') newParts[i] = oldParts[i];
           }
           item[id] = newParts.join('|') + '|' + item[id];
         }
+        dprint('relooping', 'zz ' + id + ' replace ' + ret[ret.length-1] + ' with ' + toLabelId + ' ==> ' + item[id]);
       }
     });
     return ret;
@@ -1204,8 +1205,6 @@ function analyzer(data) {
 
       // Checks whether we actually need labels. We return whether we have a loop nested inside us.
       function optimizeOutUnneededLabels(block) {
-        if (!block) return false;
-
         dprint('relooping', "//    optimizing (2) block: " + block.type + ' : ' + block.entries);
 
         var containLoop = sum(recurseBlock(block, optimizeOutUnneededLabels)) > 0;
@@ -1227,12 +1226,39 @@ function analyzer(data) {
         return assert(false);
       }
 
-      // TODO: Parallelize
+      // If a label ID is never in a multiple, then there is never a need to set it
+      function removeUneededLabelSettings(block, allLabels) {
+        // Find needed labels to be set
+        var needed = {};
+        recurseBlock(block, function noteNeeded(block) {
+dprint('zz reccc ' + [block.type, block.entries]);
+          if (block.type == 'multiple') {
+            block.entryLabels.forEach(function(entryLabel) {
+dprint('zz seen one needed! ' + dump(entryLabel));
+              needed[entryLabel.ident] = 1;
+            });
+          }
+          recurseBlock(block, noteNeeded);
+        });
+        var all = {};
+        allLabels.forEach(function(label) { all[label.ident] = 1 });
+        var unneeded = setSub(all, needed);
+dprint('zz all, unneeded: ' + keys(all) + '   ||   ' + keys(needed) + '   >>   ' + keys(unneeded) + ' : ' + [keys(all).length, keys(needed).length, keys(unneeded).length]);
+        keys(unneeded).forEach(function(un) {
+dprint('zz trying to remoof ' + un);
+          replaceLabelLabels(allLabels, set('BJSET|*|' + un), 'BNOPP|||');
+          replaceLabelLabels(allLabels, set('*|*|' + un), '*|*|||');
+        });
+      }
+
       item.functions.forEach(function(func) {
         dprint('relooping', "// loopOptimizing function: " + func.ident);
-        exploreBlockEndings(func.block);
-        optimizeBlockEndings(func.block);
-        optimizeOutUnneededLabels(func.block);
+
+        //exploreBlockEndings(func.block);
+        //optimizeBlockEndings(func.block);
+        //optimizeOutUnneededLabels(func.block);
+
+        removeUneededLabelSettings(func.block, func.labels);
       });
       return finish();
     }
diff --git a/src/parseTools.js b/src/parseTools.js
index 03a529a..e49acd4 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -782,11 +782,11 @@ function generateStructTypes(type) {
 function recurseBlock(block, func) {
   var ret = [];
   if (block.type == 'reloop') {
-    ret.push(func(block.inner));
+    if (block.inner) ret.push(func(block.inner));
   } else if (block.type == 'multiple') {
     block.entryLabels.forEach(function(entryLabel) { ret.push(func(entryLabel.block)) });
   }
-  ret.push(func(block.next));
+  if (block.next) ret.push(func(block.next));
   return ret;
 }
 
diff --git a/src/settings.js b/src/settings.js
index acdb8c1..e3babd9 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -177,7 +177,7 @@ FAKE_X86_FP80 = 0; // Replaces x86_fp80 with double. This loses precision. It is
                    // (which is nonportable anyhow).
 
 // Compiler debugging options
-DEBUG_TAGS_SHOWING = [];
+DEBUG_TAGS_SHOWING = ['relooping'];
   // Some useful items:
   //    framework
   //    frameworkLines
diff --git a/src/utility.js b/src/utility.js
index 91c4abe..ba97a39 100644
--- a/src/utility.js
+++ b/src/utility.js
@@ -248,10 +248,10 @@ function set() {
 }
 
 function setSub(x, y) {
-  var ret = set(values(x));
+  var ret = set(keys(x));
   for (yy in y) {
     if (yy in ret) {
-      delete ret.yy;
+      delete ret[yy];
     }
   }
   return ret;
diff --git a/tests/runner.py b/tests/runner.py
index 8c09820..48c5d9a 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -31,7 +31,7 @@ except:
 # Core test runner class, shared between normal tests and benchmarks
 
 class RunnerCore(unittest.TestCase):
-  save_dir = 0
+  save_dir = 1
   save_JS = 0
 
   def setUp(self):