Class: TopModule
- Inherits:
-
SdlModule
show all
- Defined in:
- lib/tdl/sdlmodule/top_module.rb,
lib/tdl/sdlmodule/top_module.rb,
lib/tdl/sdlmodule/top_module.rb,
lib/tdl/sdlmodule/top_module.rb,
lib/tdl/exlib/sdlmodule_sim.bak.rb,
lib/tdl/sdlmodule/test_unit_module.rb
Overview
Constant Summary
collapse
- @@curr_top_module =
nil
Instance Attribute Summary collapse
Attributes inherited from SdlModule
#create_tcl, #dont_gen_sv, #ex_down_code, #ex_param, #ex_port, #ex_up_code, #head_import_packages, #instance_and_children_module, #instanced_and_parent_module, #module_name, #origin_sv, #out_sv_path, #path, #real_sv_path, #target_class
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_itegration(itgt_class, nickname: nil, param: {}, pins_map: {}, implicit: false) ⇒ Object
-
#add_test_unit(*args) ⇒ Object
-
#Clock(name, freqM: 100, port: :input, pin: [], iostd: [], dsize: 1, pin_prop: nil) ⇒ Object
-
#console_argvs ⇒ Object
-
#create_add_file_tcl ⇒ Object
-
#create_xdc ⇒ Object
-
#gen_sv_module ⇒ Object
-
#gen_sv_module_verb ⇒ Object
-
#index_inst ⇒ Object
-
#initialize(name: "tdlmodule", out_sv_path: nil) ⇒ TopModule
constructor
A new instance of TopModule.
-
#Inout(name, dsize: 1, dimension: [], pin: [], iostd: [], pin_prop: nil) ⇒ Object
-
#Input(name, dsize: 1, dimension: [], pin: [], iostd: [], pin_prop: nil) ⇒ Object
-
#itgt_collect ⇒ Object
attr_accessor :cal_inst_index_proc.
-
#link_eval ⇒ Object
-
#load_pins(pins_file) ⇒ Object
-
#mix_itegrations ⇒ Object
-
#Output(name, dsize: 1, dimension: [], pin: [], iostd: [], pin_prop: nil) ⇒ Object
-
#parse_pin_prop(prop = nil) ⇒ Object
-
#pins ⇒ Object
-
#recur_pins_hash(hash) ⇒ Object
-
#Reset(name, port: :input, active: "low", pin: [], iostd: [], dsize: 1, pin_prop: nil) ⇒ Object
-
#rewrite_to_warning(path, file_name) ⇒ Object
-
#sim_test_hash ⇒ Object
-
#sim_test_hash=(hash) ⇒ Object
-
#test_unit ⇒ Object
Methods inherited from SdlModule
#<<, #>>, #Always, #AlwaysComb, #Always_comb, #Always_ff, #Assign, #CASE, #CASEX, #CommonCFGReg, #DEFAULT, #Def, #ELSE, #ELSIF, #FOR, #FOREACH, #IF, #Initial, #Instance, #Itgt_Instance, Main, #NameSpaceAdd, #Parameter, #Parameters, #StateMachine, #TrackInf, #TryDef, #WHEN, #add_children_modules, #add_parent_modules, #add_to_new_module, allmodule_name, #always_ff, #always_sim, #assert, #assert_error, #assert_format_error, #assert_old, #bits, #build_module, #call_instance, call_module, #children_inst_tree, #clog2, #debugLogic, #def_struct, #define_ele, #enum, exist_module?, #function, gen_sv_module, #gen_sv_module_text, #generate, #genvar, #has_inward_inst?, #has_signal?, #implicit_inst_module_method_missing, #initial, #initial_exec, #inout, #input, #instance_draw, #instanced, #inward_inst, #localparam, #logic, #logic_bind_, #macro_add_vcs, #macro_def, #method_missing, #negedge, #output, #parameter, #parents_inst_tree, #port, #posedge, #require_package, #rubyOP, #same_clock_domain, #show_ports, #signal, #top_module_ref?, #top_tb_ref?, #try_call_ele, #urandom_range, #var_common, #vars_define_inst, #vars_exec_inst, #vcs_string, #verify
Constructor Details
#initialize(name: "tdlmodule", out_sv_path: nil) ⇒ TopModule
Returns a new instance of TopModule.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 6
def initialize(name:"tdlmodule",out_sv_path:nil)
@@curr_top_module = self
@sim = TopModule.sim
@out_sv_path = out_sv_path
@constraint = ConstraintsVerb.new
if @sim
rewrite_to_warning(out_sv_path,"#{name}.sv")
name = "#{name}_sim"
else
rewrite_to_warning(out_sv_path,"#{name}_sim.sv")
end
@techbench = TechBenchModule.new(name:"tb_#{name}",out_sv_path:out_sv_path)
rtl_top_module = super(name:name,out_sv_path:out_sv_path)
@techbench.Instance(name,"rtl_top")
rtl_top_module
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class SdlModule
Instance Attribute Details
#constraint ⇒ Object
Returns the value of attribute constraint.
4
5
6
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 4
def constraint
@constraint
end
|
#implicit_itgt_collect ⇒ Object
Returns the value of attribute implicit_itgt_collect.
349
350
351
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 349
def implicit_itgt_collect
@implicit_itgt_collect
end
|
#sim ⇒ Object
Returns the value of attribute sim.
4
5
6
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 4
def sim
@sim
end
|
#techbench ⇒ Object
Returns the value of attribute techbench.
4
5
6
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 4
def techbench
@techbench
end
|
#vcs_path ⇒ Object
416
417
418
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 416
def vcs_path
@vcs_path
end
|
Class Method Details
.current ⇒ Object
29
30
31
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 29
def self.current
@@curr_top_module
end
|
.define_global(name, default_value) ⇒ Object
def self.recur_ref(sdlmodule,collect_str)
if sdlmodule.is_a? TopModule
@@root_ref_array << "$root.#{sdlmodule.techbench.module_name}.#{sdlmodule.instanced_and_parent_module.keys.first}.#{collect_str}"
else
return nil unless sdlmodule.instanced_and_parent_module
sdlmodule.instanced_and_parent_module.each do |k_inst,v_module|
next_collect_str = "#{k_inst}.#{collect_str}"
self.recur_ref(v_module,next_collect_str)
end
end
end
329
330
331
332
333
334
335
336
337
338
339
340
341
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 329
def self.define_global(name,default_value)
self.class_variable_set("@@#{name.to_s}",default_value)
self.define_singleton_method(name.to_s) do
self.class_variable_get("@@#{name.to_s}")
end
self.define_singleton_method("#{name.to_s}=") do |a|
self.class_variable_set("@@#{name.to_s}",a)
end
end
|
.method_missing(method, *args, &block) ⇒ Object
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 417
def self.method_missing(method,*args,&block)
sdlm = TopModule.new(name: method,out_sv_path: args[0])
@@package_names ||= []
sdlm.head_import_packages = []
sdlm.head_import_packages += @@package_names
@@package_names.each do |e|
sdlm.require_package(e,false) if e
end
@@package_names = []
sdlm.instance_exec(&block)
if args[0] && File.exist?(args[0])
sdlm.gen_sv_module_verb
unless sdlm.vcs_path
sdlm.test_unit.gen_dve_tcl(File.join(args[0],"dve.tcl"))
else
sdlm.test_unit.gen_dve_tcl(File.join(sdlm.vcs_path,"dve.tcl"))
end
sdlm.create_xdc
else
sdlm.origin_sv = true
end
sdlm
end
|
.with_package(*args) ⇒ Object
446
447
448
449
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 446
def self.with_package(*args)
@@package_names += args
return self
end
|
Instance Method Details
#add_itegration(itgt_class, nickname: nil, param: {}, pins_map: {}, implicit: false) ⇒ Object
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 356
def add_itegration(itgt_class,nickname:nil,param:{},pins_map:{},implicit:false)
@_itgt_collect_ ||= []
if pins_map.is_a? Hash
pins_map_f = pins_map
else
pins_map_f = self.pins[pins_map.to_s] || {}
end
ist = Kernel.const_get(itgt_class).new(nickname,pins_map_f,self)
@_itgt_collect_ << ist unless implicit
param.each do |k,v|
ist.send("#{k}=",v)
end
col = ist.class.get_itgt_var('itegration_link_collect',[])
if col && col.empty?
ist.inst unless ist.init_inst
ist.init_inst = true
ist.inst_index = 0
end
return ist
end
|
#add_test_unit(*args) ⇒ Object
80
81
82
83
|
# File 'lib/tdl/sdlmodule/test_unit_module.rb', line 80
def add_test_unit(*args)
@_test_unit_collect_ ||= []
@_test_unit_collect_ = @_test_unit_collect_ + args
end
|
#Clock(name, freqM: 100, port: :input, pin: [], iostd: [], dsize: 1, pin_prop: nil) ⇒ Object
204
205
206
207
208
209
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 204
def Clock(name,freqM:100,port: :input,pin:[],iostd:[],dsize:1,pin_prop:nil)
pin,iostd,pulltype,drive = parse_pin_prop(pin_prop) if pin_prop
a = super(name,port:port,freqM:freqM,pin:pin,iostd:iostd,dsize:dsize,pin_prop:pin_prop)
@constraint.add_property(a,pin,iostd,pulltype,drive)
a
end
|
#console_argvs ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 64
def console_argvs
hash = $argvs_hash
if hash[:sim]
@sim = hash[:sim]
end
bi = Proc.new do
bp = File.join(@out_sv_path,"program_files/")
Dir.mkdir(bp) unless File.exist? bp
bp
end
if hash[:gold]
@constraint.image(type: :gold,next_addr:hash[:next_cfg_addr],bitpath:bi.call)
elsif hash[:update]
@constraint.image(type: :update,bitpath:bi.call)
end
end
|
#create_add_file_tcl ⇒ Object
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 227
def create_add_file_tcl
return if @sim
fname = "#{module_name}_add_files.tcl"
fname = File.join(@out_sv_path,fname)
File.open(fname,'w') do |f|
f.puts("add_files \\")
f.puts Tdl.all_file_paths.map{ |k,v| v.gsub("\\",'/') }.join("\\\n")
end
end
|
#create_xdc ⇒ Object
218
219
220
221
222
223
224
225
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 218
def create_xdc
return if @sim
fname = "#{module_name}_constraints.xdc"
fname = File.join(@out_sv_path,fname)
File.open(fname,'w') do |f|
f.puts @constraint.xds
end
end
|
#gen_sv_module ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 115
def gen_sv_module
if @sim
Tdl.Puts "INFO: JUST GEN SV[#{@module_name}] FOR SIM "
else
Tdl.Puts "INFO: JUST GEN TechBench Modules,NO SIM"
end
super
TechBenchModule.gen_sv_module
end
|
#gen_sv_module_verb ⇒ Object
171
172
173
174
175
176
177
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 171
def gen_sv_module_verb
mix_itegrations
_exec_add_test_unit() if TopModule.sim
gen_sv_module
end
|
#index_inst ⇒ Object
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 396
def index_inst
curr_collect = (implicit_itgt_collect || []) | @_itgt_collect_
curr_collect.each do |e|
if e.init_inst
e.cal_inst_index(0)
end
end
curr_collect = curr_collect.sort { |a, b| a.inst_index <=> b.inst_index }
curr_collect.each {|e| e.inst unless e.init_inst }
end
|
#Inout(name, dsize: 1, dimension: [], pin: [], iostd: [], pin_prop: nil) ⇒ Object
197
198
199
200
201
202
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 197
def Inout(name,dsize:1,dimension:[],pin:[],iostd:[],pin_prop:nil)
pin,iostd,pulltype,drive = parse_pin_prop(pin_prop) if pin_prop
a = super(name,dsize:dsize,dimension:dimension,pin:pin,iostd:iostd)
@constraint.add_property(a,pin,iostd,pulltype,drive)
a
end
|
183
184
185
186
187
188
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 183
def Input(name,dsize:1,dimension:[],pin:[],iostd:[],pin_prop:nil)
pin,iostd,pulltype,drive = parse_pin_prop(pin_prop) if pin_prop
a = super(name,dsize:dsize,dimension:dimension,pin:pin,iostd:iostd,pin_prop:pin_prop)
@constraint.add_property(a,pin,iostd,pulltype,drive)
a
end
|
#itgt_collect ⇒ Object
attr_accessor :cal_inst_index_proc
352
353
354
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 352
def itgt_collect
@_itgt_collect_
end
|
#link_eval ⇒ Object
388
389
390
391
392
393
394
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 388
def link_eval
@_itgt_collect_ ||= []
@_itgt_collect_.each do |i|
i.link_eval
end
end
|
#load_pins(pins_file) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 37
def load_pins(pins_file)
pins_params = YAML::load(File.open(pins_file))
pins_params = recur_pins_hash(pins_params)
pins_params.define_singleton_method("[]") do |index|
pins_params.fetch(index.to_s)
end
@pins_params = pins_params
end
|
#mix_itegrations ⇒ Object
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
166
167
168
169
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 128
def mix_itegrations
self.link_eval
self.index_inst
@_itgt_collect_.each do |itgt|
itgt.silence_procs_run if itgt.respond_to?('silence_procs_run')
end
if implicit_itgt_collect
implicit_itgt_collect.each do |itgt|
itgt.silence_procs_run if itgt.respond_to?('silence_procs_run')
end
end
@_itgt_collect_.each do |itgt|
itgt.gen_children_modules()
end
if implicit_itgt_collect
implicit_itgt_collect.each do |itgt|
itgt.gen_children_modules()
end
end
end
|
#Output(name, dsize: 1, dimension: [], pin: [], iostd: [], pin_prop: nil) ⇒ Object
190
191
192
193
194
195
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 190
def Output(name,dsize:1,dimension:[],pin:[],iostd:[],pin_prop:nil)
pin,iostd,pulltype,drive = parse_pin_prop(pin_prop) if pin_prop
a = super(name,dsize:dsize,dimension:dimension,pin:pin,iostd:iostd,pin_prop:pin_prop)
@constraint.add_property(a,pin,iostd,pulltype,drive)
a
end
|
#parse_pin_prop(prop = nil) ⇒ Object
179
180
181
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 179
def parse_pin_prop(prop=nil)
return [prop["pins"],prop["iostd"],prop["pulltype"],prop["drive"]]
end
|
#pins ⇒ Object
33
34
35
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 33
def pins
@pins_params
end
|
#recur_pins_hash(hash) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 49
def recur_pins_hash(hash)
new_hash = {}
hash.each do |k,v|
if v.is_a? Hash
hash[k] = recur_pins_hash(v)
else
if v.is_a?(String) && v=~/\s/
hash[k] = v.split(/\s+/)
end
end
new_hash[k.to_sym] = hash[k]
end
return hash.merge(new_hash)
end
|
#Reset(name, port: :input, active: "low", pin: [], iostd: [], dsize: 1, pin_prop: nil) ⇒ Object
211
212
213
214
215
216
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 211
def Reset(name,port: :input,active:"low",pin:[],iostd:[],dsize:1,pin_prop:nil)
pin,iostd,pulltype,drive = parse_pin_prop(pin_prop) if pin_prop
a = super(name,port:port,active:active,pin:pin,iostd:iostd,dsize:dsize,pin_prop:pin_prop)
@constraint.add_property(a,pin,iostd,pulltype,drive)
a
end
|
#rewrite_to_warning(path, file_name) ⇒ Object
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
111
|
# File 'lib/tdl/sdlmodule/top_module.rb', line 84
def rewrite_to_warning(path,file_name)
unless path
_out_sv_path = './'
else
_out_sv_path = path
end
path_file_name = File.join(_out_sv_path,file_name)
return unless File.exist? path_file_name
basename = File.basename(path_file_name,'.sv')
File.open(path_file_name,'w') do |f|
str =
"
`timescale 1ns/1ps
module #{basename}();
initial begin
#(1us);
$warning(\"Check TopModule.sim,please!!!\");
$stop;
end
endmodule\n"
f.puts str
end
end
|
#sim_test_hash=(hash) ⇒ Object