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

#_extract_comments(file, flow_line) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 48

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

#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



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

def create(options = {}, &block)
  # 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
  if OrigenTesters::Flow.flow_comments
    top = false
    name = options[:name] || Pathname.new(file).basename('.rb').to_s.sub(/^_/, '')
    Origen.interface.flow.group(name, description: flow_comments) do
      orig_create(options, &block)
    end
  else
    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
    orig_create(options, &block)
  end
  OrigenTesters::Flow.callstack.pop
  OrigenTesters::Flow.comment_stack.pop
  OrigenTesters::Flow.flow_comments = nil if top
end

#orig_createObject



11
# File 'lib/origen_testers/origen_ext/generator/flow.rb', line 11

alias_method :orig_create, :create