Skip to content

Commit

Permalink
Finished library representation.
Browse files Browse the repository at this point in the history
 On branch master
 Your branch is up-to-date with 'github/master'.

 Changes to be committed:
	modified:   README.md
	modified:   docs/ast-nodes.dox
	modified:   src/verilog_ast.c
	modified:   src/verilog_ast.h
	modified:   src/verilog_parser.y
  • Loading branch information
ben-marshall committed Jul 4, 2016
1 parent 70cd0ee commit 3e55132
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This will get you going.

```sh
$> make setup
$> make all
$> make test
```

This will download the test suite files, setup the build directory, and
Expand Down
1 change: 0 additions & 1 deletion docs/ast-nodes.dox
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@section ast-todo AST Todo List

- Proper node for all types of identifier.
- Proper number representation node.
- Completely deprecate the @ref ast_node type.
- Types and assertions for the @ref ast_list construct.
Expand Down
28 changes: 28 additions & 0 deletions src/verilog_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,3 +2184,31 @@ ast_config_declaration * ast_new_config_declaration(

return tr;
}

/*!
@brief Creates a new library declaration node.
*/
ast_library_declaration * ast_new_library_declaration(
ast_identifier identifier,
ast_list * file_paths,
ast_list * incdirs
){
ast_library_declaration * tr =
ast_calloc(1,sizeof(ast_library_declaration));

tr -> identifier = identifier;
tr -> file_paths = file_paths;
tr -> incdirs = incdirs;
}

//! Creates and returns a new library description object.
ast_library_descriptions * ast_new_library_description(
ast_library_item_type type
){
ast_library_descriptions * tr =
ast_calloc(1,sizeof(ast_library_descriptions));

tr -> type = type;

return tr;
}
40 changes: 39 additions & 1 deletion src/verilog_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2806,10 +2806,48 @@ ast_config_declaration * ast_new_config_declaration(
@defgroup ast-node-library-source-text Library Source
@{
@ingroup ast-construction
@brief TODO
@brief Library, config and include statements / constructs.
*/

/*!
@brief Describes a library declaration of file and include paths.
*/
typedef struct ast_library_declaration_t{
ast_identifier identifier;
ast_list * file_paths;
ast_list * incdirs;
} ast_library_declaration;

/*!
@brief Creates a new library declaration node.
*/
ast_library_declaration * ast_new_library_declaration(
ast_identifier identifier,
ast_list * file_paths,
ast_list * incdirs
);

//! Describes a library item.
typedef enum ast_library_item_type_e{
LIB_LIBRARY,
LIB_INCLUDE,
LIB_CONFIG
} ast_library_item_type;

//! Super structure for different library construct types.
typedef struct ast_library_descriptions_t{
ast_library_item_type type;
union{
ast_library_declaration * library;
ast_config_declaration * config;
ast_string include;
};
} ast_library_descriptions;

//! Creates and returns a new library description object.
ast_library_descriptions * ast_new_library_description(
ast_library_item_type type
);

/*! @} */

Expand Down
87 changes: 59 additions & 28 deletions src/verilog_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
ast_cmos_switch_instance * cmos_switch_instance ;
ast_concatenation * concatenation;
ast_config_rule_statement * config_rule_statement;
ast_config_declaration * config_declaration;
ast_library_declaration * library_declaration;
ast_library_descriptions * library_descriptions;
ast_delay2 * delay2;
ast_delay3 * delay3;
ast_delay_ctrl * delay_control;
Expand Down Expand Up @@ -631,19 +634,19 @@
%type <identifier> cell_clause
%type <node> compiler_directive
%type <node> conditional_compile_directive
%type <node> config_declaration
%type <config_declaration> config_declaration
%type <config_rule_statement> config_rule_statement
%type <list> config_rule_statement_os
%type <node> default_net_type_cd
%type <identifier> design_statement
%type <node> ifdef_directive
%type <node> ifndef_directive
%type <node> include_directive
%type <node> include_statement
%type <string> include_statement
%type <list> liblist_clause
%type <node> library_declaration
%type <node> library_descriptions
%type <node> library_text
%type <library_declaration> library_declaration
%type <library_descriptions> library_descriptions
%type <list> library_text
%type <node> line_directive
%type <node> pulsestyle_declaration
%type <node> showcancelled_declaration
Expand Down Expand Up @@ -856,34 +859,62 @@ include_directive : CD_INCLUDE string;

/* A.1.1 Library Source Text */

library_text : library_descriptions
| library_text library_descriptions

library_descriptions : library_declaration
| include_statement
| config_declaration
| compiler_directives
;

library_declaration : KW_LIBRARY library_identifier
file_path_specs
SEMICOLON
| KW_LIBRARY library_identifier
file_path_specs
KW_INCDIR file_path_specs
SEMICOLON
;
library_text :
library_descriptions{
$$ = ast_list_new();
ast_list_append($$,$1);
}
| library_text library_descriptions{
$$ = $1;
ast_list_append($$,$2);
}
;

file_path_specs : file_path_spec
| file_path_specs COMMA file_path_spec
;
library_descriptions :
library_declaration{
$$ = ast_new_library_description(LIB_LIBRARY);
$$ -> library = $1;
}
| include_statement{
$$ = ast_new_library_description(LIB_INCLUDE);
$$ -> include = $1;
}
| config_declaration{
$$ = ast_new_library_description(LIB_CONFIG);
$$ -> config = $1;
}
| compiler_directives {
$$ = NULL;
}
;

library_declaration :
KW_LIBRARY library_identifier file_path_specs SEMICOLON{
$$ = ast_new_library_declaration($2,$3,ast_list_new());
}
| KW_LIBRARY library_identifier file_path_specs KW_INCDIR file_path_specs
SEMICOLON{
$$ = ast_new_library_declaration($2,$3,$5);
}
;

file_path_specs :
file_path_spec{
$$ = ast_list_new();
ast_list_append($$,$1);
}
| file_path_specs COMMA file_path_spec{
$$ = $1;
ast_list_append($$,$3);
}
;

file_path_spec : file_path
file_path_spec : file_path{$$=$1;}
;

file_path : string;
file_path : string {$$=$1;};

include_statement : KW_INCLUDE file_path_spec SEMICOLON
include_statement : KW_INCLUDE file_path_spec SEMICOLON{$$=$2;}
;

/* A.1.2 Configuration Source Text */
Expand Down

0 comments on commit 3e55132

Please sign in to comment.