def clone_function (self, fun, tag): self.nodes = {} self.vs = syntax.get_vars (fun) for n in fun.reachable_nodes (): self.nodes[n] = fun.nodes[n] self.node_tags[n] = (tag, (fun.name, n)) self.outputs[tag] = fun.outputs self.entries = [(fun.entry, tag, fun.name, fun.inputs)] self.next_node_name = max (self.nodes.keys () + [2]) + 1
def clone_function(self, fun, tag): self.nodes = {} self.vs = syntax.get_vars(fun) for n in fun.reachable_nodes(): self.nodes[n] = fun.nodes[n] detail = (fun.name, n) self.node_tags[n] = (tag, detail) self.node_tag_revs.setdefault((tag, detail), []) self.node_tag_revs[(tag, detail)].append(n) self.outputs[tag] = fun.outputs self.entries = [(fun.entry, tag, fun.name, fun.inputs)] self.next_node_name = max(self.nodes.keys() + [2]) + 1 self.inline_scripts[tag] = []
def add_function(self, fun, tag, node_renames, loop_id=None): if not fun.entry: printout("Aborting %s: underspecified %s" % (self.name, fun.name)) raise Abort() node_renames.setdefault("Ret", "Ret") node_renames.setdefault("Err", "Err") new_node_renames = {} vs = syntax.get_vars(fun) vs = dict([(v, fresh_name(v, self.vs, vs[v])) for v in vs]) ns = fun.reachable_nodes() for n in ns: assert n not in node_renames node_renames[n] = self.alloc_node(tag, (fun.name, n), loop_id=loop_id, hint=n) new_node_renames[n] = node_renames[n] for n in ns: self.nodes[node_renames[n]] = syntax.copy_rename(fun.nodes[n], (vs, node_renames)) return (new_node_renames, vs)
def compile_struct_use (function): trace ('Compiling in %s.' % function.name) vs = get_vars (function) max_node = max (function.nodes.keys () + [2]) visit_vs = vs.keys () replaces = {} while visit_vs: v = visit_vs.pop () typ = vs[v] if typ.kind == 'Struct': fields = structs[typ.name].field_list elif typ.kind == 'Array': fields = [(i, typ.el_typ) for i in range (typ.num)] else: continue new_vs = [(nm, fresh_name ('%s.%s' % (v, nm), vs, f_typ), f_typ) for (nm, f_typ) in fields] replaces[v] = new_vs visit_vs.extend ([v_nm for (_, v_nm, _) in new_vs]) for n in function.nodes: node = function.nodes[n] if node.kind == 'Basic': node.upds = compile_upds (replaces, node.upds) elif node.kind == 'Basic': assert not node.lval[1].kind in ['Struct', 'Array'] node.val = compile_accs (replaces, node.val) elif node.kind == 'Call': node.args = expand_arg_fields (replaces, node.args) node.rets = expand_lval_list (replaces, node.rets) elif node.kind == 'Cond': node.cond = compile_accs (replaces, node.cond) else: assert not 'node kind understood' function.inputs = expand_lval_list (replaces, function.inputs) function.outputs = expand_lval_list (replaces, function.outputs) return len (replaces) == 0
def add_function(self, fun, tag, node_renames, loop_id=None): if not fun.entry: printout('Aborting %s: underspecified %s' % (self.name, fun.name)) raise Abort() node_renames.setdefault('Ret', 'Ret') node_renames.setdefault('Err', 'Err') new_node_renames = {} vs = syntax.get_vars(fun) vs = dict([(v, fresh_name(v, self.vs, vs[v])) for v in vs]) ns = fun.reachable_nodes() check_no_symbols([fun.nodes[n] for n in ns]) for n in ns: assert n not in node_renames node_renames[n] = self.alloc_node(tag, (fun.name, n), loop_id=loop_id, hint=n) new_node_renames[n] = node_renames[n] for n in ns: self.nodes[node_renames[n]] = syntax.copy_rename( fun.nodes[n], (vs, node_renames)) return (new_node_renames, vs)
def compile_struct_use(function): trace('Compiling in %s.' % function.name) vs = get_vars(function) max_node = max(function.nodes.keys() + [2]) visit_vs = vs.keys() replaces = {} while visit_vs: v = visit_vs.pop() typ = vs[v] if typ.kind == 'Struct': fields = structs[typ.name].field_list elif typ.kind == 'Array': fields = [(i, typ.el_typ) for i in range(typ.num)] else: continue new_vs = [(nm, fresh_name('%s.%s' % (v, nm), vs, f_typ), f_typ) for (nm, f_typ) in fields] replaces[v] = new_vs visit_vs.extend([v_nm for (_, v_nm, _) in new_vs]) for n in function.nodes: node = function.nodes[n] if node.kind == 'Basic': node.upds = compile_upds(replaces, node.upds) elif node.kind == 'Basic': assert not node.lval[1].kind in ['Struct', 'Array'] node.val = compile_accs(replaces, node.val) elif node.kind == 'Call': node.args = expand_arg_fields(replaces, node.args) node.rets = expand_lval_list(replaces, node.rets) elif node.kind == 'Cond': node.cond = compile_accs(replaces, node.cond) else: assert not 'node kind understood' function.inputs = expand_lval_list(replaces, function.inputs) function.outputs = expand_lval_list(replaces, function.outputs) return len(replaces) == 0