gen_docu: fix missing attributes, show generation time at the end
[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 is_fragile(node):
33                 if not is_dynamic_pinned(node):
34                         print "ERROR: fragile node %s must be dynamically pinned" % node.__name__
35                 if not hasattr(node, "throws_init"):
36                         print "ERROR: fragile node %s needs a throws_init attribute" % node.__name__
37                 if not inout_contains(node.ins, "mem"):
38                         print "ERROR: fragile node %s needs an input named 'mem'" % node.__name__
39                 if not inout_contains(node.outs, "X_regular"):
40                         print "ERROR: fragile node %s needs an output named 'X_regular'" % node.__name__
41                 if not inout_contains(node.outs, "X_except"):
42                         print "ERROR: fragile node %s needs an output named 'X_except'" % node.__name__
43         else:
44                 if hasattr(node, "throws_init"):
45                         print "ERROR: throws_init only makes sense for fragile nodes"
46
47
48 def setldefault(node, attr, val):
49         # Don't use hasattr, as these things should not be inherited
50         if attr not in node.__dict__:
51                 setattr(node, attr, val)
52
53 def setdefault(node, attr, val):
54         # Don't use hasattr, as these things should not be inherited
55         if not hasattr(node, attr):
56                 setattr(node, attr, val)
57
58 def setnodedefaults(node):
59         setldefault(node, "name", node.__name__)
60         if isAbstract(node):
61                 return
62
63         setdefault(node, "ins", [])
64         setdefault(node, "arity", len(node.ins))
65         setdefault(node, "attrs", [])
66         setdefault(node, "constructor_args", [])
67         setdefault(node, "customSerializer", False)
68         if hasattr(node, "outs"):
69                 node.mode = "mode_T"