Class: HDLRuby::HDRLoad
- Inherits:
-
Object
- Object
- HDLRuby::HDRLoad
- Defined in:
- lib/HDLRuby/hdrcc.rb,
lib/HDLRuby/hdrlib.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_name+ 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 = nil) ⇒ 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_name+ from directory +dir+ with generic parameters +params+.
NOTE: +top_file+ can either be a file or a file name.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/HDLRuby/hdrcc.rb', line 111 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 |
Instance Attribute Details
#requires ⇒ Object (readonly)
The required files.
105 106 107 |
# File 'lib/HDLRuby/hdrcc.rb', line 105 def requires @requires end |
#top_instance ⇒ Object (readonly)
The top instance, only accessible after parsing the files.
102 103 104 |
# File 'lib/HDLRuby/hdrcc.rb', line 102 def top_instance @top_instance end |
Instance Method Details
#check_all ⇒ Object
Checks the read files.
208 209 210 |
# File 'lib/HDLRuby/hdrcc.rb', line 208 def check_all @checks.each { |check| check.assign_check } end |
#get_top ⇒ Object
Gets the (first) top system.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/HDLRuby/hdrcc.rb', line 219 def get_top # Get all the systems. systems = @checks.reduce([]) {|ar,check| ar + check.get_all_systems} # show? "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 # show? "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.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/HDLRuby/hdrcc.rb', line 246 def parse # Is there a top system specified yet? if @top_system == "" then # No, look for it. @top_system = get_top # show? "@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) ⇒ Object
Loads a single +file+.
NOTE: +file+ can either be a file or a file name.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/HDLRuby/hdrcc.rb', line 150 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. # show? "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) ⇒ Object
Loads all the files from +file+.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/HDLRuby/hdrcc.rb', line 182 def read_all(file = nil) unless file then if @top_file then file = @top_file else file = @top_file_name end end # show? "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.
213 214 215 216 |
# File 'lib/HDLRuby/hdrcc.rb', line 213 def show_all(outfile = $stdout) # show? "@checks.size=#{@checks.size}" @checks.each { |check| check.show(outfile) } end |