Class: RubyHDL::High::Sblock
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a block.
Instance Attribute Summary collapse
-
#sequencer ⇒ Object
readonly
Returns the value of attribute sequencer.
Instance Method Summary collapse
-
#add(statement) ⇒ Object
(also: #<<)
Add a new statement to the block.
-
#delete(statement) ⇒ Object
Delete a statement.
-
#each_arg(&ruby_block) ⇒ Object
Iterate on the arguments if any.
-
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
-
#each_statement_deep(&ruby_block) ⇒ Object
Iterate deeply on the statements.
-
#hif(cond, &ruby_block) ⇒ Object
Create a sequential if statement on +cond+.
-
#hprint(*args) ⇒ Object
Displays a string for debugging purpose.
-
#initialize(sequencer, &ruby_block) ⇒ Sblock
constructor
Create a new block for sequencer +sequencer+ and fill it by executing +ruby_block+.
-
#last_statement ⇒ Object
Get the last statement.
-
#mux(cond, *choices) ⇒ Object
Implements a multiplexer.
-
#ruby(str = nil, &ruby_block) ⇒ Object
Some arbirary Ruby code as a string +str+ or as a proc +ruby_block+.
-
#sbreak ⇒ Object
Breaks current iteration.
-
#scontinue ⇒ Object
Continues current iteration.
-
#selse(&ruby_block) ⇒ Object
(also: #helse)
Create a sequential else statement.
-
#selsif(cond, &ruby_block) ⇒ Object
(also: #helsif)
Create a sequential elsif statement on +cond+.
-
#sfor(expr, &ruby_block) ⇒ Object
Create a sequential for statement iterating over the elements of +expr+.
-
#sif(cond, &ruby_block) ⇒ Object
Create a sequential if statement on +cond+.
-
#sloop(&ruby_block) ⇒ Object
Create a sequential infinite loop statement.
-
#sreturn(val) ⇒ Object
Create a return statement.
-
#step ⇒ Object
Mark a step.
-
#steps(num) ⇒ Object
Mark several steps.
-
#sterminate ⇒ Object
Terminates the sequencer.
-
#swait(cond) ⇒ Object
Wait a given condition.
-
#swhile(cond, &ruby_block) ⇒ Object
Create a sequential while statement on +cond+.
-
#sync ⇒ Object
Mark a synchronisation.
-
#text(str) ⇒ Object
Some arbitrary code whose text is to add direction.
-
#to_c ⇒ Object
Convert to C code.
-
#to_python(l = "") ⇒ Object
Convert to Python code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
-
#unshift(statement) ⇒ Object
Unshift a new statement.
Methods inherited from SblockTop
#callable, #callable?, #each_signal, #make_inners, #make_inputs, #make_outputs, #register
Constructor Details
#initialize(sequencer, &ruby_block) ⇒ Sblock
Create a new block for sequencer +sequencer+ and fill it by executing +ruby_block+
3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3811 def initialize(sequencer,&ruby_block) super() # Sets the sequencer. @sequencer = sequencer # Initialize the statements. @statements = [] # Push the new sblock on top of the stack. RubyHDL::High.push_sblock(self) # Make signals from the arguments of the ruby block. # unsigned 32-bit integers by default. @args = [] ruby_block.parameters.each do |typ,arg| # @args << SignalI.new(arg,Void,:inner) @args << SignalI.new(arg,bit[32],:inner) end # Fill it. self.instance_exec(*@args,&ruby_block) # Pop the new sblock. RubyHDL::High.pop_sblock end |
Instance Attribute Details
#sequencer ⇒ Object (readonly)
Returns the value of attribute sequencer.
3807 3808 3809 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3807 def sequencer @sequencer end |
Instance Method Details
#add(statement) ⇒ Object Also known as: <<
Add a new statement to the block.
3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3833 def add(statement) # Add the statement. @statements.push(statement) # # If the statement is a transmit, schedule the corresponding # # signal for final update. # if statement.is_a?(Transmit) then # @sequencer.to_update(statement.left) # end statement end |
#delete(statement) ⇒ Object
Delete a statement.
3861 3862 3863 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3861 def delete(statement) @statements.delete(statement) end |
#each_arg(&ruby_block) ⇒ Object
Iterate on the arguments if any.
3876 3877 3878 3879 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3876 def each_arg(&ruby_block) return to_enum(:each_arg) unless ruby_block @args.each(&ruby_block) end |
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
3846 3847 3848 3849 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3846 def each_statement(&ruby_block) return to_enum(:each_statement) unless ruby_block @statements.each { |statement| ruby_block(statement) } end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterate deeply on the statements.
3852 3853 3854 3855 3856 3857 3858 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3852 def each_statement_deep(&ruby_block) return to_enum(:each_statement_deep) unless ruby_block @statements.each do |statement| statement.each_statement_deep(&ruby_block) ruby_block(statement) end end |
#hif(cond, &ruby_block) ⇒ Object
Create a sequential if statement on +cond+.
3958 3959 3960 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3958 def hif(cond, &ruby_block) self << RubyHDL::High::Hif.new(@sequencer,cond,&ruby_block) end |
#hprint(*args) ⇒ Object
Displays a string for debugging purpose.
4004 4005 4006 4007 4008 4009 4010 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4004 def hprint(*args) # args.each do |arg| # arg = arg.to_value if arg.is_a?(RubyHDL::High::Expression) # print arg # end self << RubyHDL::High::Print.new(@sequencer,*args) end |
#last_statement ⇒ Object
Get the last statement.
3871 3872 3873 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3871 def last_statement return @statements[-1] end |
#mux(cond, *choices) ⇒ Object
Implements a multiplexer.
3999 4000 4001 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3999 def mux(cond, *choices) return Select.new(choices[0].type,:mux,cond,*choices) end |
#ruby(str = nil, &ruby_block) ⇒ Object
Some arbirary Ruby code as a string +str+ or as a proc +ruby_block+.
4023 4024 4025 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4023 def ruby(str = nil, &ruby_block) self << RubyHDL::High::Ruby.new(str,&ruby_block) end |
#sbreak ⇒ Object
Breaks current iteration.
3933 3934 3935 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3933 def sbreak self << RubyHDL::High::Sbreak.new(@sequencer) end |
#scontinue ⇒ Object
Continues current iteration.
3938 3939 3940 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3938 def scontinue self << RubyHDL::High::Scontinue.new(@sequencer) end |
#selse(&ruby_block) ⇒ Object Also known as: helse
Create a sequential else statement.
3969 3970 3971 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3969 def selse(&ruby_block) self.last_statement.selse(&ruby_block) end |
#selsif(cond, &ruby_block) ⇒ Object Also known as: helsif
Create a sequential elsif statement on +cond+.
3963 3964 3965 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3963 def selsif(cond, &ruby_block) self.last_statement.selsif(&ruby_block) end |
#sfor(expr, &ruby_block) ⇒ Object
Create a sequential for statement iterating over the elements of +expr+.
3991 3992 3993 3994 3995 3996 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3991 def sfor(expr,&ruby_block) # Ensures there is a ruby block to avoid returning an enumerator # (returning an enumerator would be confusing for a for statement). ruby_block = proc {} unless ruby_block self << expr.seach.with_index(&ruby_block) end |
#sif(cond, &ruby_block) ⇒ Object
Create a sequential if statement on +cond+.
3953 3954 3955 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3953 def sif(cond, &ruby_block) self << RubyHDL::High::Sif.new(@sequencer,cond,&ruby_block) end |
#sloop(&ruby_block) ⇒ Object
Create a sequential infinite loop statement.
3985 3986 3987 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3985 def sloop(&ruby_block) self << RubyHDL::High::Sloop.new(@sequencer,&ruby_block) end |
#sreturn(val) ⇒ Object
Create a return statement.
3943 3944 3945 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3943 def sreturn(val) self << RubyHDL::High::Sreturn.new(@sequencer,val) end |
#step ⇒ Object
Mark a step.
3923 3924 3925 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3923 def step self << RubyHDL::High::Step.new(@sequencer) end |
#steps(num) ⇒ Object
Mark several steps.
3928 3929 3930 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3928 def steps(num) num.times { self.step } end |
#sterminate ⇒ Object
Terminates the sequencer.
3948 3949 3950 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3948 def sterminate self << RubyHDL::High::Sterminate.new(@sequencer) end |
#swait(cond) ⇒ Object
Wait a given condition.
3975 3976 3977 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3975 def swait(cond) self.swhile(~cond) end |
#swhile(cond, &ruby_block) ⇒ Object
Create a sequential while statement on +cond+.
3980 3981 3982 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3980 def swhile(cond,&ruby_block) self << RubyHDL::High::Swhile.new(@sequencer,cond,&ruby_block) end |
#sync ⇒ Object
Mark a synchronisation. For software only: stop the current sequencer for allowing sharing of variables with other ones.
4017 4018 4019 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4017 def sync self << RubyHDL::High::Sync.new(@sequencer) end |
#text(str) ⇒ Object
Some arbitrary code whose text is to add direction.
4028 4029 4030 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4028 def text(str) self << str.to_s end |
#to_c ⇒ Object
Convert to C code.
3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3897 def to_c res = "" # # Generate the arguments if any. # if @args.any? then # res = "(#{@args.map(&:to_c).join(",")})\n" # end # Generate the statements. res += "{\n" + @statements.map do |stmnt| stmnt.to_c + "\n" end.join + "\n}" return res end |
#to_python(l = "") ⇒ Object
Convert to Python code.
3911 3912 3913 3914 3915 3916 3917 3918 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3911 def to_python(l = "") res = "" # Generate the statements. res += @statements.map do |stmnt| stmnt.to_python(l) + "\n" end.join return res end |
#to_ruby ⇒ Object
Convert to Ruby code.
3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3882 def to_ruby res = "" # The arguments are ignored, as they are handled in SfunctionT. # # Generate the arguments if any. # if @args.any? then # res = "|#{@args.map(&:to_ruby).join(",")}|\n" # end # Generate the statements. res += @statements.map do |stmnt| stmnt.to_ruby + "\n" end.join return res end |
#unshift(statement) ⇒ Object
Unshift a new statement.
3866 3867 3868 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3866 def unshift(statement) @statements.unshift(statement) end |