Class: OrigenVerilog::Processor

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin
Defined in:
lib/origen_verilog/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.

Defined Under Namespace

Classes: Inline

Instance Method Summary collapse

Instance Method Details

#handler_missing(node) ⇒ Object



56
57
58
# File 'lib/origen_verilog/processor.rb', line 56

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

#inline(nodes) ⇒ Object



60
61
62
# File 'lib/origen_verilog/processor.rb', line 60

def inline(nodes)
  Inline.new(nodes)
end

#process(node) ⇒ Object

Override the default implementation of this, to allow arrays to be returned and when a handler returns nil the node is removed



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/origen_verilog/processor.rb', line 20

def process(node)
  return if node.nil?
  return node unless node.respond_to?(:to_ast)

  node = node.to_ast

  # Invoke a specific handler
  on_handler = :"on_#{node.type}"
  if respond_to? on_handler
    new_node = send on_handler, node
  else
    new_node = handler_missing(node)
  end

  new_node if new_node
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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/origen_verilog/processor.rb', line 41

def process_all(nodes)
  results = []
  nodes.to_a.each do |node|
    n = process(node)
    if n
      if n.is_a?(Inline)
        results += n
      else
        results << n
      end
    end
  end
  results
end

#run(node) ⇒ Object



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

def run(node)
  process(node)
end