Class: HDLRuby::Low::Statement

Inherits:
Base::Statement
  • Object
show all
Includes:
Hparent, Low2Symbol
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_low2sym.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_cleanup.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_with_bool.rb,
lib/HDLRuby/hruby_low_without_namespace.rb

Overview

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

Direct Known Subclasses

Block, Case, If, TimeRepeat, TimeWait, Transmit

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 included from Low2Symbol

#to_sym

Instance Method Details

#add_blocks_code(res, level) ⇒ Object

Adds the c code of the blocks to +res+ at +level+



1048
1049
1050
1051
1052
1053
1054
1055
1056
# File 'lib/HDLRuby/hruby_low2c.rb', line 1048

def add_blocks_code(res,level)
    if self.respond_to?(:each_node) then
        self.each_node do |node|
            if node.respond_to?(:add_blocks_code) then
                node.add_blocks_code(res,level)
            end
        end
    end
end

#blockObject

Get the block of the statement.



2559
2560
2561
2562
2563
2564
2565
# File 'lib/HDLRuby/hruby_low.rb', line 2559

def block
    if self.is_a?(Block)
        return self
    else
        return self.parent.block
    end
end

#blocks2seq!Object

Converts the par sub blocks to seq.



84
85
86
87
# File 'lib/HDLRuby/hruby_low2seq.rb', line 84

def blocks2seq!
    # By default, nothing to do.
    return self
end

#break_types!(types) ⇒ Object

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



480
481
482
483
484
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 480

def break_types!(types)
    self.each_node do |node|
        node.break_types!(types)
    end
end

#cloneObject

Clones (deeply)

Raises:



2541
2542
2543
2544
# File 'lib/HDLRuby/hruby_low.rb', line 2541

def clone
    raise AnyError,
          "Internal error: clone is not defined for class: #{self.class}"
end

#delete_unless!(keep) ⇒ Object

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



116
117
118
# File 'lib/HDLRuby/hruby_low_cleanup.rb', line 116

def delete_unless!(keep)
    # By default nothing to do.
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)

Raises:



2547
2548
2549
2550
# File 'lib/HDLRuby/hruby_low.rb', line 2547

def eql?(obj)
    raise AnyError,
        "Internal error: eql? is not defined for class: #{self.class}"
end

#explicit_types!Object

Explicit the types conversions in the statement.



73
74
75
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 73

def explicit_types!
    raise "Should implement explicit_types for class #{self.class}."
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!



462
463
464
465
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 462

def extract_declares!
    # By default, nothing to do.
    return []
end

#hashObject

Hash function.

Raises:



2553
2554
2555
2556
# File 'lib/HDLRuby/hruby_low.rb', line 2553

def hash
    raise AnyError,
        "Internal error: hash is not defined for class: #{self.class}"
end

#mix?(mode = nil) ⇒ Boolean

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

Returns:

  • (Boolean)


91
92
93
94
# File 'lib/HDLRuby/hruby_low2seq.rb', line 91

def mix?(mode = nil)
    # By default, no mix block.
    return false
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.



513
514
515
516
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 513

def replace_expressions!(node2rep)
    # By default: nothing to do.
    return {}
end

#replace_names!(former, nname) ⇒ Object

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



468
469
470
471
472
473
474
475
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 468

def replace_names!(former,nname)
    # By default: try to replace the name recursively.
    self.each_node_deep do |node|
        if node.respond_to?(:name) && node.name == former then
            node.set_name!(nname)
        end
    end
end

#to_c(level = 0) ⇒ Object

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

Raises:



1042
1043
1044
1045
# File 'lib/HDLRuby/hruby_low2c.rb', line 1042

def to_c(level = 0)
    # Should never be here.
    raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
end

#to_high(level = 0) ⇒ Object

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

Raises:



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

def to_high(level = 0)
    # Should never be here.
    raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
end

#to_upper_space!Object

Moves the declarations to the upper namespace.



455
456
457
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 455

def to_upper_space!
    # By default, nothing to do.
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:



852
853
854
855
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 852

def to_vhdl(vars, level = 0)
    # Should never be here.
    raise AnyError, "Internal error: to_vhdl should be implemented in class :#{self.class}"
end

#top_blockObject

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



2568
2569
2570
# File 'lib/HDLRuby/hruby_low.rb', line 2568

def top_block
    return self.parent.is_a?(Behavior) ? self : self.parent.top_block
end

#top_scopeObject

Gets the top scope, i.e. the first scope of the current system.



2573
2574
2575
# File 'lib/HDLRuby/hruby_low.rb', line 2573

def top_scope
    return self.top_block.parent.top_scope
end

#with_boolean!Object

Converts to a variable-compatible system.

NOTE: the result is the same Behaviour.



85
86
87
88
89
90
91
# File 'lib/HDLRuby/hruby_low_with_bool.rb', line 85

def with_boolean!
    self.each_node do |node| 
        if node.is_a?(Expression) && node.boolean? then
            node.set_type!(HDLRuby::Low::Boolean)
        end
    end
end