class HDLRuby::HDRLoad
Class for loading HDLRuby
files.
Constants
- TOP_NAME
TOP_NAME
= “hdr_top_instance”
Attributes
requires[R]
The required files.
top_instance[R]
The top instance, only accessible after parsing the files.
Public Class Methods
new(top_system,top_file,dir,*params)
click to toggle source
Creates a new loader for a top_system
system in file top_file_name
from directory dir
with generic parameters params
.
NOTE: top_file
can either be a file or a file name.
# File lib/HDLRuby/hdrcc.rb, line 58 def initialize(top_system,top_file,dir,*params) # Sets the top and the looking directory. @top_system = top_system.to_s # @top_file can either be a file or a string giving the file name. if top_file.respond_to?(:path) then @top_file = top_file @top_file_name = top_file.path else @top_file = nil @top_file_name = top_file.to_s end @dir = dir.to_s @params = params # The list of the standard library files to exclude for # checking. # Get the directory of the HDLRuby and Ruby standard libraries. @std_dirs = $LOAD_PATH # @std_dirs << File.dirname(__FILE__) + "/std" # # Gather the files with their path to std. # @std_files = Dir[@std_dir + "/*"] # The list of required files. @requires = [] # The list of the code texts (the first one should be the one # containing the top system). @texts = [] # The list of the code checkers. @checks = [] # The name of the top instance @top_name = TOP_NAME end
Public Instance Methods
check_all()
click to toggle source
Checks the read files.
# File lib/HDLRuby/hdrcc.rb, line 155 def check_all @checks.each { |check| check.assign_check } end
get_top()
click to toggle source
Gets the (first) top system.
# File lib/HDLRuby/hdrcc.rb, line 166 def get_top # Get all the systems. systems = @checks.reduce([]) {|ar,check| ar + check.get_all_systems} # puts "First systems=#{systems}" # Remove the systems that are instantiated or included # (they cannot be tops) @checks.each do |check| # The instances check.get_all_instances(systems).each do |instance| systems.delete(check.get_instance_system(instance)) end # The explicitly included systems check.get_all_includes(systems).each do |included| systems.delete(check.get_include_system(included)) end # The system included when declaring (inheritance) check.get_all_inherits(systems).each do |inherit| systems -= check.get_inherit_systems(inherit) end end # puts "Now systems=#{systems}" # Return the first top of the list. return systems[-1] end
parse()
click to toggle source
Load the HDLRuby
structure from an instance of the top module.
# File lib/HDLRuby/hdrcc.rb, line 193 def parse # Is there a top system specified yet? if @top_system == "" then # No, look for it. @top_system = get_top # puts "@top_system=#{@top_system}" unless @top_system then # Not found? Error. # Maybe it is a parse error, look for it. bind = TOPLEVEL_BINDING.clone eval("require 'HDLRuby'\n\nconfigure_high\n\n",bind) eval(@texts[0],bind,@top_file_name,1) # No parse error found. raise "Cannot find a top system." unless @top_system end end # Initialize the environment for processing the hdr file. bind = TOPLEVEL_BINDING.clone eval("require 'HDLRuby'\n\nconfigure_high\n\n",bind) # Process it. eval(@texts[0],bind,@top_file_name,1) # Get the resulting instance if @params.empty? then # There is no generic parameter @top_instance = eval("#{@top_system} :#{@top_name}\n#{@top_name}",bind) else # There are generic parameters @top_instance = # eval("#{@top_system} :#{@top_name},#{@params.join(",")}\n#{@top_name}",bind) eval("#{@top_system}(#{@params.join(",")}).(:#{@top_name})\n#{@top_name}",bind) end end
read(file)
click to toggle source
Loads a single file
.
NOTE: file
can either be a file or a file name.
# File lib/HDLRuby/hdrcc.rb, line 97 def read(file) # Resolve the file. if file.respond_to?(:read) then found = file else found = File.join(@dir,file) unless File.exist?(found) then founds = Dir.glob(@std_dirs.map do |path| File.join(path,file) end) if founds.empty? then # No standard file with this name, this is an error. raise "Unknown required file: #{file}." else # A standard file is found, skip it since it does not # need to be read. # puts "Standard files: #{founds}" return false end end end # Load the file. @texts << File.read(found) if found.respond_to?(:path) then @checks << Checker.new(@texts[-1],found.path) else @checks << Checker.new(@texts[-1]) end return true end
read_all(file = nil)
click to toggle source
Loads all the files from file
.
# File lib/HDLRuby/hdrcc.rb, line 129 def read_all(file = nil) unless file then if @top_file then file = @top_file else file = @top_file_name end end # puts "read_all with file=#{file}" # Read the file # read(file) unless read(file) then # The file is to skip. return end # Get its required files. requires = @checks[-1].get_all_requires + @checks[-1].get_all_require_relatives requires.each do |file| read_all(file) end @requires += requires @requires.uniq! end
show_all(outfile = $stdout)
click to toggle source
Displays the syntax tree of all the files.
# File lib/HDLRuby/hdrcc.rb, line 160 def show_all(outfile = $stdout) # puts "@checks.size=#{@checks.size}" @checks.each { |check| check.show(outfile) } end