Verilog Parser
verilog_preprocessor.h
Go to the documentation of this file.
1 
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 #include "verilog_ast.h"
12 #include "verilog_ast_common.h"
13 
14 #ifndef VERILOG_PREPROCESSOR_H
15 #define VERILOG_PREPROCESSOR_H
16 
31 // ----------------------- Default Net Type Directives ------------------
32 
37 typedef struct verilog_default_net_type_t{
38  unsigned int token_number;
39  unsigned int line_number;
42 
45  unsigned int token_number,
46  unsigned int line_number,
47  ast_net_type type
48 );
49 
50 // ----------------------- Line Directives ------------------------------
51 
53 typedef struct verilog_line_directive_t{
54  unsigned int line;
55  char * file;
56  unsigned char level;
58 
59 // ----------------------- Timescale Directives -------------------------
60 
62 typedef struct verilog_timescale_directive_t{
63  char * scale;
64  char * precision;
66 
67 // ----------------------- resetall directives --------------------------
68 
74 
75 // ----------------------- Connected Drive Directives -------------------
76 
82  ast_primitive_strength direction;
83 );
84 
85 // ----------------------- Include Directives ---------------------------
86 
88 typedef struct verilog_include_directive_t{
89  char * filename;
90  unsigned int lineNumber;
93 
99  char * filename, //<! The file to include.
100  unsigned int lineNumber
101 );
102 
103 // ----------------------- `define Directives ---------------------------
104 
108 typedef struct verilog_macro_directive_t{
109  unsigned int line;
110  char * macro_id;
111  char * macro_value;
113 
118  unsigned int line,
119  char * macro_name,
120  char * macro_text,
121  size_t text_len
122 );
123 
128  char * macro_name
129 );
130 
131 // ----------------------- Conditional Compilation Directives -----------
132 
139 typedef struct verilog_preprocessor_conditional_context_t{
140  char * condition;
146 
150  char * condition,
151  int line_number
152 );
153 
162  char * macro_name,
163  unsigned int lineno,
164  ast_boolean is_ndef
165 );
166 
172 void verilog_preprocessor_elseif(char * macro_name, unsigned int lineno);
173 
178 void verilog_preprocessor_else (unsigned int lineno);
179 
184 void verilog_preprocessor_endif (unsigned int lineno);
185 
186 
187 // ----------------------- Preprocessor Context -------------------------
188 
189 /*
190 @brief Stores all of the contextual information used by the pre-processor.
191 @details Stores things like:
192 - Macro names and evaluations.
193 - Default net types.
194 - In Cell Defines.
195 - IF/ELSE pre-processor directives.
196 - Timescale directives
197 */
198 typedef struct verilog_preprocessor_context_t{
200  unsigned int token_count;
202 
203  char * scratch;
204 
214 
215 
227 
228 
234 
243  char * file
244 );
245 
252 );
253 
259 );
260 
261 
267 
268 
273 
278  unsigned int token_number,
279  unsigned int line_number,
280  ast_net_type type
281 );
282 
285 #endif
286 
void verilog_preprocessor_else(unsigned int lineno)
Handles an else statement being encountered.
Definition: verilog_preprocessor.c:362
verilog_preprocessor_conditional_context * verilog_preprocessor_new_conditional_context(char *condition, int line_number)
Creates and returns a new conditional context.
Definition: verilog_preprocessor.c:256
void verilog_preprocessor_macro_define(unsigned int line, char *macro_name, char *macro_text, size_t text_len)
Instructs the preprocessor to register a new macro definition.
Definition: verilog_preprocessor.c:192
verilog_timescale_directive timescale
Timescale information.
Definition: verilog_preprocessor.h:209
void verilog_preproc_exit_cell_define()
Tells the preprocessor we are no longer defining PLI modules.
Definition: verilog_preprocessor.c:70
Contains Declarations of datastructures and functions which represent and operate on the Verilog Abst...
ast_list * search_dirs
Where to look for include files.
Definition: verilog_preprocessor.h:212
char * macro_value
The value it expands to.
Definition: verilog_preprocessor.h:111
ast_list * includes
Include directives.
Definition: verilog_preprocessor.h:207
int line_number
Where the `ifdef came from.
Definition: verilog_preprocessor.h:141
char * macro_id
The name of the macro.
Definition: verilog_preprocessor.h:110
verilog_preprocessor_context * verilog_new_preprocessor_context()
Creates a new pre-processor context.
Definition: verilog_preprocessor.c:8
A hash table object.
Definition: verilog_ast_common.h:209
ast_stack * current_file
Stack of files currently being parsed.
Definition: verilog_preprocessor.h:205
void verilog_preprocessor_nounconnected_drive(ast_primitive_strength direction;)
Handles the entering of a no-unconnected drive directive.
ast_net_type
Describes the type of a net in Verilog.
Definition: verilog_ast.h:2372
unsigned int line
The line to set the current counter to.
Definition: verilog_preprocessor.h:54
ast_boolean emit
Only emit tokens iff true.
Definition: verilog_preprocessor.h:199
char * verilog_preprocessor_current_file(verilog_preprocessor_context *preproc)
Returns the file currently being parsed by the context, or NULL.
Definition: verilog_preprocessor.c:53
char * condition
The definition to check for.
Definition: verilog_preprocessor.h:140
void verilog_preprocessor_resetall()
Handles the encounter of a `resetall directive as described in annex 19.6 of the spec.
Definition: verilog_preprocessor.c:115
char * precision
Precision of each timestep.
Definition: verilog_preprocessor.h:64
char * scale
The timescale to simulate on.
Definition: verilog_preprocessor.h:63
unsigned int token_number
Token number of the directive.
Definition: verilog_preprocessor.h:38
verilog_include_directive * verilog_preprocessor_include(char *filename, unsigned int lineNumber)
Handles the encounter of an include directive.
Definition: verilog_preprocessor.c:139
ast_stack * ifdefs
Storage for conditional compile stack.
Definition: verilog_preprocessor.h:211
void verilog_preproc_default_net(unsigned int token_number, unsigned int line_number, ast_net_type type)
Registers a new default net type directive.
Definition: verilog_preprocessor.c:96
verilog_default_net_type * verilog_new_default_net_type(unsigned int token_number, unsigned int line_number, ast_net_type type)
Creates and returns a new default net type directive.
Definition: verilog_preprocessor.c:76
ast_primitive_strength unconnected_drive_pull
nounconnectedrive
Definition: verilog_preprocessor.h:210
ast_list * net_types
Storage for default nettype directives.
Definition: verilog_preprocessor.h:208
ast_hashtable * macrodefines
`define kvp matching.
Definition: verilog_preprocessor.h:206
Keeps track of the points at which default net type directives are encountered.
Definition: verilog_preprocessor.h:37
void verilog_preprocessor_macro_undefine(char *macro_name)
Removes a macro definition from the preprocessors lookup table.
Definition: verilog_preprocessor.c:243
void verilog_preprocessor_elseif(char *macro_name, unsigned int lineno)
Handles an elseif statement being encountered.
Definition: verilog_preprocessor.c:320
ast_boolean in_cell_define
TRUE iff we are in a cell define.
Definition: verilog_preprocessor.h:201
char * file
The file we should pretend stuff comes from.
Definition: verilog_preprocessor.h:55
ast_boolean file_found
Can we find the file?
Definition: verilog_preprocessor.h:91
ast_boolean wait_for_endif
Emit nothing more until `endif.
Definition: verilog_preprocessor.h:144
unsigned int line
Line number of the directive.
Definition: verilog_preprocessor.h:109
void verilog_free_preprocessor_context(verilog_preprocessor_context *tofree)
Frees a preprocessor context and all child constructs.
Definition: verilog_preprocessor.c:60
void verilog_preprocessor_set_file(verilog_preprocessor_context *preproc, char *file)
Clears the stack of files being parsed, and sets the current file to the supplied string...
Definition: verilog_preprocessor.c:38
ast_boolean condition_passed
Did the condition pass?
Definition: verilog_preprocessor.h:142
char * scratch
A scratch variable. DO NOT USE.
Definition: verilog_preprocessor.h:203
Container struct for the linked list data structure.
Definition: verilog_ast_common.h:41
A very simple stack.
Definition: verilog_ast_common.h:131
ast_boolean is_ndef
True if directive was `ifndef.
Definition: verilog_preprocessor.h:143
Contains Declarations of value-independent data structures like linked lists which are used in the as...
ast_boolean
Stores the values of booleans.
Definition: verilog_ast.h:94
void verilog_preprocessor_endif(unsigned int lineno)
Handles an else statement being encountered.
Definition: verilog_preprocessor.c:411
Stores information on an include directive.
Definition: verilog_preprocessor.h:88
verilog_preprocessor_context * yy_preproc
Stores all information needed for the preprocessor.
Definition: verilog_preprocessor.h:198
unsigned int line_number
Line number of the directive.
Definition: verilog_preprocessor.h:39
ast_net_type type
The net type.
Definition: verilog_preprocessor.h:40
unsigned int lineNumber
The line number of the directive.
Definition: verilog_preprocessor.h:90
unsigned int token_count
Keeps count of tokens processed.
Definition: verilog_preprocessor.h:200
A simple container for macro directives.
Definition: verilog_preprocessor.h:108
Describes a line directive.
Definition: verilog_preprocessor.h:53
char * filename
The file to include.
Definition: verilog_preprocessor.h:89
void verilog_preproc_enter_cell_define()
Tells the preprocessor we are now defining PLI modules and to tag them as such.
Definition: verilog_preprocessor.c:65
void verilog_preprocessor_ifdef(char *macro_name, unsigned int lineno, ast_boolean is_ndef)
Handles an ifdef statement being encountered.
Definition: verilog_preprocessor.c:274
unsigned char level
Level of include depth.
Definition: verilog_preprocessor.h:56
Describes a simulation timescale directive.
Definition: verilog_preprocessor.h:62
Stores information regarding a particular level of conditional compilation.
Definition: verilog_preprocessor.h:139
ast_primitive_strength
Describes the drive strength of a single primitive.
Definition: verilog_ast.h:1912