Verilog Parser

Super-group for data-structures representing the kinds of expressions that Verilog has. More...

Modules

 Expression Primaries
 Expresses primary terms of expressions. These can be sub-expressions, numbers, identifiers etc.
 

Data Structures

struct  ast_expression
 Storage type for an entire expression / subexpression tree. More...
 

Enumerations

enum  ast_expression_type {
  PRIMARY_EXPRESSION, UNARY_EXPRESSION, BINARY_EXPRESSION, RANGE_EXPRESSION_UP_DOWN,
  RANGE_EXPRESSION_INDEX, MINTYPMAX_EXPRESSION, CONDITIONAL_EXPRESSION, MODULE_PATH_PRIMARY_EXPRESSION,
  MODULE_PATH_BINARY_EXPRESSION, MODULE_PATH_UNARY_EXPRESSION, MODULE_PATH_CONDITIONAL_EXPRESSION, MODULE_PATH_MINTYPMAX_EXPRESSION,
  STRING_EXPRESSION
}
 Describes the kind of expression a node contains. More...
 

Functions

char * ast_expression_tostring (ast_expression *exp)
 A utility function for converting an ast expression tree back into a string representation. More...
 
ast_expression * ast_new_binary_expression (ast_expression *left, ast_expression *right, ast_operator operation, ast_node_attributes *attr, ast_boolean constant)
 Creates a new binary infix expression with the supplied operands. More...
 
ast_expression * ast_new_conditional_expression (ast_expression *condition, ast_expression *if_true, ast_expression *if_false, ast_node_attributes *attr)
 Creates a new conditional expression node. More...
 
ast_expression * ast_new_expression_primary (ast_primary *p)
 Creates and returns a new expression primary. More...
 
ast_expression * ast_new_index_expression (ast_expression *left)
 Creates a new range index expression with the supplied operands. More...
 
ast_expression * ast_new_mintypmax_expression (ast_expression *min, ast_expression *typ, ast_expression *max)
 Creates a new (min,typical,maximum) expression. More...
 
ast_expression * ast_new_range_expression (ast_expression *left, ast_expression *right)
 Creates a new range expression with the supplied operands. More...
 
ast_expression * ast_new_string_expression (ast_string string)
 Creates a new string expression. More...
 
ast_expression * ast_new_unary_expression (ast_primary *operand, ast_operator operation, ast_node_attributes *attr, ast_boolean constant)
 Creates a new unary expression with the supplied operation. More...
 
char * ast_operator_tostring (ast_operator op)
 Returns the string representation of an operator;.
 

Detailed Description

Super-group for data-structures representing the kinds of expressions that Verilog has.

Enumeration Type Documentation

Describes the kind of expression a node contains.

Enumerator
PRIMARY_EXPRESSION 

A straight value.

UNARY_EXPRESSION 

A unary op: "~bits" for example.

BINARY_EXPRESSION 

The "normal" expression.

RANGE_EXPRESSION_UP_DOWN 

Bit range expression.

RANGE_EXPRESSION_INDEX 

Bit index expression.

MINTYPMAX_EXPRESSION 

Minimum typical maximum.

CONDITIONAL_EXPRESSION 

Conditional expression.

STRING_EXPRESSION 

Just a normal string. No operations.

Function Documentation

char* ast_expression_tostring ( ast_expression *  exp)

A utility function for converting an ast expression tree back into a string representation.

Parameters
[in]exp- The expression to turn into a string.
Returns
The string representation of the passed expression or an empty string if exp is NULL.
Parameters
[in]exp- The expression to turn into a string.
ast_expression* ast_new_binary_expression ( ast_expression *  left,
ast_expression *  right,
ast_operator  operation,
ast_node_attributes *  attr,
ast_boolean  constant 
)

Creates a new binary infix expression with the supplied operands.

Parameters
[in]left- LHS of the infix operation.
[in]right- RHS of the infix operation.
[in]operation- What do we do?!
[in]attr- Attributes applied to the expression.
[in]constant- Is this a constant expression we can simplify?

Creates a new binary infix expression with the supplied operands.

Note
Sets the type of the expression
ast_expression* ast_new_conditional_expression ( ast_expression *  condition,
ast_expression *  if_true,
ast_expression *  if_false,
ast_node_attributes *  attr 
)

Creates a new conditional expression node.

Parameters
[in]condition- Decides which result expression is presented.
[in]if_true- executed if condition == true (!0)
[in]if_false- executed if condition == false (0).
[in]attr- Attributes
Note
The condition is stored in the aux member, if_true in left, and if_false on the right.

Can be used to represent ternary operations:

1 assign stall = mem_error || mem_stall ? 1'b0 : global_stall;
Note
The condition is stored in the aux member, if_true in left, and if_false on the right.
ast_expression* ast_new_expression_primary ( ast_primary p)

Creates and returns a new expression primary.

This is simply an expression instance wrapped around a primary instance for the purposes of mirroring the expression tree gramamr. Whether or not the expression is constant is denoted by the type member of the passed primary.

Parameters
[in]p- The primary to insert into the expression.

This is simply an expression instance wrapped around a primary instance for the purposes of mirroring the expression tree gramamr. Whether or not the expression is constant is denoted by the type member of the passed primary.

ast_expression* ast_new_index_expression ( ast_expression *  left)

Creates a new range index expression with the supplied operands.

Parameters
[in]left- The single expression index into an array.

Used to represent code like...

1 wire [32:0] adder_result;
2 assign overflow = adder_result[32];

Here, accessing the 32nd bit of adder_result is an index expression.

ast_expression* ast_new_mintypmax_expression ( ast_expression *  min,
ast_expression *  typ,
ast_expression *  max 
)

Creates a new (min,typical,maximum) expression.

If the mintypmax expression only specifies a typical value, then the min and max arguments should be NULL, and only typ set.

Parameters
[in]min- Minimum value in the distribution.
[in]typ- Typical / average.
[in]max- Maximum value in the distribution.

If the mintypmax expression only specifies a typical value, then the min and max arguments should be NULL, and only typ set.

ast_expression* ast_new_range_expression ( ast_expression *  left,
ast_expression *  right 
)

Creates a new range expression with the supplied operands.

Parameters
[in]left- The Upper range of the expression
[in]right- The lower range of the expression.

For example, when specifying a simple bus in verilog:

1 wire [31:0] bus_data;

Then the 31 would go into left, and the 0 into the right.

ast_expression* ast_new_string_expression ( ast_string  string)

Creates a new string expression.

Parameters
[in]string- The string. Duh.
ast_expression* ast_new_unary_expression ( ast_primary operand,
ast_operator  operation,
ast_node_attributes *  attr,
ast_boolean  constant 
)

Creates a new unary expression with the supplied operation.

Parameters
[in]operand- The thing to operate on.
[in]operation- What do we do?!
[in]attr- Expression attributes.
[in]constant- Is this a constant expression we can simplify?