Class: Verilog::File
- Inherits:
-
Object
- Object
- Verilog::File
- Defined in:
- lib/verilog/file.rb
Overview
< Class::File
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #absolute_filename ⇒ Object
- #includes ⇒ Object
-
#initialize(filename, options = {}) ⇒ File
constructor
A new instance of File.
- #instantiations ⇒ Object
- #module_name ⇒ Object
- #read ⇒ Object
-
#read_from_disk ⇒ Object
Alias method.
- #save ⇒ Object
Constructor Details
#initialize(filename, options = {}) ⇒ File
Returns a new instance of File.
8 9 10 11 12 |
# File 'lib/verilog/file.rb', line 8 def initialize( filename, ={} ) @filename = filename @options = @options[:path] ||= '' end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
6 7 8 |
# File 'lib/verilog/file.rb', line 6 def contents @contents end |
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/verilog/file.rb', line 6 def filename @filename end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/verilog/file.rb', line 5 def @options end |
Instance Method Details
#absolute_filename ⇒ Object
37 38 39 |
# File 'lib/verilog/file.rb', line 37 def absolute_filename ::File.join( @options[:path], @filename ) end |
#includes ⇒ Object
58 59 60 61 62 63 |
# File 'lib/verilog/file.rb', line 58 def includes inc = [] @contents.scan(/(^\s*`include [\'\"])(.*)([\'\"])/i){ inc << $2 } return inc end |
#instantiations ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/verilog/file.rb', line 49 def instantiations inst = [] @contents.scan(/(^\s*)(\w*)\s+\w+\s*(\([.,\(\)\w\s]*\))?;/mi){ inst << $2 } #Hack, module will also match the instatiation syntax, rempve via array subtraction inst = inst - ['module'] return inst end |
#module_name ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/verilog/file.rb', line 41 def module_name if @contents.match(/(^\s*module *)(.*)(;|\s*\()/i) return $2 else return "" end end |
#read ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/verilog/file.rb', line 19 def read if ::File.exist?( absolute_filename ) ::File.open( absolute_filename, "rb") do |f| @contents = f.read end else #TODO raise correct exception here puts "ERROR File Not Found #{absolute_filename}" end end |
#read_from_disk ⇒ Object
Alias method
15 16 17 |
# File 'lib/verilog/file.rb', line 15 def read_from_disk read() end |
#save ⇒ Object
31 32 33 34 35 |
# File 'lib/verilog/file.rb', line 31 def save ::File.open( absolute_filename, "w" ) do |f| f.write @contents end end |