changeset 3:b6dce61b934a

oprydning1
author Sigurd Meldgaard <stm@daimi.au.dk>
date Wed, 12 Nov 2008 18:21:31 +0100
parents b8efe2734cc6
children 5f850f623c69
files flow.py graph.py
diffstat 2 files changed, 43 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/flow.py	Wed Nov 12 15:12:11 2008 +0100
+++ b/flow.py	Wed Nov 12 18:21:31 2008 +0100
@@ -4,54 +4,6 @@
 import secret_ifs
 
 
-class FunctionFinder(ast.NodeVisitor):
-
-    def visit_FunctionDef(self, node):
-        self.generic_visit(node)
-        print node.name
-
-
-class Node:
-    count = 0
-
-    def __init__(self, msg = ""):
-        self.out=[]
-        Node.count += 1
-        self.nr = str(Node.count)
-        self.msg = msg
-
-
-class Graph:
-
-    def __init__(self, entry, ex):
-        self.entry = entry
-        self.ex = ex
-
-    def to_dot(self):
-        taken = set()
-        print "digraph G {"
-        print "  in -> %s" % self.entry.nr
-        print '  in [shape = plaintext, label=""]'
-        print "  %s -> out" % self.ex.nr
-        print '  out [shape = plaintext, label=""]'
-        stack = [self.entry]
-        while(True):
-            while(True):
-                if len(stack)==0:
-                    current = None
-                    break
-                current = stack.pop()
-                if current not in taken:
-                    break
-            if not current:
-                break
-            print '    %s [label="%s"]' % (current.nr, current.msg)
-            taken.add(current)
-            for i in current.out:
-                print "    %s->%s;" % (current.nr, i.nr)
-
-            stack += current.out # list concatenation
-        print "}"
 
 
 def init_statements(node, initial, combine):
@@ -113,74 +65,6 @@
             print(child.outsecret)
 
 
-def expr_secret(exp, secret_variables):
-    "Returns True if the expression exp should be considered secret"
-    if(isinstance(exp, ast.BoolOp)):
-        assert len(exp.values) == 2, "Not implemented"
-        return (expr_secret(exp.values[0], secret_variables)
-                 or expr_secret(exp.values[1], secret_variables))
-    elif(isinstance(exp, ast.BinOp)):
-        return (expr_secret(exp.left, secret_variables)
-                 or expr_secret(exp.right, secret_variables))
-    elif(isinstance(exp, ast.Compare)):
-        if len(exp.ops)>1:
-            assert False, "Not implemented"
-        if len(exp.comparators)>1:
-            assert False, "Not implemented"
-            return (expr_secret(exp.left, secret_variables)
-                 or expr_secret(exp.comparators[0], secret_variables))
-    elif(isinstance(exp, ast.UnaryOp)):
-            return (expr_secret(exp.operand, secret_variables))
-    elif(isinstance(exp, ast.Lambda)):
-        assert False, "Not implemented"
-    elif(isinstance(exp, ast.IfExp)):
-        assert False, "Not implemented"
-    elif(isinstance(exp, ast.Dict)):
-        return any([expr_secret(i, secret_variables) for i in exp.values])
-    elif(isinstance(exp, ast.ListComp)):
-        assert False, "Not implemented"
-    elif(isinstance(exp, ast.Name)):
-        return exp.id in secret_variables
-    elif(isinstance(exp, ast.Num)):
-        return False
-    elif(isinstance(exp, ast.Yield)):
-        assert False, "Not implemented"
-    elif(isinstance(exp, ast.Call)):
-        if(not (isinstance(exp.func, ast.Name)
-           and eval(exp.func.id).secret)):
-            if(any([expr_secret(i, secret_variables) for i in exp.args])):
-                util.error("Call of non-secret value with secret argument")
-            else:
-                return False
-        else:
-            return True # For now
-    else:
-        assert False, "Not implemented of type %s" % type(exp)
-
-
-def secret_join(in_nodes):
-    """This is a may-analysis, so take the union"""
-    r = set()
-    for i in in_nodes:
-        r|=i.outsecret
-    return r
-
-
-def secret_combine(node, ins):
-    r = ins
-    global first
-    if(node is first): # Todo: Hack
-        r = node.outsecret
-    if(isinstance(node, ast.Assign)):
-        if(expr_secret(node.value, ins)):
-            r = r | set([node.targets[0].id])
-        else:
-            print "fr", r
-            r = r - set([node.targets[0].id])
-            print "efter", r
-    return r
-
-
 class Flow():
 
     def __init__(self):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graph.py	Wed Nov 12 18:21:31 2008 +0100
@@ -0,0 +1,43 @@
+
+
+class Node:
+    count = 0
+
+    def __init__(self, msg = ""):
+        self.out=[]
+        Node.count += 1
+        self.nr = str(Node.count)
+        self.msg = msg
+
+
+class Graph:
+
+    def __init__(self, entry, ex):
+        self.entry = entry
+        self.ex = ex
+
+    def to_dot(self):
+        taken = set()
+        print "digraph G {"
+        print "  in -> %s" % self.entry.nr
+        print '  in [shape = plaintext, label=""]'
+        print "  %s -> out" % self.ex.nr
+        print '  out [shape = plaintext, label=""]'
+        stack = [self.entry]
+        while(True):
+            while(True):
+                if len(stack)==0:
+                    current = None
+                    break
+                current = stack.pop()
+                if current not in taken:
+                    break
+            if not current:
+                break
+            print '    %s [label="%s"]' % (current.nr, current.msg)
+            taken.add(current)
+            for i in current.out:
+                print "    %s->%s;" % (current.nr, i.nr)
+
+            stack += current.out # list concatenation
+        print "}"