Class: HDLRuby::Low::Print

Inherits:
Statement show all
Defined in:
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.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_subsignals.rb,
lib/HDLRuby/hruby_low_casts_without_expression.rb

Overview

Describes a print statement: not synthesizable!

Direct Known Subclasses

High::Print

Constant Summary

Constants included from Low2Symbol

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

Instance Attribute Summary

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods inherited from Statement

#add_blocks_code, #add_make_block, #behavior, #block, #blocks2seq!, #break_types!, #delete_related!, #delete_unless!, #each_statement, #extract_declares!, #fix_scope_refnames!, #mix?, #par_in_seq2seq!, #parent_system, #replace_expressions!, #replace_names!, #scope, #to_ch, #to_hdr, #to_seq!, #to_upper_space!, #top_block, #top_scope, #use_name?, #with_boolean!

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#absolute_ref, #hierarchy, #no_parent!, #scope

Constructor Details

#initialize(*args) ⇒ Print

Creates a new statement for printing +args+.



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

def initialize(*args)
    super()
    # Process the arguments.
    @args = args.map do |arg|
        arg.parent = self 
        arg
    end
end

Instance Method Details

#boolean_in_assign2select!Object

Converts booleans in assignments to select operators.



71
72
73
74
75
# 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!Object

Extracts the expressions from the casts.



72
73
74
75
76
# 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

#cloneObject

Clones the TimeWait (deeply)



4133
4134
4135
# File 'lib/HDLRuby/hruby_low.rb', line 4133

def clone
    return Print.new(*@args.map { |arg| arg.clone })
end

#delete_arg!(arg) ⇒ Object

Delete an arg.



633
634
635
636
637
638
639
640
641
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 633

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) ⇒ Object

Iterates over each argument.

Returns an enumerator if no ruby block is given.



4108
4109
4110
4111
4112
4113
# File 'lib/HDLRuby/hruby_low.rb', line 4108

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) ⇒ Object

Iterates over the sub blocks.



4157
4158
4159
4160
4161
4162
4163
4164
4165
# File 'lib/HDLRuby/hruby_low.rb', line 4157

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) ⇒ Object

Iterates over all the blocks contained in the current block.



4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
# File 'lib/HDLRuby/hruby_low.rb', line 4168

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) ⇒ Object

Iterates over each object deeply.

Returns an enumerator if no ruby block is given.



4118
4119
4120
4121
4122
4123
4124
4125
# File 'lib/HDLRuby/hruby_low.rb', line 4118

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) ⇒ Object

Iterates over the expression children if any.



4138
4139
4140
4141
4142
4143
4144
# File 'lib/HDLRuby/hruby_low.rb', line 4138

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) ⇒ Object

Iterates over the nodes deeply if any.



4147
4148
4149
4150
4151
4152
4153
4154
# File 'lib/HDLRuby/hruby_low.rb', line 4147

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) ⇒ Object

Iterates over all the statements contained in the current block.



4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
# File 'lib/HDLRuby/hruby_low.rb', line 4181

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) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


4097
4098
4099
4100
4101
4102
4103
# File 'lib/HDLRuby/hruby_low.rb', line 4097

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!Object

Explicit the types conversions in the statement.



103
104
105
106
107
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 103

def explicit_types!
    # Recurse on the arguments.
    self.map_args!(&:explicit_types)
    return self
end

#extract_selects!Object

Extract the Select expressions.



177
178
179
180
181
182
183
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 177

def extract_selects!
    selects = []
    self.map_args! do |arg|
        arg.extract_selects_to!(selects)
    end
    return selects
end

#hashObject

Hash function.



4128
4129
4130
# File 'lib/HDLRuby/hruby_low.rb', line 4128

def hash
    return @args.hash
end

#map_args!(&ruby_block) ⇒ Object Also known as: map_nodes!

Maps on the arguments.



622
623
624
625
626
627
628
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 622

def map_args!(&ruby_block)
    @args.map! do |arg|
        arg = ruby_block.call(arg)
        arg.parent = self unless arg.parent
        arg
    end
end

#replace_args!(node2rep) ⇒ Object

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.



649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 649

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

#signal2subs!Object

Decompose the hierarchical signals in the statements.



151
152
153
154
155
# File 'lib/HDLRuby/hruby_low_without_subsignals.rb', line 151

def signal2subs!
    # Recurse on the arguments.
    self.map_args! { |arg| arg.signal2subs! }
    return 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)

def to_c(res,level = 0) # Save the state of the value pool. # res = (" " * ((level)*3)) res << (" " * ((level)*3)) res << " 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" res << "printer.print_string_value(" arg.to_c(res) res << ");\n" else # res << "printer.print_string_name(" + arg.to_c + ");\n" res << "printer.print_string_name(" arg.to_c(res) res << ");\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 Generates the C text of the equivalent HDLRuby code. +level+ is the hierachical level of the object. def to_c(level = 0)



1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
# File 'lib/HDLRuby/hruby_low2c.rb', line 1517

def to_c(res,level = 0)
    # Save the value pool state.
    res << (" " * (level*3)) << "PV;\n"
    # Generate the print for each argument.
    self.each_arg do |arg|
        if (arg.is_a?(StringE)) then
            res << (" " * (level*3))
            res << "printer.print_string(\"" + 
                Low2C.c_string(arg.content) + "\");\n"
        elsif (arg.is_a?(Expression)) then
            arg.to_c(res)
            res << (" " * (level*3))
            res << "printer.print_string_value(pop());\n"
        else
            arg.to_c(res)
            res << "printer.print_string_name(pop());\n"
        end
    end
    # Restore the value pool state.
    res << (" " * (level*3)) << "RV;\n"
    return res
end

#to_highObject

Creates a new high print statement.



333
334
335
336
# File 'lib/HDLRuby/hruby_low2high.rb', line 333

def to_high
    return HDLRuby::High::Print.new(
        *self.each_arg.map {|arg| arg.to_high })
end

#to_verilog(spc = 3) ⇒ Object

Converts the print to Verilog code.



238
239
240
241
242
243
# File 'lib/HDLRuby/hruby_verilog.rb', line 238

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) ⇒ 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.



933
934
935
936
937
938
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 933

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