4
5
6
7
8
9
10
11
12
13
14
15
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/origen/model/exporter.rb', line 4
def export(name, options = {})
options = {
include_pins: true,
include_registers: true,
include_sub_blocks: true,
include_timestamp: true,
file_path: nil
}.merge(options)
file = options[:file_path] || export_path(name, options)
dir = options[:dir_path] || export_dir(options)
path_to_file = Pathname.new(File.join(dir, file))
FileUtils.rm_rf(path_to_file.sub_ext('').to_s) if File.exist?(path_to_file.sub_ext('').to_s)
FileUtils.rm_rf(path_to_file.to_s) if File.exist?(path_to_file.to_s)
FileUtils.mkdir_p(path_to_file.dirname)
File.open(path_to_file, 'w') do |f|
export_wrap_with_namespaces(f, options) do |indent|
f.puts((' ' * indent) + 'def self.extended(model)')
indent += 2
if top_level?
unless Origen.top_level.packages.empty?
spaces = ' ' * indent
Origen.top_level.packages.each { |p| f.puts "#{spaces}model.add_package :#{p}\n" }
end
end
if options[:include_pins]
if top_level?
pins.each do |id, pin|
f.puts export_pin(id, pin, indent: indent)
end
pin_groups.each do |id, pins|
f.puts export_pin_group(id, pins, indent: indent)
end
power_pins.each do |id, pin|
f.puts export_pin(id, pin, indent: indent, method: :add_power_pin, attributes: [:voltage, :current_limit])
end
power_pin_groups.each do |id, pins|
f.puts export_pin_group(id, pins, indent: indent, method: :add_power_pin_group)
end
ground_pins.each do |id, pin|
f.puts export_pin(id, pin, indent: indent, method: :add_ground_pin)
end
ground_pin_groups.each do |id, pins|
f.puts export_pin_group(id, pins, indent: indent, method: :add_ground_pin_group)
end
virtual_pins.each do |id, pin|
f.puts export_pin(id, pin, indent: indent, method: :add_virtual_pin)
end
f.puts
end
end
if options[:include_sub_blocks]
sub_blocks.each do |name, block|
f.puts export_sub_block(name, block, options.merge(indent: indent, file_path: file, dir_path: dir))
end
f.puts unless sub_blocks.empty?
end
if options[:include_registers]
regs.each do |name, reg|
f.puts export_reg(name, reg, indent: indent)
end
end
indent -= 2
f.puts((' ' * indent) + 'end')
end
end
end
|