Class: HDLRuby::Low::TimeRepeat

Inherits:
Statement
  • Object
show all
Defined in:
lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2seq.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_without_namespace.rb

Overview

Extends the When class with functionality for moving the declarations to the upper namespace.

Direct Known Subclasses

High::TimeRepeat

Constant Summary

Constants included from Low2Symbol

Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable

Instance Attribute Summary collapse

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods inherited from Statement

#add_blocks_code, #block, #break_types!, #delete_unless!, #top_block, #top_scope, #with_boolean!

Methods included from Low2Symbol

#to_sym

Constructor Details

#initialize(statement, delay) ⇒ TimeRepeat

Creates a new timed loop statement execute in a loop +statement+ until +delay+ has passed.



3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
# File 'lib/HDLRuby/hruby_low.rb', line 3289

def initialize(statement,delay)
    # Check and set the statement.
    unless statement.is_a?(Statement)
        raise AnyError,
              "Invalid class for a statement: #{statement.class}."
    end
    @statement = statement
    # And set its parent.
    statement.parent = self

    # Check and set the delay.
    unless delay.is_a?(Delay)
        raise AnyError, "Invalid class for a delay: #{delay.class}."
    end
    @delay = delay
    # And set its parent.
    delay.parent = self
end

Instance Attribute Details

#delayObject (readonly)

The delay until the loop is repeated



3282
3283
3284
# File 'lib/HDLRuby/hruby_low.rb', line 3282

def delay
  @delay
end

#statementObject (readonly)

The statement to execute.



3285
3286
3287
# File 'lib/HDLRuby/hruby_low.rb', line 3285

def statement
  @statement
end

Instance Method Details

#blocks2seq!Object

Converts the par sub blocks to seq.



178
179
180
181
182
# File 'lib/HDLRuby/hruby_low2seq.rb', line 178

def blocks2seq!
    # Converts the statement.
    self.statement.blocks2seq!
    return self
end

#cloneObject

Clones the TimeRepeat (deeply)



3322
3323
3324
# File 'lib/HDLRuby/hruby_low.rb', line 3322

def clone
    return TimeRepeat(@statement.clone,@delay.clone)
end

#each_block(&ruby_block) ⇒ Object

Iterates over the sub blocks.



3345
3346
3347
3348
3349
3350
3351
# File 'lib/HDLRuby/hruby_low.rb', line 3345

def each_block(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_block) unless ruby_block
    # A ruby block?
    # Apply it on the statement if it is a block.
    ruby_block.call(@statement) if statement.is_a?(Block)
end

#each_block_deep(&ruby_block) ⇒ Object

Iterates over all the blocks contained in the current block.



3354
3355
3356
3357
3358
3359
3360
# File 'lib/HDLRuby/hruby_low.rb', line 3354

def each_block_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_block_deep) unless ruby_block
    # A ruby block?
    # Recurse on the statement.
    @statement.each_block_deep(&ruby_block)
end

#each_node(&ruby_block) ⇒ Object

Iterates over the expression children if any.



3327
3328
3329
3330
3331
3332
# File 'lib/HDLRuby/hruby_low.rb', line 3327

def each_node(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node) unless ruby_block
    # A ruby block? Apply it on the child.
    ruby_block.call(@statement)
end

#each_node_deep(&ruby_block) ⇒ Object

Iterates over the nodes deeply if any.



3335
3336
3337
3338
3339
3340
3341
3342
# File 'lib/HDLRuby/hruby_low.rb', line 3335

def each_node_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # And recurse on the child
    @statement.each_node_deep(&ruby_block)
end

#each_statement_deep(&ruby_block) ⇒ Object

Iterates over all the statements contained in the current block.



3363
3364
3365
3366
3367
3368
3369
3370
3371
# File 'lib/HDLRuby/hruby_low.rb', line 3363

def each_statement_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_statement_deep) unless ruby_block
    # A ruby block?
    # Apply it on self.
    ruby_block.call(self)
    # Recurse on the statement.
    @statement.each_statement_deep(&ruby_block)
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


3309
3310
3311
3312
3313
3314
# File 'lib/HDLRuby/hruby_low.rb', line 3309

def eql?(obj)
    return false unless obj.is_a?(TimeRepeat)
    return false unless @delay.eql?(obj.delay)
    return false unless @statement.eql?(obj.statement)
    return true
end

#explicit_types!Object

Explicit the types conversions in the time repeat.



152
153
154
155
156
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 152

def explicit_types!
    # Recurse on the statement.
    self.statement.explicit_types!
    return self
end

#extract_declares!Object

Extract the declares from the scope and returns them into an array.

NOTE: do not recurse into the sub scopes or behaviors!



650
651
652
653
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 650

def extract_declares!
    # Recurse on the statement.
    return self.statement.extract_declares!
end

#hashObject

Hash function.



3317
3318
3319
# File 'lib/HDLRuby/hruby_low.rb', line 3317

def hash
    return [@delay,@statement].hash
end

#map_nodes!(&ruby_block) ⇒ Object

Maps on the child.



935
936
937
938
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 935

def map_nodes!(&ruby_block)
    @statement = ruby_block.call(@statement)
    @statement.parent = self unless @statement.parent
end

#mix?(mode = nil) ⇒ Boolean

Tell if there is a mix block. +mode+ is the mode of the upper block.

Returns:

  • (Boolean)


186
187
188
189
# File 'lib/HDLRuby/hruby_low2seq.rb', line 186

def mix?(mode = nil)
    # Check the statement.
    return self.statement.mix?(mode)
end

#replace_expressions!(node2rep) ⇒ Object

Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement. Returns the actually replaced nodes and their corresponding replacement.

NOTE: the replacement is duplicated.



946
947
948
949
950
951
952
953
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 946

def replace_expressions!(node2rep)
    res = {}
    # Recurse on the children.
    self.each_node do |node|
        res.merge!(node.replace_expressions!(node2rep))
    end
    return res
end

#replace_names!(former, nname) ⇒ Object

Replaces recursively +former+ name by +nname+ until it is redeclared.



656
657
658
659
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 656

def replace_names!(former,nname)
    # Recurse on the statement.
    self.statement.replace_names!(former,nname)
end

#set_delay!(delay) ⇒ Object

Sets the delay.



924
925
926
927
928
929
930
931
932
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 924

def set_delay!(delay)
    # Check and set the delay.
    unless delay.is_a?(Delay)
        raise AnyError, "Invalid class for a delay: #{delay.class}."
    end
    @delay = delay
    # And set its parent.
    delay.parent = self
end

#set_statement!(statement) ⇒ Object

Sets the statement.



912
913
914
915
916
917
918
919
920
921
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 912

def set_statement!(statement)
    # Check and set the statement.
    unless statement.is_a?(Statement)
        raise AnyError,
              "Invalid class for a statement: #{statement.class}."
    end
    @statement = statement
    # And set its parent.
    statement.parent = self
end

#to_c(level = 0) ⇒ Object

Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
# File 'lib/HDLRuby/hruby_low2c.rb', line 1248

def to_c(level = 0)
    # The resulting string.
    res = " " * level*3
    # Generate an infinite loop executing the block and waiting.
    res << "for(;;) {\n"
    res << "#{self.to_c(level+1)}\n"
    res = " " * (level+1)*3
    res << Low2C.wait_code(self,level)
    # Return the resulting string.
    return res
end

#to_high(level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/HDLRuby/hruby_low2high.rb', line 454

def to_high(level = 0)
    # The resulting string.
    res = " " * (level*3)
    # Generate the header.
    res << "repeat " << self.delay.to_high(level) << " do\n"
    # Generate the statement to repeat.
    res << self.statement.to_high(level+1)
    # Close the repeat.
    res << " " * (level*3) << "end\n"
    # Return the resulting string.
    return res
end

#to_upper_space!Object

Moves the declarations to the upper namespace.



642
643
644
645
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 642

def to_upper_space!
    # Recurse on the statement.
    self.statement.to_upper_space!
end

#to_vhdl(vars, level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +vars+ is the list of the variables and +level+ is the hierachical level of the object.

Raises:



997
998
999
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 997

def to_vhdl(vars,level = 0)
    raise AnyError, "Internal error: TimeRepeat not supported yet for conversion to VHDL."
end