Class: HDLRuby::HDRLoad
- Inherits:
-
Object
- Object
- HDLRuby::HDRLoad
- Defined in:
- lib/HDLRuby/hdrcc.rb
Overview
Class for loading HDLRuby files.
Constant Summary collapse
- TOP_NAME =
TOP_NAME = "hdr_top_instance"
"__"
Instance Attribute Summary collapse
-
#requires ⇒ Object
readonly
The required files.
-
#top_instance ⇒ Object
readonly
The top instance, only accessible after parsing the files.
Instance Method Summary collapse
-
#check_all ⇒ Object
Checks the read files.
-
#get_top ⇒ Object
Gets the (first) top system.
-
#initialize(top_system, top_file, dir, *params) ⇒ HDRLoad
constructor
Creates a new loader for a +top_system+ system in file +top_file+ from directory +dir+ with generic parameters +params+.
-
#parse ⇒ Object
Load the HDLRuby structure from an instance of the top module.
-
#read(file) ⇒ Object
Loads a single +file+.
-
#read_all(file = @top_file) ⇒ Object
Loads all the files from +file+.
-
#show_all(outfile = $stdout) ⇒ Object
Displays the syntax tree of all the files.
Constructor Details
#initialize(top_system, top_file, dir, *params) ⇒ HDRLoad
Creates a new loader for a +top_system+ system in file +top_file+ from directory +dir+ with generic parameters +params+.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/HDLRuby/hdrcc.rb', line 53 def initialize(top_system,top_file,dir,*params) # Sets the top and the looking directory. @top_system = top_system.to_s @top_file = top_file.to_s @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 |
Instance Attribute Details
#requires ⇒ Object (readonly)
The required files.
49 50 51 |
# File 'lib/HDLRuby/hdrcc.rb', line 49 def requires @requires end |
#top_instance ⇒ Object (readonly)
The top instance, only accessible after parsing the files.
46 47 48 |
# File 'lib/HDLRuby/hdrcc.rb', line 46 def top_instance @top_instance end |
Instance Method Details
#check_all ⇒ Object
Checks the read files.
126 127 128 |
# File 'lib/HDLRuby/hdrcc.rb', line 126 def check_all @checks.each { |check| check.assign_check } end |
#get_top ⇒ Object
Gets the (first) top system.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/HDLRuby/hdrcc.rb', line 137 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 ⇒ Object
Load the HDLRuby structure from an instance of the top module.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/HDLRuby/hdrcc.rb', line 164 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,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,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) ⇒ Object
Loads a single +file+.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/HDLRuby/hdrcc.rb', line 83 def read(file) # Resolve the file. found = File.join(@dir,file) unless File.exist?(found) then founds = Dir.glob(@std_dirs.map {|path| File.join(path,file) }) 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 # Load the file. # @texts << File.read(File.join(@dir,file) ) @texts << File.read(found) # @checks << Checker.new(@texts[-1],file) @checks << Checker.new(@texts[-1],found) return true end |
#read_all(file = @top_file) ⇒ Object
Loads all the files from +file+.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/HDLRuby/hdrcc.rb', line 107 def read_all(file = @top_file) # 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) ⇒ Object
Displays the syntax tree of all the files.
131 132 133 134 |
# File 'lib/HDLRuby/hdrcc.rb', line 131 def show_all(outfile = $stdout) # puts "@checks.size=#{@checks.size}" @checks.each { |check| check.show(outfile) } end |