class HDLRuby::Low::Print

Describes a print statement: not synthesizable!

Extends the Print class with generation of C text.

Add the conversion to high.

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

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

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

Extends the Print class with fixing of types and constants.

Decribes a print statement.

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

Enhance Print with generation of verilog code.

Public Class Methods

new(*args) click to toggle source

Creates a new statement for printing args.

Calls superclass method
# File lib/HDLRuby/hruby_low.rb, line 3666
def initialize(*args)
    super()
    # Process the arguments.
    @args = args.map do |arg|
        arg.parent = self 
        arg
    end
end

Public Instance Methods

boolean_in_assign2select!() click to toggle source

Converts booleans in assignments to select operators.

# File lib/HDLRuby/hruby_low_bool2select.rb, line 71
def boolean_in_assign2select!
    # Apply on the arguments.
    self.map_args! { |arg| arg.boolean_in_assign2select }
    return self
end
casts_without_expression!() click to toggle source

Extracts the expressions from the casts.

# File lib/HDLRuby/hruby_low_casts_without_expression.rb, line 72
def casts_without_expression!
    # Apply on the arguments.
    self.map_args!(&:casts_without_expression)
    return self
end
clone() click to toggle source

Clones the TimeWait (deeply)

# File lib/HDLRuby/hruby_low.rb, line 3712
def clone
    return Print.new(*@args.map { |arg| arg.clone })
end
delete_arg!(arg) click to toggle source

Delete an arg.

# File lib/HDLRuby/hruby_low_mutable.rb, line 645
def delete_arg!(arg)
    if @args.include?(arg) then
        # The arg is present, delete it.
        @args.delete(arg)
        # And remove its parent.
        arg.parent = nil
    end
    arg
end
each_arg(&ruby_block) click to toggle source

Iterates over each argument.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 3687
def each_arg(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_arg) unless ruby_block
    # A ruby block? First apply it to each argument.
    @args.each(&ruby_block)
end
each_block(&ruby_block) click to toggle source

Iterates over the sub blocks.

# File lib/HDLRuby/hruby_low.rb, line 3736
def each_block(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_block) unless ruby_block
    # A ruby block?
    # Recurse on each argument.
    @args.each do |arg|
        arg.each_block(&ruby_block) if arg.respond_to?(:each_block)
    end
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 3747
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 each argument.
    @args.each do |arg|
        if arg.respond_to?(:each_block_deep) then
            arg.each_block_deep(&ruby_block)
        end
    end
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 3697
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 arguments.
    self.each_arg(&ruby_block)
end
each_node(&ruby_block) click to toggle source

Iterates over the expression children if any.

# File lib/HDLRuby/hruby_low.rb, line 3717
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 each argument.
    @args.each(&ruby_block)
end
each_node_deep(&ruby_block) click to toggle source

Iterates over the nodes deeply if any.

# File lib/HDLRuby/hruby_low.rb, line 3726
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 apply it on each argument.
    @args.each(&ruby_block)
end
each_statement_deep(&ruby_block) click to toggle source

Iterates over all the statements contained in the current block.

# File lib/HDLRuby/hruby_low.rb, line 3760
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 each argument.
    @args.each do |arg|
        if arg.respond_to?(:each_statement_deep) then
            arg.each_statement_deep(&ruby_block)
        end
    end
end
eql?(obj) click to toggle source

Comparison for hash: structural comparison.

# File lib/HDLRuby/hruby_low.rb, line 3676
def eql?(obj)
    return false unless obj.is_a?(Print)
    return false if @args.each.zip(obj.each_arg).any? do |a0,a1|
        !a0.eql?(a1)
    end
    return true
end
explicit_types!() click to toggle source

Explicit the types conversions in the statement.

# File lib/HDLRuby/hruby_low_fix_types.rb, line 96
def explicit_types!
    # Recurse on the arguments.
    self.map_args!(&:explicit_types)
    return self
end
extract_selects!() click to toggle source

Extract the Select expressions.

# File lib/HDLRuby/hruby_low_without_select.rb, line 170
def extract_selects!
    selects = []
    self.map_args! do |arg|
        arg.extract_selects_to!(selects)
    end
    return selects
end
hash() click to toggle source

Hash function.

# File lib/HDLRuby/hruby_low.rb, line 3707
def hash
    return @args.hash
end
map_args!(&ruby_block) click to toggle source

Maps on the arguments.

# File lib/HDLRuby/hruby_low_mutable.rb, line 634
def map_args!(&ruby_block)
    @args.map! do |arg|
        arg = ruby_block.call(arg)
        arg.parent = self unless arg.parent
        arg
    end
end
Also aliased as: map_nodes!
map_nodes!(&ruby_block)
Alias for: map_args!
replace_args!(node2rep) click to toggle source

Replaces sub arguments 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 661
def replace_args!(node2rep)
    # First recurse on the children.
    res = {}
    self.each_node do |node|
        res.merge!(node.replace_args!(node2rep))
    end
    # Is there a replacement of on a sub node?
    self.map_nodes! do |sub|
        rep = node2rep[sub]
        if rep then
            # Yes, do it.
            rep = rep.clone
            node = sub
            # node.set_parent!(nil)
            # And register the replacement.
            res[node] = rep
            rep
        else
            sub
        end
    end
    return res
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 1132
def to_c(level = 0)
    # Save the state of the value pool.
    res = (" " * ((level)*3))
    res << "{\n"
    res << (" " * ((level+1)*3))
    res << "unsigned int pool_state = get_value_pos();\n"
    # Perform the copy and the touching only if the new content
    # is different.
    res << (" " * ((level+1)*3))
    # Is it a sequential execution model?
    seq = self.block.mode == :seq ? "_seq" : ""
    # Generate the print.
    self.each_arg do |arg|
        if (arg.is_a?(StringE)) then
            res << "printer.print_string(\"" + 
                Low2C.c_string(arg.content) + "\");\n"
        elsif (arg.is_a?(Expression)) then
            res << "printer.print_string_value(" + arg.to_c + ");\n"
        else
            res << "printer.print_string_name(" + arg.to_c + ");\n"
        end
    end
    # Restore the value pool state.
    res << (" " * ((level+1)*3))
    res << "set_value_pos(pool_state);\n"
    res << (" " * ((level)*3))
    res << "}\n"
    return res
end
to_high() click to toggle source

Creates a new high print statement.

# File lib/HDLRuby/hruby_low2high.rb, line 309
def to_high
    return HDLRuby::High::Print.new(
        *self.each_arg.map {|arg| arg.to_high })
end
to_verilog(spc = 3) click to toggle source

Converts the system to Verilog code.

# File lib/HDLRuby/hruby_verilog.rb, line 118
def to_verilog(spc = 3)
    code = "#{" " * spc}$write(#{self.each_arg.map do |arg|
    arg.to_verilog
    end.join(",") });"
    return code
end
to_vhdl(vars,level = 0) click to toggle source

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.

# File lib/HDLRuby/hruby_low2vhd.rb, line 921
def to_vhdl(vars,level = 0)
    # Generate a report statement.
    return " " * (level*3) + "report " + self.each_arg.map do |arg|
        arg.to_vhdl
    end.join(" & ") + ";\n"
end