/* ** HDL4SE: 软件Verilog综合仿真平台 ** Copyright (C) 2021-2021, raoxianhong ** LCOM: 轻量级组件对象模型 ** Copyright (C) 2021-2021, raoxianhong ** 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_expr.c 修改记录: 202106021610: rxh, initial version 202106061502: rxh, modify from expr to expr */ #include "stdio.h" #include "stdlib.h" #include "string.h" #include "object.h" #include "dlist.h" #include "verilog_parsetree.h" #define IMPLEMENT_GUID #include "verilog_expr.h" #undef IMPLEMENT_GUID typedef struct _sExpr { OBJECT_HEADER INTERFACE_DECLARE(IVerilogNode) VERILOGNODE_VARDECLARE DLIST_VARDECLARE int exprtype; const char* value; IVerilogNode** range0; IVerilogNode** range1; int op; IVerilogNode** expr0; IVerilogNode** expr1; IVerilogNode** expr2; IDListVarPtr attributes; IDListVarPtr elementselect; }sExpr; OBJECT_FUNCDECLARE(expr, CLSID_VERILOG_EXPR); VERILOGNODE_FUNCDECLARE(expr, CLSID_VERILOG_EXPR, sExpr); DLIST_FUNCIMPL(expr, CLSID_VERILOG_EXPR, sExpr); OBJECT_FUNCIMPL(expr, sExpr, CLSID_VERILOG_EXPR); QUERYINTERFACE_BEGIN(expr, CLSID_VERILOG_EXPR) QUERYINTERFACE_ITEM(IID_VERILOG_NODE, IVerilogNode, sExpr) QUERYINTERFACE_ITEM(IID_DLIST, IDList, sExpr) QUERYINTERFACE_END static const char *exprModuleInfo() { return "1.1.0-20210606.1504 Expression "; } static int exprCreate(const PARAMITEM * pParams, int paramcount, HOBJECT * pObject) { sExpr * pobj; pobj = (sExpr *)malloc(sizeof(sExpr)); if (pobj == NULL) return -1; memset(pobj, 0, sizeof(sExpr)); *pObject = 0; DLIST_VARINIT(pobj, expr); VERILOGNODE_VARINIT(pobj, CLSID_VERILOG_EXPR); INTERFACE_INIT(IVerilogNode, pobj, expr, verilognode); /*返回生成的对象*/ OBJECT_RETURN_GEN(expr, pobj, pObject, CLSID_VERILOG_EXPR); return EIID_OK; } static void exprDestroy(HOBJECT object) { sExpr * pobj; pobj = (sExpr *)objectThis(object); if (pobj->value) free(pobj->value); objectRelease(pobj->expr0); objectRelease(pobj->expr1); objectRelease(pobj->expr2); objectRelease(pobj->range0); objectRelease(pobj->range1); dlistRemoveAll(pobj->attributes); objectRelease(pobj->attributes); dlistRemoveAll(pobj->elementselect); objectRelease(pobj->elementselect); free(pobj); } /* 功能:判断对象是否是一个有效对象 参数: object -- 对象数据指针 返回值: 0 -- 对象是无效的 1 -- 对象是有效的 */ static int exprValid(HOBJECT object) { return 1; } static int output_operator(FILE* pFile, int opt, int op) { fprintf(pFile, operator_name[op]); } static int output_attributes(FILE* pFile, int opt, sExpr* pobj) { if (dlistItemCount(pobj->attributes) > 0) { fprintf(pFile, "(* "); verilog_dump_node_list(pobj->attributes, pFile, opt, ", "); fprintf(pFile, " *) "); } return 0; } static int expr_verilognode_dump(HOBJECT object, FILE * pFile, int opt) { sExpr * pobj; pobj = (sExpr *)objectThis(object); switch (pobj->exprtype) { case EXPRTYPE_NUMBER: case EXPRTYPE_STRING: fprintf(pFile, pobj->value); break; case EXPRTYPE_PARAM: case EXPRTYPE_LOCALPARAM: fprintf(pFile, pobj->value); break; case EXPRTYPE_BINOP: objectCall2(pobj->expr0, dump, pFile, opt); output_operator(pFile, opt, pobj->op); output_attributes(pFile, opt, pobj); objectCall2(pobj->expr1, dump, pFile, opt); break; case EXPRTYPE_UNOP: output_operator(pFile, opt, pobj->op); output_attributes(pFile, opt, pobj); objectCall2(pobj->expr0, dump, pFile, opt); break; case EXPRTYPE_IFOP: objectCall2(pobj->expr0, dump, pFile, opt); fprintf(pFile, "?"); output_attributes(pFile, opt, pobj); objectCall2(pobj->expr1, dump, pFile, opt); fprintf(pFile, ":"); objectCall2(pobj->expr2, dump, pFile, opt); break; default: fprintf(pFile, "", pobj->exprtype); break; } return 0; } HOBJECT verilogparseCreateExpr( int exprtype, const char* value, HOBJECT range0, HOBJECT range1, int op, HOBJECT expr0, HOBJECT expr1, HOBJECT expr2, IDListVarPtr attributes, IDListVarPtr elementselect ) { HOBJECT expr = NULL; sExpr * pobj; A_u_t_o_registor_expr(); objectCreate(CLSID_VERILOG_EXPR, NULL, 0, &expr); if (expr == NULL) return NULL; pobj = (sExpr *)objectThis(expr); if (value != NULL) pobj->value = strdup(value); else pobj->value = NULL; pobj->exprtype = exprtype; pobj->op = op; pobj->attributes = attributes; pobj->elementselect = elementselect; objectQueryInterface(expr0, IID_VERILOG_NODE, (void**)&pobj->expr0); objectRelease(expr0); objectQueryInterface(expr1, IID_VERILOG_NODE, (void**)&pobj->expr1); objectRelease(expr1); objectQueryInterface(expr2, IID_VERILOG_NODE, (void**)&pobj->expr2); objectRelease(expr2); objectQueryInterface(range0, IID_VERILOG_NODE, (void**)&pobj->range0); objectRelease(range0); objectQueryInterface(range1, IID_VERILOG_NODE, (void**)&pobj->range1); objectRelease(range1); return expr; }