Class: Origen::CodeGenerators::Block

Inherits:
Base
  • Object
show all
Includes:
BlockCommon
Defined in:
lib/origen/code_generators/block.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BlockCommon

#class_name, #create_files, #extract_model_name, #validate_args_common

Methods inherited from Base

inherited, name, namespace

Methods included from Actions

#add_acronyms, #add_autoload, #add_config, #add_source, #camelcase, #comment_config, #config, #environment, #gem, #gem_group, #generate, #git, #initialize, #lib, #rakefile, #readme, #underscored_app_namespace

Methods included from Actions::Helpers

#add_type_to_namespaces, #class_name_to_blocks_dir, #class_name_to_lib_file, #internal_depth, #resource_path, #resource_path_to_blocks_dir, #resource_path_to_class, #resource_path_to_lib_file, #unless_has_method, #unless_valid_underscored_identifier, #validate_resource_path

Class Method Details

class_option :duts, type: :boolean, desc: ‘Instantiate the new sub-block in all DUT models’, default: true class_option :instance, desc: ‘The main NAME argument will be the name given to the model and the instantiated sub-block, optionally provide a different name for the instance’



9
10
11
# File 'lib/origen/code_generators/block.rb', line 9

def self.banner
  'origen new block [TYPE/]DERIVATIVE [BLOCK]'
end

Instance Method Details

#completedObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/origen/code_generators/block.rb', line 144

def completed
  add_acronyms
  puts
  if @nested
    puts 'New sub-block created and instantiated.'.green
  else
    if @sub_block_instantiated
      puts 'New sub-block created and instantiated within your DUT(s) as:'.green + "  dut.#{@final_namespaces[1]}"
    else
      puts 'New sub-block created, you can instantiate it within your blocks like this:'.green
      puts
      puts "  #{@line}"
    end
  end
  puts
end

#instantiate_sub_blockObject



79
80
81
82
83
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
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
# File 'lib/origen/code_generators/block.rb', line 79

def instantiate_sub_block
  if @nested
    # First create the parent's sub_blocks.rb file if it doesn't exist
    f = "#{@dir.parent}.rb"
    unless File.exist?(f)
      @nested = false
      orig_fullname = @fullname
      orig_resouce_path = @resource_path
      @fullname = @fullname.split('::')
      @fullname.pop
      @fullname = @fullname.join('::')
      @resource_path = @resource_path.split('/')
      @resource_path.pop
      @resource_path = @resource_path.join('/')
      template 'templates/code_generators/sub_blocks.rb', f
      @fullname = orig_fullname
      @resource_path = orig_resouce_path
      @nested = true
    end

    line = "sub_block :#{@final_name}, class_name: '#{@fullname}'#, base_address: 0x4000_0000"
    append_to_file f, "\n#{line}"
  else
    @line = "sub_block :#{@final_namespaces[1]}, class_name: '#{class_name}'#, base_address: 0x4000_0000"

    unless duts.empty?
      puts
      @dut_index = [nil]
      index = 1
      duts.each do |name, children|
        index = print_dut(name, index, children, 0)
      end
      puts
      puts 'DO YOU WANT TO INSTANTIATE THIS SUB-BLOCK IN YOUR DUT MODELS?'
      puts
      puts 'If so enter the number(s) of the DUT(s) you wish to add it to from the list above, separating multiple entries with a space'
      puts '(note that adding it to a parent DUT in the hierarchy will already be adding it to all of its children).'
      puts
      response = ask 'Enter the DUT number(s), or just press return to skip:'

      done = []
      response.strip.split(/\s+/).each do |index|
        index = index.to_i
        target = @dut_index[index]
        if target
          # Don't add the sub-block to children if we've already added it to the parent, this will
          # cause an already defined sub-block error since it will be added by both instantiations
          unless done.any? { |c| target =~ /^#{c}::/ }
            done << target
            sub_blocks = class_name_to_blocks_dir(target).join('sub_blocks.rb')
            unless sub_blocks.exist?
              orig = @fullname
              @fullname = target
              template 'templates/code_generators/sub_blocks.rb', sub_blocks
              @fullname = orig
            end
            @sub_block_instantiated = true
            append_to_file sub_blocks, "\n#{@line}"
          end
        end
      end
    end
  end
end

#setupObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/origen/code_generators/block.rb', line 63

def setup
  @generate_model = true
  @generate_pins = false
  @generate_timesets = !@nested
  @generate_parameters = !@nested
  if @nested
    @final_name = args.last
    @fullname = resource_path_to_class(args.first)
    @dir = resource_path_to_blocks_dir(args.first).join('sub_blocks', @final_name)
    @namespaces = add_type_to_namespaces(@fullname.split('::').map(&:underscore))
  else
    extract_model_name
  end
  create_files
end

#validate_argsObject



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
# File 'lib/origen/code_generators/block.rb', line 36

def validate_args
  if args.size > 2 || args.size == 0
    msg = args.size == 0 ? 'At least one argument is' : 'No more than two arguments are'
    msg << " expected by the block generator, e.g. 'origen new block atd/atd16bit', 'origen new block sampler app/blocks/atd/derivatives/atd16bit"
    puts msg
    exit 1
  end

  if args.size == 2
    validate_args_common(args.last)
  else
    validate_args_common
  end

  @nested = args.size == 2
  if !@nested && args.first.split('/').size == 1
    msg = "You must supply a leading type to the name of the block, e.g. 'origen new block atd/atd16bit'"
    puts msg
    exit 1
  end
  if @nested && args.last.split('/').size != 1
    msg = "No leading type is allowed when generating a nested block, e.g. 'origen new block sampler app/blocks/atd/derivatives/atd16bit"
    puts msg
    exit 1
  end
end