Module: Origen::CodeGenerators

Defined in:
lib/origen/code_generators.rb,
lib/origen/code_generators/dut.rb,
lib/origen/code_generators/base.rb,
lib/origen/code_generators/block.rb,
lib/origen/code_generators/klass.rb,
lib/origen/code_generators/model.rb,
lib/origen/code_generators/module.rb,
lib/origen/code_generators/semver.rb,
lib/origen/code_generators/actions.rb,
lib/origen/code_generators/feature.rb,
lib/origen/code_generators/timever.rb,
lib/origen/code_generators/block_common.rb
more...

Defined Under Namespace

Modules: Actions, BlockCommon Classes: Base, Block, Dut, Error, Feature, Klass, Mod, Model, Semver, Timever

Class Method Summary collapse

Class Method Details

.find_by_name(name) ⇒ Object

[View source]

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/origen/code_generators.rb', line 71

def self.find_by_name(name)
  names = name.split(':')
  case names.size
  when 1
    gen = origen_generators[names.first]
    return gen if gen
  when 2
    if names.first == 'origen'
      gen = origen_generators[names.first]
    else
      gen = plugin_generators[names.first][names.last]
    end
    return gen if gen
  end
  puts "Couldn't find a code generator named: #{name}"
  puts
  puts 'This is the list of available generators:'
  puts
  print_generators
  puts
end

.help(command = 'new') ⇒ Object

Show help message with available generators.

[View source]

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/origen/code_generators.rb', line 94

def self.help(command = 'new')
  puts <<-END
Add pre-built features and code snippets to your application.

This command will generate code for your application to implement a given feature. In some
cases this will be a complete feature and in others it will provide a starting point for you
to further customize.

END
  puts "Usage: origen #{command} FEATURE [args] [options]"
  puts
  puts 'General options:'
  puts "  -h, [--help]     # Print feature's options and usage"
  puts '  -p, [--pretend]  # Run but do not make any changes'
  puts '  -f, [--force]    # Overwrite files that already exist'
  puts '  -s, [--skip]     # Skip files that already exist'
  puts '  -q, [--quiet]    # Suppress status output'
  puts
  puts "The available features are listed below, run 'origen new <feature> -h' for more info."
  puts

  print_generators
  puts
end

.invoke(name, args = ARGV, config = {}) ⇒ Object

Receives a namespace, arguments and the behavior to invoke the generator. It's used as the default entry point for generate, destroy and update commands.

[View source]

56
57
58
59
60
61
62
# File 'lib/origen/code_generators.rb', line 56

def self.invoke(name, args = ARGV, config = {})
  load_generators
  if klass = find_by_name(name)
    args << '--help' if args.empty? && klass.arguments.any?(&:required?)
    klass.start(args, config)
  end
end

.invoke_internal(name, args = ARGV, config = {}) ⇒ Object

Like invoke, but will also make internal-use only generators available commands.

[View source]

66
67
68
69
# File 'lib/origen/code_generators.rb', line 66

def self.invoke_internal(name, args = ARGV, config = {})
  load_internal_generators
  invoke(name, args, config)
end

.load_generatorsObject

[View source]

29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/origen/code_generators.rb', line 29

def self.load_generators
  return if @generators_loaded

  # Load Origen's generators
  require_relative 'code_generators/block_common'
  require_relative 'code_generators/dut'
  require_relative 'code_generators/block'
  require_relative 'code_generators/feature'
  require_relative 'code_generators/model'
  require_relative 'code_generators/klass'
  require_relative 'code_generators/module'
  # Load generators from plugins, TBD what the API will be here
  @generators_loaded = true
end

.load_internal_generatorsObject

Loaded separately so as not to pollute the generated list of generators available to users

[View source]

45
46
47
48
49
50
51
# File 'lib/origen/code_generators.rb', line 45

def self.load_internal_generators
  return if @internal_generators_loaded

  require_relative 'code_generators/semver'
  require_relative 'code_generators/timever'
  @internal_generators_loaded = true
end

.no_color!Object

Remove the color from output.

[View source]

17
18
19
# File 'lib/origen/code_generators.rb', line 17

def self.no_color!
  Thor::Base.shell = Thor::Shell::Basic
end

.origen_generatorsObject

[View source]

21
22
23
# File 'lib/origen/code_generators.rb', line 21

def self.origen_generators
  @origen_generators ||= {}
end

.plugin_generatorsObject

[View source]

25
26
27
# File 'lib/origen/code_generators.rb', line 25

def self.plugin_generators
  @plugin_generators ||= {}
end
[View source]

119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/origen/code_generators.rb', line 119

def self.print_generators
  load_generators
  origen_generators.each do |name, _gen|
    puts name
  end
  plugin_generators.each do |namespace, generators|
    next if namespace.to_s == 'origen_app_generators'

    puts
    generators.each do |_name, gen|
      puts "#{namespace}:#{gen}"
    end
  end
end