Module: ClassHDL

Defined in:
lib/tdl/exlib/test_point.rb,
lib/tdl/exlib/test_point.rb,
lib/tdl/class_hdl/hdl_assign.rb,
lib/tdl/class_hdl/hdl_random.rb,
lib/tdl/class_hdl/hdl_struct.rb,
lib/tdl/class_hdl/hdl_verify.rb,
lib/tdl/class_hdl/hdl_foreach.rb,
lib/tdl/class_hdl/hdl_initial.rb,
lib/tdl/class_hdl/hdl_package.rb,
lib/tdl/class_hdl/hdl_function.rb,
lib/tdl/class_hdl/hdl_generate.rb,
lib/tdl/class_hdl/hdl_always_ff.rb,
lib/tdl/class_hdl/hdl_module_def.rb,
lib/tdl/class_hdl/hdl_module_def.rb,
lib/tdl/class_hdl/hdl_module_def.rb,
lib/tdl/class_hdl/hdl_always_comb.rb,
lib/tdl/class_hdl/hdl_block_ifelse.rb,
lib/tdl/class_hdl/hdl_block_ifelse.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb

Overview

Defined Under Namespace

Modules: AssignDefOpertor, RandomNum Classes: BlocAssertIF, BlockCASE, BlockCASEDEFAULT, BlockCASEWHEN, BlockCASEX, BlockELSE, BlockELSIF, BlockFOR, BlockFOREACH, BlockIF, ClassEdge, ClassNegedge, ClassPosedge, ClearGenerateSlaverBlock, ClearSdlModule, DefFunction, DefStruct, EnumStruct, GenerateBlock, GlobalVar, HDLAlwaysBlock, HDLAlwaysCombBlock, HDLAlwaysFFBlock, HDLAlwaysSIMBlock, HDLAssignBlock, HDLAssignGenerateBlock, HDLFunction, HDLFunctionIvoke, HDLInitialBlock, ImplicitInstModule, ImplicitPortBase, ImplicitPortBasePackage, ImplicitPortInout, ImplicitPortInput, ImplicitPortOutput, OpertorChain, SdlPackage, StructBlock, StructMeta, StructVar, Verify

Constant Summary collapse

OP_SYMBOLS =
%w{+ - * / % > < >= <= == != << | & ^}

Class Method Summary collapse

Class Method Details

.Always(sdl_m: nil, posedge: [], negedge: [], &block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/tdl/class_hdl/hdl_always_ff.rb', line 103

def self.Always(sdl_m: nil,posedge: [],negedge: [],&block)
    ClassHDL::AssignDefOpertor.with_new_assign_block(ClassHDL::HDLAlwaysBlock.new(sdl_m)) do |ab|
        ab.posedges = posedge
        ab.negedges = negedge

        AssignDefOpertor.with_rollback_opertors(:new,&block)
        # return ClassHDL::AssignDefOpertor.curr_assign_block
        AssignDefOpertor.with_rollback_opertors(:old) do
            sdl_m.Logic_draw.push ab.instance
        end
    end
end

.AlwaysComb(sdl_m, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/tdl/class_hdl/hdl_always_comb.rb', line 34

def self.AlwaysComb(sdl_m,&block)
    ClassHDL::AssignDefOpertor.with_new_assign_block(ClassHDL::HDLAlwaysCombBlock.new(sdl_m)) do |ab|
        AssignDefOpertor.with_rollback_opertors(:new,&block)
        # return ClassHDL::AssignDefOpertor.curr_assign_block
        AssignDefOpertor.with_rollback_opertors(:old) do
            sdl_m.Logic_draw.push ab.instance
        end
    end
end

.AlwaysFF(sdl_m: nil, posedge: [], negedge: [], &block) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/tdl/class_hdl/hdl_always_ff.rb', line 116

def self.AlwaysFF(sdl_m: nil,posedge: [],negedge: [],&block)
    ClassHDL::AssignDefOpertor.with_new_assign_block(ClassHDL::HDLAlwaysFFBlock.new(sdl_m)) do |ab|
        ab.posedges = posedge
        ab.negedges = negedge

        AssignDefOpertor.with_rollback_opertors(:new,&block)
        # return ClassHDL::AssignDefOpertor.curr_assign_block
        AssignDefOpertor.with_rollback_opertors(:old) do
            sdl_m.Logic_draw.push ab.instance
        end
    end
end

.AlwaysSIM(sdl_m: nil, posedge: [], negedge: [], &block) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/tdl/class_hdl/hdl_always_ff.rb', line 157

def self.AlwaysSIM(sdl_m: nil,posedge: [],negedge: [],&block)
    ClassHDL::AssignDefOpertor.with_new_assign_block(ClassHDL::HDLAlwaysSIMBlock.new(sdl_m)) do |ab|
        ab.posedges = posedge
        ab.negedges = negedge

        AssignDefOpertor.with_rollback_opertors(:new,&block)
        # return ClassHDL::AssignDefOpertor.curr_assign_block
        AssignDefOpertor.with_rollback_opertors(:old) do
            sdl_m.Logic_draw.push ab.instance
        end
    end
end

.Assign(sdl_m, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/tdl/class_hdl/hdl_assign.rb', line 38

def self.Assign(sdl_m,&block)
    # ClassHDL::AssignDefOpertor.curr_assign_block = ClassHDL::HDLAssignBlock.new
    ClassHDL::AssignDefOpertor.with_new_assign_block(ClassHDL::HDLAssignBlock.new(sdl_m)) do |ab|
        AssignDefOpertor.with_rollback_opertors(:new,&block)
        # return ClassHDL::AssignDefOpertor.curr_assign_block
        AssignDefOpertor.with_rollback_opertors(:old) do 
            sdl_m.Logic_draw.push ClassHDL::AssignDefOpertor.curr_assign_block.instance
        end
    end
end

.compact_op_ch(str) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 32

def self.compact_op_ch(str)
    if str =~ /^(?<head>[\w\.\[\]\:]+\s*)(?<eq><?=\s*)\((?<body>.+)\)$/
        rel_str = $~[:head] + $~[:eq] + $~[:body]
    else 
        rel_str = str
    end
end

.define_func_block_method(sdlm, *argv) ⇒ Object

为 function 块内定义 argv 方法



247
248
249
250
251
252
253
# File 'lib/tdl/class_hdl/hdl_function.rb', line 247

def self.define_func_block_method(sdlm,*argv)
    argv.each do |e|
        sdlm.define_singleton_method(e.name) do 
            e 
        end
    end
end

.disable_SdlModule_portObject

redefine sdlmodule input output



171
172
173
174
175
176
177
178
# File 'lib/tdl/class_hdl/hdl_function.rb', line 171

def self.disable_SdlModule_port
    symbs = [:Input,:Output,:Inout]
    symbs.each do |symb|
        SdlModule.class_eval do
            alias_method "_function_bak_#{symb}__",symb
        end
    end
end

.enable_SdlModule_portObject



180
181
182
183
184
185
186
187
# File 'lib/tdl/class_hdl/hdl_function.rb', line 180

def self.enable_SdlModule_port
    symbs = [:Input,:Output,:Inout]
    symbs.each do |symb|
        SdlModule.class_eval do
            alias_method symb,"_function_bak_#{symb}__"
        end
    end
end

.Function(sdl_m, name, return_type, *argvs, &block) ⇒ Object



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
# File 'lib/tdl/class_hdl/hdl_function.rb', line 120

def self.Function(sdl_m,name,return_type,*argvs,&block)
    define_func_block_method(sdl_m,*argvs)
    func_inst = ClassHDL::HDLFunction.new(sdl_m,name,return_type,*argvs)
    ## 给 sdl module 定义函数方法
    sdl_m.define_singleton_method(name) do |*fargvs|
        # new_op = OpertorChain.new 
        # new_op.tree.push([func_inst.ivoked(*fargvs)])
        # new_op.slaver= true
        # AssignDefOpertor.curr_assign_block.opertor_chains.push(new_op)
        # new_op
        fargvs.each do |e|
            if e.is_a? OpertorChain
                e.slaver = true 
            end
        end
        
        HDLFunctionIvoke.new(func_inst,*fargvs)
    end

    ClassHDL::AssignDefOpertor.with_new_assign_block(func_inst) do |ab|

        AssignDefOpertor.with_rollback_opertors(:old) do
            argvs.each do |e|
               
            end
        end
        AssignDefOpertor.with_rollback_opertors(:new,&block)
        # return ClassHDL::AssignDefOpertor.curr_assign_block
        AssignDefOpertor.with_rollback_opertors(:old) do
            sdl_m.Logic_draw.push ab.instance
        end
    end
    remove_func_block_method(sdl_m,*argvs)
    func_inst.open_ivoke = true
end

.Initial(sdl_m, block_name = nil, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/tdl/class_hdl/hdl_initial.rb', line 53

def self.Initial(sdl_m,block_name=nil,&block)
    ClassHDL::AssignDefOpertor.with_new_assign_block(ClassHDL::HDLInitialBlock.new(sdl_m)) do |ab|
        AssignDefOpertor.with_rollback_opertors(:new,&block)
        # return ClassHDL::AssignDefOpertor.curr_assign_block
        AssignDefOpertor.with_rollback_opertors(:old) do
            sdl_m.Logic_draw.push ab.instance(block_name)
        end
    end
end

.new_def_SdlModule_portObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/tdl/class_hdl/hdl_function.rb', line 189

def self.new_def_SdlModule_port
    SdlModule.class_eval do 
        def Input(name,dsize:1,dimension:[],pin:[],iostd:[],pin_prop:nil)
            port_name_chk(name)
            # pin,iostd = parse_pin_prop(pin_prop) if pin_prop
            # RedefOpertor.with_normal_operators do
            ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do 
                tmp = Logic.new(name:name,dsize:dsize,port:"input",dimension:dimension, belong_to_module: self)
                # add_to_new_module("@port_logics",tmp)
                # add_method_to_itgt(name,tmp)
                tmp
            end
        end
    
        def Output(name,dsize:1,dimension:[],pin:[],iostd:[],pin_prop:nil)
            port_name_chk(name)
            # pin,iostd = parse_pin_prop(pin_prop) if pin_prop
            # RedefOpertor.with_normal_operators do
            ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
                tmp = Logic.new(name:name,dsize:dsize,port:"output logic",dimension:dimension, belong_to_module: self)
                # add_to_new_module("@port_logics",tmp)
    
                if block_given?
                    yield(tmp)
                end
                # define_method(name) do
                # add_method_to_itgt(name,tmp)
                tmp
            end
        end
    
        def Inout(name,dsize:1,dimension:[],pin:[],iostd:[],pin_prop:nil)
            port_name_chk(name)
            # pin,iostd = parse_pin_prop(pin_prop) if pin_prop
            # RedefOpertor.with_normal_operators do
            ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
                tmp = Logic.new(name:name,dsize:dsize,port:"inout",dimension:dimension)
                # add_to_new_module("@port_logics",tmp)
    
                if block_given?
                    yield(tmp)
                end
                # define_method(name) do
                # add_method_to_itgt(name,tmp)
                tmp
            end
        end
    end
end

.remove_func_block_method(sdlm, *argv) ⇒ Object



255
256
257
258
259
260
261
262
# File 'lib/tdl/class_hdl/hdl_function.rb', line 255

def self.remove_func_block_method(sdlm,*argv)
    argv.each do |e|
        # sdlm.define_singleton_method(e.name) do 
        #     method_missing(e.name)
        # end
        sdlm.instance_eval("undef #{e.name}")
    end
end

.Struct(name, sdlm, pre_type, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 16

def self.Struct(name,sdlm,pre_type,&block) 
    tmp_sm = ClassHDL::StructBlock.new(sdlm)
    ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do 
        tmp_sm.instance_exec(&block)
    end

    str = (tmp_sm.vars_define_inst + "\n")
    str.gsub!(/\/\/.*/,"")
    str.gsub!(/[\t|\n]+/m,"\n")
    unless pre_type.to_s == 'union'
        head_str = "typedef struct #{pre_type}{\n"
    else 
        head_str = "typedef union {\n"
    end
    end_str  = "} #{name.to_s};\n"

    mstr = String.new(head_str+str+end_str)
    mstr.define_singleton_method("inst") do 
        self 
    end
    sdlm.Logic_collect << mstr

    # 获取 结构体内的变量
    all_collect = []
    SdlModule.class_variable_get('@@ele_array').each do |e|
        head_str = e.to_s 
        all_collect = all_collect + tmp_sm.send("#{head_str}_collect")
    end

    return all_collect

end

.with_disable_SdlModule_port(&block) ⇒ Object



239
240
241
242
243
244
245
# File 'lib/tdl/class_hdl/hdl_function.rb', line 239

def self.with_disable_SdlModule_port(&block)
    disable_SdlModule_port
    new_def_SdlModule_port
    rel = block.call 
    enable_SdlModule_port
    rel
end