def simulate( self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None ): """ Invoke the simulator and target the given *entity* in the given *library*. If the optional argument *gui* is set to False the simulator will execute as a console application otherwise it will run as a GUI. This function is blocking and will only continue when the simulator terminates. The optional argument *generics* provides a dictionary of *generic name*/*generic value*key, value pairs that are passed to the simulator as a command line argument. This allowsyou to set generics present on the entity being simulated. The optional argument *do* can be used to supply a string argument to be interpreted by the simulator as a script to execute after loading. """ # Add any custom arguments from the project file arguments = self.project.get_tool_arguments(self.name, 'simulate') arguments = shlex.split(['', arguments][arguments is not None]) arguments += args # Add any includes for libname, path in includes.items(): arguments += ['-L', libname] # Add project libraries for libname in self.project.get_libraries(): arguments += ['-L', libname] # Map any generics for name, binding in generics.items(): arguments += ['-G{0}={1}'.format(name, binding)] # Enable or disable the GUI arguments += [['-c'], ['-i']][gui] # Apply any DO commands if duration is not None: if duration <= 0: duration = '-all' else: duration = utils.seconds_to_timestring(duration) do = 'set NumericStdNoWarnings 1\n' + 'run ' + duration + ';quit' arguments += ['-do', '{0}'.format(do)] # Finish processing arguments and invoke vsim # arguments += ['-L ' + library for library in includes.keys()] arguments += ['{0}.{1}'.format(library, entity)] ret, stdout, stderr = Modelsim._call( self.vsim, arguments, cwd=self.project.get_simulation_directory(), quiet=False ) return ret, stdout, stderr
def simulate( self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None ): cwd = self.project.get_simulation_directory() # Execute FUSE on the design files: fuse_args = [ library + '.' + entity, '-o', self.sim_exe_name, ] # Set simulator generics for name, binding in generics.items(): fuse_args += ['--generic_top', name + '=' + str(binding)] Isim._call(self.fuse, fuse_args, cwd=cwd, quiet=False) # Fuse generates a simulation executable, this can be called now with # the specified simulator arguments: sim_args = [] if gui: sim_args += ['-gui'] # Create a TCL file: with open(os.path.join(cwd, self.sim_tcl_name), 'w') as f: # Set run duration if duration is not None: if duration <= 0: duration = 'all' else: duration = utils.seconds_to_timestring(duration) f.write('run {0}\n'.format(duration)) f.write('exit\n') sim_args += ['-tclbatch', self.sim_tcl_name] # Run the simulation ret, stdout, stderr = Isim._call( os.path.join(cwd, self.sim_exe_name), sim_args, cwd=self.project.get_simulation_directory(), quiet=False ) return ret, stdout, stderr
def simulate(self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None): cwd = self.project.get_simulation_directory() # Execute FUSE on the design files: fuse_args = [ library + '.' + entity, '-o', self.sim_exe_name, ] # Set simulator generics for name, binding in generics.items(): fuse_args += ['--generic_top', name + '=' + str(binding)] Isim._call(self.fuse, fuse_args, cwd=cwd, quiet=False) # Fuse generates a simulation executable, this can be called now with # the specified simulator arguments: sim_args = [] if gui: sim_args += ['-gui'] # Create a TCL file: with open(os.path.join(cwd, self.sim_tcl_name), 'w') as f: # Set run duration if duration is not None: if duration <= 0: duration = 'all' else: duration = utils.seconds_to_timestring(duration) f.write('run {0}\n'.format(duration)) f.write('exit\n') sim_args += ['-tclbatch', self.sim_tcl_name] # Run the simulation ret, stdout, stderr = Isim._call( os.path.join(cwd, self.sim_exe_name), sim_args, cwd=self.project.get_simulation_directory(), quiet=False) return ret, stdout, stderr
def simulate( self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None ): # Elaborate args = [ '-e', '--work=' + library, entity, ] Ghdl._call( self.ghdl, args, cwd=self.project.get_simulation_directory() ) # Run command args = [ '-r', '--work=' + library, ] # Primary Unit args += [entity] # Map any generics for name, binding in generics.items(): args += ['-g{0}={1}'.format(name, binding)] if duration is not None: if duration > 0: args += [ '--stop-time=' + utils.seconds_to_timestring(duration) ] # Run the simulation ret, stdout, stderr = Ghdl._call( self.ghdl, args, cwd=self.project.get_simulation_directory(), quiet=False ) return ret, stdout, stderr
def simulate(self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None): # Elaborate args = [ '-e', '--work=' + library, entity, ] Ghdl._call(self.ghdl, args, cwd=self.project.get_simulation_directory()) # Run command args = [ '-r', '--work=' + library, ] # Primary Unit args += [entity] # Map any generics for name, binding in generics.items(): args += ['-g{0}={1}'.format(name, binding)] if duration is not None: if duration > 0: args += [ '--stop-time=' + utils.seconds_to_timestring(duration) ] # Run the simulation ret, stdout, stderr = Ghdl._call( self.ghdl, args, cwd=self.project.get_simulation_directory(), quiet=False) return ret, stdout, stderr
def simulate(self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None): cwd = self.project.get_simulation_directory() # Set simulator generics # NOTE: Different behavior is required when calling xelab on Windows # as the command line argument to xelab '-generic_top' does not work # correctly. See: https://github.com/pabennett/chiptools/issues/1 if sys.platform == "win32": xelab_args = "" # use a string sequence for Vivado on Windows if gui: xelab_args += "-debug all" # Add generics for name, binding in generics.items(): # TODO: The -generic_top argument formatting is hacked here for # Vivado simulator on Windows. Xilinx may address this issue in # the future, which will mean this code needs modifying again. # The issue is present in Vivado 2015.4 xelab_args += "-generic_top" + " " + name + '"' + "=" + '"' + str(binding) + " " # Add external includes for libname, path in includes.items(): xelab_args += "-lib" + " " + libname + '"' + "=" + '"' + path + " " # Add project libraries for libname in self.project.get_libraries(): xelab_args += "-lib" + " " + libname + '"' + "=" + '"' + libname + " " # Library Name # Library Path # Execute XELAB on the design files: xelab_args += " " + library + "." + str(entity) xelab_args += " " + "-s" + " " + str(entity) Vivado._call_str_args(self.xelab, xelab_args, cwd=cwd, quiet=False) else: # Normal behavior on other platforms. xelab_args = [] if gui: xelab_args += ["-debug", "all"] # Add generics for name, binding in generics.items(): xelab_args += ["-generic_top", name + "=" + str(binding) + " "] # Add external includes for libname, path in includes.items(): xelab_args += ["-lib", libname + "=" + str(path) + " "] # Add project libraries for libname in self.project.get_libraries(): xelab_args += ["-lib", libname + "=" + str(libname) + " "] # Execute XELAB on the design files: xelab_args += [library + "." + str(entity)] xelab_args += ["-s", str(entity)] Vivado._call(self.xelab, xelab_args, cwd=cwd, quiet=False) # Fuse generates a simulation executable, this can be called now with # the specified simulator arguments: sim_args = [] if gui: sim_args += ["-gui"] sim_args += ["-onfinish", "stop"] sim_args += ["-onerror", "stop"] else: sim_args += ["-onfinish", "quit"] sim_args += ["-onerror", "quit"] # Create a TCL file: with open(os.path.join(cwd, self.sim_tcl_name), "w") as f: # Set run duration if duration is not None: if duration <= 0: duration = "all" else: duration = utils.seconds_to_timestring(duration) f.write( ( "if { [catch {%(command)s} result] } {\n" + ' puts stderr "Command failed: $result"\n' + " exit 1\n" + "}\n" ) % dict(command="run {0}\n".format(duration)) ) f.write("exit\n") sim_args += ["-tclbatch", self.sim_tcl_name] # Path to snapshot to execute sim_args += [entity] # Run the simulation ret, stdout, stderr = Vivado._call( self.xsim, sim_args, cwd=self.project.get_simulation_directory(), quiet=False ) return ret, stdout, stderr
def simulate(self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None): cwd = self.project.get_simulation_directory() # Set simulator generics # NOTE: Different behavior is required when calling xelab on Windows # as the command line argument to xelab '-generic_top' does not work # correctly. See: https://github.com/pabennett/chiptools/issues/1 if sys.platform == 'win32': xelab_args = '' # use a string sequence for Vivado on Windows if gui: xelab_args += '-debug all' # Add generics for name, binding in generics.items(): # TODO: The -generic_top argument formatting is hacked here for # Vivado simulator on Windows. Xilinx may address this issue in # the future, which will mean this code needs modifying again. # The issue is present in Vivado 2015.4 xelab_args += ('-generic_top' + ' ' + name + '\"' + '=' + '\"' + str(binding) + ' ') # Add external includes for libname, path in includes.items(): xelab_args += ('-lib' + ' ' + libname + '\"' + '=' + '\"' + path + ' ') # Add project libraries for libname in self.project.get_libraries(): xelab_args += ( '-lib' + ' ' + libname + # Library Name '\"' + '=' + '\"' + libname + ' ' # Library Path ) # Execute XELAB on the design files: xelab_args += (' ' + library + '.' + str(entity)) xelab_args += (' ' + '-s' + ' ' + str(entity)) Vivado._call_str_args(self.xelab, xelab_args, cwd=cwd, quiet=False) else: # Normal behavior on other platforms. xelab_args = [] if gui: xelab_args += ['-debug', 'all'] # Add generics for name, binding in generics.items(): xelab_args += [ '-generic_top', name + '=' + str(binding) + ' ', ] # Add external includes for libname, path in includes.items(): xelab_args += [ '-lib', libname + '=' + str(path) + ' ', ] # Add project libraries for libname in self.project.get_libraries(): xelab_args += [ '-lib', libname + '=' + str(libname) + ' ', ] # Execute XELAB on the design files: xelab_args += [library + '.' + str(entity)] xelab_args += ['-s', str(entity)] Vivado._call(self.xelab, xelab_args, cwd=cwd, quiet=False) # Fuse generates a simulation executable, this can be called now with # the specified simulator arguments: sim_args = [] if gui: sim_args += ['-gui'] sim_args += ['-onfinish', 'stop'] sim_args += ['-onerror', 'stop'] else: sim_args += ['-onfinish', 'quit'] sim_args += ['-onerror', 'quit'] # Create a TCL file: with open(os.path.join(cwd, self.sim_tcl_name), 'w') as f: # Set run duration if duration is not None: if duration <= 0: duration = 'all' else: duration = utils.seconds_to_timestring(duration) f.write(('if { [catch {%(command)s} result] } {\n' + ' puts stderr \"Command failed: $result\"\n' + ' exit 1\n' + '}\n') % dict(command='run {0}\n'.format(duration))) f.write('exit\n') sim_args += ['-tclbatch', self.sim_tcl_name] # Path to snapshot to execute sim_args += [entity] # Run the simulation ret, stdout, stderr = Vivado._call( self.xsim, sim_args, cwd=self.project.get_simulation_directory(), quiet=False) return ret, stdout, stderr
def simulate( self, library, entity, gui=False, generics={}, includes={}, args=[], duration=None ): cwd = self.project.get_simulation_directory() # Set simulator generics # NOTE: Different behavior is required when calling xelab on Windows # as the command line argument to xelab '-generic_top' does not work # correctly. See: https://github.com/pabennett/chiptools/issues/1 if sys.platform == 'win32': xelab_args = '' # use a string sequence for Vivado on Windows if gui: xelab_args += '-debug all' for name, binding in generics.items(): # TODO: The -generic_top argument formatting is hacked here for # Vivado simulator on Windows. Xilinx may address this issue in # the future, which will mean this code needs modifying again. # The issue is present in Vivado 2015.4 xelab_args += ( '-generic_top' + ' ' + name.upper() + '\"' + '=' + '\"' + str(binding) + ' ' ) # Execute XELAB on the design files: xelab_args += (' ' + library + '.' + str(entity)) xelab_args += (' ' + '-s' + ' ' + str(entity)) Vivado._call_str_args(self.xelab, xelab_args, cwd=cwd, quiet=False) else: # Normal behavior on other platforms. xelab_args = [] if gui: xelab_args += ['-debug', 'all'] for name, binding in generics.items(): xelab_args += [ '-generic_top', name.upper() + '=' + str(binding) + ' ' , ] # Execute XELAB on the design files: xelab_args += [library + '.' + str(entity)] xelab_args += ['-s', str(entity)] Vivado._call(self.xelab, xelab_args, cwd=cwd, quiet=False) # Fuse generates a simulation executable, this can be called now with # the specified simulator arguments: sim_args = [] if gui: sim_args += ['-gui'] sim_args += ['-onfinish', 'stop'] sim_args += ['-onerror', 'stop'] else: sim_args += ['-onfinish', 'quit'] sim_args += ['-onerror', 'quit'] # Create a TCL file: with open(os.path.join(cwd, self.sim_tcl_name), 'w') as f: # Set run duration if duration is not None: if duration <= 0: duration = 'all' else: duration = utils.seconds_to_timestring(duration) f.write( ( 'if { [catch {%(command)s} result] } {\n' + ' puts stderr \"Command failed: $result\"\n' + ' exit 1\n' + '}\n' ) % dict(command='run {0}\n'.format(duration)) ) f.write('exit\n') sim_args += ['-tclbatch', self.sim_tcl_name] # Path to snapshot to execute sim_args += [entity] # Run the simulation ret, stdout, stderr = Vivado._call( self.xsim, sim_args, cwd=self.project.get_simulation_directory(), quiet=False ) return ret, stdout, stderr