Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Added helper function for printing the name of identifiers.
Browse files Browse the repository at this point in the history
 On branch master
 Your branch is up-to-date with 'origin/master'.

 Changes to be committed:
	modified:   ../../src/verilog_ast.c
	modified:   ../../src/verilog_ast.h
  • Loading branch information
ben-marshall committed Jul 15, 2016
1 parent 67d2ffc commit 0621ddd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/verilog_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,37 @@ ast_source_item * ast_new_source_item(ast_source_item_type type){
return tr;
}


/*!
@brief Simply returns the fully qualified representation of an identifier as
a string.
@details Where the identifier is "simple" or a system id, then the identifier
will just be returned as a character array. Where it is a hierarchical
idenifier, then a dot separated string of all identifiers in the hierarchy
will be returned.
@param [in] id - The identifier object to return a string representation of.
@returns A copy of the identifiers full name, as a null terminated character
array.
*/
char * ast_identifier_tostring(ast_identifier id)
{
size_t len = strlen(id -> identifier+1);
char * tr = calloc(len,sizeof(char));
memcpy(tr, id -> identifier, len);

ast_identifier walker = id;

while(walker -> next != NULL)
{
walker = walker -> next;

size_t len = strlen(walker -> identifier+1) + len;
tr = realloc(tr,len);
strcat(tr, walker -> identifier);
}
return tr;
}

ast_identifier ast_new_identifier(
char * identifier,
unsigned int from_line
Expand Down
14 changes: 14 additions & 0 deletions src/verilog_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include "verilog_ast_common.h"

Expand Down Expand Up @@ -2961,6 +2962,19 @@ struct ast_identifier_t{
};
};

/*!
@brief Simply returns the fully qualified representation of an identifier as
a string.
@details Where the identifier is "simple" or a system id, then the identifier
will just be returned as a character array. Where it is a hierarchical
idenifier, then a dot separated string of all identifiers in the hierarchy
will be returned.
@param [in] id - The identifier object to return a string representation of.
@returns A copy of the identifiers full name, as a null terminated character
array.
*/
char * ast_identifier_tostring(ast_identifier id);

/*!
@brief Creates and returns a new node representing an identifier.
@details By default, the returned identifier has the ID_UNKNOWN type,
Expand Down

0 comments on commit 0621ddd

Please sign in to comment.