Class: CrossOrigen::OrigenFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/cross_origen/origen_format.rb

Constant Summary collapse

SUB_BLOCK_ATTRS =
{
  base_address:    'IP base address',
  byte_order:      'Describes endianness of the IP.  Values possible are :big_endian and :little_endian',
  lau:             'IP Least Addressable Unit: Values possible are (1..32)',
  version:         'IP version',
  instance:        'IP instance',
  instance_module: 'IP module',
  class_name:      'Class name',
  instance:        'IP instance',
  instance_module: 'IP module',
  addr_block_name: 'Address block name',
  space:           'Address block space'
}
FILE_COMMENTS =
{
  class: "\# This file is created by Origen via CrossOrigen::OrigenFormat#export, and is read-only.\n\# If you need to make changes, re-open the class\n",
  incl:  "\# This file is created by Origen via CrossOrigen::OrigenFormat#export, and is read-only"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OrigenFormat

Returns a new instance of OrigenFormat.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cross_origen/origen_format.rb', line 26

def initialize(options = {})
  options = {
    obj:               $dut,
    path:              "#{Origen.root!}/output",
    instantiate_level: :top
  }.update(options)
  @obj = options[:obj]
  @output_dir = options[:path]
  @inst_level = options[:instantiate_level]
  fail "@instantiate_level must be either set to ':top' or ':sub_block'" unless [:top, :sub_block].include?(@inst_level)
  @top_level_path = "#{output_dir}/top_level.rb"
  @incl_path = "#{output_dir}/sub_blocks.rb"
  @incl_dir = "#{output_dir}/import"
  @top_level_hierarchy = get_namespace(options)
  @top_level_class = @top_level_hierarchy.keys.last

  # first key is file type (:bom or :incl) and second is object name
  @file_content = Hash.new do |h, k|
    h[k] = {}
  end
end

Instance Attribute Details

#file_contentObject (readonly)

Returns the value of attribute file_content.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def file_content
  @file_content
end

#incl_dirObject (readonly)

Returns the value of attribute incl_dir.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def incl_dir
  @incl_dir
end

#incl_pathObject (readonly)

Returns the value of attribute incl_path.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def incl_path
  @incl_path
end

#inst_levelObject (readonly)

Returns the value of attribute inst_level.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def inst_level
  @inst_level
end

#objObject (readonly)

Returns the value of attribute obj.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def obj
  @obj
end

#output_dirObject (readonly)

Returns the value of attribute output_dir.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def output_dir
  @output_dir
end

#top_level_classObject (readonly)

Returns the value of attribute top_level_class.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def top_level_class
  @top_level_class
end

#top_level_hierarchyObject (readonly)

Returns the value of attribute top_level_hierarchy.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def top_level_hierarchy
  @top_level_hierarchy
end

#top_level_pathObject (readonly)

Returns the value of attribute top_level_path.



24
25
26
# File 'lib/cross_origen/origen_format.rb', line 24

def top_level_path
  @top_level_path
end

Instance Method Details

#exportObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cross_origen/origen_format.rb', line 48

def export
  # Delete any previous files
  FileUtils.rm_rf(@incl_dir) if File.exist?(@incl_dir)
  FileUtils.mkdir_p(@incl_dir)

  # Check if previous version of top-level files exist and delete them
  File.delete(@top_level_path) if File.exist?(@top_level_path)
  File.delete(@incl_path) if File.exist?(@incl_path)

  # Create the sub_block objects in the top_level.rb file
  # This method will create each required class file recursively (indirectly)
  # and will gather all of the information required to create the include file.
  # In essence it does it all
  create_bom
end