Class: RubyHDL::High::Sblock

Inherits:
SblockTop show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implementation of a block.

Instance Attribute Summary collapse

Instance Method Summary collapse

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+



4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4432

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

#sequencerObject (readonly)

Returns the value of attribute sequencer.



4428
4429
4430
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4428

def sequencer
  @sequencer
end

Instance Method Details

#add(statement) ⇒ Object Also known as: <<

Add a new statement to the block.



4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4454

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.



4482
4483
4484
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4482

def delete(statement)
  @statements.delete(statement)
end

#each_arg(&ruby_block) ⇒ Object

Iterate on the arguments if any.



4497
4498
4499
4500
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4497

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.



4467
4468
4469
4470
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4467

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.



4473
4474
4475
4476
4477
4478
4479
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4473

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

#expression(type, str, *args) ⇒ Object

Some arbitrary expression code whose text is to add direction.



4664
4665
4666
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4664

def expression(type,str,*args)
  RubyHDL::High::VerbatimExpression.new(type,str,*args)
end

#hif(cond, &ruby_block) ⇒ Object

Create a sequential if statement on +cond+.



4589
4590
4591
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4589

def hif(cond, &ruby_block)
  self << RubyHDL::High::Hif.new(@sequencer,cond,&ruby_block)
end

#hprint(*args) ⇒ Object

Displays a string for debugging purpose.



4635
4636
4637
4638
4639
4640
4641
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4635

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_statementObject

Get the last statement.



4492
4493
4494
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4492

def last_statement
  return @statements[-1]
end

#mux(cond, *choices) ⇒ Object

Implements a multiplexer.



4630
4631
4632
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4630

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+.



4654
4655
4656
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4654

def ruby(str = nil, &ruby_block)
  self << RubyHDL::High::Ruby.new(str,&ruby_block)
end

#sbreakObject

Breaks current iteration.



4564
4565
4566
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4564

def sbreak
  self << RubyHDL::High::Sbreak.new(@sequencer)
end

#scontinueObject

Continues current iteration.



4569
4570
4571
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4569

def scontinue
  self << RubyHDL::High::Scontinue.new(@sequencer)
end

#selse(&ruby_block) ⇒ Object Also known as: helse

Create a sequential else statement.



4600
4601
4602
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4600

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+.



4594
4595
4596
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4594

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+.



4622
4623
4624
4625
4626
4627
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4622

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+.



4584
4585
4586
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4584

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.



4616
4617
4618
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4616

def sloop(&ruby_block)
  self << RubyHDL::High::Sloop.new(@sequencer,&ruby_block)
end

#sreturn(val) ⇒ Object

Create a return statement.



4574
4575
4576
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4574

def sreturn(val)
  self << RubyHDL::High::Sreturn.new(@sequencer,val)
end

#stepObject

Mark a step.



4554
4555
4556
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4554

def step
  self << RubyHDL::High::Step.new(@sequencer)
end

#steps(num) ⇒ Object

Mark several steps.



4559
4560
4561
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4559

def steps(num)
  num.times { self.step }
end

#sterminateObject

Terminates the sequencer.



4579
4580
4581
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4579

def sterminate
  self << RubyHDL::High::Sterminate.new(@sequencer)
end

#swait(cond) ⇒ Object

Wait a given condition.



4606
4607
4608
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4606

def swait(cond)
  self.swhile(~cond)
end

#swhile(cond, &ruby_block) ⇒ Object

Create a sequential while statement on +cond+.



4611
4612
4613
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4611

def swhile(cond,&ruby_block)
  self << RubyHDL::High::Swhile.new(@sequencer,cond,&ruby_block)
end

#syncObject

Mark a synchronisation. For software only: stop the current sequencer for allowing sharing of variables with other ones.



4648
4649
4650
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4648

def sync
  self << RubyHDL::High::Sync.new(@sequencer)
end

#text(str, *args) ⇒ Object

Some arbitrary text statement without any processing.



4659
4660
4661
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4659

def text(str,*args)
  self << RubyHDL::High::VerbatimStatement.new(str,*args)
end

#to_cObject

Convert to C code.



4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4518

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.



4532
4533
4534
4535
4536
4537
4538
4539
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4532

def to_python(l = "")
  res = ""
  # Generate the statements.
  res += @statements.map do |stmnt|
    stmnt.to_python(l) + "\n"
  end.join
  return res
end

#to_rubyObject

Convert to Ruby code.



4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4503

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

#to_tf(l = "") ⇒ Object

Convert to TensorFlow code.



4542
4543
4544
4545
4546
4547
4548
4549
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4542

def to_tf(l = "")
  res = ""
  # Generate the statements.
  res += @statements.map do |stmnt|
    stmnt.to_tf(l) + "\n"
  end.join
  return res
end

#unshift(statement) ⇒ Object

Unshift a new statement.



4487
4488
4489
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4487

def unshift(statement)
  @statements.unshift(statement)
end