Getting Started » History » Version 3
Alexander Kamkin, 05/06/2014 07:58 AM
1 | 1 | Alexander Kamkin | h1. Getting Started |
---|---|---|---|
2 | |||
3 | 3 | Alexander Kamkin | This is a step-by-step instruction for getting started with developing a VeriTrans backend and using it within the Verilog translator environment. The term _backend_ refers to a component that traverses an _abstract syntax tree_ (_AST_) of the Verilog description and processes it in some way (e.g., constructs the internal representation and/or converts the description into some other language). The document is illustrated by the example of @VerilogPrinter@ (see the package @ru.ispras.verilog.parser.sample@). |
4 | |||
5 | 1 | Alexander Kamkin | h2. Developing a Backend |
6 | |||
7 | 3 | Alexander Kamkin | Technically, a backend is a Java object that implements the @VerilogBackend@ interface (the method @start@). Here is an example: |
8 | 1 | Alexander Kamkin | |
9 | 3 | Alexander Kamkin | <pre><code class="java"> |
10 | 1 | Alexander Kamkin | import ru.ispras.verilog.parser.VerilogBackend; |
11 | import ru.ispras.verilog.parser.model.*; |
||
12 | 3 | Alexander Kamkin | ... |
13 | 1 | Alexander Kamkin | |
14 | /** |
||
15 | 3 | Alexander Kamkin | * This class illustrates development of a Verilog backend. |
16 | 1 | Alexander Kamkin | */ |
17 | public final class VerilogPrinter extends VerilogBackend |
||
18 | { |
||
19 | /** |
||
20 | 3 | Alexander Kamkin | * Processes the abstract syntax tree (AST). |
21 | * |
||
22 | * @param root the AST''s root. |
||
23 | 1 | Alexander Kamkin | */ |
24 | public void start(final VerilogNode root) |
||
25 | { |
||
26 | 3 | Alexander Kamkin | ... |
27 | 1 | Alexander Kamkin | } |
28 | 3 | Alexander Kamkin | } |
29 | </code></pre> |
||
30 | |||
31 | To ease development of a backend, one can use @VerilogTreeWalker@, a VeriTrans class that implements AST traversal. The @VerilogTreeWalker@''s constructor takes two parameters: (1) a reference to the tree''s root and (2) a visitor to be applied to the tree nodes: |
||
32 | |||
33 | <pre><code class="java"> |
||
34 | import ru.ispras.verilog.parser.walker.*; |
||
35 | |||
36 | public void start(final VerilogNode root) |
||
37 | { |
||
38 | VerilogTreeWalker walker = new VerilogTreeWalker(root, new VerilogNodePrinter()); |
||
39 | walker.start(); |
||
40 | 1 | Alexander Kamkin | } |
41 | </code></pre> |
||
42 | 2 | Alexander Kamkin | |
43 | h2. Registering a Backend |