Class: LibFST::Reader::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/libfst/reader.rb,
ext/libfst_rb.c

Overview

A Scope corresponds to a design element

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesArray<Attribute>

Returns:



146
147
148
# File 'lib/libfst/reader.rb', line 146

def attributes
  @attributes
end

#childrenArray<Scope> (readonly)

Returns:



148
149
150
# File 'lib/libfst/reader.rb', line 148

def children
  @children
end

#componentString? (readonly)

Returns:

  • (String, nil)


144
145
146
# File 'lib/libfst/reader.rb', line 144

def component
  @component
end

#nameString (readonly)

Returns:

  • (String)


143
144
145
# File 'lib/libfst/reader.rb', line 143

def name
  @name
end

#parentScope?

Returns:



147
148
149
# File 'lib/libfst/reader.rb', line 147

def parent
  @parent
end

#typeSymbol (readonly)

Returns Either :vcd_module, :vcd_task, :vcd_function, :vcd_begin, :vcd_fork, :vcd_generate, :vcd_struct, :vcd_union, :vcd_class, :vcd_interface, :vcd_package, :vcd_program, :vhdl_architecture, :vhdl_procedure, :vhdl_function, :vhdl_record, :vhdl_process, :vhdl_block, :vhdl_for_generate, :vhdl_if_generate, :vhdl_generate or :vhdl_package.

Returns:

  • (Symbol)

    Either :vcd_module, :vcd_task, :vcd_function, :vcd_begin, :vcd_fork, :vcd_generate, :vcd_struct, :vcd_union, :vcd_class, :vcd_interface, :vcd_package, :vcd_program, :vhdl_architecture, :vhdl_procedure, :vhdl_function, :vhdl_record, :vhdl_process, :vhdl_block, :vhdl_for_generate, :vhdl_if_generate, :vhdl_generate or :vhdl_package



142
143
144
# File 'lib/libfst/reader.rb', line 142

def type
  @type
end

#variablesArray<Variable> (readonly)

Returns:



145
146
147
# File 'lib/libfst/reader.rb', line 145

def variables
  @variables
end

Instance Method Details

#pathString

Returns:

  • (String)


162
163
164
165
166
167
168
169
170
171
# File 'lib/libfst/reader.rb', line 162

def path
  return @path if @path
  s = self
  p = ''
  until s.nil?
    p = "/#{s.name}#{p}"
    s = s.parent
  end
  @path = p
end

#to_sString

Returns:

  • (String)


174
175
176
# File 'lib/libfst/reader.rb', line 174

def to_s
  "<#{self.class.name} #{path}, type: #{@type}, component: \"#{@component}\">"
end

#treeString

Returns:

  • (String)


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/libfst/reader.rb', line 180

def tree(prefix = '', last: true, first: true)
  str = prefix + (first ? '' : (last ? '└─ ' : '├─ '))
  str += "\e[34;1m#{@name}\e[0m (#{@type})\n"
  prefix += (first ? '' : (last ? '   ' : '│  '))
  mxvarnamelen = ([0] + @variables.collect{|v| v.name.length}).max
  mxlenlen = ([0] + @variables.collect { |v| v.length == 0 ? 0 : v.length.to_s.length }).max
  @variables.each_with_index do |v, i|
    l = (@children.empty? and (i+1 == @variables.length))
    str += prefix + (l ? '└─ ' : '├─ ') + v.name + ' '*(mxvarnamelen+1-v.name.length)
    str += case v.direction
           when :input  then ' I '
           when :output then ' O '
           when :inout  then 'IO '
           else              '   '
           end
    str += (v.length > 0 ? v.length.to_s : '').rjust(mxlenlen)
    str += " #{v.type}\n"
  end
  @children.each_with_index do |c, i|
    str += c.tree(prefix, (i+1 == @children.length), false)
  end
  str
end