Class: RubyHDL::High::Select
- Inherits:
-
Expression
- Object
- Expression
- RubyHDL::High::Select
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes the software implementation of an select operation.
Instance Attribute Summary
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(type, operator, sel, *choices) ⇒ Select
constructor
Create a new select operation with +type+ data type, selection operand +sel+ and possible choices +choices+.
-
#to_c ⇒ Object
Convert to C code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
Methods inherited from Expression
#<=, #[], #mux, #sdownto, #seach, #stimes, #supto, #to_expr, #to_value
Constructor Details
#initialize(type, operator, sel, *choices) ⇒ Select
Create a new select operation with +type+ data type, selection operand +sel+ and possible choices +choices+.
1993 1994 1995 1996 1997 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1993 def initialize(type,operator,sel,*choices) super(type) @sel = sel.to_expr @choices = choices.map(&:to_expr) end |
Instance Method Details
#to_c ⇒ Object
Convert to C code.
2008 2009 2010 2011 2012 2013 2014 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2008 def to_c # return "switch(#{@sel.to_c}) {\n" + # @choices.map.with_index do |choice,i| # "case #{i}:\n#{choice.to_c}\nbreak;" # end.join("\n") + "\n}" return "#{@sel.to_c} ? #{@choices[1].to_c} : #{@choices[0].to_c}" end |
#to_ruby ⇒ Object
Convert to Ruby code.
2000 2001 2002 2003 2004 2005 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2000 def to_ruby return "case(#{@sel.to_ruby}) ; " + @choices.map.with_index do |choice,i| "when #{i} ; #{choice.to_ruby} ; " end.join + "end" end |