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_python(l = "") ⇒ Object
Convert to Python 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+.
2066 2067 2068 2069 2070 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2066 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.
2081 2082 2083 2084 2085 2086 2087 2088 2089 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2081 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 @sequencer.clk_up_c + "\n#{@sel.to_c} ? #{@choices[1].to_c} : #{@choices[0].to_c}" + @sequencer.clk_up_c end |
#to_python(l = "") ⇒ Object
Convert to Python code.
2092 2093 2094 2095 2096 2097 2098 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2092 def to_python(l = "") return @sequencer.clk_up_python(l) + "\n#{l}match #{@sel.to_python}:\n" + @choices.map.with_index do |choice,i| "#{l} case #{i}:\n #{choice.to_python(l + " ")}\n" end.join + @sequencer.clk_up_pyhton(l) end |
#to_ruby ⇒ Object
Convert to Ruby code.
2073 2074 2075 2076 2077 2078 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2073 def to_ruby return @sequencer.clk_up + "\ncase(#{@sel.to_ruby}) ; " + @choices.map.with_index do |choice,i| "when #{i} ; #{choice.to_ruby} ; " end.join + "end\n" + @sequencer.clk_up end |