提交 8758741b 编写于 作者: 饶先宏's avatar 饶先宏

202105312153

上级 27be67ac
......@@ -3,17 +3,24 @@ cmake_minimum_required (VERSION 3.8)
add_library (verilog_parser STATIC
"verilog_attrspec.c"
"verilog_attrspec.h"
"verilog_keyword.c"
"verilog_keyword.h"
"verilog_module.c"
"verilog_module.h"
"verilog_parser.h"
"verilog_parser.c"
"verilog_parsetree.c"
"verilog_parsetree.h"
"verilog_parameter.c"
"verilog_parameter.h"
"verilog_ptrlistitem.c"
"verilog_ptrlistitem.h"
"verilog_root.c"
"verilog_root.h"
"verilog_scanner.c"
"verilog_keyword.h")
"verilog_keyword.h"
)
include_directories("../../lcom/include")
include_directories("../hdl4secell/include")
......
......@@ -30,7 +30,7 @@
*/
/*
* verilog_attrspec.c
* verilog_parameter.c
修改记录:
202105311542: rxh, initial version
*/
......@@ -42,62 +42,69 @@
#include "dlist.h"
#include "verilog_parsetree.h"
#define IMPLEMENT_GUID
#include "verilog_attrspec.h"
#include "verilog_parameter.h"
#undef IMPLEMENT_GUID
typedef struct _sAttrSpec {
typedef struct _sParameter {
OBJECT_HEADER
INTERFACE_DECLARE(IVerilogNode)
VERILOGNODE_VARDECLARE
DLIST_VARDECLARE
const char* pname;
IVerilogNode ** expr;
}sAttrSpec;
OBJECT_FUNCDECLARE(attrspec, CLSID_VERILOG_ATTRSPEC);
VERILOGNODE_FUNCDECLARE(attrspec, CLSID_VERILOG_ATTRSPEC, sAttrSpec);
DLIST_FUNCIMPL(attrspec, CLSID_VERILOG_ATTRSPEC, sAttrSpec);
OBJECT_FUNCIMPL(attrspec, sAttrSpec, CLSID_VERILOG_ATTRSPEC);
QUERYINTERFACE_BEGIN(attrspec, CLSID_VERILOG_ATTRSPEC)
QUERYINTERFACE_ITEM(IID_VERILOG_NODE, IVerilogNode, sAttrSpec)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sAttrSpec)
int param_type;
int param_data_type;
int param_issigned;
HOBJECT param_range_msb; /* expression */
HOBJECT param_range_lsb; /* expression */
const char* name;
HOBJECT expr;
}sParameter;
OBJECT_FUNCDECLARE(parameter, CLSID_VERILOG_PARAMETER);
VERILOGNODE_FUNCDECLARE(parameter, CLSID_VERILOG_PARAMETER, sParameter);
DLIST_FUNCIMPL(parameter, CLSID_VERILOG_PARAMETER, sParameter);
OBJECT_FUNCIMPL(parameter, sParameter, CLSID_VERILOG_PARAMETER);
QUERYINTERFACE_BEGIN(parameter, CLSID_VERILOG_PARAMETER)
QUERYINTERFACE_ITEM(IID_VERILOG_NODE, IVerilogNode, sParameter)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sParameter)
QUERYINTERFACE_END
static const char *attrspecModuleInfo()
static const char *parameterModuleInfo()
{
return "1.0.0-20210428.0952 Verilog Attribute Spec ";
return "1.0.0-20210428.0952 Verilog Parameter ";
}
static int attrspecCreate(const PARAMITEM * pParams, int paramcount, HOBJECT * pObject)
static int parameterCreate(const PARAMITEM * pParams, int paramcount, HOBJECT * pObject)
{
sAttrSpec * pobj;
pobj = (sAttrSpec *)malloc(sizeof(sAttrSpec));
sParameter * pobj;
pobj = (sParameter *)malloc(sizeof(sParameter));
if (pobj == NULL)
return -1;
memset(pobj, 0, sizeof(sAttrSpec));
memset(pobj, 0, sizeof(sParameter));
*pObject = 0;
DLIST_VARINIT(pobj, attrspec);
VERILOGNODE_VARINIT(pobj, CLSID_VERILOG_ATTRSPEC);
INTERFACE_INIT(IVerilogNode, pobj, attrspec, verilognode);
DLIST_VARINIT(pobj, parameter);
VERILOGNODE_VARINIT(pobj, CLSID_VERILOG_PARAMETER);
INTERFACE_INIT(IVerilogNode, pobj, parameter, verilognode);
/*返回生成的对象*/
OBJECT_RETURN_GEN(attrspec, pobj, pObject, CLSID_VERILOG_ATTRSPEC);
OBJECT_RETURN_GEN(parameter, pobj, pObject, CLSID_VERILOG_PARAMETER);
return EIID_OK;
}
static void attrspecDestroy(HOBJECT object)
static void parameterDestroy(HOBJECT object)
{
sAttrSpec * pobj;
pobj = (sAttrSpec *)objectThis(object);
if (pobj->pname)
free(pobj->pname);
sParameter * pobj;
pobj = (sParameter *)objectThis(object);
if (pobj->name)
free(pobj->name);
objectRelease(pobj->expr);
objectRelease(pobj->param_range_msb);
objectRelease(pobj->param_range_lsb);
free(pobj);
}
......@@ -109,31 +116,44 @@ static void attrspecDestroy(HOBJECT object)
0 -- 对象是无效的
1 -- 对象是有效的
*/
static int attrspecValid(HOBJECT object)
static int parameterValid(HOBJECT object)
{
return 1;
}
static int attrspec_verilognode_dump(HOBJECT object, FILE * pFile, int opt)
static int parameter_verilognode_dump(HOBJECT object, FILE * pFile, int opt)
{
sAttrSpec * pobj;
pobj = (sAttrSpec *)objectThis(object);
sParameter * pobj;
pobj = (sParameter *)objectThis(object);
return 0;
}
HOBJECT verilogparseCreateAttrSpec(const char* name, HOBJECT constexpression)
HOBJECT verilogparseCreateParameter(
int param_type,
int param_data_type,
int param_issigned,
HOBJECT param_range_msb, /* expression */
HOBJECT param_range_lsb, /* expression */
const char* name,
HOBJECT constexpression
)
{
HOBJECT attrspec = NULL;
sAttrSpec * pobj;
A_u_t_o_registor_attrspec();
objectCreate(CLSID_VERILOG_ATTRSPEC, NULL, 0, &attrspec);
if (attrspec == NULL)
HOBJECT parameter = NULL;
sParameter * pobj;
A_u_t_o_registor_parameter();
objectCreate(CLSID_VERILOG_PARAMETER, NULL, 0, &parameter);
if (parameter == NULL)
return NULL;
pobj = (sAttrSpec *)objectThis(attrspec);
pobj->pname = strdup(name);
objectQueryInterface(constexpression, IID_VERILOG_NODE, (void**)&pobj->expr);
return attrspec;
pobj = (sParameter *)objectThis(parameter);
pobj->param_type = param_type;
pobj->param_data_type = param_data_type;
pobj->param_issigned = param_issigned;
pobj->param_range_msb = param_range_msb;
pobj->param_range_lsb = param_range_lsb;
pobj->name = name;
pobj->expr = constexpression;
return parameter;
}
此差异已折叠。
......@@ -55,9 +55,10 @@ extern int yydebug;
#include "verilog_module.h"
#include "verilog_keyword.h"
#include "verilog_attrspec.h"
#include "verilog_ptrlistitem.h"
#include "verilog_parameter.h"
#line 61 "D:/gitwork/hdl4se/parser/verilog_parser.h"
#line 62 "D:/gitwork/hdl4se/parser/verilog_parser.h"
/* Token kinds. */
#ifndef YYTOKENTYPE
......@@ -254,19 +255,24 @@ extern int yydebug;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 74 "D:/gitwork/hdl4se/parser/verilog_parser.y"
#line 75 "D:/gitwork/hdl4se/parser/verilog_parser.y"
HOBJECT treenode;
HOBJECT obj;
struct _two_obj {
HOBJECT obj[2];
}two_obj;
struct _str_bind_obj {
const char * key;
HOBJECT obj;
}str_bind_obj;
char * string;
int token;
int operator;
int ival;
IDListVar list;
#line 270 "D:/gitwork/hdl4se/parser/verilog_parser.h"
#line 276 "D:/gitwork/hdl4se/parser/verilog_parser.h"
};
typedef union YYSTYPE YYSTYPE;
......
......@@ -67,12 +67,14 @@
#include "verilog_module.h"
#include "verilog_keyword.h"
#include "verilog_attrspec.h"
#include "verilog_ptrlistitem.h"
#include "verilog_parameter.h"
}
/* token types */
%union {
HOBJECT treenode;
HOBJECT obj;
struct _two_obj {
HOBJECT obj[2];
}two_obj;
......@@ -138,10 +140,10 @@
%type <string> attr_name identifier module_identifier topmodule_identifier parameter_identifier
%type <ival> enable_gatetype
%type <ival> parameter_type
%type <two_obj> range range_option
%type <str_bind_obj> param_assignment
%type <obj> param_assignment
%type <treenode> attr_spec
%type <treenode> constant_mintypmax_expression
......@@ -150,7 +152,8 @@
%type <list> attribute_instance_list attribute_instance attribute_instance_spec_list
%type <list> module_parameter_port_list module_param_list parameter_declaration
%type <list> module_parameter_port_list module_param_list parameter_declaration
list_of_param_assignments
%type <list> list_of_port_declarations
list_of_ports module_item_list non_port_module_item_list
......@@ -557,8 +560,11 @@ signed_option:
range_option:
{
$$.obj[0] = NULL;
$$.obj[1] = NULL;
}
| range {
$$ = $1;
}
;
......@@ -573,6 +579,24 @@ parameter_declaration :
KW_PARAMETER signed_option range_option list_of_param_assignments {
}
| KW_PARAMETER parameter_type list_of_param_assignments {
IDListVarPtr pitem, pitemtemp;
IMapStr2PtrItem ** assignitem;
dlistInit(&$$);
pitem = $3.__dlist_pNext;
while (pitem != &$3) {
pitemtemp = pitem->__dlist_pNext;
if (0 == objectQueryInterface(pitem, IID_MAPSTR2PTRITEM, (void **)&assignitem)) {
const char *name;
HOBJECT expr;
HOBJECT paramitem;
objectCall1(assignitem, GetName, &name);
objectCall1(assignitem, GetData, &expr);
paramitem = verilogparseCreateParameter(PARAM_TYPE_PARAM, $2, 0, NULL, NULL, name, expr);
dlistAppendItem(&$$, paramitem);
}
pitem = pitemtemp;
}
dlistRemoveAll(&$3);
}
;
......@@ -583,12 +607,16 @@ specparam_declaration :
parameter_type :
KW_INTEGER {
$$ = PARAM_DATA_TYPE_INTEGER;
}
| KW_REAL {
$$ = PARAM_DATA_TYPE_REAL;
}
| KW_REALTIME {
$$ = PARAM_DATA_TYPE_REALTIME;
}
| KW_TIME {
$$ = PARAM_DATA_TYPE_TIME;
}
;
......@@ -928,8 +956,12 @@ list_of_event_identifiers :
list_of_param_assignments :
param_assignment {
dlistInit(&$$);
dlistAppendItem(&$$, $1);
}
| list_of_param_assignments ',' param_assignment {
$$ = $1;
dlistAppendItem(&$$, $3);
}
;
......@@ -993,8 +1025,7 @@ net_decl_assignment :
param_assignment :
parameter_identifier '=' constant_mintypmax_expression {
$$.key = $1;
$$.obj = $3;
$$ = verilogparseCreatePtrListItem($1, $3);
}
;
......
......@@ -64,6 +64,7 @@ typedef struct sIVerilogNode {
_obj##_verilognode_dump, \
};
DEFINE_GUID(IID_MAPSTR2PTRITEM, 0xa18c8f3, 0xe5d1, 0x4f74, 0x83, 0xe8, 0x60, 0x7f, 0xd8, 0x56, 0xb9, 0x7c);
typedef struct sIMapStr2PtrItem {
OBJECT_INTERFACE
int (*GetName)(HOBJECT object, const char** pname);
......
......@@ -42,7 +42,7 @@
#include "dlist.h"
#include "verilog_parsetree.h"
#define IMPLEMENT_GUID
#include "verilog_module.h"
#include "verilog_ptrlistitem.h"
#undef IMPLEMENT_GUID
typedef struct _sMapStr2PtrItem {
......@@ -83,7 +83,7 @@ static int ptrlistitemCreate(const PARAMITEM * pParams, int paramcount, HOBJECT
*pObject = 0;
DLIST_VARINIT(pobj, ptrlistitem);
VERILOGNODE_VARINIT(pobj, CLSID_VERILOG_PTRLISTITEM);
INTERFACE_INIT(IMapStr2PtrItem, pobj, ptrlistitem, verilognode);
INTERFACE_INIT(IMapStr2PtrItem, pobj, ptrlistitem, mapstr2ptr);
/*返回生成的对象*/
OBJECT_RETURN_GEN(ptrlistitem, pobj, pObject, CLSID_VERILOG_PTRLISTITEM);
......@@ -111,146 +111,36 @@ static int ptrlistitemValid(HOBJECT object)
return 1;
}
static int ptrlistitem_verilognode_dump(HOBJECT object, FILE * pFile, int opt)
static int ptrlistitem_mapstr2ptr_GetName(HOBJECT object, const char** pname)
{
sMapStr2PtrItem * pobj;
pobj = (sMapStr2PtrItem *)objectThis(object);
sMapStr2PtrItem* pobj;
pobj = (sMapStr2PtrItem*)objectThis(object);
*pname = pobj->name;
return 0;
}
return 0;
static int ptrlistitem_mapstr2ptr_GetData(HOBJECT object, void** ppData)
{
sMapStr2PtrItem* pobj;
pobj = (sMapStr2PtrItem*)objectThis(object);
*ppData = pobj->ptr;
return 0;
}
HOBJECT HOBJECT verilogparseCreatePtrListItem(const char * name, void* ptr)
HOBJECT verilogparseCreatePtrListItem(const char * name, void* ptr)
{
HOBJECT module = NULL;
sMapStr2PtrItem * pModule;
HOBJECT obj = NULL;
sMapStr2PtrItem * pobj;
A_u_t_o_registor_ptrlistitem();
objectCreate(CLSID_VERILOG_PTRLISTITEM, NULL, 0, &module);
if (module == NULL)
objectCreate(CLSID_VERILOG_PTRLISTITEM, NULL, 0, &obj);
if (obj == NULL)
return NULL;
pModule = (sMapStr2PtrItem *)objectThis(module);
pModule->attributes = attributes;
pModule->identifier = identifier;
pModule->module_parameters = *parameters;
if(ports != NULL) {
pModule->module_ports = *ports;
}
/*
for(i = 0; i < constructs -> items; i++)
{
ast_module_item * construct = ast_list_get(constructs, i);
if(construct -> type == MOD_ITEM_PORT_DECLARATION && ports == NULL){
// Only accept ports declared this way iff the ports argument to
// this function is NULL, signifying the old style of port
// declaration.
ast_list_append(tr -> module_ports,
construct -> port_declaration);
}
else if(construct -> type == MOD_ITEM_GENERATED_INSTANTIATION){
ast_list_append(tr -> generate_blocks,
construct -> generated_instantiation);
}
else if(construct -> type == MOD_ITEM_PARAMETER_DECLARATION) {
ast_list_append(tr -> module_parameters,
construct -> parameter_declaration);
}
else if(construct -> type == MOD_ITEM_SPECIFY_BLOCK){
ast_list_append(tr -> specify_blocks,
construct -> specify_block);
}
else if(construct -> type == MOD_ITEM_SPECPARAM_DECLARATION){
ast_list_append(tr -> specparams,
construct -> specparam_declaration);
}
else if(construct -> type == MOD_ITEM_PARAMETER_OVERRIDE){
ast_list_append(tr -> parameter_overrides,
construct -> parameter_override);
}
else if(construct -> type == MOD_ITEM_CONTINOUS_ASSIGNMENT){
ast_list_append(tr -> continuous_assignments,
construct -> continuous_assignment);
}
else if(construct -> type == MOD_ITEM_GATE_INSTANTIATION){
ast_list_append(tr -> gate_instantiations,
construct -> gate_instantiation);
}
else if(construct -> type == MOD_ITEM_UDP_INSTANTIATION){
ast_list_append(tr -> udp_instantiations,
construct -> udp_instantiation);
}
else if(construct -> type == MOD_ITEM_MODULE_INSTANTIATION){
ast_list_append(tr -> module_instantiations,
construct -> module_instantiation);
}
else if(construct -> type == MOD_ITEM_INITIAL_CONSTRUCT){
ast_statement_block * toadd = ast_extract_statement_block(
BLOCK_SEQUENTIAL_INITIAL, construct -> initial_construct);
ast_list_append(tr -> initial_blocks ,toadd);
}
else if(construct -> type == MOD_ITEM_ALWAYS_CONSTRUCT){
ast_statement_block * toadd = ast_extract_statement_block(
BLOCK_SEQUENTIAL_ALWAYS, construct -> always_construct);
ast_list_append(tr -> always_blocks,toadd);
}
else if(construct -> type == MOD_ITEM_NET_DECLARATION){
tr -> net_declarations = ast_list_concat(
tr -> net_declarations,
ast_new_net_declaration(construct -> net_declaration));
}
else if(construct -> type == MOD_ITEM_REG_DECLARATION){
tr -> reg_declarations = ast_list_concat(
tr -> reg_declarations,
ast_new_reg_declaration(construct -> reg_declaration));
}
else if(construct -> type == MOD_ITEM_INTEGER_DECLARATION){
tr -> integer_declarations = ast_list_concat(
tr -> integer_declarations,
ast_new_var_declaration(construct -> integer_declaration));
}
else if(construct -> type == MOD_ITEM_REAL_DECLARATION){
tr -> real_declarations = ast_list_concat(
tr -> real_declarations,
ast_new_var_declaration(construct -> real_declaration));
}
else if(construct -> type == MOD_ITEM_TIME_DECLARATION){
tr -> time_declarations = ast_list_concat(
tr -> time_declarations,
ast_new_var_declaration(construct -> time_declaration));
}
else if(construct -> type == MOD_ITEM_REALTIME_DECLARATION){
tr -> realtime_declarations = ast_list_concat(
tr -> realtime_declarations,
ast_new_var_declaration(construct -> realtime_declaration));
}
else if(construct -> type == MOD_ITEM_EVENT_DECLARATION){
tr -> event_declarations = ast_list_concat(
tr -> event_declarations,
ast_new_var_declaration(construct -> event_declaration));
}
else if(construct -> type == MOD_ITEM_GENVAR_DECLARATION){
tr -> genvar_declarations = ast_list_concat(
tr -> genvar_declarations,
ast_new_var_declaration(construct -> genvar_declaration));
}
else if(construct -> type == MOD_ITEM_TASK_DECLARATION){
ast_list_append(tr -> task_declarations,
construct -> task_declaration);
}
else if(construct -> type == MOD_ITEM_FUNCTION_DECLARATION){
ast_list_append(tr -> function_declarations,
construct -> function_declaration);
}
else
{
printf("ERROR: Unsupported module construct type: %d\n",
construct -> type);
assert(0); // Fail out because this should *never* happen
}
}
return tr;
}*/
return module;
pobj = (sMapStr2PtrItem *)objectThis(obj);
pobj->name = name;
pobj->ptr = ptr;
return obj;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册