class HDLRuby::Low::When

Describes a when for a case statement.

Extends the When class with generation of C text.

Extends the When class with generation of hdr text.

Add the conversion to high.

Extends the When class with functionality for converting par block to seq.

Extends the When class with conversion to symbol.

Extends the When class with generation of HDLRuby::High text.

Extends the When class with functionality for converting booleans in assignments to select operators.

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

Extends the When class with functionality for breaking assingments to concats.

Extends the When class with fixing of types and constants.

Describes a when for a case statement.

Extends the When class with separation between signals and variables.

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

Extends the If class with functionality for converting select expressions to case statements.

Attributes

match[R]

The value to match.

statement[R]

The statement to execute in in case of match.

Public Class Methods

new(match,statement) click to toggle source

Creates a new when for a casde statement that executes statement on match.

# File lib/HDLRuby/hruby_low.rb, line 3283
def initialize(match,statement)
    # Checks the match.
    unless match.is_a?(Expression)
        raise AnyError, "Invalid class for a case match: #{match.class}"
    end
    # Checks statement.
    unless statement.is_a?(Statement)
        raise AnyError,
              "Invalid class for a statement: #{statement.class}"
    end
    # Set the match.
    @match = match
    # Set the statement.
    @statement = statement
    # And set their parents.
    match.parent = statement.parent = self
end

Public Instance Methods

add_blocks_code(res,level) click to toggle source

Adds the c code of the blocks to res at level

# File lib/HDLRuby/hruby_low2c.rb, line 1248
def add_blocks_code(res,level)
    self.statement.add_blocks_code(res,level)
end
add_make_block(res,level) click to toggle source

Adds the creation of the blocks to res at level.

# File lib/HDLRuby/hruby_low2c.rb, line 1253
def add_make_block(res,level)
    self.statement.add_make_block(res,level)
end
blocks2seq!() click to toggle source

Converts the par sub blocks to seq.

# File lib/HDLRuby/hruby_low2seq.rb, line 135
def blocks2seq!
    # Convert the statement.
    self.statement.blocks2seq!
    return self
end
boolean_in_assign2select!() click to toggle source

Converts booleans in assignments to select operators.

# File lib/HDLRuby/hruby_low_bool2select.rb, line 107
def boolean_in_assign2select!
    # No need to apply on the match!
    # # Apply on the match.
    # self.set_match!(self.match.boolean_in_assign2select)
    # Apply on the statement.
    self.statement.boolean_in_assign2select!
    return self
end
break_types!(types) click to toggle source

Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before. types include the resulting types.

# File lib/HDLRuby/hruby_low_without_namespace.rb, line 594
def break_types!(types)
    self.each_node do |node|
        # Need to break only in the case of a cast.
        if node.is_a?(Cast) then
            node.type.break_types!(types)
        end
    end
end
casts_without_expression!() click to toggle source

Extracts the expressions from the casts.

# File lib/HDLRuby/hruby_low_casts_without_expression.rb, line 105
def casts_without_expression!
    # Apply on the match.
    self.set_match!(self.match.casts_without_expression)
    # Apply on the statement.
    self.statement.casts_without_expression!
    return self
end
clone() click to toggle source

Clones the When (deeply)

# File lib/HDLRuby/hruby_low.rb, line 3332
def clone
    return When.new(@match.clone,@statement.clone)
end
delete_unless!(keep) click to toggle source

Removes the signals and corresponding assignments whose name is not in keep.

# File lib/HDLRuby/hruby_low_cleanup.rb, line 145
def delete_unless!(keep)
    # Recurse on the statement.
    self.statement.delete_unless!(keep)
end
each_block(&ruby_block) click to toggle source

Iterates over the sub blocks.

# File lib/HDLRuby/hruby_low.rb, line 3348
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) click to toggle source

Iterates over all the blocks contained in the current block.

# File lib/HDLRuby/hruby_low.rb, line 3357
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) click to toggle source

Iterates over each object deeply.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 3307
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 match.
    self.match.each_deep(&ruby_block)
    # Then apply on the statement.
    self.statement.each_deep(&ruby_block)
end
each_node(&ruby_block) click to toggle source

Interates over the children.

# File lib/HDLRuby/hruby_low.rb, line 3375
def each_node(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node) unless ruby_block
    # A ruby block?
    # Appy it on the children.
    ruby_block.call(@match)
    ruby_block.call(@statement)
end
each_node_deep(&ruby_block) click to toggle source

Iterates over the nodes deeply if any.

# File lib/HDLRuby/hruby_low.rb, line 3385
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 children
    @match.each_node_deep(&ruby_block)
    @statement.each_node_deep(&ruby_block)
end
each_statement(&ruby_block) click to toggle source

Iterates over each sub statement if any.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 3339
def each_statement(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_statement) unless ruby_block
    # A ruby block?
    # Appy it on the statement child.
    ruby_block.call(@statement)
end
each_statement_deep(&ruby_block) click to toggle source

Iterates over all the stamements of the block and its sub blocks.

# File lib/HDLRuby/hruby_low.rb, line 3366
def each_statement_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_statement_deep) unless ruby_block
    # A ruby block?
    # Recurse on the statement.
    @statement.each_statement_deep(&ruby_block)
end
eql?(obj) click to toggle source

Comparison for hash: structural comparison.

# File lib/HDLRuby/hruby_low.rb, line 3319
def eql?(obj)
    return false unless obj.is_a?(When)
    return false unless @match.eql?(obj.match)
    return false unless @statement.eql?(obj.statement)
    return true
end
explicit_types!(type) click to toggle source

Explicit the types conversions in the when where type is the type of the selecting value.

# File lib/HDLRuby/hruby_low_fix_types.rb, line 130
def explicit_types!(type)
    # Recurse on the match, it must be of type.
    self.set_match!(self.match.explicit_types(type))
    # Recurse on the statement.
    self.statement.explicit_types!
    return self
end
extract_declares!() click to toggle source

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

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

# File lib/HDLRuby/hruby_low_without_namespace.rb, line 578
def extract_declares!
    # Recurse on the statement.
    return self.statement.extract_declares!
end
extract_selects!() click to toggle source

Extract the Select expressions.

NOTE: work on the match only.

# File lib/HDLRuby/hruby_low_without_select.rb, line 200
def extract_selects!
    selects = []
    self.set_match!(self.match.extract_selects_to!(selects))
    return selects
end
hash() click to toggle source

Hash function.

# File lib/HDLRuby/hruby_low.rb, line 3327
def hash
    return [@match,@statement].hash
end
map_nodes!(&ruby_block) click to toggle source

Maps on the children (including the match).

# File lib/HDLRuby/hruby_low_mutable.rb, line 836
def map_nodes!(&ruby_block)
    @match = ruby_block.call(@match)
    @match.parent = self unless @match.parent
    @statement = ruby_block.call(@statement)
    @statement.parent = self unless @statement.parent
end
mix?(mode = nil) click to toggle source

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

# File lib/HDLRuby/hruby_low2seq.rb, line 143
def mix?(mode = nil)
    # Check the statement.
    return statement.mix?(mode)
end
replace_expressions!(node2rep) click to toggle source

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.

# File lib/HDLRuby/hruby_low_mutable.rb, line 849
def replace_expressions!(node2rep)
    # First recurse on the children.
    res = {}
    self.each_node do |node|
        res.merge!(node.replace_expressions!(node2rep))
    end
    # Is there a replacement to do on the value?
    rep = node2rep[self.match]
    if rep then
        # Yes, do it.
        rep = rep.clone
        node = self.match
        # node.set_parent!(nil)
        self.set_match!(rep)
        # And register the replacement.
        res[node] = rep
    end

    return res
end
replace_names!(former,nname) click to toggle source

Replaces recursively former name by nname until it is redeclared.

# File lib/HDLRuby/hruby_low_without_namespace.rb, line 584
def replace_names!(former,nname)
    # Recurse on the match.
    self.match.replace_names!(former,nname)
    # Recurse on the statement.
    self.statement.replace_names!(former,nname)
end
set_match!(match) click to toggle source

Sets the match.

# File lib/HDLRuby/hruby_low_mutable.rb, line 811
def set_match!(match)
    # Checks the match.
    unless match.is_a?(Expression)
        raise AnyError, "Invalid class for a case match: #{match.class}"
    end
    # Set the match.
    @match = match
    # And set their parents.
    match.parent = self
end
set_statement!(statement) click to toggle source

Sets the statement.

# File lib/HDLRuby/hruby_low_mutable.rb, line 823
def set_statement!(statement)
    # Checks statement.
    unless statement.is_a?(Statement)
        raise AnyError,
              "Invalid class for a statement: #{statement.class}"
    end
    # Set the statement.
    @statement = statement
    # And set their parents.
    statement.parent = self
end
to_c(level = 0) click to toggle source

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

# File lib/HDLRuby/hruby_low2c.rb, line 1228
def to_c(level = 0)
    # The result string.
    res = " " * level*3
    # Generate the match.
    res << "case " << self.match.to_c(level+1) << ": {\n"
    # Generate the statement.
    res << self.statement.to_c(level+1)
    # Adds a break
    res << " " * (level+1)*3 << "break;\n"
    res << " " * level*3 << "}\n"
    # Returns the result.
    return res
end
to_ch() click to toggle source

Generates the content of the h file.

# File lib/HDLRuby/hruby_low2c.rb, line 1243
def to_ch
    return self.statement.to_ch
end
to_hdr(level = 0) click to toggle source

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

# File lib/HDLRuby/hruby_low2hdr.rb, line 381
def to_hdr(level = 0)
    # The result string.
    res = " " * (level*3)
    # Generate the match.
    res << "hwhen " << self.match.to_hdr(level+1) << " do\n"
    # Generate the statement.
    res << self.statement.to_hdr(level+1)
    # Close the when.
    res << " " * (level*3) << "end\n"
    # Returns the result.
    return res
end
to_high() click to toggle source

Creates a new high when.

# File lib/HDLRuby/hruby_low2high.rb, line 275
def to_high
    return HDLRuby::High::When.new(self.match.to_high,
                                   self.statement.to_high)
end
to_upper_space!() click to toggle source

Moves the declarations to the upper namespace.

# File lib/HDLRuby/hruby_low_without_namespace.rb, line 570
def to_upper_space!
    # Recurse on the statement.
    self.statement.to_upper_space!
end
to_vhdl(vars,type,level = 0) click to toggle source

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

# File lib/HDLRuby/hruby_low2vhd.rb, line 969
def to_vhdl(vars,type,level = 0)
    # The result string.
    res = " " * (level*3)
    # Generate the match.
    res << "when " << Low2VHDL.to_type(type,self.match) << " =>\n"
    # Generate the statement.
    res << self.statement.to_vhdl(vars,level+1)
    # Returns the result.
    return res
end
top_block() click to toggle source

Gets the top block, i.e. the first block of the current behavior.

# File lib/HDLRuby/hruby_low.rb, line 3396
def top_block
    # return self.parent.is_a?(Behavior) ? self : self.parent.top_block
    return self.parent.top_block
end
use_name?(*names) click to toggle source

Tell if the statement includes a signal whose name is one of names. NOTE: for the when check only the match.

# File lib/HDLRuby/hruby_low.rb, line 3403
def use_name?(*names)
    return @match.use_name?(*name)
end
with_var(upper = nil) click to toggle source

Converts to a variable-compatible case where upper is the upper block if any.

NOTE: the result is a new case.

# File lib/HDLRuby/hruby_low_with_var.rb, line 299
def with_var(upper = nil)
    return When.new(self.match.clone,self.statement.with_var(upper))
end