Class: Verilog::File

Inherits:
Object
  • Object
show all
Defined in:
lib/verilog/file.rb

Overview

< Class::File

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={} )
  @filename         = filename
  @options          = options
  @options[:path] ||= ''
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



6
7
8
# File 'lib/verilog/file.rb', line 6

def contents
  @contents
end

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/verilog/file.rb', line 6

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/verilog/file.rb', line 5

def options
  @options
end

Instance Method Details

#absolute_filenameObject



37
38
39
# File 'lib/verilog/file.rb', line 37

def absolute_filename
  ::File.join( @options[:path], @filename ) 
end

#includesObject



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

#instantiationsObject



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_nameObject



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

#readObject



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_diskObject

Alias method



15
16
17
# File 'lib/verilog/file.rb', line 15

def read_from_disk
  read()
end

#saveObject



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