Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
饶先宏
hdl4se
提交
8758741b
H
hdl4se
项目概览
饶先宏
/
hdl4se
通知
12
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hdl4se
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8758741b
编写于
5月 31, 2021
作者:
饶先宏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
202105312153
上级
27be67ac
变更
7
展开全部
显示空白变更内容
内联
并排
Showing
7 changed file
with
2174 addition
and
2184 deletion
+2174
-2184
parser/CMakeLists.txt
parser/CMakeLists.txt
+8
-1
parser/verilog_parameter.c
parser/verilog_parameter.c
+65
-45
parser/verilog_parser.c
parser/verilog_parser.c
+2028
-1993
parser/verilog_parser.h
parser/verilog_parser.h
+10
-4
parser/verilog_parser.y
parser/verilog_parser.y
+37
-6
parser/verilog_parsetree.h
parser/verilog_parsetree.h
+1
-0
parser/verilog_ptrlistitem.c
parser/verilog_ptrlistitem.c
+25
-135
未找到文件。
parser/CMakeLists.txt
浏览文件 @
8758741b
...
...
@@ -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"
)
...
...
parser/verilog_parameter.c
浏览文件 @
8758741b
...
...
@@ -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
_s
AttrSpec
{
typedef
struct
_s
Parameter
{
OBJECT_HEADER
INTERFACE_DECLARE
(
IVerilogNode
)
VERILOGNODE_VARDECLARE
DLIST_VARDECLARE
const
char
*
pname
;
IVerilogNode
**
expr
;
}
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
(
attrspec
,
CLSID_VERILOG_ATTRSPEC
);
OBJECT_FUNCDECLARE
(
parameter
,
CLSID_VERILOG_PARAMETER
);
VERILOGNODE_FUNCDECLARE
(
attrspec
,
CLSID_VERILOG_ATTRSPEC
,
sAttrSpec
);
DLIST_FUNCIMPL
(
attrspec
,
CLSID_VERILOG_ATTRSPEC
,
sAttrSpec
);
OBJECT_FUNCIMPL
(
attrspec
,
sAttrSpec
,
CLSID_VERILOG_ATTRSPEC
);
VERILOGNODE_FUNCDECLARE
(
parameter
,
CLSID_VERILOG_PARAMETER
,
sParameter
);
DLIST_FUNCIMPL
(
parameter
,
CLSID_VERILOG_PARAMETER
,
sParameter
);
OBJECT_FUNCIMPL
(
parameter
,
sParameter
,
CLSID_VERILOG_PARAMETER
);
QUERYINTERFACE_BEGIN
(
attrspec
,
CLSID_VERILOG_ATTRSPEC
)
QUERYINTERFACE_ITEM
(
IID_VERILOG_NODE
,
IVerilogNode
,
s
AttrSpec
)
QUERYINTERFACE_ITEM
(
IID_DLIST
,
IDList
,
s
AttrSpec
)
QUERYINTERFACE_BEGIN
(
parameter
,
CLSID_VERILOG_PARAMETER
)
QUERYINTERFACE_ITEM
(
IID_VERILOG_NODE
,
IVerilogNode
,
s
Parameter
)
QUERYINTERFACE_ITEM
(
IID_DLIST
,
IDList
,
s
Parameter
)
QUERYINTERFACE_END
static
const
char
*
attrspec
ModuleInfo
()
static
const
char
*
parameter
ModuleInfo
()
{
return
"1.0.0-20210428.0952 Verilog
Attribute Spec
"
;
return
"1.0.0-20210428.0952 Verilog
Parameter
"
;
}
static
int
attrspec
Create
(
const
PARAMITEM
*
pParams
,
int
paramcount
,
HOBJECT
*
pObject
)
static
int
parameter
Create
(
const
PARAMITEM
*
pParams
,
int
paramcount
,
HOBJECT
*
pObject
)
{
s
AttrSpec
*
pobj
;
pobj
=
(
s
AttrSpec
*
)
malloc
(
sizeof
(
sAttrSpec
));
s
Parameter
*
pobj
;
pobj
=
(
s
Parameter
*
)
malloc
(
sizeof
(
sParameter
));
if
(
pobj
==
NULL
)
return
-
1
;
memset
(
pobj
,
0
,
sizeof
(
s
AttrSpec
));
memset
(
pobj
,
0
,
sizeof
(
s
Parameter
));
*
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
attrspec
Destroy
(
HOBJECT
object
)
static
void
parameter
Destroy
(
HOBJECT
object
)
{
s
AttrSpec
*
pobj
;
pobj
=
(
s
AttrSpec
*
)
objectThis
(
object
);
if
(
pobj
->
p
name
)
free
(
pobj
->
p
name
);
s
Parameter
*
pobj
;
pobj
=
(
s
Parameter
*
)
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
attrspec
Valid
(
HOBJECT
object
)
static
int
parameter
Valid
(
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
)
{
s
AttrSpec
*
pobj
;
pobj
=
(
s
AttrSpec
*
)
objectThis
(
object
);
s
Parameter
*
pobj
;
pobj
=
(
s
Parameter
*
)
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
;
s
AttrSpec
*
pobj
;
A_u_t_o_registor_
attrspec
();
objectCreate
(
CLSID_VERILOG_
ATTRSPEC
,
NULL
,
0
,
&
attrspec
);
if
(
attrspec
==
NULL
)
HOBJECT
parameter
=
NULL
;
s
Parameter
*
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
;
}
parser/verilog_parser.c
浏览文件 @
8758741b
此差异已折叠。
点击以展开。
parser/verilog_parser.h
浏览文件 @
8758741b
...
...
@@ -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 7
4
"D:/gitwork/hdl4se/parser/verilog_parser.y"
#line 7
5
"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 27
0
"D:/gitwork/hdl4se/parser/verilog_parser.h"
#line 27
6
"D:/gitwork/hdl4se/parser/verilog_parser.h"
};
typedef
union
YYSTYPE
YYSTYPE
;
...
...
parser/verilog_parser.y
浏览文件 @
8758741b
...
...
@@ -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_gate
type
%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
...
...
@@ -151,6 +153,7 @@
%type <list> attribute_instance_list attribute_instance attribute_instance_spec_list
%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);
}
;
...
...
parser/verilog_parsetree.h
浏览文件 @
8758741b
...
...
@@ -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
);
...
...
parser/verilog_ptrlistitem.c
浏览文件 @
8758741b
...
...
@@ -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
;
}
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
*
p
Module
;
HOBJECT
obj
=
NULL
;
sMapStr2PtrItem
*
p
obj
;
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录