Class: VhdlDoctest::Types::StdLogicVector

Inherits:
Object
  • Object
show all
Defined in:
lib/vhdl_doctest/types/std_logic_vector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length) ⇒ StdLogicVector

Returns a new instance of StdLogicVector.



3
4
5
# File 'lib/vhdl_doctest/types/std_logic_vector.rb', line 3

def initialize(length)
  @length = length
end

Class Method Details

.parse(str) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/vhdl_doctest/types/std_logic_vector.rb', line 15

def self.parse(str)
  str = str.strip
  if str.match(/\Astd_logic_vector/i)
    if str.strip.match(/\((\d+)\s+downto\s+0\)\Z/i)
      new($1.to_i + 1)
    else
      raise "#{ str } is std_logic_vector, but not 'x downto 0'"
    end
  end
end

Instance Method Details

#format(v) ⇒ Object



11
12
13
# File 'lib/vhdl_doctest/types/std_logic_vector.rb', line 11

def format(v)
  '"' + (2**@length + v).to_s(2)[-@length.. -1]+ '"'
end

#to_vhdlObject



7
8
9
# File 'lib/vhdl_doctest/types/std_logic_vector.rb', line 7

def to_vhdl
  "std_logic_vector(#{@length-1} downto 0)"
end