Class: SdlInst

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/sdlmodule/sdlmodule_instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin: nil, name: 'inst') ⇒ SdlInst

Returns a new instance of SdlInst.



13
14
15
16
17
18
19
20
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 13

def initialize(origin:nil,name:'inst')
    @origin = origin
    @inner_port_hash = Hash.new
    @inst_port_hash = Hash.new
    @inst_param_hash = Hash.new
    @name = name
    Tdl.add_to_all_file_paths(@origin.module_name.to_s,@origin.real_sv_path) if @origin.real_sv_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *argvs, &block) ⇒ Object (private)



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 316

def method_missing(method_id,*argvs,&block)
    methods_pool = @origin.instance_variable_get("@_add_to_new_module_vars")
    method_str = method_id.to_s
    # if  methods_pool.include?(method_str)
    #     if argvs.empty?
    #         if inst_port_hash.key?(method_str)
    #             inst_port_hash[method_str]
    #         elsif inst_param_hash.key?(method_str)
    #             inst_param_hash[method_str]
    #         else 
    #             @origin.public_send(method_id,*argvs,&block)
    #         end
    #     else 
    #         ## 带参数,及函数带连接
    #         self[method_id] = argvs[0]
    #     end
    # else
    #     super
    #     # raise TdlError.new("SDL Instance dont have method `#{method_id}`")
    # end

    if inst_port_hash.key? method_str
        if argvs.empty?
            inst_port_hash[method_str]
        else  
            self[method_id] = argvs[0]
        end
    elsif inst_param_hash.key? method_str
        if argvs.empty?
            inst_param_hash[method_str]
        else  
            self[method_id] = argvs[0]
        end
    else  
        super 
    end

    # if argvs.empty?
    #     if inst_port_hash.key?(method_str)
    #         inst_port_hash[method_str]
    #     elsif inst_param_hash.key?(method_str)
    #         inst_param_hash[method_str]
    #     else 
    #         @origin.public_send(method_id,*argvs,&block)
    #     end
    # else 
    #     ## 带参数,及函数带连接
    #     self[method_id] = argvs[0]
    # end
end

Instance Attribute Details

#belong_to_moduleObject

Returns the value of attribute belong_to_module.



9
10
11
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 9

def belong_to_module
  @belong_to_module
end

#inner_port_hashObject

Returns the value of attribute inner_port_hash.



7
8
9
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 7

def inner_port_hash
  @inner_port_hash
end

#inst_param_hashObject

Returns the value of attribute inst_param_hash.



7
8
9
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 7

def inst_param_hash
  @inst_param_hash
end

#inst_port_hashObject

Returns the value of attribute inst_port_hash.



7
8
9
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 7

def inst_port_hash
  @inst_port_hash
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 9

def name
  @name
end

#originObject (readonly)

Returns the value of attribute origin.



11
12
13
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 11

def origin
  @origin
end

Instance Method Details

#[](key) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 42

def [](key)
    key = key.to_s
    if inst_param_hash.key? key
        # inst_param_hash[key]
        Parameter(key)
    elsif inst_port_hash.key? key
        # inst_port_hash[key]
        Ports(key)
    else
        printf_keys
        raise TdlError.new("#{@origin.module_name} dont have port [#{key} :CLASS #{key.class}]")
    end
end

#[]=(key, value) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 56

def []=(key,value)
    key = key.to_s
    if inst_param_hash.key? key
        inst_param_hash[key] = value
    elsif inst_port_hash.key? key
        ## 判断 接口类型是否一样
        # if @origin.send(key).is_a?(InfElm) && value.is_a?(InfElm)
        if @origin.send(key).is_a?(TdlSpace::TdlBaseInterface) && value.is_a?(TdlSpace::TdlBaseInterface)
            if @origin.send(key).class != value.class 
                raise TdlError.new("#{@origin.module_name} port type<#{@origin.send(key).class}> isnot same as #{value.name} <#{value.class}>")
            else 
                # raise TdlError.new("#{@origin.module_name} port type isnot same as #{value.module_name}")
                if value.modport_type
                    if @origin.send(key).modport_type.to_s != value.modport_type.to_s
                        # raise TdlError.new("[#{@origin.module_name}] port[#{key}][#{@origin.send(key).port}] type isnot same as [#{value}][#{value.port}]")
                        # puts "[#{@origin.module_name}] port[#{key}][#{@origin.send(key).port}] type isnot same as [#{value}][#{value.port}]"
                        inst_port_hash[key] = VCSCompatable::auto_vcs_cpt_connect(@origin.send(key) ,value)
                    else 
                        inst_port_hash[key] = value
                    end
                else 
                    inst_port_hash[key] = value
                end
            end
        else 
            inst_port_hash[key] = value
        end 
    else
        printf_keys
        raise TdlError.new("#{@origin.module_name} dont have port [#{key} :CLASS #{key.class}]")
    end
end

#_last_hier_signal(key) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 116

def _last_hier_signal(key)
    @_name_collect ||= hier_name_collect

    if key.is_a? BaseElm
        key_str = key.signal
    elsif key.is_a? String
        key_str = key
    elsif key.is_a? Symbol
        key_str = key.to_s
    else
        raise TdlError.new("#{@origin.module_name} hier signal key type error")
    end

    if @_name_collect.include? key_str
        "#{inst_name}.#{key_str}"
    else
        raise TdlError.new("#{@origin.module_name} INST #{inst_name} dont have #{key_str}")
    end
end

#hier_inst_collectObject



310
311
312
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 310

def hier_inst_collect
    ois = @origin.instance_variable_get("@sub_instanced")
end

#hier_signal(*keys) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 89

def hier_signal(*keys)
    RedefOpertor.with_normal_operators do
        if keys.size == 1
            _last_hier_signal(keys[0])
        else
            @_inst_collect ||= hier_inst_collect
            cl = @_inst_collect.find do |e|
                if keys[0].is_a? SdlInst
                    keys[0].inst_name == e.inst_name
                elsif keys[0].is_a?(String) || keys[0].is_a?(Symbol)
                    kstr = keys[0].to_s
                    kstr == e.inst_name
                else
                    raise TdlError.new("#{@origin.module_name} hier signal key type error")
                end
            end

            unless cl
                raise TdlError.new("#{@origin.module_name} INST #{inst_name} dont have #{keys[0].to_s}")
            end

            "#{cl.inst_name}."+hier_signal(*keys[1,keys.size])
        end
    end
end

#inst_drawObject



137
138
139
140
141
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 137

def inst_draw
"#{@origin.module_name} #{inst_param}#{inst_name}(
#{inst_port}
);"
end

#inst_nameObject



143
144
145
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 143

def inst_name
    @name.to_s
end

#output(*args) ⇒ Object Also known as: input, inout, param, parameter



381
382
383
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 381

def output(*args)
    return SdlInstSimplePortSugar.new(self) 
end

#Parameter(key) ⇒ Object



34
35
36
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 34

def Parameter(key)
    read_hash_value(inst_param_hash,key)
end

#port(*args) ⇒ Object Also known as: data_inf_c, axi_stream_inf, data_inf, axi4



370
371
372
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 370

def port(*args)
    return SdlInstPortSugar.new(self)
end

#Ports(key) ⇒ Object



38
39
40
# File 'lib/tdl/sdlmodule/sdlmodule_instance.rb', line 38

def Ports(key)
    read_hash_value(inst_port_hash,key)
end