def create_component_by_type(self, requested_type, parent_inst_path="", name="", parent=None): """ Create a component of the requested uvm_component type. :param requested_type: Type type to be overridden :param parent_inst_path: The inst path if we are looking for inst overrides :param name: Concatenated with parent_inst_path if it exists for inst overrides :param parent: The parent component :return: a uvm_component with the name an parent given. If the type is is not in the factory we raise UVMFactoryError """ if name is None: raise error_classes.UVMFactoryError( "Parameter name must be specified in function call.") new_type = self.__find_override(requested_type, parent_inst_path, name) if new_type is None: raise error_classes.UVMFactoryError( f"{requested_type} not in uvm_factory()") new_comp = new_type(name, parent) return new_comp
def create_component_by_name(self, requested_type_name, parent_inst_path="", name="", parent=None): """ Create a components using the name of the requested uvm_component type :param requested_type_name: the type that could be overridden :param parent_inst_path: A path if we are checking for inst overrides :param name: The name of the new object. :param parent: The component's parent component :return: A uvm_object with the name given """ if name is None: raise error_classes.UVMFactoryError( "Parameter name must be specified in create_component_by_name") try: requested_type = utility_classes.FactoryData().classes[ requested_type_name] # noqa except KeyError: requested_type = requested_type_name new_obj = self.create_component_by_type(requested_type, parent_inst_path, name, parent) return new_obj
def set_type_override_by_name(self, original_type_name, override_type_name, replace=True): """ Override one type with another type globally using strings containing the type names. :param original_type_name: The name of the type to be overridden or an arbitrary string. :param override_type_name: The name of the overriding type. It must have been declared. :param replace: If the override already exists only replace if this is True :return: """ assert isinstance(original_type_name, str), "Original_name must be a string" assert isinstance(override_type_name, str), "Override_name must be a string" try: override_type = self.fd.classes[override_type_name] except KeyError: raise error_classes.UVMFactoryError(f"{override_type_name}" + " has not been defined.") # Set type override by name can use an arbitrary string as a key instead of a type # Fortunately Python dicts don't care about the type of the key. try: original_type = self.fd.classes[original_type_name] except KeyError: original_type = original_type_name if (original_type not in self.fd.overrides) or replace: self.__set_override(original_type, override_type)
def find_override_by_name(self, requested_type_name, full_inst_path): """ Given a path and the name of a class return its overriding class object :param requested_type_name: :param full_inst_path: :return: class object """ assert (isinstance(requested_type_name, str)), \ f"requested_type_name must be a string not a {type(requested_type_name)}" # noqa requested_type = None # Appeasing the linter try: requested_type = self.fd.classes[requested_type_name] except KeyError: error_classes.UVMFactoryError( f"{requested_type_name} is not a defined class name") return self.find_override_by_type(requested_type, full_inst_path)
def create_object_by_type(self, requested_type, parent_inst_path="", name=""): """ 8.3.1.5 Creation :param requested_type: The type that we request but that can be overridden :param parent_inst_path: The get_full_name path of the parent :param name: The name of the instance requested_type("name") :return: Type that is child of uvm_object. If the type is is not in the factory we raise UVMFactoryError """ new_type = self.__find_override(requested_type, parent_inst_path, name) if new_type is None: raise error_classes.UVMFactoryError( f"{requested_type} not in uvm_factory()") return new_type(name)
def set_inst_override_by_name(self, original_type_name, override_type_name, full_inst_path): """ Override a specific instance using strings that contain the names of the types. :param original_type_name: the name of type being replaced :param override_type_name: the name of the substitute type :param full_inst_path: The path to the instance :return: """ # Here we use the names of classes instead of the classes. # The original_name doesn't need to be the name of a class, # it can be an arbitrary string. The override_name must # be the name of a class. # # Later we will retrieve this by searching through the # keys for a match to a path and then checking that # the name given in the search matches the original_name assert isinstance(full_inst_path, str), \ "The inst_path must be a string" assert isinstance(original_type_name, str), \ "Original_name must be a string" assert isinstance(override_type_name, str), \ "Override_name must be a string" try: override_type = self.fd.classes[override_type_name] except KeyError: raise error_classes.UVMFactoryError(f"{override_type_name}" + " has not been defined.") # Set type override by name can use an arbitrary string as a key # instead of a type. Fortunately Python dicts don't care about # the type of the key. try: original_type = self.fd.classes[original_type_name] except KeyError: original_type = original_type_name self.__set_override(original_type, override_type, full_inst_path)