Browse Source

Faster (async) symbol resolution and linking

Yentl Van Tendeloo 9 years ago
parent
commit
ffe42a90a3
1 changed files with 22 additions and 7 deletions
  1. 22 7
      interface/HUTN/hutn_compiler/linker.py

+ 22 - 7
interface/HUTN/hutn_compiler/linker.py

@@ -1,19 +1,30 @@
 import sys
 import urllib
 import urllib2
+import json
+
+def flush_data(address, data, username):
+    if data:
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": username})), timeout=10).read()
+    return []
 
 def link(address, username, objects, fast):
     # Read out all symbol tables that are to be linked
     definers = {}
     users = {}
+    data = []
+
     if not fast:
         definers["main"] = None
         for obj in objects:
-            print("[SYMB] %s" % (obj))
-            urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '3', "username": username}))).read()
-            urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '"read_symbols"', "username": username}))).read()
-            urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '"%s"' % obj, "username": username}))).read()
+            data.append(("V", '3'))
+            data.append(("V", '"read_symbols"'))
+            data.append(("V", '"%s"' % obj))
 
+        data = flush_data(address, data, username)
+
+        for obj in objects:
+            print("[SYMB] %s" % (obj))
             v = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read()
             lst = v.rsplit("=", 1)[1]
             lst = lst.split("\n")
@@ -38,11 +49,15 @@ def link(address, username, objects, fast):
 
     # Ok, we know that all symbols can be defined with this set of files, now link their initializers together
     initializers = []
+    for obj in objects:
+        data.append(("V", '3'))
+        data.append(("V", '"read_initializers"'))
+        data.append(("V", '"%s"' % obj))
+
+    data = flush_data(address, data, username)
+
     for obj in objects:
         print("[LINK] %s" % (obj))
-        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '3', "username": username}))).read()
-        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '"read_initializers"', "username": username}))).read()
-        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '"%s"' % obj, "username": username}))).read()
         v = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username}))).read()
         start = str(v.split("&", 1)[0].split("=")[1])
         initializers.append(start)