def add_sim_modules_to_project(tags, sim_dict, user_paths): #utils.pretty_print_dict(tags) #utils.pretty_print_dict(sim_dict) #Get the directory of where to put the sim modules base_dir = utils.resolve_path(tags["BASE_DIR"]) project_dir = tags["PROJECT_NAME"] out_dir = os.path.join(base_dir, "sim", "sim_modules") if not os.path.exists(out_dir): utils.create_dir(out_dir) #Find all the file locations module_filename = utils.find_module_filename(sim_dict["name"], user_paths) module_filepath = utils.find_rtl_file_location(module_filename, user_paths) out_file_path = os.path.join(out_dir, module_filename) #print "copy %s > %s" % (module_filepath, out_file_path) shutil.copy2(module_filepath, os.path.join(out_dir, out_file_path)) #Get the locations for each of the auxilary files for f in sim_dict["aux_files"]: module_path = utils.find_rtl_file_location(f) out_file_path = os.path.join(out_dir, f) #print "copy %s > %s" % (module_path, out_file_path) shutil.copy2(module_path, os.path.join(out_dir, f))
def resolve_dependencies(filename, debug=True): """resolve_dependencies given a filename determine if there are any modules it depends on, recursively search for any files found in order to extrapolate all dependencies Args: filename: The filename to resolve dependencies for Return: Nothing Raises: ModuleFactoryError """ result = True ldebug = debug if debug: print "in resolve dependencies" local_file_list = [] if debug: print "working on filename: " + filename if (has_dependencies(filename, debug=ldebug)): if debug: print "found dependencies!" deps = get_list_of_dependencies(filename, debug=ldebug) for d in deps: try: dep_filename = utils.find_module_filename(d, user_paths, debug=ldebug) except ModuleError as ex: print "Dependency Warning: %s" % (str(ex)) print "Module Name: %s" % (d) print "This warning may be due to:" print "\tIncluding a simulation only module" print "\tIncluding a vendor specific module" print "\tA module that was not found" continue if debug: print "found the filename: " + dep_filename #check this file out for dependecies, then append that on to the local list resolve_dependencies(dep_filename, debug=ldebug) if debug: print "found all sub dependencies for: " + dep_filename local_file_list.append(dep_filename) #go through the local file list and add anything found to the list of dependencies or verilog files for f in local_file_list: if f not in verilog_dependency_list and f not in verilog_file_list: if debug: print "found dependency: " + f verilog_dependency_list.append(f) return
def resolve_dependencies(self, filename, debug = True): """resolve_dependencies given a filename determine if there are any modules it depends on, recursively search for any files found in order to extrapolate all dependencies Args: filename: The filename to resolve dependencies for Return: Nothing Raises: ModuleFactoryError """ result = True ldebug = debug if debug: print "in resolve dependencies" local_file_list = [] if debug: print "working on filename: " + filename if (self.has_dependencies(filename, debug = ldebug)): if debug: print "found dependencies!" deps = self.get_list_of_dependencies(filename, debug = ldebug) for d in deps: try: dep_filename = utils.find_module_filename(d, self.user_paths, debug = ldebug) except ModuleNotFound as ex: print "Dependency Warning: %s" % (str(ex)) print "Module Name: %s" % (d) print "This warning may be due to:" print "\tIncluding a simulation only module" print "\tIncluding a vendor specific module" print "\tA module that was not found" continue if debug: print "found the filename: " + dep_filename #check this file out for dependecies, then append that on to the local list self.resolve_dependencies(dep_filename, debug = ldebug) if debug: print "found all sub dependencies for: " + dep_filename local_file_list.append(dep_filename) #go through the local file list and add anything found to the list of dependencies or verilog files for f in local_file_list: if (f not in self.verilog_dependency_list) and (f not in self.verilog_file_list): if debug: print "found dependency: " + f self.verilog_dependency_list.append(f) return
def generate_sub_slave_dict(sim_dict, debug = False): #Get sim module tags filename = utils.find_module_filename(sim_dict["name"]) filepath = utils.find_rtl_file_location(filename) sim_tags = vutils.get_module_tags(filepath) bind_dict = sim_tags["ports"] sim_tags["bind"] = {} #Go through each dictionary entry and determine the direction for signal in sim_dict["bind"]: #XXX: Don't support subset of busses yet sim_tags["bind"][signal] = {} sim_tags["bind"][signal]["loc"] = sim_dict["bind"][signal] sim_tags["bind"][signal]["direction"] = get_bind_direction(signal, sim_tags) return sim_tags
def process_file(self, filename, file_dict, directory="", debug=False): """process_file read in a file, modify it (if necessary), then write it to the location specified by the directory variable Args: filename: the name of the file to process file_dict: dictionary associated with this file directory: output directory Return: Raises: ModuleFactoryError IOError """ verbose = False debug = False if (filename.endswith(".v")): self.verilog_file_list.append(filename) if debug: print "in process file" print "\t%s" % filename #maybe load a tags?? #using the location value in the file_dict find the file and #pull it into a buf self.buf = "" file_location = "" paths = self.user_paths #There are two types of files #ones that are copied over from a location #ones that are generated by scripts #The file is specified by a location and basically needs to be copied over if file_dict.has_key("location"): #print "Location: %s" % file_dict["location"] #file_location = os.path.join( utils.nysa_base, loc = file_dict["location"].split("/") #print "Loc list: %s" % str(loc) if loc[0] == "${NYSA}": loc[0] = utils.nysa_base #print "Loc list: %s" % str(loc) file_location = "/" for d in loc: file_location = os.path.join(file_location, d) if (debug): print ("getting file: " + filename + " from location: " + file_location) found_file = False try: filein = open(os.path.join(utils.resolve_path(file_location), filename)) self.buf = filein.read() filein.close() found_file = True except IOError as err: pass if not found_file: if debug: print "searching for file...", try: absfilename = utils.find_rtl_file_location(filename, self.user_paths) filepath = os.path.dirname(os.path.dirname(absfilename)) paths.insert(0, filepath) paths = list(set(paths)) filein = open(absfilename) self.buf = filein.read() filein.close() except: if debug: print "Failed to find file" raise ModuleFactoryError("File %s not found searched %s and in the HDL dir (%s)" % (filename, \ file_location, \ utils.nysa_base + os.path.sep + "cbuilder" + os.path.sep + "verilog")) if verbose: print "found file!" print "file content: " + self.buf #File is generated by a script elif (not file_dict.has_key("gen_script")): raise ModuleFactoryError( "File %s does not declare a location or a \ script! Check the template file" % filename) if verbose: print "Project name: " + self.tags["PROJECT_NAME"] #if the generation flag is set in the dictionary if "gen_script" in file_dict: if debug: print "found the generation script" print "run generation script: " + file_dict["gen_script"] #open up the new gen module ms = sys.modules.keys() gs = "" for m in ms: if m.endswith("gen_scripts"): gs = m #print "gs: %s" % gs cl = __import__("%s.gen" % gs, fromlist=[gs]) #cl = importlib.import_module("gen_scripts", "gen") #if debug: # print "cl: " + str(cl) Gen = getattr(gen, "Gen") if debug: print "Gen: " + str(Gen) self.gen_module = __import__("%s.%s" % (gs, file_dict["gen_script"]), fromlist=[gs]) gen_success_flag = False #find the script and dynamically add it for name in dir(self.gen_module): obj = getattr(self.gen_module, name) # print "object type: " + str(obj) #XXX: debug section start if verbose: print "name: " + name if isclass(obj): if verbose: print "\tobject type: " + str(obj) print "\tis class" if issubclass(obj, cl.Gen): if verbose: print "\t\tis subclass" #XXX: debug section end if isclass(obj) and issubclass(obj, cl.Gen) and obj is not cl.Gen: self.gen = obj() if verbose: print "obj = " + str(self.gen) self.buf = self.gen.gen_script(tags = self.tags, buf = self.buf, user_paths = self.user_paths) gen_success_flag = True if not gen_success_flag: raise ModuleFactoryError("Failed to execute the generation script %s" % file_dict["gen_script"]) else: #no script to execute, just tags self.apply_tags() if verbose: print self.buf if (len(self.buf) > 0): result = self.write_file(directory, filename) if self.has_dependencies(filename): deps = self.get_list_of_dependencies(filename) for d in deps: try: f = utils.find_module_filename(d, self.user_paths) if (len(f) == 0): print "Error: couldn't find dependency filename" continue if (f not in self.verilog_dependency_list and f not in self.verilog_file_list): if debug: print "found dependency: " + f self.verilog_dependency_list.append(f) except ModuleNotFound as err: continue
def _resolve_dependency_for_module(self, module_path): vpos = 0 buf = "" try: filein = open(module_path) buf = str(filein.read()) filein.close() except IOError as e: raise ModuleError("File %s not found" % module_path) buf = utils.remove_comments(buf) include_buf = buf while len(include_buf.partition("`include")[2]) > 0: ifname = include_buf.partition("`include")[2] ifname = ifname.splitlines()[0] ifname = ifname.strip() ifname = ifname.strip("\"") #self.logger.debug("Found ifname: %s" % ifname) module = None try: filename = utils.find_module_filename(ifname, self.user_paths) module_tags = vutils.get_module_tags(filename, self.user_paths) module = Module(module_tags, path = filename, user_paths = self.user_paths, instance_name = None, is_include_file = True, depth = self.depth + 1) except ModuleError: self.logger.debug("Didn't find verilog module with filename: %s" % ifname) module_tags = {} module_tags["module"] = ifname module = Module(module_tags, path = None, user_paths = self.user_paths, instance_name = None, is_include_file = True, depth = self.depth + 1) module.set_vpos(vpos) vpos + 1 include_buf = include_buf.partition("`include")[2] for n in module.get_module_graph().nodes(): #m = module.get_module_graph().node[n] #self.graph.add_node(n) #self.graph.node[n] = m #if n not in self.graph.nodes(): m = module.get_module_graph().node[n] self.graph.add_node(id(m)) self.graph.node[id(m)] = m self.graph.add_edges_from(module.get_module_graph().edges()) self.graph.add_edge(id(self), id(module)) self.logger.debug("Looking for actual modules...") module_dict = self.find_modules_within_buffer(buf.partition(")")[2]) for instance in module_dict: module_type = module_dict[instance] self.logger.info("module_type: %s" % module_type) module = None #print "Module Type: %s" % module_type try: filename = utils.find_module_filename(module_type, self.user_paths) #print "Filename: %s" % filename module_tags = vutils.get_module_tags(filename, user_paths = self.user_paths) #print "got tags..." module = Module(module_tags, path = filename, user_paths = self.user_paths, instance_name = instance, is_include_file = False, depth = self.depth + 1) except ModuleError: #self.logger.debug("Didn't find verilog module with filename :%s" % module_type) module_tags = {} module_tags["module"] = module_type module = Module(module_tags, path = None, user_paths = self.user_paths, instance_name = instance, is_include_file = False, depth = self.depth + 1) for n in module.get_module_graph().nodes(): m = module.get_module_graph().node[n] self.graph.add_node(id(m)) self.graph.node[id(m)] = m module.set_vpos(vpos) vpos + 1 #self.graph.add_nodes_from(module.get_module_graph().nodes()) self.graph.add_edges_from(module.get_module_graph().edges()) self.graph.add_edge(id(self), id(module))
def _resolve_dependency_for_module(self, module_path): vpos = 0 buf = "" try: filein = open(module_path) buf = str(filein.read()) filein.close() except IOError as e: raise ModuleError("File %s not found" % module_path) buf = utils.remove_comments(buf) include_buf = buf while len(include_buf.partition("`include")[2]) > 0: ifname = include_buf.partition("`include")[2] ifname = ifname.splitlines()[0] ifname = ifname.strip() ifname = ifname.strip("\"") #self.logger.debug("Found ifname: %s" % ifname) module = None try: filename = utils.find_module_filename(ifname, self.user_paths) module_tags = vutils.get_module_tags(filename, self.user_paths) module = Module(module_tags, path=filename, user_paths=self.user_paths, instance_name=None, is_include_file=True, depth=self.depth + 1) except ModuleError: self.logger.debug( "Didn't find verilog module with filename: %s" % ifname) module_tags = {} module_tags["module"] = ifname module = Module(module_tags, path=None, user_paths=self.user_paths, instance_name=None, is_include_file=True, depth=self.depth + 1) module.set_vpos(vpos) vpos + 1 include_buf = include_buf.partition("`include")[2] for n in module.get_module_graph().nodes(): #m = module.get_module_graph().node[n] #self.graph.add_node(n) #self.graph.node[n] = m #if n not in self.graph.nodes(): m = module.get_module_graph().node[n] self.graph.add_node(id(m)) self.graph.node[id(m)] = m self.graph.add_edges_from(module.get_module_graph().edges()) self.graph.add_edge(id(self), id(module)) self.logger.debug("Looking for actual modules...") module_dict = self.find_modules_within_buffer(buf.partition(")")[2]) for instance in module_dict: module_type = module_dict[instance] self.logger.info("module_type: %s" % module_type) module = None #print "Module Type: %s" % module_type try: filename = utils.find_module_filename(module_type, self.user_paths) #print "Filename: %s" % filename module_tags = vutils.get_module_tags( filename, user_paths=self.user_paths) #print "got tags..." module = Module(module_tags, path=filename, user_paths=self.user_paths, instance_name=instance, is_include_file=False, depth=self.depth + 1) except ModuleError: #self.logger.debug("Didn't find verilog module with filename :%s" % module_type) module_tags = {} module_tags["module"] = module_type module = Module(module_tags, path=None, user_paths=self.user_paths, instance_name=instance, is_include_file=False, depth=self.depth + 1) for n in module.get_module_graph().nodes(): m = module.get_module_graph().node[n] self.graph.add_node(id(m)) self.graph.node[id(m)] = m module.set_vpos(vpos) vpos + 1 #self.graph.add_nodes_from(module.get_module_graph().nodes()) self.graph.add_edges_from(module.get_module_graph().edges()) self.graph.add_edge(id(self), id(module))