Module: RubyHDL::High
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Defined Under Namespace
Modules: SEnumerable Classes: Binary, Expression, Ref, RefIndex, RefName, RefRange, Ruby, Sblock, SblockTop, Sbreak, Scall, Scontinue, Select, SequencerT, SfunctionT, Sif, SignalI, Siter, Sloop, Step, Sterminate, Swhile, Sync, Transmit, Type, TypeDef, TypeFloat, TypeGen, TypeSigned, TypeStruct, TypeTuple, TypeUnsigned, TypeVector, Unary, Value
Constant Summary collapse
- SBLOCK_STACK =
The stack of SW blocks.
[ SblockTop.new ]
- RUBY_OPERATOR =
The translation of operators into Ruby code.
{ # Unary operators. :"-@" => "-(%s)", :"+@" => "+(%s)", :"~" => "~(%s)", :abs => "(%s).abs", :boolean => "%s", :bit => "%s", :signed => "%s", :unsigned => "(%s) & 0xFFFFFFFFFFFFFFFF", # Binary operators. :"+" => "(%s)+(%s)", :"-" => "(%s)-(%s)", :"*" => "(%s)*(%s)", :"/" => "(%s)/(%s)", :"%" => "(%s)%%(%s)", :"**" => "(%s)**(%s)", :"&" => "(%s)&(%s)", :"|" => "(%s)|(%s)", :"^" => "(%s)^(%s)", :"<<" => "(%s)<<(%s)", :">>" => "(%s)>>(%s)", :"==" => "(%s)==(%s)", :"!=" => "(%s)!=(%s)", :"<" => "(%s)<(%s)", :">" => "(%s)>(%s)", :"<=" => "(%s)<=(%s)",:">=" => "(%s)>=(%s)" }
- C_OPERATOR =
The translation of operators into C code.
{ # Unary operators. :"-@" => "-(%s)", :"+@" => "+(%s)", :"~" => "~(%s)", :abs => "(%s).abs", :boolean => "%s", :bit => "%s", :signed => "%s", :unsigned => "(%s) & 0xFFFFFFFFFFFFFFFF", # Binary operators. :"+" => "(%s)+(%s)", :"-" => "(%s)-(%s)", :"*" => "(%s)*(%s)", :"/" => "(%s)/(%s)", :"%" => "(%s)%%(%s)", :"**" => "pow((%s),(%s))", :"&" => "(%s)&(%s)", :"|" => "(%s)|(%s)", :"^" => "(%s)^(%s)", :"<<" => "(%s)<<(%s)", :">>" => "(%s)>>(%s)", :"==" => "(%s)==(%s)", :"!=" => "(%s)!=(%s)", :"<" => "(%s)<(%s)", :">" => "(%s)>(%s)", :"<=" => "(%s)<=(%s)",:">=" => "(%s)>=(%s)" }
- Void =
The void type
define_type(:void)
- Bit =
The bit type.
define_type(:bit)
- Signed =
The signed bit type.
define_type(:signed)
- Unsigned =
The unsigned bit type.
define_type(:unsigned)
- Float =
The float bit type
define_type(:float)
- StringT =
The string type
define_type(:string)
- @@absoluteCounter =
The absolute name counter.
-1 # The absolute name counter.
- @@uniq_names =
Set.new(Symbol.all_symbols.map {|sym| sym.to_s})
Class Method Summary collapse
-
.call_sblock(m, *args, &ruby_block) ⇒ Object
Calling a method from the stack.
-
.define_type(name) ⇒ Object
Defines a basic type +name+.
- .global_sblock ⇒ Object
- .pop_sblock ⇒ Object
- .push_sblock(sblock) ⇒ Object
- .top_sblock ⇒ Object
-
.uniq_name(base = "") ⇒ Object
Generates an absolute uniq name.
Instance Method Summary collapse
-
#sdef(name, &ruby_block) ⇒ Object
Create a new function named +name+, built using block +ruby_block+.
-
#sequencer(clk = nil, start = nil, &ruby_block) ⇒ Object
Create a new sequencer block, with clock counter +clk+ and run control +start+.
-
#struct(content) ⇒ Object
Creates an unnamed structure type from a +content+.
-
#typedef(name, &ruby_block) ⇒ Object
Declares a high-level generic type named +name+, and using +ruby_block+ for construction.
Class Method Details
.call_sblock(m, *args, &ruby_block) ⇒ Object
Calling a method from the stack.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 123 def self.call_sblock(m,*args,&ruby_block) SBLOCK_STACK.reverse_each do |sblock| if sblock.callable?(m) then # return sblock.callable(m,*args,&ruby_block) res = sblock.callable(m,*args,&ruby_block) return res end end # Method not found. method_missing(m,*args,&ruby_block) end |
.define_type(name) ⇒ Object
Defines a basic type +name+.
973 974 975 976 977 978 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 973 def self.define_type(name) name = name.to_sym type = Type.new(name) self.send(:define_method,name) { type } return type end |
.global_sblock ⇒ Object
106 107 108 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 106 def self.global_sblock SBLOCK_STACK[0] end |
.pop_sblock ⇒ Object
118 119 120 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 118 def self.pop_sblock SBLOCK_STACK.pop end |
.push_sblock(sblock) ⇒ Object
114 115 116 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 114 def self.push_sblock(sblock) SBLOCK_STACK << sblock end |
.top_sblock ⇒ Object
110 111 112 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 110 def self.top_sblock SBLOCK_STACK[-1] end |
.uniq_name(base = "") ⇒ Object
Generates an absolute uniq name.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 23 def self.uniq_name(base = "") @@absoluteCounter += 1 name = base.to_s + ":#{@@absoluteCounter}" if @@uniq_names.include?(name) then # The symbol exists, try again. return self.uniq_name else @@uniq_names.add(name) return name.to_sym end end |
Instance Method Details
#sdef(name, &ruby_block) ⇒ Object
Create a new function named +name+, built using block +ruby_block+.
3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3483 def sdef(name,&ruby_block) name = name.to_sym # Get the arguments of the ruby_block. args = ruby_block.parameters.map {|typ,name| name.to_s } # Register the call to the function. RubyHDL::High.register(name.to_sym) do |args| cur_seq = Ruby::HDL::High.top_sblock.sequencer unless cur_seq.sfunction?(name) then # Need to create a new sfunction. # Push a new empty sblock for building the function. RubyHDL::High.push_sblock(SblockTop.new) args.each do |arg| RubyHDL::High.top_sblock.make_inners(Void,arg.to_sym) end # Execute the ruby block in a sequencer environment for building # the sblock. sblock = Sblock.new(cur_seq,&ruby_block) RubyHDL::High.pop_sblock # Create the function. function = SfunctionT.new(name,args,sblock) # Add it to the sequencer. cur_seq.add_sfunction(name) end Scall.new(cur_seq,name,args) end end |
#sequencer(clk = nil, start = nil, &ruby_block) ⇒ Object
Create a new sequencer block, with clock counter +clk+ and run control +start+
3478 3479 3480 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3478 def sequencer(clk = nil, start = nil, &ruby_block) return SequencerT.new(clk,start,&ruby_block) end |
#struct(content) ⇒ Object
Creates an unnamed structure type from a +content+.
1602 1603 1604 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1602 def struct(content) return TypeStruct.new(:"",:little,content) end |
#typedef(name, &ruby_block) ⇒ Object
Declares a high-level generic type named +name+, and using +ruby_block+ for construction.
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1610 def typedef(name, &ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? type = TypeGen.new(name,&ruby_block) define_singleton_method(name.to_sym) do |*args| if (args.size < ruby_block.arity) then # Not enough arguments get generic type as is. type else # There are arguments, specialize the type. gtype = type.generate(*args) # And add it as a local type of the system. RubyHDL::High.top_sblock.add_type(gtype) gtype end end end |