def decorated(*args, **kwargs): result = f(*args, **kwargs) assigned_gate = kwargs.get("gate") if assigned_gate is None: assigned_gate = args[1] hal_py.log_info("Function: {}, {}-ID: {}, Gate-ID: {}".format(message, object_type, args[0].id, assigned_gate.id)) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) if result.gate is None: hal_py.log_info("Function: {}".format(message) + ", Gate-ID: {empty}") else: hal_py.log_info("Function: {}, Gate-ID: {}".format(message, result.gate.id)) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) result_id = -1 if result is not None: result_id = result.id hal_py.log_info("Function: {}, {}-ID: {}".format(message, object_type, result_id)) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) assigned_gate_id = kwargs.get("gate_id") if assigned_gate_id is None: assigned_gate_id = args[1] hal_py.log_info("Function: {}, Grouping-ID: {}, Gate-ID: {}".format(message, args[0].id, assigned_gate_id)) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) if result is not None: hal_py.log_info("Function: {}, Gate-ID: {}".format(message, result.id)) else: hal_py.log_info("Function: {}, Gate-ID: -1".format(message)) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: {}, {}-ID(s): {{".format(message, type) possible_arg_names = ["gate", "net", "module", "gates", "nets", "modules", "gate_id", "net_id", "module_id", "gate_ids", "net_ids", "module_ids"] item_to_select = None for arg_name in possible_arg_names: if kwargs.get(arg_name) is not None: item_to_select = kwargs.get(arg_name) break; if item_to_select is None: item_to_select = args[1] if isinstance(item_to_select, list): if len(item_to_select) > 0 and isinstance(item_to_select[0], int): sorted_list = sorted(item_to_select) log_string += "".join([str(id) + ", " for id in sorted_list])[:-2] + "}" else: sorted_list = sorted(item_to_select, key=lambda gate: gate.id) log_string += "".join([str(g.id) + ", " for g in sorted_list])[:-2] + "}" else: if isinstance(item_to_select, int): log_string += str(item_to_select) + "}" else: log_string += str(item_to_select.id) + "}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) result_gate = result.gate if result_gate is not None: hal_py.log_info("Function: {}, Gate-ID: {}, Predecessor-ID: {}".format(message, str(args[0].id), result_gate.id)) else: hal_py.log_info("Function: {}, Gate-ID: {}, Predecessor-ID: -1".format(message, str(args[0].id))) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) gate = kwargs.get("gate") if gate is None: gate = args[1] log_string = "Function: " + message + ", " + object_type + "-ID: " + str(args[0].id) + ", Gate-ID: " + str(gate.id) hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) gate_id = kwargs.get("gate_id") if kwargs.get("gate_id") is not None else args[1] # gate_id = kwargs.get("gate_id") # if gate_id is None: # gate_id = args[1] log_string = "Function: {}, Grouping-ID: {}, Gate-ID: {}".format(message, args[0].id, gate_id) hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: " + message + ", Gate-IDs: {" if len(result) == 0: log_string += "empty}" else: sorted_endpoints = sorted(result, key=lambda ep: ep.gate.id) log_string += "".join([str(endpoint.gate.id) + ", " for endpoint in sorted_endpoints])[:-2] + "}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: " + message + " , Module-IDs: {" if len(result) == 0: log_string += "empty}" else: sorted_modules = sorted(result, key=lambda module: module.id) log_string += "".join([str(mod.id) + ", " for mod in sorted_modules])[:-2] + "}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: " + message + ", Module-ID: " + str(args[0].id) + ", Gate-IDs: {" if len(result) == 0: log_string += "empty}" else: sorted_gates = sorted(result, key=lambda gate: gate.id) log_string += "".join([str(g.id) + ", " for g in sorted_gates])[:-2] + "}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) gate_ids = result.gates module_id = result.id log_string = "Function: " + message + ", Module-ID: " + str(module_id) + ", Gate-IDs: {" if len(gate_ids) != 0: sorted_gate_ids = sorted(gate_ids, key=lambda gate: gate.id) log_string += "".join([str(g.id) + ", " for g in sorted_gate_ids])[:-2] + "}" else: log_string += "empty}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: " + message + ", Net-IDs: {" if len(result) == len(args[0].nets): log_string += "all}" elif len(result) == 0: log_string += "empty}" else: sorted_result = sorted(result, key=lambda net: net.id) log_string += "".join([str(n.id) + ", " for n in sorted_result])[:-2] + "}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) net_id = -1 if kwargs.get("net") is None: if kwargs.get("net_id") is None: net_id = args[1].id if isinstance(args[1], hal_py.Net) else args[1] else: net_id = kwargs.get("net_id") else: net_id = kwargs.get("net").id log_string = "Function: {}, Grouping-ID: {}, Net-ID: {}".format(message, args[0].id, net_id) hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: {}, {}-ID(s): {{".format(message, type) if len(result) == 0: log_string += "}" else: if isinstance(result[0], int): log_string += "".join([str(id) +", " for id in sorted(result)])[:-2] + "}" else: id_list = [item.id for item in result] log_string += "".join([str(id) + ", " for id in sorted(id_list)])[:-2] + "}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: " + message + ", " + str(obect_type) + "-ID: " + str(args[0].id) + ", Gate-IDs: {" if len(result) == 0: log_string += "empty}" else: sorted_gates = sorted(result) if isinstance(result[0], int) else sorted(result, key=lambda gate: gate.id) #sorted_gates = sorted(result, key=lambda gate: gate.id) if isinstance(result[0], int): log_string += "".join([str(g) + ", " for g in sorted_gates])[:-2] + "}" else: log_string += "".join([str(g.id) + ", " for g in sorted_gates])[:-2] + "}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): module_to_delete = kwargs.get("module") if module_to_delete is None: module_to_delete = args[1] module_id = module_to_delete.id gate_ids = module_to_delete.gates result = f(*args, **kwargs) log_string = "Function: " + message + ", Module-ID: " + str(module_id) + ", Gate-IDs: {" if len(gate_ids) != 0: sorted_gate_ids = sorted(gate_ids, key=lambda gate: gate.id) log_string += "".join([str(g.id) + ", " for g in sorted_gate_ids])[:-2] + "}" else: log_string += "empty}" hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: " + message end_result_list = [] for list in result: if len(list) == 0: end_result_list.append([]) else: if isinstance(list[0], int): end_result_list.append(sorted(list)) else: end_result_list.append(sorted([item.id for item in list])) log_string += ", Gate-ID(s): " + str(end_result_list[0]) + ", Net-ID(s): " + str(end_result_list[1]) + ", Module-ID(s): " + str(end_result_list[2]) log_string = log_string.replace("[", "{").replace("]", "}") hal_py.log_info(log_string) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) hal_py.log_info("Function: {}, {}-ID: {}".format(message, object_type, args[0].id)) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) hal_py.log_info("Function: {}, Module-ID: {}".format(message, result.id)) return result
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: " + message # first 3 different structures where only a gate, net or module is passed to the function # these are handled in the same manner possible_args_type1 = [("gate", hal_py.Gate), ("net", hal_py.Net), ("module", hal_py.Module)] tmp_param_value = None for arg_tup in possible_args_type1: tmp_param_value = kwargs.get(arg_tup[0]) if tmp_param_value is None and len(args) >= 2: if isinstance(args[1], arg_tup[1]): log_string += ", {}-Id: {{".format(str(arg_tup[0]).capitalize()) + str(args[1].id) + "}" elif tmp_param_value is not None: log_string += ", {}-Id: {{".format(str(arg_tup[0]).capitalize()) + str(tmp_param_value.id) + "}" # next evaluate the lists of gates, nets and modules and the different position they can occur, depending # on which parameter-signatur is passed to the function, e.g. the param-name "gates" can only occur on pos 1, # "nets" on pos 1 and 2 and "modules" on pos 1 and 3 # the name, the first and the second possible position and the desired object type within the list # (the "gates" parameter is a bit hacky because it has only 1 possible position (so just use a very # big number so the second check for arg-length always returns false (could also check if the # first condition was already visited (with a boolean) possible_args_type2 = [("gates", 1, 10000, hal_py.Gate), ("nets", 1, 2, hal_py.Net), ("modules", 1, 3, hal_py.Module)] tmp_param_value = None # a bit hacky but i need to check if an empty net or module list has already # been logged so that the next for-loop does not log an empty list again logged_empty_gate_list = False logged_empty_net_list = False logged_empty_module_list = False for arg_tup in possible_args_type2: tmp_param_value = kwargs.get(arg_tup[0]) if tmp_param_value is None: if len(args) >= arg_tup[1]+1 and isinstance(args[arg_tup[1]], list): if len(args[arg_tup[1]]) > 0 and isinstance(args[arg_tup[1]][0], arg_tup[3]): sorted_item_ids = sorted(args[arg_tup[1]], key = lambda item: item.id) log_string += ", " + arg_tup[0].capitalize()[:-1] + "-Id(s): {" + "".join([str(i.id) + ", " for i in sorted_item_ids])[:-2] + "}" elif len(args[arg_tup[1]]) == 0: if ("net" in arg_tup[0] and not logged_empty_net_list) or ("module" in arg_tup[0] and not logged_empty_module_list) or ("gate" in arg_tup[0] and not logged_empty_gate_list): log_string += ", " + arg_tup[0].capitalize()[:-1] + "-Id(s): {}" logged_empty_gate_list = True if "gate" in arg_tup[0] else logged_empty_gate_list logged_empty_net_list = True if "net" in arg_tup[0] else logged_empty_net_list logged_empty_module_list = True if "module" in arg_tup[0] else logged_empty_module_list if len(args) >= arg_tup[2]+1 and isinstance(args[arg_tup[2]], list): if len(args[arg_tup[2]]) > 0 and isinstance(args[arg_tup[2]][0], arg_tup[3]): sorted_item_ids = sorted(args[arg_tup[2]], key = lambda item: item.id) log_string += ", " + arg_tup[0].capitalize()[:-1] + "-Id(s): {" + "".join([str(i.id) + ", " for i in sorted_item_ids])[:-2] + "}" elif len(args[arg_tup[2]]) == 0: if ("net" in arg_tup[0] and not logged_empty_net_list) or ("module" in arg_tup[0] and not logged_empty_module_list) or ("gate" in arg_tup[0] and not logged_empty_gate_list): log_string += ", " + arg_tup[0].capitalize()[:-1] + "-Id(s): {}" logged_empty_gate_list = True if "gate" in arg_tup[0] else logged_empty_gate_list logged_empty_net_list = True if "net" in arg_tup[0] else logged_empty_net_list logged_empty_module_list = True if "module" in arg_tup[0] else logged_empty_module_list elif tmp_param_value is not None: if len(tmp_param_value) == 0: if ("net" in arg_tup[0] and not logged_empty_net_list) or ("module" in arg_tup[0] and not logged_empty_module_list) or ("gate" in arg_tup[0] and not logged_empty_gate_list): logged_empty_gate_list = True if "gate" in arg_tup[0] else logged_empty_gate_list logged_empty_net_list = True if "net" in arg_tup[0] else logged_empty_net_list logged_empty_module_list = True if "module" in arg_tup[0] else logged_empty_module_list sorted_item_ids = sorted(tmp_param_value, key=lambda item: item.id) log_string += ", " + arg_tup[0].capitalize()[:-1] + "-Id(s): {" + "".join([str(i.id) + ", " for i in sorted_item_ids])[:-2] + "}" else: sorted_item_ids = sorted(tmp_param_value, key=lambda item: item.id) log_string += ", " + arg_tup[0].capitalize()[:-1] + "-Id(s): {" + "".join([str(i.id) + ", " for i in sorted_item_ids])[:-2] + "}" possible_args_type3 = [("gate_ids", 1), ("net_ids", 2), ("module_ids", 3)] tmp_param_value = None for arg_tup in possible_args_type3: tmp_param_value = kwargs.get(arg_tup[0]) if tmp_param_value is None and len(args) >= arg_tup[1]+1 and isinstance(args[arg_tup[1]], list) and len(args[arg_tup[1]]) > 0 and isinstance(args[arg_tup[1]][0], int): sorted_item_ids = sorted(args[arg_tup[1]]) log_string += ", {}-Id(s): {{".format(arg_tup[0].capitalize()[:-4]) + "".join([str(i) + ", " for i in sorted_item_ids])[:-2] + "}" elif tmp_param_value is not None: if ("net" in arg_tup[0] and not logged_empty_net_list) or ("module" in arg_tup[0] and not logged_empty_module_list) or ("gate" in arg_tup[0] and not logged_empty_gate_list): sorted_item_ids = sorted(tmp_param_value) log_string += ", {}-Id(s): {{".format(arg_tup[0].capitalize()[:-4]) + "".join([str(i) + ", " for i in sorted_item_ids])[:-2] + "}" hal_py.log_info(log_string) return result
hal_py.Net.set_data = generic_decorator("Net.set_data", "Net", hal_py.Net.set_data) hal_py.Net.set_name = generic_decorator("Net.set_name", "Net", hal_py.Net.set_name) hal_py.Net.get_source = net_get_source("Net.get_source", hal_py.Net.get_source) hal_py.Net.get_sources = net_get_destinations_get_sources("Net.get_sources", hal_py.Net.get_sources) hal_py.Net.get_destinations = net_get_destinations_get_sources("Net.get_destinations", hal_py.Net.get_destinations) ####### Module Functions hal_py.Module.assign_gate = module_grouping_assign_gate("Module.assign_gate", "Module", hal_py.Module.assign_gate) hal_py.Module.get_gates = module_grouping_get_gates("Module.get_gates", "Module", hal_py.Module.get_gates) hal_py.Module.remove_gate = module_grouping_remove_gate("Module.remove_gate", "Module", hal_py.Module.remove_gate) ###### Endpoint Functions hal_py.Endpoint.get_gate = endpoint_get_gate("Endpoint.get_gate", hal_py.Endpoint.get_gate) ###### Grouping Functions hal_py.Grouping.get_id = generic_decorator("Grouping.get_id", "Grouping", hal_py.Grouping.get_id) hal_py.Grouping.get_name = generic_decorator("Grouping.get_name", "Grouping", hal_py.Grouping.get_name) hal_py.Grouping.get_netlist = generic_decorator("Grouping.get_netlist", "Grouping", hal_py.Grouping.get_netlist) hal_py.Grouping.set_name = generic_decorator("Grouping.set_name", "Grouping", hal_py.Grouping.set_name) hal_py.Grouping.assign_gate = module_grouping_assign_gate("Grouping.assign_gate", "Grouping", hal_py.Grouping.assign_gate) hal_py.Grouping.assign_gate_by_id = grouping_assign_gate_by_id("Grouping.assign_gate_by_id", hal_py.Grouping.assign_gate_by_id) hal_py.Grouping.get_gates = module_grouping_get_gates("Grouping.get_gates", "Grouping", hal_py.Grouping.get_gates) hal_py.Grouping.get_gate_ids = module_grouping_get_gates("Grouping.get_gate_ids", "Grouping", hal_py.Grouping.get_gate_ids) hal_py.Grouping.remove_gate = module_grouping_remove_gate("Grouping.remove_gate", "Grouping", hal_py.Grouping.remove_gate) hal_py.Grouping.remove_gate_by_id = grouping_remove_gate_by_id("Grouping.remove_gate_by_id", hal_py.Grouping.remove_gate_by_id) hal_py.Grouping.assign_net = grouping_assign_net("Grouping.assign_net", hal_py.Grouping.assign_net) hal_py.Grouping.assign_net_by_id = grouping_assign_net("Grouping.assign_net_by_id", hal_py.Grouping.assign_net_by_id) else: hal_py.log_info("Already decorated. Not applying again.")
def decorated(*args, **kwargs): result = f(*args, **kwargs) log_string = "Function: {}, Grouping-Id: ".format(message) + str(result.id) hal_py.log_info(log_string) return result