Verilog Parser
Preprocessor

This module contains all code and information on the preprocessor and how it works / is implemented. More...

Data Structures

struct  verilog_default_net_type
 Keeps track of the points at which default net type directives are encountered. More...
 
struct  verilog_include_directive
 Stores information on an include directive. More...
 
struct  verilog_line_directive
 Describes a line directive. More...
 
struct  verilog_macro_directive
 A simple container for macro directives. More...
 
struct  verilog_preprocessor_conditional_context
 Stores information regarding a particular level of conditional compilation. More...
 
struct  verilog_preprocessor_context
 
struct  verilog_timescale_directive
 Describes a simulation timescale directive. More...
 

Functions

void verilog_free_preprocessor_context (verilog_preprocessor_context *tofree)
 Frees a preprocessor context and all child constructs.
 
verilog_default_net_typeverilog_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. More...
 
verilog_preprocessor_contextverilog_new_preprocessor_context ()
 Creates a new pre-processor context. More...
 
void verilog_preproc_default_net (unsigned int token_number, unsigned int line_number, ast_net_type type)
 Registers a new default net type directive. More...
 
void verilog_preproc_enter_cell_define ()
 Tells the preprocessor we are now defining PLI modules and to tag them as such.
 
void verilog_preproc_exit_cell_define ()
 Tells the preprocessor we are no longer defining PLI modules.
 
char * verilog_preprocessor_current_file (verilog_preprocessor_context *preproc)
 Returns the file currently being parsed by the context, or NULL. More...
 
void verilog_preprocessor_else (unsigned int lineno)
 Handles an else statement being encountered. More...
 
void verilog_preprocessor_elseif (char *macro_name, unsigned int lineno)
 Handles an elseif statement being encountered. More...
 
void verilog_preprocessor_endif (unsigned int lineno)
 Handles an else statement being encountered. More...
 
void verilog_preprocessor_ifdef (char *macro_name, unsigned int lineno, ast_boolean is_ndef)
 Handles an ifdef statement being encountered. More...
 
verilog_include_directiveverilog_preprocessor_include (char *filename, unsigned int lineNumber)
 Handles the encounter of an include directive. More...
 
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. More...
 
void verilog_preprocessor_macro_undefine (char *macro_name)
 Removes a macro definition from the preprocessors lookup table. More...
 
verilog_preprocessor_conditional_contextverilog_preprocessor_new_conditional_context (char *condition, int line_number)
 Creates and returns a new conditional context. More...
 
void verilog_preprocessor_nounconnected_drive (ast_primitive_strength direction;)
 Handles the entering of a no-unconnected drive directive. More...
 
void verilog_preprocessor_resetall ()
 Handles the encounter of a `resetall directive as described in annex 19.6 of the spec.
 
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. More...
 

Variables

verilog_preprocessor_contextyy_preproc
 Stores all information needed for the preprocessor. More...
 

Detailed Description

This module contains all code and information on the preprocessor and how it works / is implemented.

The preprocessor is implemented mostly as part of the lexer, with the various compiler directives handled within the verilog_preprocessor_context structure and it's associated functions.

Function Documentation

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.

Parameters
token_numberToken number of the directive.
line_numberLine number of the directive.
typeThe net type.
verilog_preprocessor_context* verilog_new_preprocessor_context ( )

Creates a new pre-processor context.

This is called once at the beginning of a parse call.

void verilog_preproc_default_net ( unsigned int  token_number,
unsigned int  line_number,
ast_net_type  type 
)

Registers a new default net type directive.

Adds a record of the directive to the end of the linked list "net_types" in the global yy_preproc.

Parameters
token_numberToken number of the directive.
line_numberLine number of the directive.
typeThe net type.
char* verilog_preprocessor_current_file ( verilog_preprocessor_context preproc)

Returns the file currently being parsed by the context, or NULL.

Parameters
[in]preproc- The context to get the current file for.
void verilog_preprocessor_else ( unsigned int  lineno)

Handles an else statement being encountered.

Parameters
[in]lineno- The line the directive occurs on.
void verilog_preprocessor_elseif ( char *  macro_name,
unsigned int  lineno 
)

Handles an elseif statement being encountered.

Parameters
[in]macro_name- The macro to test if defined or not.
[in]lineno- The line the directive occurs on.
[in]macro_name- The macro to test if defined or not.
void verilog_preprocessor_endif ( unsigned int  lineno)

Handles an else statement being encountered.

Parameters
[in]lineno- The line the directive occurs on.
void verilog_preprocessor_ifdef ( char *  macro_name,
unsigned int  lineno,
ast_boolean  is_ndef 
)

Handles an ifdef statement being encountered.

Parameters
[in]macro_name- The macro to test if defined or not.
[in]lineno- The line the directive occurs on.
[in]is_ndef- TRUE IFF the directive is ifndef. Else the directive isifdef and this should be FALSE.
[in]macro_name- The macro to test if defined or not.
Parameters
linenoline number of the directive.
is_ndefIs this an ifndef or ifdef directive.
verilog_include_directive* verilog_preprocessor_include ( char *  filename,
unsigned int  lineNumber 
)

Handles the encounter of an include directive.

Returns
A pointer to the newly created directive reference.
Parameters
lineNumberThe line number of the directive.
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.

Parameters
lineThe line the defininition comes from.
macro_nameThe macro identifier.
macro_textThe value the macro expands to.
text_lenLength in bytes of macro_text.
void verilog_preprocessor_macro_undefine ( char *  macro_name)

Removes a macro definition from the preprocessors lookup table.

Parameters
macro_nameThe name of the macro to remove.
verilog_preprocessor_conditional_context* verilog_preprocessor_new_conditional_context ( char *  condition,
int  line_number 
)

Creates and returns a new conditional context.

Parameters
conditionThe definition to check for.
line_numberWhere the `ifdef came from.
void verilog_preprocessor_nounconnected_drive ( ast_primitive_strength direction;  )

Handles the entering of a no-unconnected drive directive.

Parameters
[in]direction- Where should an unconnected line be pulled?
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.

Parameters
[in,out]preproc- The context who's file name is being set.
[in]file- The file path to put as the current file.

Variable Documentation

Stores all information needed for the preprocessor.

This does not usually need to be accessed by the programmer, and certainly should never be written to unless you are defining your own default directives. For example, if I was writing my own simulated and wanted to add my own "__IS_MY_SIMULATOR__" pre-defined macro, it can be done by accessing this variable, and using the verilog_preprocessor_macro_define function.

Note
This is a global variable. Treat it with care!