clarify some node comments
[libfirm] / scripts / spec_util.py
1 abstracts = set()
2 def abstract(cls):
3         abstracts.add(cls)
4         return cls
5 def isAbstract(nodetype):
6         return nodetype in abstracts
7
8 def is_dynamic_pinned(node):
9         return node.pinned in ["memory", "exception"]
10
11 def is_fragile(node):
12         return hasattr(node, "flags") and "fragile" in node.flags
13
14 def inout_contains(l, name):
15         for entry in l:
16                 if entry[0] == name:
17                         return True
18         return False
19
20 def verify_node(node):
21         if not hasattr(node, "pinned"):
22                 print "%s: NO PINNED SET" % node.__name__
23         elif node.pinned not in ["yes", "no", "memory", "exception"]:
24                 print "%s: UNKNOWN PINNED MODE: %s" % (node.__name__, node.pinned)
25
26         if not hasattr(node, "flags") and not isAbstract(node):
27                 print "WARNING: no flags specified for %s\n" % node.__name__
28         elif type(node.flags) != list:
29                 print "ERROR: flags of %s not a list" % node.__name__
30         if hasattr(node, "pinned_init") and not is_dynamic_pinned(node):
31                 print "ERROR: node %s has pinned_init attribute but is not marked as dynamically pinned" % node.__name__
32         if hasattr(node, "flags") and "uses_memory" in node.flags:
33                 if not inout_contains(node.ins, "mem"):
34                         print "ERROR: memory op %s needs an input named 'mem'" % node.__name__
35         if is_fragile(node):
36                 if not is_dynamic_pinned(node):
37                         print "ERROR: fragile node %s must be dynamically pinned" % node.__name__
38                 if not hasattr(node, "throws_init"):
39                         print "ERROR: fragile node %s needs a throws_init attribute" % node.__name__
40                 if not inout_contains(node.outs, "X_regular"):
41                         print "ERROR: fragile node %s needs an output named 'X_regular'" % node.__name__
42                 if not inout_contains(node.outs, "X_except"):
43                         print "ERROR: fragile node %s needs an output named 'X_except'" % node.__name__
44         else:
45                 if hasattr(node, "throws_init"):
46                         print "ERROR: throws_init only makes sense for fragile nodes"
47
48
49 def setldefault(node, attr, val):
50         # Don't use hasattr, as these things should not be inherited
51         if attr not in node.__dict__:
52                 setattr(node, attr, val)
53
54 def setdefault(node, attr, val):
55         # Don't use hasattr, as these things should not be inherited
56         if not hasattr(node, attr):
57                 setattr(node, attr, val)
58
59 def setnodedefaults(node):
60         setldefault(node, "name", node.__name__)
61         if isAbstract(node):
62                 return
63
64         setdefault(node, "ins", [])
65         setdefault(node, "arity", len(node.ins))
66         setdefault(node, "attrs", [])
67         setdefault(node, "constructor_args", [])
68         setdefault(node, "customSerializer", False)
69         if hasattr(node, "outs"):
70                 node.mode = "mode_T"