Class: OrigenTesters::ATP::Processor

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin
Defined in:
lib/origen_testers/atp/processor.rb

Overview

The base processor, this provides a default handler for all node types and will not make any changes to the AST, i.e. an equivalent AST will be returned by the process method.

Child classes of this should be used to implement additional processors to modify or otherwise work with the AST.

Instance Method Summary collapse

Instance Method Details

#add_global_flag(flag) ⇒ Object



70
71
72
73
74
75
# File 'lib/origen_testers/atp/processor.rb', line 70

def add_global_flag(flag)
  # Had to do @@ because the state got lost after the recursive calls
  @@globals ||= {}
  @@globals[:flags] ||= []
  @@globals[:flags] << flag
end

#clean_flag(flag) ⇒ Object



96
97
98
99
100
# File 'lib/origen_testers/atp/processor.rb', line 96

def clean_flag(flag)
  flag = flag.dup.to_s
  flag[0] = '' if flag[0] == '$'
  flag.downcase
end

#extract_globals(flow) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/origen_testers/atp/processor.rb', line 77

def extract_globals(flow)
  @@globals ||= {}
  if v = flow.find(:global)
    @@globals[:flags] ||= []
    @@globals[:flags] += Array(v.find_all(:flag)).map(&:value) if v.respond_to?(:find_all) && v.method(:find_all).parameters.size == 1
  end
end

#extract_volatiles(flow) ⇒ Object



49
50
51
52
53
54
# File 'lib/origen_testers/atp/processor.rb', line 49

def extract_volatiles(flow)
  @volatiles = {}
  if v = flow.find(:volatile)
    @volatiles[:flags] = Array(v.find_all(:flag)).map(&:value)
  end
end

#global_flag?(flag) ⇒ Boolean

Returns true if the given flag name has been marked as global

Returns:

  • (Boolean)


91
92
93
94
# File 'lib/origen_testers/atp/processor.rb', line 91

def global_flag?(flag)
  result = global_flags.any? { |f| clean_flag(f) == clean_flag(flag) }
  result
end

#global_flagsObject



85
86
87
88
# File 'lib/origen_testers/atp/processor.rb', line 85

def global_flags
  @@globals ||= {}
  @@globals[:flags] || []
end

#handler_missing(node) ⇒ Object



45
46
47
# File 'lib/origen_testers/atp/processor.rb', line 45

def handler_missing(node)
  node.updated(nil, process_all(node.children))
end

#process(node) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/origen_testers/atp/processor.rb', line 18

def process(node)
  if node.respond_to?(:to_ast)
    super(node)
  else
    node
  end
end

#process_all(nodes) ⇒ Object

Some of our processors remove a wrapping node from the AST, returning a node of type :inline containing the children which should be inlined. Here we override the default version of this method to deal with handlers that return an inline node in place of a regular node.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/origen_testers/atp/processor.rb', line 30

def process_all(nodes)
  results = []
  nodes.to_a.each do |node|
    n = process(node)
    if n.respond_to?(:type) && n.type == :inline
      results += n.children
    elsif n.respond_to?(:type) && n.type == :global
      add_global_flag(n.to_a[0].value)
    else
      results << n unless n.respond_to?(:type) && n.type == :remove
    end
  end
  results
end

#run(node) ⇒ Object



14
15
16
# File 'lib/origen_testers/atp/processor.rb', line 14

def run(node)
  process(node)
end

#volatile?(flag) ⇒ Boolean

Returns true if the given flag name has been marked as volatile

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/origen_testers/atp/processor.rb', line 65

def volatile?(flag)
  result = volatile_flags.any? { |f| clean_flag(f) == clean_flag(flag) }
  result
end

#volatile_flagsObject



56
57
58
59
60
61
62
# File 'lib/origen_testers/atp/processor.rb', line 56

def volatile_flags
  unless @volatiles
    fail 'You must first call extract_volatiles(node) from your on_flow hander method'
  end

  @volatiles[:flags] || []
end