Class: HDLRuby::High::Std::PipelineT

Inherits:
Object
  • Object
show all
Includes:
HScope_missing
Defined in:
lib/HDLRuby/std/pipeline.rb

Overview

Describes a high-level pipeline type.

Defined Under Namespace

Classes: PipeSignal, Stage

Constant Summary

Constants included from Hmissing

Hmissing::High, Hmissing::NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HScope_missing

#h_missing, #method_missing

Methods included from Hmissing

#method_missing

Constructor Details

#initialize(name) ⇒ PipelineT

Creates a new pipeline type with +name+.

The proc +ruby_block+ is executed when instantiating the fsm.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/HDLRuby/std/pipeline.rb', line 77

def initialize(name)
    # Check and set the name
    @name = name.to_sym

    # Initialize the internals of the pipeline.


    # Initialize the environment for building the pipeline

    # The stages
    @stages = []

    # The event synchronizing the pipeline
    @mk_ev = proc { $clk.posedge }

    # The reset
    @mk_rst = proc { $rst }

    # Creates the namespace to execute the pipeline block in.
    @namespace = Namespace.new(self)

    # Generates the function for setting up the pipeline.
    obj = self # For using the right self within the proc
    HDLRuby::High.space_reg(@name) do |&ruby_block|
        if ruby_block then
            # Builds the pipeline.
            obj.build(&ruby_block)
        else
            # Return the pipeline as is.
            return obj
        end
    end

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HDLRuby::High::HScope_missing

Instance Attribute Details

#nameObject (readonly)

The name of the pipeline type.



69
70
71
# File 'lib/HDLRuby/std/pipeline.rb', line 69

def name
  @name
end

#namespaceObject (readonly)

The namespace associated with the pipeline



72
73
74
# File 'lib/HDLRuby/std/pipeline.rb', line 72

def namespace
  @namespace
end

Instance Method Details

#build(&ruby_block) ⇒ Object

builds the pipeline by executing +ruby_block+.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/HDLRuby/std/pipeline.rb', line 113

def build(&ruby_block)
    # Use local variable for accessing the attribute since they will
    # be hidden when opening the sytem.
    name      = @name
    stages    = @stages
    namespace = @namespace
    this      = self
    mk_ev     = @mk_ev
    mk_rst    = @mk_rst
    scope     = HDLRuby::High.cur_system.scope

    return_value = nil

    # Enters the current system
    HDLRuby::High.cur_system.open do
        sub do
            HDLRuby::High.space_push(namespace)
            # Execute the instantiation block
            return_value =HDLRuby::High.top_user.instance_exec(&ruby_block)
            HDLRuby::High.space_pop

            # Create the pipeline code.
            
            # Declare and register the pipeline registers generators.
            prs = []
            stages.each do |st|
                st.each do |rn|
                    r = PipeSignal.new(name.to_s+"::"+rn.to_s,scope)
                    prs << r
                    namespace.add_method(rn) { r }
                end
            end

            # Build the pipeline structure.
            return_value = par(mk_ev.call) do
                hif(mk_rst.call == 0) do
                    # No reset, pipeline handling.
                    stages.each do |st|
                        # Generate the code for the stage.
                        HDLRuby::High.space_push(namespace)
                        HDLRuby::High.top_user.instance_exec(&st.code)
                        HDLRuby::High.space_pop
                    end
                end
                helse do
                    prs.each { |r| r <= 0 }
                end
            end
        end
    end

    return return_value
end

#for_event(event = nil, &ruby_block) ⇒ Object

Sets the event synchronizing the pipeline.



170
171
172
173
174
175
176
177
178
# File 'lib/HDLRuby/std/pipeline.rb', line 170

def for_event(event = nil,&ruby_block)
    if event then
        # An event is passed as argument, use it.
        @mk_ev = proc { event.to_event }
    else
        # No event given, use the ruby_block as event generator.
        @mk_ev = ruby_block
    end
end

#for_reset(reset = nil, &ruby_block) ⇒ Object

Sets the reset.



181
182
183
184
185
186
187
188
189
# File 'lib/HDLRuby/std/pipeline.rb', line 181

def for_reset(reset = nil,&ruby_block)
    if reset then
        # An reset is passed as argument, use it.
        @mk_rst = proc { reset.to_expr }
    else
        # No reset given, use the ruby_block as event generator.
        @mk_rst = ruby_block
    end
end

#stage(*regs, &ruby_block) ⇒ Object

Declare a new stage synchronized on registers declared in +regs+ and executing +ruby_block+.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/HDLRuby/std/pipeline.rb', line 194

def stage(*regs, &ruby_block)
    # Create the resulting state
    result = Stage.new
    # Test and set the registers.
    regs.each do |reg|
        # Ensure it is a symbol.
        reg = reg.to_sym
        # Add it.
        result << reg
    end
    # Sets the generation code.
    result.code = ruby_block
    # Add it to the list of states.
    @stages << result
    # Return it.
    return result
end