Class: HDLRuby::Low::Indexers

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/hruby_verilog.rb

Overview

Class for generating the truncating functions in verilog. Such function are necessary as expression cannot be truncated directly.

Instance Method Summary collapse

Constructor Details

#initializeIndexers

Returns a new instance of Indexers.



123
124
125
# File 'lib/HDLRuby/hruby_verilog.rb', line 123

def initialize
    @indexers = []
end

Instance Method Details

#add(typI, typR) ⇒ Object Also known as: <<

Add an indexer to of expression of verilog type +typI+ returning verilog type +typR+.



129
130
131
132
# File 'lib/HDLRuby/hruby_verilog.rb', line 129

def add(typI,typR)
    # Add them
    @indexers << [typI,typR]
end

#dumpObject

Generate the indexing functions.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/HDLRuby/hruby_verilog.rb', line 144

def dump
    # Ensure there is only one indexing function per range.
    @indexers.sort!.uniq!
    # Generate the resulting code.
    codeT = ""
    @indexers.each do |(typI,typR)|
        codeT << "     function #{typR} "
        codeT << self.indexer_name(typI,typR) 
        codeT << "(input #{typI} val, input integer idx);\n"
        codeT << "         " << self.indexer_name(typI,typR) << " = "
        codeT << "val[idx];\n"
        codeT << "      endfunction\n\n"
    end
    # Clears the indexers.
    @indexers = []
    return codeT
end

#indexer_name(typI, typR) ⇒ Object

Generate an indexer function name for expression of verilog type +typI+ returning verilog type +typR+.



138
139
140
141
# File 'lib/HDLRuby/hruby_verilog.rb', line 138

def indexer_name(typI,typR)
    # Generate the name.
    return "indexer_#{name_to_verilog(typI)}_#{name_to_verilog(typR)}"
end