Class: Origen::Generator::Pattern

Inherits:
Object
  • Object
show all
Includes:
Comparator
Defined in:
lib/origen/generator/pattern.rb

Defined Under Namespace

Classes: DummyIterator

Instance Method Summary collapse

Methods included from Comparator

#check_for_changes, #relative_path_to

Instance Method Details

#close(options = {}) ⇒ Object



58
59
60
# File 'lib/origen/generator/pattern.rb', line 58

def close(options = {})
  pattern_close(options)
end

#create(options = {}) ⇒ Object



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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/origen/generator/pattern.rb', line 62

def create(options = {})
  @create_options = options
  unless Origen.tester
    puts 'The current target has not instantiated a tester and pattern generation cannot run.'
    puts 'Add something like this to your target file:'
    puts ''
    puts '  $tester = Origen::Tester::J750.new'
    puts ''
    exit 1
  end
  Origen.tester.generating = :pattern

  job.output_file_body = options.delete(:name).to_s if options[:name]

  # Order the iterators by the order that their enable keys appear in the options, pad
  # any missing iterators with a dummy function...
  iterators = options.map do |key, _val|
    Origen.app.pattern_iterators.find { |iterator| iterator.key == key }
  end.compact
  iterators << DummyIterator.new while iterators.size < 10

  args = []

  # Couldn't get this to work fully dynamically, so hard-coded for 10 custom
  # iterators for now, should be plenty for any application in the meantime.
  # Should revisit this when time allows and remove this limitation by changing
  # this to a recursive structure.
  iterators[0].invoke(options) do |arg0|
    args[0] = arg0
    iterators[1].invoke(options) do |arg1|
      args[1] = arg1
      iterators[2].invoke(options) do |arg2|
        args[2] = arg2
        iterators[3].invoke(options) do |arg3|
          args[3] = arg3
          iterators[4].invoke(options) do |arg4|
            args[4] = arg4
            iterators[5].invoke(options) do |arg5|
              args[5] = arg5
              iterators[6].invoke(options) do |arg6|
                args[6] = arg6
                iterators[7].invoke(options) do |arg7|
                  args[7] = arg7
                  iterators[8].invoke(options) do |arg8|
                    args[8] = arg8
                    iterators[9].invoke(options) do |arg9|
                      args[9] = arg9
                      # Refresh the target to start all settings from scratch each time
                      # This is an easy way to reset all registered values
                      Origen.app.reload_target!(skip_first_time: true)

                      # Final call back to the project to allow it to make any pattern name specific
                      # configuration changes
                      Origen.app.listeners_for(:before_pattern).each do |listener|
                        listener.before_pattern(job.output_pattern_filename)
                      end

                      # Work out the final pattern name based on the current iteration
                      job.reset_output_pattern_filename
                      iterators.each_with_index do |iterator, i|
                        if iterator.enabled?(options)
                          job.output_pattern_filename =
                            iterator.pattern_name.call(job.output_pattern_filename, args[i])
                        end
                      end

                      # Allow custom pattern postfix
                      unless options[:pat_postfix].to_s.empty?
                        job.output_pattern_filename = job.output_pattern_filename.sub(job.output_postfix + job.output_extension, "_#{options[:pat_postfix]}" + job.output_postfix + job.output_extension)
                      end

                      pattern_wrapper(iterators, args, options) do
                        # Call iterator setups, whatever these return are passed to the pattern
                        yield_items = []
                        iterators.each_with_index do |iterator, i|
                          if iterator.enabled?(options)
                            yield_items << iterator.setup.call(args[i])
                          end
                        end

                        yield(*yield_items)
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
  @create_options = nil
end

#create_optionsObject

Returns the options passed to the current create block



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

def create_options
  @create_options || {}
end

#logObject



16
17
18
# File 'lib/origen/generator/pattern.rb', line 16

def log
  Origen.log
end

#open(options = {}) ⇒ Object

The recommended way to create a pattern is to wrap it within a Pattern.create block, however occasionally the need may arise to manually open and close a pattern, this method can be used in that case in association with the close method.

Pattern iterators are not supported when creating a pattern in this way.



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
# File 'lib/origen/generator/pattern.rb', line 31

def open(options = {})
  if block_given?
    create(options) do |*args|
      yield(*args)
    end
  else
    job.output_file_body = options.delete(:name).to_s if options[:name]

    # Refresh the target to start all settings from scratch each time
    # This is an easy way to reset all registered values
    Origen.app.reload_target!(skip_first_time: true)

    # Final call back to the project to allow it to make any pattern name specific
    # configuration changes
    Origen.app.listeners_for(:before_pattern).each do |listener|
      listener.before_pattern(job.output_pattern_filename)
    end

    # Allow custom pattern postfix
    unless options[:pat_postfix].to_s.empty?
      job.output_pattern_filename = job.output_pattern_filename.sub(job.output_postfix + job.output_extension, "_#{options[:pat_postfix]}" + job.output_postfix + job.output_extension)
    end

    pattern_open(options)
  end
end

#resetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This is called before each new pattern source is executed



175
176
177
# File 'lib/origen/generator/pattern.rb', line 175

def reset
  $desc = nil  # Clear the description
end

#split(options = {}) ⇒ Object

Split a running Pattern.create block into multiple patterns.

The output that has been generated up until the point where this is called will be written and a new pattern will be opened to contain the remainder of the pattern content generated by the block.

Each additional pattern section created by calling this method will have ‘_partN’ appended to the original pattern name.



166
167
168
169
170
# File 'lib/origen/generator/pattern.rb', line 166

def split(options = {})
  pattern_close(options.merge(call_shutdown_callbacks: false))
  job.inc_split_counter
  pattern_open(options.merge(call_startup_callbacks: false))
end