Module: HDLRuby::High::Htype

Includes:
Tprocess
Included in:
Type, TypeDef, TypeStruct, TypeTuple, TypeVector
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/std/sequencer_sync.rb

Overview

Enhance the Htype module for creating a shared signal.

Constant Summary collapse

High =
HDLRuby::High

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Tprocess

#&, #*, #+, #+@, #-@, #/, #<<, #==, #abs, #lr, #make, #resolve, #slice, #~

Class Method Details

.included(base) ⇒ Object

Ensures initialize registers the type name



1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
# File 'lib/HDLRuby/hruby_high.rb', line 1603

def self.included(base) # built-in Ruby hook for modules
    base.class_eval do    
        original_method = instance_method(:initialize)
        define_method(:initialize) do |*args, &block|
            original_method.bind(self).call(*args, &block)
            # Registers the name (if not empty).
            self.register(name) unless name.empty?
        end
    end
end

Instance Method Details

#[](rng) ⇒ Object

Creates a new vector type of range +rng+ and with current type as base.



1684
1685
1686
# File 'lib/HDLRuby/hruby_high.rb', line 1684

def [](rng)
    return TypeVector.new(:"",self,rng)
end

#binary(operator, expr0, expr1) ⇒ Object

Performs binary operation +operator+ on expressions +expr0+ and +expr1+.



1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
# File 'lib/HDLRuby/hruby_high.rb', line 1743

def binary(operator, expr0, expr1)
    # Look for a specific computation method.
    comp = comp_operator(operator)
    if self.respond_to?(comp) then
        # Found, use it.
        self.send(comp,expr0,expr1)
    else
        # Not found, back to default generation of binary expression.
        return Binary.new(self.send(operator,expr1.type),operator,
                          expr0,expr1)
    end
end

#comp_operator(op) ⇒ Object

Gets the computation method for +operator+.



1724
1725
1726
# File 'lib/HDLRuby/hruby_high.rb', line 1724

def comp_operator(op)
    return (op.to_s + ":C").to_sym
end

#constant(hsh) ⇒ Object

Declares high-level untyped constant signals by name and value given by +hsh+ of the current type.



1717
1718
1719
# File 'lib/HDLRuby/hruby_high.rb', line 1717

def constant(hsh)
    High.top_user.make_constants(self,hsh)
end

#define_operator(operator, &ruby_block) ⇒ Object

Redefinition of +operator+.



1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
# File 'lib/HDLRuby/hruby_high.rb', line 1757

def define_operator(operator,&ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # Register the operator as overloaded.
    @overloads ||= {}
    @overloads[operator] = ruby_block
    # Set the new method for the operator.
    self.define_singleton_method(comp_operator(operator)) do |*args|
        # puts "Top user=#{HDLRuby::High.top_user}"
        HDLRuby::High.top_user.sub(HDLRuby.uniq_name) do
            ruby_block.call(*args)
        end
    end
end

#define_operator_with_context(operator, &ruby_block) ⇒ Object

Redefinition of +operator+ when requiring the context to be passed as argument (normally only used internally).



1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
# File 'lib/HDLRuby/hruby_high.rb', line 1774

def define_operator_with_context(operator,&ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # Register the operator as overloaded.
    @overloads ||= {}
    @overloads[operator] = ruby_block
    # Set the new method for the operator.
    self.define_singleton_method(comp_operator(operator)) do |*args|
        # puts "Top user=#{HDLRuby::High.top_user}"
        HDLRuby::High.top_user.sub(HDLRuby.uniq_name) do
            # It is assumed that the first argument of the ruby_block
            # is the context in which it must be executed.
            ruby_block.call(self,*args)
        end
    end
end

#each_overload(&ruby_block) ⇒ Object

Interates over the overloaded operators.



1792
1793
1794
1795
1796
1797
# File 'lib/HDLRuby/hruby_high.rb', line 1792

def each_overload(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_overload) unless ruby_block
    # A block? Apply it on each overload if any.
    @overloads.each(&ruby_block) if @overloads
end

#htype?Boolean

Tells htype has been included.

Returns:

  • (Boolean)


1615
1616
1617
# File 'lib/HDLRuby/hruby_high.rb', line 1615

def htype?
    return true
end

#inner(*names) ⇒ Object

Declares high-level untyped inner signals named +names+ of the current type.



1711
1712
1713
# File 'lib/HDLRuby/hruby_high.rb', line 1711

def inner(*names)
    High.top_user.make_inners(self,*names)
end

#inout(*names) ⇒ Object

Declares high-level untyped inout signals named +names+ of the current type.



1704
1705
1706
1707
# File 'lib/HDLRuby/hruby_high.rb', line 1704

def inout(*names)
    # High.top_user.make_inouts(self.instantiate,*names)
    High.top_user.make_inouts(self,*names)
end

#input(*names) ⇒ Object

Declares high-level input signals named +names+ of the current type.



1691
1692
1693
# File 'lib/HDLRuby/hruby_high.rb', line 1691

def input(*names)
    High.top_user.make_inputs(self,*names)
end

#leftObject

Gets the type as left value.

NOTE: used for asymetric types like TypeSystemI.



1657
1658
1659
1660
# File 'lib/HDLRuby/hruby_high.rb', line 1657

def left
    # By default self.
    self
end

#name=(name) ⇒ Object

Sets the +name+.

NOTE: can only be done if the name is not already set.



1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
# File 'lib/HDLRuby/hruby_high.rb', line 1628

def name=(name)
    unless @name.empty? then
        raise AnyError, "Name of type already set to: #{@name}."
    end
    # Checks and sets the name.
    name = name.to_sym
    if name.empty? then
        raise AnyError, "Cannot set an empty name."
    end
    @name = name
    # Registers the name.
    self.register(name)
end

#output(*names) ⇒ Object

Declares high-level untyped output signals named +names+ of the current type.



1697
1698
1699
1700
# File 'lib/HDLRuby/hruby_high.rb', line 1697

def output(*names)
    # High.top_user.make_outputs(self.instantiate,*names)
    High.top_user.make_outputs(self,*names)
end

#register(name) ⇒ Object

Register the +name+ of the type.



1643
1644
1645
1646
1647
1648
1649
1650
1651
# File 'lib/HDLRuby/hruby_high.rb', line 1643

def register(name)
    if self.name.empty? then
        raise AnyError, "Cannot register with empty name."
    else
        # Sets the hdl-like access to the type.
        obj = self # For using the right self within the proc
        High.space_reg(name) { obj }
    end
end

#rightObject

Gets the type as right value.

NOTE: used for asymetric types like TypeSystemI.



1665
1666
1667
1668
# File 'lib/HDLRuby/hruby_high.rb', line 1665

def right
    # By default self.
    self
end

#shared(*args) ⇒ Object

Create new shared signals from +args+. +args+ can be a name of list of names or a hash associating names to default values.



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 360

def shared(*args)
    # # Process the arguments.
    # Create the shared signal.
    sig = nil
    args.each do |arg|
        if arg.is_a?(Hash) then
            arg.each do |k,v|
                sig = SharedSignalI.new(self,k,v)
            end
        else
            sig = SharedSignalI.new(self,arg)
        end
    end
    return sig
end

#to_typeObject

Converts to a type. Returns self since it is already a type.



1621
1622
1623
# File 'lib/HDLRuby/hruby_high.rb', line 1621

def to_type
    return self
end

#typedef(name) ⇒ Object

Declares a new type definition with +name+ equivalent to current one.



1673
1674
1675
1676
1677
1678
1679
1680
# File 'lib/HDLRuby/hruby_high.rb', line 1673

def typedef(name)
    # Create the new type.
    typ = TypeDef.new(name,self)
    # Register it.
    High.space_reg(name) { typ }
    # Return it.
    return typ
end

#unary(operator, expr) ⇒ Object

Performs unary operation +operator+ on expression +expr+.



1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
# File 'lib/HDLRuby/hruby_high.rb', line 1729

def unary(operator,expr)
    # Look for a specific computation method.
    comp = comp_operator(operator)
    if self.respond_to?(comp) then
        # Found, use it.
        self.send(comp,expr)
    else
        # Not found, back to default generation of unary expression.
        return Unary.new(self.send(operator),operator,expr)
    end
end