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_low2hdr.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_bool2select.rb,
lib/HDLRuby/hruby_low_without_select.rb,
lib/HDLRuby/hruby_low_without_namespace.rb,
lib/HDLRuby/hruby_low_casts_without_expression.rb

Overview

Extends the TimeRepeat class with functionality for extracting expressions from cast.

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, #add_make_block, #behavior, #block, #break_types!, #delete_related!, #delete_unless!, #each_statement, #par_in_seq2seq!, #parent_system, #scope, #to_ch, #to_seq!, #top_block, #top_scope, #use_name?, #with_boolean!

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#hierarchy, #no_parent!, #scope

Constructor Details

#initialize(statement, delay) ⇒ TimeRepeat

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



4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
# File 'lib/HDLRuby/hruby_low.rb', line 4053

def initialize(statement,delay)
    # Check and set the statement.
    unless statement.is_a?(Statement)
        raise AnyError,
              "Invalid class for a statement: #{statement.class}."
    end
    super()
    @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



4046
4047
4048
# File 'lib/HDLRuby/hruby_low.rb', line 4046

def delay
  @delay
end

#statementObject (readonly)

The statement to execute.



4049
4050
4051
# File 'lib/HDLRuby/hruby_low.rb', line 4049

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

#boolean_in_assign2select!Object

Converts booleans in assignments to select operators.



162
163
164
165
166
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 162

def boolean_in_assign2select!
    # Simply recurse on the stamtement.
    self.statement.boolean_in_assign2select!
    return self
end

#casts_without_expression!Object

Extracts the expressions from the casts.



147
148
149
150
151
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 147

def casts_without_expression!
    # Simply recurse on the stamtement.
    self.statement.casts_without_expression!
    return self
end

#cloneObject

Clones the TimeRepeat (deeply)



4101
4102
4103
# File 'lib/HDLRuby/hruby_low.rb', line 4101

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

#each_block(&ruby_block) ⇒ Object

Iterates over the sub blocks.



4124
4125
4126
4127
4128
4129
4130
# File 'lib/HDLRuby/hruby_low.rb', line 4124

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.



4133
4134
4135
4136
4137
4138
4139
# File 'lib/HDLRuby/hruby_low.rb', line 4133

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_deep(&ruby_block) ⇒ Object

Iterates over each object deeply.

Returns an enumerator if no ruby block is given.



4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
# File 'lib/HDLRuby/hruby_low.rb', line 4076

def each_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # Then apply on the statement.
    self.statement.each_deep(&ruby_block)
    # Then apply on the delay.
    self.delay.each_deep(&ruby_block)
end

#each_node(&ruby_block) ⇒ Object

Iterates over the expression children if any.



4106
4107
4108
4109
4110
4111
# File 'lib/HDLRuby/hruby_low.rb', line 4106

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.



4114
4115
4116
4117
4118
4119
4120
4121
# File 'lib/HDLRuby/hruby_low.rb', line 4114

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.



4142
4143
4144
4145
4146
4147
4148
4149
4150
# File 'lib/HDLRuby/hruby_low.rb', line 4142

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)


4088
4089
4090
4091
4092
4093
# File 'lib/HDLRuby/hruby_low.rb', line 4088

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.



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

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!



660
661
662
663
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 660

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

#extract_selects!Object

Extract the Select expressions.



116
117
118
119
120
121
122
123
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 116

def extract_selects!
    # Simply recruse on the statement.
    if self.statement.is_a?(Block) then
        return []
    else
        return self.statement.extract_selects!
    end
end

#hashObject

Hash function.



4096
4097
4098
# File 'lib/HDLRuby/hruby_low.rb', line 4096

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

#map_nodes!(&ruby_block) ⇒ Object

Maps on the child.



1076
1077
1078
1079
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1076

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

#process_to_vhdl(vars, level = 0) ⇒ Object

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



1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1070

def process_to_vhdl(vars,level = 0)
    # Generate a separate process for the repeated statement with
    # a wait.
    # The resulting string.
    res = " " * (level*3)
    # Generate the header.
    unless  self.block.name.empty? then
        res << Low2VHDL.vhdl_name(self.block.name) << ": "
    end
    res << "process \n"
    # Generate the content.
    res << " " * (level*3)
    res << "begin\n"
    # Adds the wait.
    res << " " * ((level+1)*3)
    res << "wait for " << self.delay.to_vhdl(level) << ";\n" 
    # Generate the remaining of the body.
    res << self.statement.to_vhdl(vars,level+1)
    # Close the process.
    res << " " * (level*3)
    res << "end process;\n\n"
    # Return the result.
    return res
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.



1087
1088
1089
1090
1091
1092
1093
1094
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1087

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.



666
667
668
669
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 666

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

#set_delay!(delay) ⇒ Object

Sets the delay.



1065
1066
1067
1068
1069
1070
1071
1072
1073
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1065

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.



1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1053

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(res, level = 0) ⇒ Object

Generates the C text of the equivalent HDLRuby code. +level+ is the hierachical level of the object. def to_c(level = 0)



1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
# File 'lib/HDLRuby/hruby_low2c.rb', line 1809

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

#to_hdr(level = 0) ⇒ Object

Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.



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

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

#to_highObject

Creates a new high repreat statement.



328
329
330
331
# File 'lib/HDLRuby/hruby_low2high.rb', line 328

def to_high
    return HDLRuby::High::TimeReapeat.new(self.delay.to_high,
                                          self.statement.to_high)
end

#to_upper_space!Object

Moves the declarations to the upper namespace.



652
653
654
655
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 652

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.



1061
1062
1063
1064
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1061

def to_vhdl(vars,level = 0)
    # Nothing to do, see process_to_vhdl
    return ""
end