verilog_parsetree.h 6.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**   this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
**   this list of conditions and the following disclaimer in the documentation
**   and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
**   derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* verilog_parsetree.h
  修改记录:
	202105280612: rxh, initial version
*/
饶先宏's avatar
饶先宏 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

#ifndef __VERILOG_PARSETREE_H
#define __VERILOG_PARSETREE_H

#ifdef __cplusplus
extern "C" {
#endif

#ifndef _ASMLANGUAGE

#include "guid.h"

DEFINE_GUID(IID_VERILOG_ROOT, 0xa1fbe4b5, 0xbfb6, 0x41e2, 0xb2, 0xf, 0x5c, 0x14, 0xd1, 0xdf, 0x7c, 0x20);
DEFINE_GUID(IID_VERILOG_NODE, 0x88ec245f, 0xff4c, 0x4d5a, 0xb3, 0xe, 0x59, 0x70, 0x85, 0x42, 0x14, 0x20);

typedef struct sIVerilogNode {
  OBJECT_INTERFACE
  int (*dump)(HOBJECT object, FILE * pFile, int opt);
饶先宏's avatar
饶先宏 已提交
55
  int (*procheck)(HOBJECT object, HOBJECT module, void * param);
饶先宏's avatar
饶先宏 已提交
56
  int (*gencode)(HOBJECT object, FILE* pFile, HOBJECT module, void* param);
饶先宏's avatar
饶先宏 已提交
57 58 59 60 61 62 63
}IVerilogNode;

#define VERILOGNODE_VARDECLARE
#define VERILOGNODE_VARINIT(_objptr, _clsid)

#define VERILOGNODE_FUNCDECLARE(_obj, _clsid, _localstruct) \
  static int _obj##_verilognode_dump(HOBJECT object, FILE * pFile, int opt); \
饶先宏's avatar
饶先宏 已提交
64
  static int _obj##_verilognode_procheck(HOBJECT object, HOBJECT module, void * param); \
饶先宏's avatar
饶先宏 已提交
65
  static int _obj##_verilognode_gencode(HOBJECT object, FILE * pFile, HOBJECT module, void * param); \
饶先宏's avatar
饶先宏 已提交
66 67 68
  static const IVerilogNode _obj##_verilognode_interface = { \
		INTERFACE_HEADER(_obj, IVerilogNode, _localstruct) \
		_obj##_verilognode_dump, \
69 70
		_obj##_verilognode_procheck, \
		_obj##_verilognode_gencode, \
饶先宏's avatar
饶先宏 已提交
71 72
};

73 74
int verilog_dump_node_list(IDListVarPtr list, FILE* pFile, int opt, const char * gap, int itemperline);
int verilog_dump_mapstr2ptr_list(IDListVarPtr list, FILE* pFile, int opt, const char * gap, int itemperline);
75

饶先宏's avatar
饶先宏 已提交
76
int verilog_procheck_node_list(IDListVarPtr list, HOBJECT module, void * param);
饶先宏's avatar
饶先宏 已提交
77
int verilog_gencode_node_list(IDListVarPtr list, FILE* pFile, HOBJECT module, void* param);
饶先宏's avatar
饶先宏 已提交
78

饶先宏's avatar
饶先宏 已提交
79 80
typedef struct sIVerilogRoot {
  OBJECT_INTERFACE
饶先宏's avatar
饶先宏 已提交
81
  int (*add_module)(HOBJECT object, IConstStringVar* name, HOBJECT module);
82 83
  int (*find_module)(HOBJECT object, const char *name, HOBJECT *module);
  int (*gencode)(HOBJECT object, FILE * pFile, const char * topmodulename, void * param);
饶先宏's avatar
饶先宏 已提交
84 85 86 87 88 89
}IVerilogRoot;

#define VERILOGROOT_VARDECLARE
#define VERILOGROOT_VARINIT(_objptr, _clsid)

#define VERILOGROOT_FUNCDECLARE(_obj, _clsid, _localstruct) \
90 91 92 93
    static int _obj##_verilogroot_add_module(HOBJECT object, IConstStringVar *name, HOBJECT module); \
    static int _obj##_verilogroot_find_module(HOBJECT object, const char *name, HOBJECT *module); \
    static int _obj##_verilogroot_gencode(HOBJECT object, FILE* pFile, const char* topmodulename, void* param); \
static const IVerilogRoot _obj##_verilogroot_interface = { \
饶先宏's avatar
饶先宏 已提交
94 95
		INTERFACE_HEADER(_obj, IVerilogRoot, _localstruct) \
		_obj##_verilogroot_add_module, \
96 97
		_obj##_verilogroot_find_module, \
		_obj##_verilogroot_gencode, \
饶先宏's avatar
饶先宏 已提交
98
};
99 100 101 102 103

int hdl4se_parser_SetPreProcess(HOBJECT object);
int hdl4se_parser_AddLog(const char * log);
int hdl4se_parser_GetCurrentFile(IConstStringVar** pfilename, int* lineno, int* linepos, int* filepos);
char* hdl4se_parse_logbuf();
饶先宏's avatar
饶先宏 已提交
104
    
饶先宏's avatar
饶先宏 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
enum VAR_TYPE {
    VAR_TYPE_NONE,
    VAR_TYPE_SUPPLY0,
    VAR_TYPE_SUPPLY1,
    VAR_TYPE_TRI,
    VAR_TYPE_TRIAND,
    VAR_TYPE_TRIOR,
    VAR_TYPE_TRI0,
    VAR_TYPE_TRI1,
    VAR_TYPE_UWIRE,
    VAR_TYPE_WIRE,
    VAR_TYPE_WAND,
    VAR_TYPE_WOR,
    VAR_TYPE_INTEGER,
    VAR_TYPE_TIME,
    VAR_TYPE_REG,
饶先宏's avatar
饶先宏 已提交
121 122
};

饶先宏's avatar
饶先宏 已提交
123

饶先宏's avatar
饶先宏 已提交
124 125 126 127 128 129
enum VECT_OR_SCALAR {
    VS_NONE,
    VS_VECTORED,
    VS_SCALARED,
};

饶先宏's avatar
饶先宏 已提交
130 131
enum exprtype {
	EXPRTYPE_NUMBER,
饶先宏's avatar
饶先宏 已提交
132 133
    EXPRTYPE_BIGNUMBER,
    EXPRTYPE_PARAM,
饶先宏's avatar
饶先宏 已提交
134 135 136 137 138 139 140
	EXPRTYPE_LOCALPARAM,
	EXPRTYPE_STRING,
	EXPRTYPE_UNOP,
	EXPRTYPE_BINOP,
	EXPRTYPE_IFOP,
    EXPRTYPE_IDENT,
    EXPRTYPE_HIERARCHICAL_IDENT,
141
    EXPRTYPE_EMIT,
饶先宏's avatar
饶先宏 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
};

enum RANGE_TYPE {
	RANGE_TYPE_NONE,
	RANGE_TYPE_BITSELECT,
	RANGE_TYPE_PARTSELECT,
	RANGE_TYPE_STARTPLUSWIDTH,
	RANGE_TYPE_STARTMINUSWIDTH,
};

enum PORT_DIRECT {
	PORT_DIRECT_INPUT,
	PORT_DIRECT_INOUT,
	PORT_DIRECT_OUTPUT,
	PORT_DIRECT_UNKNOW,
饶先宏's avatar
饶先宏 已提交
157
    PORT_DIRECT_ASPRE,
饶先宏's avatar
饶先宏 已提交
158 159
};

160
enum PARAM_TYPE {
饶先宏's avatar
饶先宏 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
	PARAM_TYPE_PARAM,
	PARAM_TYPE_LOCAL,
	PARAM_TYPE_SPEC,
	PARAM_TYPE_ASPRE,
};

enum PARAM_DATA_TYPE {
	PARAM_DATA_TYPE_INTEGER,
	PARAM_DATA_TYPE_TIME,
	PARAM_DATA_TYPE_REAL,
	PARAM_DATA_TYPE_REALTIME,
};

enum OPERATOR {
    OP_L_NOT,
    OP_B_NOT,
    OP_B_AND,
    OP_B_NAND,
    OP_B_OR,
    OP_B_NOR,
    OP_B_XOR,
    OP_B_EQU,
    OP_PLUS,
    OP_MINUS,
    OP_MUL,
    OP_DIV,
    OP_MOD,
    OP_POW,
    OP_L_EQ,
    OP_L_NEQ,
    OP_C_EQ,
    OP_C_NEQ,
    OP_L_AND,
    OP_L_OR,
    OP_LT,
    OP_LTE,
    OP_GT,
    OP_GTE,
    OP_LSR,
    OP_LSL,
    OP_ASR,
    OP_ASL,
};

205 206 207 208 209 210 211 212 213 214 215
typedef struct _expr_code {
    int exprtype;
    union {
        int op;
        int index;
        const char* value;
        const char* name;
    };
}expr_code;

int const_expr_eval(int expr_infosize, expr_code *expr_info, int paramcount, IBigNumber***parameters);
216
const char * const_expr_list_eval(int expr_infosize, expr_code* expr_info, int paramcount, IBigNumber*** parameters);
饶先宏's avatar
饶先宏 已提交
217
const char* const_expr_eval_const_param(int expr_infosize, expr_code* expr_info, int paramcount, IBigNumber*** parameters);
218

饶先宏's avatar
饶先宏 已提交
219 220 221 222 223 224 225
#endif    

#ifdef __cplusplus
}
#endif

#endif