Class: Parameter

Inherits:
BaseElm show all
Includes:
BaseModule, ClassHDL::RandomNum
Defined in:
lib/tdl/elements/parameter.rb,
lib/tdl/elements/parameter.rb,
lib/tdl/elements/parameter.rb,
lib/tdl/elements/parameter.rb,
lib/tdl/class_hdl/hdl_random.rb,
lib/tdl/axi4/axi4_interconnect_verb.rb

Overview

require_relative “.././axi4”

Constant Summary collapse

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

Instance Attribute Summary collapse

Attributes inherited from BaseElm

#belong_to_module

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassHDL::RandomNum

#precent_false, #precent_true

Methods included from BaseModule

#length, #to_s

Methods inherited from BaseElm

#matrix, #name_copy, #path_refs, recfg_nc, #s, #signal

Methods included from TdlSpace::ExCreateTP

#create_tp, #root_ref

Constructor Details

#initialize(name: "P", value: 100, local: false, port: false, show: true, type: nil) ⇒ Parameter

Returns a new instance of Parameter.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tdl/elements/parameter.rb', line 9

def initialize(name: "P",value:100,local:false,port:false,show:true,type:nil)
    @name = name
    @local = local
    # @id = GlobalParam.CurrTdlModule.BindEleClassVars.Parameter.id
    @port = port
    @show = show
    @value = value
    @type = type
    # if @port
    #     GlobalParam.CurrTdlModule.BindEleClassVars.Parameter.ports << self
    # else
    #     GlobalParam.CurrTdlModule.BindEleClassVars.Parameter.inst_stack << method(:inst)
    # end
end

Instance Attribute Details

#ghostObject

Returns the value of attribute ghost.



7
8
9
# File 'lib/tdl/elements/parameter.rb', line 7

def ghost
  @ghost
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/tdl/elements/parameter.rb', line 7

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/tdl/elements/parameter.rb', line 7

def name
  @name
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/tdl/elements/parameter.rb', line 7

def type
  @type
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/tdl/elements/parameter.rb', line 7

def value
  @value
end

#vcs_stringObject

Returns the value of attribute vcs_string.



7
8
9
# File 'lib/tdl/elements/parameter.rb', line 7

def vcs_string
  @vcs_string
end

Class Method Details

.parse_params(parameter_str) ⇒ Object

parse text for autogen method and constant ###



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
# File 'lib/tdl/elements/parameter.rb', line 93

def self.parse_params(parameter_str)
    if parameter_str.nil? || parameter_str.strip.empty?
        return nil
    end
    params = []
    parameter_str = parameter_str.gsub(/\/\/.*$/,'')
    if parameter_str && !parameter_str.strip.empty?
        params = parameter_str.split(/,\s*$/).map do |e|
            me = e.match(/(?<vcs>parameter|parameter_string|parameter_longstring)(\(\d+\))?\s*(\[.*?\]|\s+|real|bit|string|longint)\s*(?<name>\w+)\s*=\s*(?<value>.*)/)
            # me = e.match(/(?<vcs>parameter|parameter_string)\s*(\[.*?\]|\s+|real|bit|string|longint)\s*(?<name>\w+)\s*=\s*(?<value>.*)/)
            # me_value = me["value"].downcase
            next unless me
            me_value = me["value"]
            ex_me = e.match(/\(\*\s*show\s*=\s*"false"\s*\*\)/)
            if me && !ex_me
                h = Hash.new
                h[:type] = Parameter
                me_integer = me_value.match(/^\s*\d+\s*$/)
                me_mth0 = me_value.match(/["](?<str_name>.+?)["]/)
                me_mth3 = me_value.match(/\$clog2/)
                me_mth4 = me_value.match(/^[A-Z]([A-Z]|[0-9]|\+|-|\*|\/|%|_)+[A-Z0-9]$/)
                me_mth2 = me_value.match(/(?<bit_name>^\d+$|^\d+(=|-|\*|\/){1,2}\d+)/i)
                me_mth1 = me_value.match(/(?<bit_name>\d*'(h|d|b|sh|sd|sb)\w+|^\d+$|\d+(=|-|\*|\/){1,2}\d+)/i)
                me_mth5 = me_value.match(/\{.+\}/)
                if me_value
                    h[:name] = me["name"].downcase
                    h[:origin_name] = me["name"]
                    if me_mth5
                        h[:value]   = "NqString.new(\"#{me_value}\")"
                    elsif me_integer
                        h[:value]   = me_value
                    elsif me_mth0
                        h[:value]   = '"'+me_mth0["str_name"]+'"'
                    elsif me_mth2
                        h[:value]   = me_mth1["bit_name"]
                    elsif me_mth1
                        h[:value]   = '"'+me_mth1["bit_name"]+'"'
                    elsif me_mth3
                        h[:value]   = "NqString.new('#{me_value}')"
                    elsif me_mth4
                        h[:value]   = "NqString.new('#{me_value}')"
                    else
                        h[:value]   = '"'+me_value.strip+'"'
                    end
                end

                h[:port_len]  = h[:origin_name].length
                # h[:type] = Parameter

                h[:inst_ex_port] = lambda { |ml|
                    if ml+4 >= h[:origin_name].length
                        ll = ml+4 - h[:origin_name].length
                    else
                        ll = 1
                    end

                    "    .#{h[:origin_name]}"+" "*(ll)+"(\#{align_signal(#{h[:name]})})"
                }

                yield h

                h
            else
                nil
            end
        end
    end
    params.compact
end

Instance Method Details

#[](a, b = nil) ⇒ Object

def signal

if @port
    "#{@name}"
else
    "#{@name}_#{@id}"
end

end



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tdl/elements/parameter.rb', line 41

def [](a,b=nil)
    if a.is_a? ClassHDL::OpertorChain
        a.slaver = true
    end

    if b.is_a? ClassHDL::OpertorChain
        b.slaver = true
    end

    if b
        sqstr = "[#{a.to_s}:#{b.to_s}]"
    else
        sqstr = "[#{a.to_s}]"
    end
    signal.concat sqstr
end

#always_times(&block) ⇒ Object



274
275
276
277
278
279
# File 'lib/tdl/elements/parameter.rb', line 274

def always_times(&block)
    with_tap_id do
        str = times(pt_id,&block)
        GenInnerStr.new(str)
    end
end

#clog2Object



194
195
196
# File 'lib/tdl/elements/parameter.rb', line 194

def clog2
    return "$clog2(#{signal})".to_nq
end

#cmod(x) ⇒ Object



198
199
200
201
# File 'lib/tdl/elements/parameter.rb', line 198

def cmod(x)
    ## 返回最小整数使得 self 小于等于 x*rel 
    return "#{signal}/#{x}+(#{signal}%#{x}!=0)".to_nq
end

#eql?(a) ⇒ Boolean

Returns:

  • (Boolean)


311
312
313
314
315
316
317
# File 'lib/tdl/elements/parameter.rb', line 311

def eql?(a)
    if a.is_a? Parameter
        self.value.eql? a.value
    else
        self.value.eql? a
    end
end

#generator(&block) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/tdl/elements/parameter.rb', line 212

def generator(&block)
    with_tap_id do
        tmp_sm = GenBlockModule.new(name:"#{belong_to_module.module_name}_#{name}_generator_tmp_top_#{pg_id}",belong_to_module:belong_to_module)
        gstr = yield("#{name}_KK".to_nq,tmp_sm)  # KK, str_collect

        str = ""

        if gstr.is_a? GenInnerStr
            str += gstr
        end

        str += (tmp_sm.instance_draw + tmp_sm.vars_exec_inst)
        # belong_to_module.Logic_inst << tmp_sm.vars_define_inst
        belong_to_module.Logic_draw << generator_block(str)
    end
end

#generator_times(&block) ⇒ Object

for .. for ..



267
268
269
270
271
272
# File 'lib/tdl/elements/parameter.rb', line 267

def generator_times(&block)     # for .. for ..
    with_tap_id do
        str = times(pg_id,&block)
        GenInnerStr.new(str)
    end
end

#instObject



24
25
26
27
28
29
30
31
# File 'lib/tdl/elements/parameter.rb', line 24

def inst
    return "" if @ghost
    unless @local
        "parameter #{@type.to_s} #{@name}   = #{align_signal(@value)};"
    else
        "localparam #{@type.to_s} #{@name}  = #{align_signal(@value)};"
    end
end

#inst_port(align_len = 7) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tdl/elements/parameter.rb', line 62

def inst_port(align_len = 7)
    unless @show
        show_str = "//(* show = \"false\" *)\n    "
    else
        show_str = ""
    end
    if @port
        unless vcs_string
            with_new_align(0) do
                show_str + ("parameter" + " #{@type.to_s} " + @name.to_s + " " + " "*align_len + "= #{align_signal(@value)}")
            end
        else 
            with_new_align(0) do
                show_str + ("`parameter_longstring(#{vcs_string}) " + @name.to_s + " " + " "*align_len + "= #{align_signal(@value)}")
            end
        end
    end
end

#port_lengthObject



58
59
60
# File 'lib/tdl/elements/parameter.rb', line 58

def port_length
    ("parameter" + " #{@type.to_s} " + @name.to_s + " ").length
end

#real_dataObject



5
6
7
# File 'lib/tdl/axi4/axi4_interconnect_verb.rb', line 5

def real_data
    @value
end