Module: Origen::Model::Exporter
- Defined in:
- lib/origen/model/exporter.rb
Instance Method Summary collapse
-
#export(name, options = {}) ⇒ Object
Export the model.
- #import(name, options = {}) ⇒ Object
Instance Method Details
#export(name, options = {}) ⇒ Object
Export the model
Options defaults:
include_pins: true
include_registers: true
include_sub_blocks: true
include_timestamp: true
rm_rb_only: nil # delete only .rb files, default is rm -rf * Origen.root/vendor/lib/models/name
Use the rm_rb_only option if the export dir is under revision control and the dir contains revision control metadata
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/origen/model/exporter.rb', line 14 def export(name, = {}) = { include_pins: true, include_registers: true, include_sub_blocks: true, include_timestamp: true, file_path: nil }.merge() # file_path is for internal use, don't pass it from the application, use the :dir option if you # want to change where the exported files are file = [:file_path] || export_path(name, ) dir = [:dir_path] || export_dir() path_to_file = Pathname.new(File.join(dir, file)) if File.exist?(path_to_file.sub_ext('').to_s) if [:rm_rb_only] Dir.glob(path_to_file.sub_ext('').to_s + '/**/*.rb').each { |f| FileUtils.rm_f(f) } else FileUtils.rm_rf(path_to_file.sub_ext('').to_s) end end 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, ) do |indent| f.puts((' ' * indent) + 'def self.extended(model)') indent += 2 if top_level? # Write out packages if any 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 [: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 [:include_sub_blocks] sub_blocks.each do |name, block| f.puts export_sub_block(name, block, .merge(indent: indent, file_path: file, dir_path: dir)) end f.puts unless sub_blocks.empty? end if [: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 |
#import(name, options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/origen/model/exporter.rb', line 92 def import(name, = {}) path = File.join(export_dir(), export_path(name, )) if File.exist?(path) require path if .key?(:namespace) && ![:namespace] extend name.to_s.gsub('.', '_').camelcase.constantize else if [:namespace] extend "#{[:namespace].to_s.gsub('.', '_').camelcase}::#{name.to_s.gsub('.', '_').camelcase}".constantize else extend "#{Origen.app.namespace}::#{name.to_s.gsub('.', '_').camelcase}".constantize end end true else if [:allow_missing] false else fail "The import for #{name} could not be found at #{path}" end end end |