Class: Origen::Generator::Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_testers/origen_ext/generator/flow.rb

Instance Method Summary collapse

Instance Method Details

#_create(options = {}, &block) ⇒ Object

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.



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
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 95

def _create(options = {}, &block)
  options = {
    reload_target: true
  }.merge(options)
  # Make the top level flow globally available, this helps to assign test descriptions
  # to the correct flow whenever tests are instantiated from sub-flows
  if Origen.interface_loaded? && Origen.interface.top_level_flow
    sub_flow = true
    if Origen.tester.doc?
      Origen.interface.flow.start_section
    end
  else
    sub_flow = false
  end
  job.output_file_body = options.delete(:name).to_s if options[:name]
  if sub_flow
    interface = Origen.interface
    if reload_target?(interface, options)
      Origen.app.reload_target!
      Origen.tester.generating = :program
    end
    opts = Origen.generator.option_pipeline.pop || {}
    Origen.interface.startup(options) if Origen.interface.respond_to?(:startup)
    interface.instance_exec(opts, &block)
    Origen.interface.shutdown(options) if Origen.interface.respond_to?(:shutdown)
    if Origen.tester.doc?
      Origen.interface.flow.stop_section
    end
    interface.close(flow: true, sub_flow: true)
  else
    Origen.log.info "Generating... #{Origen.file_handler.current_file.basename}"
    interface = Origen.reset_interface(options)
    if reload_target?(interface, options)
      Origen.app.reload_target!
      Origen.tester.generating = :program
    end
    Origen.interface.set_top_level_flow
    Origen.interface.flow_generator.set_flow_description(Origen.interface.consume_comments)
    options[:top_level] = true
    Origen.interface.flow.instance_variable_set('@top_level', Origen.interface.flow)
    Origen.interface.flow.on_top_level_set if Origen.interface.flow.respond_to?(:on_top_level_set)
    Origen.app.listeners_for(:on_flow_start).each do |listener|
      listener.on_flow_start(options)
    end
    Origen.interface.startup(options) if Origen.interface.respond_to?(:startup)
    interface.instance_eval(&block)
    Origen.interface.generate_eof_charz_tests if Origen.interface.respond_to?(:generate_eof_charz_tests)
    Origen.interface.shutdown(options) if Origen.interface.respond_to?(:shutdown)
    interface.at_flow_end if interface.respond_to?(:at_flow_end)
    Origen.app.listeners_for(:on_flow_end).each do |listener|
      listener.on_flow_end(options)
    end
    interface.close(flow: true)
  end
end

#_extract_comments(file, flow_line) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 159

def _extract_comments(file, flow_line)
  flow_comments = []
  comments = {}
  comment = nil
  File.readlines(file).each_with_index do |line, i|
    if comment
      if line =~ /^\s*#-(.*)/
        # Nothing, just ignore but keep the comment open
      elsif line =~ /^\s*#(.*)/
        comment << Regexp.last_match(1).strip
      else
        comment = nil
      end
    else
      if line =~ /^\s*#[^-](.*)/
        if i < flow_line
          comment = flow_comments
        else
          comment = []
          comments[i + 1] = comment
        end
        comment << Regexp.last_match(1).strip
      end
    end
  end
  [flow_comments, comments]
end

#_sub_flow(name, options, &block) ⇒ Object

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.



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
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 64

def _sub_flow(name, options, &block)
  @top_level_flow ||= Origen.interface.flow
  parent = Origen.interface.flow
  # If the parent flow already has a child flow of this name then we need to generate a
  # new unique name/id
  # Also generate a new name when the child flow name matches the parent flow name, SMT8.2
  # onwards does not allow this
  if parent.children[name] || parent.name.to_s == name.to_s
    i = 0
    tempname = name
    while parent.children[tempname] || parent.name.to_s == tempname.to_s
      i += 1
      tempname = "#{name}_#{i}"
    end
    name = tempname
  end
  if parent
    id = parent.path + ".#{name}"
  else
    id = name
  end
  sub_flow = Origen.interface.with_flow(id) do
    Origen.interface.flow.instance_variable_set(:@top_level, @top_level_flow)
    Origen.interface.flow.instance_variable_set(:@parent, parent)
    _create(options, &block)
  end
  parent.children[name] = sub_flow
  [parent, sub_flow]
end

#create(options = {}, &block) ⇒ Object

Create a call stack of flows so that we can work out where the nodes of the ATP AST originated from



13
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
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 13

def create(options = {}, &block)
  options = {
    reload_target: true,
    name:          OrigenTesters::Flow.name_stack.pop
  }.merge(options)
  # Patch for Windows operation since the path can start with something like "C:/"
  if caller[0] =~ /(:(\/|\\))/
    orig_separator = Regexp.last_match(1)
    file, line = *caller[0].sub(/:(\/|\\)/, '_ORIG_SEPARATOR_').split(':')
    file = file.sub('_ORIG_SEPARATOR_', orig_separator)
  else
    file, line = *caller[0].split(':')
  end
  OrigenTesters::Flow.callstack << file
  flow_comments, comments = *_extract_comments(OrigenTesters::Flow.callstack.last, line.to_i)
  OrigenTesters::Flow.comment_stack << comments
  OrigenTesters::Flow.ht_comments = {}
  comments.each do |src_line, com_array|
    flow_src_line = src_line + com_array.size
    OrigenTesters::Flow.ht_comments[flow_src_line] = com_array
  end
  if OrigenTesters::Flow.flow_comments
    top = false
    name = options[:name] || Pathname.new(file).basename('.rb').to_s.sub(/^_/, '')
    # Generate imports as separate sub-flow files on this platform
    if tester.v93k? && tester.smt8?
      parent, sub_flow = *_sub_flow(name, options, &block)
      path = sub_flow.output_file.relative_path_from(Origen.file_handler.output_directory)
      parent.atp.sub_flow(sub_flow.atp.raw, path: path.to_s)
    else
      Origen.interface.flow.group(name, description: flow_comments) do
        _create(options, &block)
      end
    end
  else
    @top_level_flow = nil
    OrigenTesters::Flow.flow_comments = flow_comments
    if options.key?(:unique_ids)
      OrigenTesters::Flow.unique_ids = options.delete(:unique_ids)
    else
      OrigenTesters::Flow.unique_ids = true
    end
    top = true
    _create(options, &block)
  end
  OrigenTesters::Flow.callstack.pop
  OrigenTesters::Flow.comment_stack.pop
  OrigenTesters::Flow.flow_comments = nil if top
end

#jobObject



155
156
157
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 155

def job
  Origen.app.current_job
end

#resetObject



151
152
153
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 151

def reset
  Origen.interface.clear_top_level_flow if Origen.interface_loaded?
end