testprograms are outdated and not maintained
[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 verify_node(node):
12         if not hasattr(node, "pinned"):
13                 print "%s: NO PINNED SET" % node.__name__
14         elif node.pinned not in ["yes", "no", "memory", "exception"]:
15                 print "%s: UNKNOWN PINNED MODE: %s" % (node.__name__, node.pinned)
16
17         if not hasattr(node, "flags") and not isAbstract(node):
18                 print "WARNING: no flags specified for %s\n" % node.__name__
19         elif type(node.flags) != list:
20                 print "ERROR: flags of %s not a list" % node.__name__
21
22 def setldefault(node, attr, val):
23         # Don't use hasattr, as these things should not be inherited
24         if attr not in node.__dict__:
25                 setattr(node, attr, val)
26
27 def setdefault(node, attr, val):
28         # Don't use hasattr, as these things should not be inherited
29         if not hasattr(node, attr):
30                 setattr(node, attr, val)
31
32 def setnodedefaults(node):
33         setldefault(node, "name", node.__name__)
34         if isAbstract(node):
35                 return
36
37         setdefault(node, "ins", [])
38         setdefault(node, "arity", len(node.ins))
39         setdefault(node, "attrs", [])
40         setdefault(node, "constructor_args", [])
41         setldefault(node, "constrname", node.name)
42         if hasattr(node, "outs"):
43                 node.mode = "mode_T"