Module: HDLRuby::High::Hmux
Overview
Module providing methods for declaring select expressions.
Instance Method Summary collapse
-
#mux(select, *choices) ⇒ Object
Creates an operator selecting from +select+ one of the +choices+.
Instance Method Details
#mux(select, *choices) ⇒ Object
Creates an operator selecting from +select+ one of the +choices+.
NOTE: * +choices+ can either be a list of arguments or an array. If +choices+ has only two entries (and it is not a hash), +value+ will be converted to a boolean. * The type of the select is computed as the largest no integer-constant choice. If only constant integer choices, use the largest type of them.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/HDLRuby/hruby_high.rb', line 209 def mux(select,*choices) # Process the choices. choices = choices.flatten(1) if choices.size == 1 choices.map! { |choice| choice.to_expr } # Compute the type of the select as the largest no # integer-constant type. # If only such constants, use the largest type of them. type = choices.reduce(Bit) do |type,choice| unless choice.is_a?(Value) && choice.type == Integer then type.width >= choice.type.width ? type : choice.type else type end end unless type then type = choices.reduce(Bit) do |type,choice| type.width >= choice.type.width ? type : choice.type end end # Generate the select expression. return Select.new(type,"?",select.to_expr,*choices) end |