提交 8d4bac45 编写于 作者: 饶先宏's avatar 饶先宏

202105272128

上级 4f694da1
......@@ -7,6 +7,7 @@ project ("hdl4se")
# 包含子项目。
add_subdirectory ("preprocess")
add_subdirectory ("parser")
add_subdirectory ("testpreprocess")
add_subdirectory ("hdl4secell")
add_subdirectory ("hdl4sesim")
......
......@@ -4,7 +4,7 @@
cmake_minimum_required (VERSION 3.8)
add_executable (counter "include/counter.h" "src/counter.c" "../../../glfw/deps/glad_gl.c" "src/main.c")
target_link_libraries(counter hdl4sesim preprocess hdl4secell bignumber digitled glfw lcom)
target_link_libraries(counter hdl4sesim hdl4secell bignumber digitled glfw lcom)
include_directories("../../../lcom/include")
include_directories("../../hdl4sesim/include")
......

cmake_minimum_required (VERSION 3.8)
add_library (verilog_parser STATIC
"verilog_ast.h"
"verilog_ast_common.h"
"verilog_ast_mem.h"
"verilog_keyword.c"
"verilog_module.c"
"verilog_module.h"
"verilog_parser.tab.c"
"verilog_parser.tab.h"
"verilog_parsetree.c"
"verilog_parsetree.h"
"verilog_root.c"
"verilog_root.h"
"verilog_scanner.c"
)
include_directories("../../lcom/include")
include_directories("../hdl4secell/include")
include_directories("../bignumber/include")
add_custom_command(OUTPUT verilog_scanner.c
COMMAND flex ARGS verilog_scanner.l
)
add_custom_command(OUTPUT verilog_parser.tab.c verilog_parser.tab.h
COMMAND bison ARGS verilog_parser.y)
此差异已折叠。
/*!
@file verilog_ast_common.h
@brief Contains Declarations of value-independent data structures like
linked lists which are used in the ast.
*/
#include "stdarg.h"
#include "stdlib.h"
#include "string.h"
#include "verilog_ast_mem.h"
#ifndef VERILOG_AST_COMMON_H
#define VERILOG_AST_COMMON_H
// --------------- Linked List ------------------------
/*!
@defgroup ast-linked-lists Linked List
@{
@ingroup ast-utility
*/
//! Typedef for the ast_list_element_t
typedef struct ast_list_element_t ast_list_element;
/*!
@brief Storage container for a single element in the linked list.
*/
struct ast_list_element_t{
ast_list_element * next;
void * data;
};
/*!
@brief Container struct for the linked list data structure.
*/
typedef struct ast_list_t {
ast_list_element * head; //!< The "front" of the list.
ast_list_element * tail; //!< The "end" of the list.
ast_list_element * walker; //!< Used to "walk" along the list.
unsigned int items; //!< Number of items in the list.
unsigned int current_item; //! Current position of walker in list.
} ast_list;
/*!
@brief Creates and returns a pointer to a new linked list.
*/
ast_list * ast_list_new ();
/*!
@brief Frees the memory of the supplied linked list.
@note Does not free the memory of the data elements in the list, only
the list construct itself.
*/
void ast_list_free(ast_list * list);
/*!
@brief Adds a new item to the end of a linked list.
*/
void ast_list_append(ast_list * list, void * data);
/*!
@brief Adds a new item to the front of a linked list.
*/
void ast_list_preappend(ast_list * list, void * data);
/*!
@brief Finds and returns the i'th item in the linked list.
@details Returns a void* pointer. The programmer must be sure to cast this
as the correct type.
*/
void * ast_list_get(ast_list * list, unsigned int item);
/*!
@brief Removes the i'th item from a linked list.
*/
void ast_list_remove_at(ast_list * list, unsigned int i);
/*!
@brief concatenates the two supplied lists into one.
@param head - This will form the "front" of the new list.
@param tail - This will form the "end" of the new list.
@details This function takes all the elements in tail and appends them
to those in head. The tail argument is then released from memory, and the
original head pointer is returned, with all data items still in tact.
*/
ast_list * ast_list_concat(ast_list * head, ast_list * tail);
/*!
@brief Searches the list, returning true or false if the data item supplied is
contained within it.
@details Performs a *pointer* comparison. That is, if the internal list
pointer has the same address as the supplied data pointer, the item is
considered to be found.
*/
int ast_list_contains(
ast_list * list,
void * data
);
/*! @} */
// ----------------------- Stack --------------------------------------
/*!
@defgroup ast-stack Stack
@{
@ingroup ast-utility
*/
//! Typedef for the ast_stack_element_t
typedef struct ast_stack_element_t ast_stack_element;
/*!
@brief Storage container for a single element in the stack
*/
struct ast_stack_element_t{
ast_stack_element * next;
void * data;
};
//! A very simple stack.
typedef struct ast_stack_t{
unsigned int depth; //!< How many items are on the stack?
ast_stack_element * items; //!< The stack of items.
} ast_stack;
/*!
@brief Creates and returns a new stack object.
*/
ast_stack * ast_stack_new();
/*!
@brief Free the stack, but not it's contents
*/
void ast_stack_free(ast_stack * stack);
/*!
@brief Push a new item to the top of the stack.
@param [inout] stack - The stack to push to.
@param [in] item - The thing to push onto the stack.
*/
void ast_stack_push(
ast_stack * stack,
void * item
);
/*!
@brief Pop the top item from the top of the stack.
@param [inout] stack - The stack to pop from.
*/
void * ast_stack_pop(
ast_stack * stack
);
/*!
@brief Peek at the top item on the top of the stack.
@param [inout] stack - The stack to peek at
*/
void * ast_stack_peek(
ast_stack * stack
);
/*!
@brief Peek at the item *below* the top item on the top of the stack.
@param [inout] stack - The stack to peek into
*/
void * ast_stack_peek2(
ast_stack * stack
);
/*! @} */
// ----------------------- Hash Table ---------------------------------
/*!
@defgroup ast-hashtable Hash Table
@{
@ingroup ast-utility
@brief A *very* simple hash table implemented (for now) over a linked list.
@details This can be used for simple key-value pair storage. Current
access time is O(n) for a table with N elements in it.
@warning This is a *terrible* way to implement a hash table. It doesn't
even do any hashing!
@todo Re-implement over a proper hash table structure.
*/
/*! @} */
//! A single element in the hash table.
typedef struct ast_hashtable_element_t{
char * key; //!< The key for the element.
void * data; //!< The data associated with they key.
} ast_hashtable_element;
//! A hash table object.
typedef struct ast_hashtable_t{
ast_list * elements; //!< The items.
unsigned int size; //!< The number of elements in the table.
} ast_hashtable;
typedef enum ast_hashtable_result_e{
HASH_SUCCESS = 0,
HASH_FAIL = 1,
HASH_KEY_COLLISION = 2,
HASH_KEY_NOT_FOUND = 3
} ast_hashtable_result;
//! Creates and returns a new hashtable.
ast_hashtable * ast_hashtable_new();
//! Frees an existing hashtable, but not it's contents, only the structure.
void ast_hashtable_free(
ast_hashtable * table //!< The table to free.
);
//! Inserts a new item into the hashtable.
ast_hashtable_result ast_hashtable_insert(
ast_hashtable * table, //!< The table to insert into.
char * key, //!< The key to insert with.
void * value //!< The data being added.
);
//! Returns an item from the hashtable.
ast_hashtable_result ast_hashtable_get(
ast_hashtable * table, //!< The table to fetch from.
char * key, //!< The key of the data to fetch.
void ** value //!< [out] The data being returned.
);
//! Removes a key value pair from the hashtable.
ast_hashtable_result ast_hashtable_delete(
ast_hashtable * table, //!< The table to delete from.
char * key //!< The key to delete.
);
//! Updates an existing item in the hashtable.
ast_hashtable_result ast_hashtable_update(
ast_hashtable * table, //!< The table to update.
char * key, //!< The key to update with.
void * value //!< The new data item to update.
);
#endif
/*!
@file verilog_ast_mem.h
@brief Contains Declarations of datastructures and functions for helping to
manage dynamic memory allocation within the library.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#ifndef VERILOG_AST_MEM_H
#define VERILOG_AST_MEM_H
//! Typedef over ast_memory_T
typedef struct ast_memory_t ast_memory;
//! Stores information on some allocated memory as a linked list.
struct ast_memory_t{
size_t size; //!< Amount of memory allocated.
void * data; //!< Pointer to the allocated memory.
ast_memory * next; //!< Next element to be allocated.
};
//! Iterates over all allocated memory and frees it.
void ast_free_all();
//! Duplicates the supplied null terminated string.
char * ast_strdup(char * in);
/*!
@brief A simple wrapper around calloc.
@details This function is identical to calloc, but uses the head and
walker variables above to keep a linked list of all heap memory that the
AST construction allocates. This makes it very easy to clean up afterward
using the @ref ast_free_all function.
@param [in] num - Number of elements to allocate space for.
@param [in] size - The size of each element being allocated.
@returns A pointer to the start of the block of memory allocated.
*/
void * ast_calloc(size_t num, size_t size);
#endif
#include "verilog_parser.tab.h"
#include "string.h"
#define DEFKEYWORD(id, n) {KW_##id, n}
static struct s_key_word_list {
int keyid;
const char *name;
} key_word_list[] = {
DEFKEYWORD(ALWAYS ,"always"),
DEFKEYWORD(AND ,"and"),
DEFKEYWORD(ASSIGN ,"assign"),
DEFKEYWORD(AUTOMATIC ,"automatic"),
DEFKEYWORD(BEGIN ,"begin"),
DEFKEYWORD(BUF ,"buf"),
DEFKEYWORD(BUFIF0 ,"bufif0"),
DEFKEYWORD(BUFIF1 ,"bufif1"),
DEFKEYWORD(CASE ,"case"),
DEFKEYWORD(CASEX ,"casex"),
DEFKEYWORD(CASEZ ,"casez"),
DEFKEYWORD(CELL ,"cell"),
DEFKEYWORD(CMOS ,"cmos"),
DEFKEYWORD(CONFIG ,"config"),
DEFKEYWORD(DEASSIGN ,"deassign"),
DEFKEYWORD(DEFAULT ,"default"),
DEFKEYWORD(DEFPARAM ,"defparam"),
DEFKEYWORD(DESIGN ,"design"),
DEFKEYWORD(DISABLE ,"disable"),
DEFKEYWORD(EDGE ,"edge"),
DEFKEYWORD(ELSE ,"else"),
DEFKEYWORD(END ,"end"),
DEFKEYWORD(ENDCASE ,"endcase"),
DEFKEYWORD(ENDCONFIG ,"endconfig"),
DEFKEYWORD(ENDFUNCTION ,"endfunction"),
DEFKEYWORD(ENDGENERATE ,"endgenerate"),
DEFKEYWORD(ENDMODULE ,"endmodule"),
DEFKEYWORD(ENDPRIMITIVE ,"endprimitive"),
DEFKEYWORD(ENDSPECIFY ,"endspecify"),
DEFKEYWORD(ENDTABLE ,"endtable"),
DEFKEYWORD(ENDTASK ,"endtask"),
DEFKEYWORD(EVENT ,"event"),
DEFKEYWORD(FOR ,"for"),
DEFKEYWORD(FORCE ,"force"),
DEFKEYWORD(FOREVER ,"forever"),
DEFKEYWORD(FORK ,"fork"),
DEFKEYWORD(FUNCTION ,"function"),
DEFKEYWORD(GENERATE ,"generate"),
DEFKEYWORD(GENVAR ,"genvar"),
DEFKEYWORD(HIGHZ0 ,"highz0"),
DEFKEYWORD(HIGHZ1 ,"highz1"),
DEFKEYWORD(IF ,"if"),
DEFKEYWORD(IFNONE ,"ifnone"),
DEFKEYWORD(INCDIR ,"-incdir"),
DEFKEYWORD(INCLUDE ,"include"),
DEFKEYWORD(INITIAL ,"initial"),
DEFKEYWORD(INOUT ,"inout"),
DEFKEYWORD(INPUT ,"input"),
DEFKEYWORD(INSTANCE ,"instance"),
DEFKEYWORD(INTEGER ,"integer"),
DEFKEYWORD(JOIN ,"join"),
DEFKEYWORD(LARGE ,"large"),
DEFKEYWORD(LIBLIST ,"liblist"),
DEFKEYWORD(LIBRARY ,"library"),
DEFKEYWORD(LOCALPARAM ,"localparam"),
DEFKEYWORD(MACROMODULE ,"macromodule"),
DEFKEYWORD(MEDIUM ,"medium"),
DEFKEYWORD(MODULE ,"module"),
DEFKEYWORD(NAND ,"nand"),
DEFKEYWORD(NEGEDGE ,"negedge"),
DEFKEYWORD(NMOS ,"nmos"),
DEFKEYWORD(NOR ,"nor"),
DEFKEYWORD(NOSHOWCANCELLED ,"noshowcancelled"),
DEFKEYWORD(NOT ,"not"),
DEFKEYWORD(NOTIF0 ,"notif0"),
DEFKEYWORD(NOTIF1 ,"notif1"),
DEFKEYWORD(OR ,"or"),
DEFKEYWORD(OUTPUT ,"output"),
DEFKEYWORD(PARAMETER ,"parameter"),
DEFKEYWORD(PMOS ,"pmos"),
DEFKEYWORD(POSEDGE ,"posedge"),
DEFKEYWORD(PRIMITIVE ,"primitive"),
DEFKEYWORD(PULL0 ,"pull0"),
DEFKEYWORD(PULL1 ,"pull1"),
DEFKEYWORD(PULLDOWN ,"pulldown"),
DEFKEYWORD(PULLUP ,"pullup"),
DEFKEYWORD(PULSESTYLE_ONEVENT ,"pulsestyle_onevent"),
DEFKEYWORD(PULSESTYLE_ONDETECT ,"pulsestyle_ondetect"),
DEFKEYWORD(RCMOS ,"rcmos"),
DEFKEYWORD(REAL ,"real"),
DEFKEYWORD(REALTIME ,"realtime"),
DEFKEYWORD(REG ,"reg"),
DEFKEYWORD(RELEASE ,"release"),
DEFKEYWORD(REPEAT ,"repeat"),
DEFKEYWORD(RNMOS ,"rnmos"),
DEFKEYWORD(RPMOS ,"rpmos"),
DEFKEYWORD(RTRAN ,"rtran"),
DEFKEYWORD(RTRANIF0 ,"rtranif0"),
DEFKEYWORD(RTRANIF1 ,"rtranif1"),
DEFKEYWORD(SCALARED ,"scalared"),
DEFKEYWORD(SHOWCANCELLED ,"showcancelled"),
DEFKEYWORD(SIGNED ,"signed"),
DEFKEYWORD(SMALL ,"small"),
DEFKEYWORD(SPECIFY ,"specify"),
DEFKEYWORD(SPECPARAM ,"specparam"),
DEFKEYWORD(STRONG0 ,"strong0"),
DEFKEYWORD(STRONG1 ,"strong1"),
DEFKEYWORD(SUPPLY0 ,"supply0"),
DEFKEYWORD(SUPPLY1 ,"supply1"),
DEFKEYWORD(TABLE ,"table"),
DEFKEYWORD(TASK ,"task"),
DEFKEYWORD(TIME ,"time"),
DEFKEYWORD(TRAN ,"tran"),
DEFKEYWORD(TRANIF0 ,"tranif0"),
DEFKEYWORD(TRANIF1 ,"tranif1"),
DEFKEYWORD(TRI0 ,"tri0"),
DEFKEYWORD(TRI1 ,"tri1"),
DEFKEYWORD(TRI ,"tri"),
DEFKEYWORD(TRIAND ,"triand"),
DEFKEYWORD(TRIOR ,"trior"),
DEFKEYWORD(TRIREG ,"trireg"),
DEFKEYWORD(UNSIGNED ,"unsigned"),
DEFKEYWORD(USE ,"use"),
DEFKEYWORD(VECTORED ,"vectored"),
DEFKEYWORD(WAIT ,"wait"),
DEFKEYWORD(WAND ,"wand"),
DEFKEYWORD(WEAK0 ,"weak0"),
DEFKEYWORD(WEAK1 ,"weak1"),
DEFKEYWORD(WHILE ,"while"),
DEFKEYWORD(WIRE ,"wire"),
DEFKEYWORD(WOR ,"wor"),
DEFKEYWORD(XNOR ,"xnor"),
DEFKEYWORD(XOR ,"xor"),
};
int verilog_find_reserved_word(const char * ident)
{
int i;
for (i = 0;i<sizeof(key_word_list)/sizeof(key_word_list[0]);i++) {
if (strcmp(ident, key_word_list[i].name) == 0)
return key_word_list[i].keyid;
}
return -1;
}
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "object.h"
#include "dlist.h"
#include "verilog_parsetree.h"
#define IMPLEMENT_GUID
#include "verilog_module.h"
#undef IMPLEMENT_GUID
typedef struct _sVerilogModule {
OBJECT_HEADER
INTERFACE_DECLARE(IVerilogNode)
VERILOGNODE_VARDECLARE
DLIST_VARDECLARE
HOBJECT attributes;
HOBJECT identifier;
IDListVar always_blocks;
IDListVar continuous_assignments;
IDListVar event_declarations;
IDListVar function_declarations;
IDListVar gate_instantiations;
IDListVar genvar_declarations;
IDListVar generate_blocks;
IDListVar initial_blocks;
IDListVar integer_declarations;
IDListVar local_parameters;
IDListVar module_instantiations;
IDListVar module_parameters;
IDListVar module_ports;
IDListVar net_declarations;
IDListVar parameter_overrides;
IDListVar real_declarations;
IDListVar realtime_declarations;
IDListVar reg_declarations;
IDListVar specify_blocks;
IDListVar specparams;
IDListVar task_declarations;
IDListVar time_declarations;
IDListVar udp_instantiations;
}sVerilogModule;
OBJECT_FUNCDECLARE(verilogmodule, CLSID_VERILOG_MODULE_DECLARATION);
VERILOGNODE_FUNCDECLARE(verilogmodule, CLSID_VERILOG_MODULE_DECLARATION, sVerilogModule);
DLIST_FUNCIMPL(verilogmodule, CLSID_VERILOG_MODULE_DECLARATION, sVerilogModule);
OBJECT_FUNCIMPL(verilogmodule, sVerilogModule, CLSID_VERILOG_MODULE_DECLARATION);
QUERYINTERFACE_BEGIN(verilogmodule, CLSID_VERILOG_MODULE_DECLARATION)
QUERYINTERFACE_ITEM(IID_VERILOG_NODE, IVerilogNode, sVerilogModule)
QUERYINTERFACE_ITEM(IID_DLIST, IDList, sVerilogModule)
QUERYINTERFACE_END
static const char *verilogmoduleModuleInfo()
{
return "1.0.0-20210428.0952 Verilog moudle";
}
static int verilogmoduleCreate(const PARAMITEM * pParams, int paramcount, HOBJECT * pObject)
{
sVerilogModule * pobj;
pobj = (sVerilogModule *)malloc(sizeof(sVerilogModule));
if (pobj == NULL)
return -1;
memset(pobj, 0, sizeof(sVerilogModule));
dlistInit(&pobj->always_blocks);
dlistInit(&pobj->continuous_assignments);
dlistInit(&pobj->event_declarations);
dlistInit(&pobj->function_declarations);
dlistInit(&pobj->gate_instantiations);
dlistInit(&pobj->genvar_declarations);
dlistInit(&pobj->generate_blocks);
dlistInit(&pobj->initial_blocks);
dlistInit(&pobj->integer_declarations);
dlistInit(&pobj->local_parameters);
dlistInit(&pobj->module_instantiations);
dlistInit(&pobj->module_parameters);
dlistInit(&pobj->module_ports);
dlistInit(&pobj->net_declarations);
dlistInit(&pobj->parameter_overrides);
dlistInit(&pobj->real_declarations);
dlistInit(&pobj->realtime_declarations);
dlistInit(&pobj->reg_declarations);
dlistInit(&pobj->specify_blocks);
dlistInit(&pobj->specparams);
dlistInit(&pobj->task_declarations);
dlistInit(&pobj->time_declarations);
dlistInit(&pobj->udp_instantiations);
*pObject = 0;
DLIST_VARINIT(pobj, verilogmodule);
VERILOGNODE_VARINIT(pobj, CLSID_VERILOG_MODULE_DECLARATION);
INTERFACE_INIT(IVerilogNode, pobj, verilogmodule, verilognode);
/*返回生成的对象*/
OBJECT_RETURN_GEN(verilogmodule, pobj, pObject, CLSID_VERILOG_MODULE_DECLARATION);
return EIID_OK;
}
static void verilogmoduleDestroy(HOBJECT object)
{
sVerilogModule * pTree;
pTree = (sVerilogModule *)objectThis(object);
free(pTree);
}
/*
功能:判断对象是否是一个有效对象
参数:
object -- 对象数据指针
返回值:
0 -- 对象是无效的
1 -- 对象是有效的
*/
static int verilogmoduleValid(HOBJECT object)
{
return 1;
}
static int verilogmodule_verilognode_dump(HOBJECT object, FILE * pFile, int opt)
{
sVerilogModule * pTree;
pTree = (sVerilogModule *)objectThis(object);
return 0;
}
HOBJECT verilogparseCreateModuleDeclaration(
HOBJECT attributes,
HOBJECT identifier,
IDListVarPtr parameters,
IDListVarPtr ports,
IDListVarPtr constructs
)
{
HOBJECT module = NULL;
sVerilogModule * pModule;
A_u_t_o_registor_verilogmodule();
objectCreate(CLSID_VERILOG_MODULE_DECLARATION, NULL, 0, &module);
if (module == NULL)
return NULL;
pModule = (sVerilogModule *)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;
}
#ifndef __VERILOG_MODULE_H
#define __VERILOG_MODULE_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ASMLANGUAGE
#include "guid.h"
DEFINE_GUID(CLSID_VERILOG_MODULE_DECLARATION, 0x6aabba73, 0x8d57, 0x47f6, 0xb5, 0x2f, 0xaf, 0xc4, 0x1f, 0x55, 0x7b, 0xe);
HOBJECT verilogparseCreateModuleDeclaration(
HOBJECT attributes,
HOBJECT identifier,
IDListVarPtr parameters,
IDListVarPtr ports,
IDListVarPtr constructs
);
#endif
#ifdef __cplusplus
}
#endif
#endif
此差异已折叠。
/* A Bison parser, made by GNU Bison 3.7. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YY_VERILOG_PARSER_TAB_H_INCLUDED
# define YY_YY_VERILOG_PARSER_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* "%code requires" blocks. */
#line 24 "verilog_parser.y"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "verilog_parsetree.h"
#include "verilog_ast.h"
#include "verilog_root.h"
#include "verilog_module.h"
#line 59 "verilog_parser.tab.h"
/* Token kinds. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
YYEMPTY = -2,
YYEOF = 0, /* "end of file" */
YYerror = 256, /* error */
YYUNDEF = 257, /* "invalid token" */
END = 258, /* END */
ANY = 259, /* ANY */
NEWLINE = 260, /* NEWLINE */
SPACE = 261, /* SPACE */
TAB = 262, /* TAB */
AT = 263, /* AT */
COMMA = 264, /* COMMA */
HASH = 265, /* HASH */
DOT = 266, /* DOT */
EQ = 267, /* EQ */
COLON = 268, /* COLON */
IDX_PRT_SEL = 269, /* IDX_PRT_SEL */
SEMICOLON = 270, /* SEMICOLON */
OPEN_BRACKET = 271, /* OPEN_BRACKET */
CLOSE_BRACKET = 272, /* CLOSE_BRACKET */
OPEN_SQ_BRACKET = 273, /* OPEN_SQ_BRACKET */
CLOSE_SQ_BRACKET = 274, /* CLOSE_SQ_BRACKET */
OPEN_SQ_BRACE = 275, /* OPEN_SQ_BRACE */
CLOSE_SQ_BRACE = 276, /* CLOSE_SQ_BRACE */
BIN_VALUE = 277, /* BIN_VALUE */
OCT_VALUE = 278, /* OCT_VALUE */
HEX_VALUE = 279, /* HEX_VALUE */
DEC_VALUE = 280, /* DEC_VALUE */
DEC_BASE = 281, /* DEC_BASE */
BIN_BASE = 282, /* BIN_BASE */
OCT_BASE = 283, /* OCT_BASE */
HEX_BASE = 284, /* HEX_BASE */
NUM_REAL = 285, /* NUM_REAL */
NUM_SIZE = 286, /* NUM_SIZE */
UNSIGNED_NUMBER = 287, /* UNSIGNED_NUMBER */
SYSTEM_ID = 288, /* SYSTEM_ID */
SIMPLE_ID = 289, /* SIMPLE_ID */
ESCAPED_ID = 290, /* ESCAPED_ID */
DEFINE_ID = 291, /* DEFINE_ID */
ATTRIBUTE_START = 292, /* ATTRIBUTE_START */
ATTRIBUTE_END = 293, /* ATTRIBUTE_END */
COMMENT_LINE = 294, /* COMMENT_LINE */
COMMENT_BLOCK = 295, /* COMMENT_BLOCK */
STRING = 296, /* STRING */
STAR = 297, /* STAR */
PLUS = 298, /* PLUS */
MINUS = 299, /* MINUS */
ASL = 300, /* ASL */
ASR = 301, /* ASR */
LSL = 302, /* LSL */
LSR = 303, /* LSR */
DIV = 304, /* DIV */
POW = 305, /* POW */
MOD = 306, /* MOD */
GTE = 307, /* GTE */
LTE = 308, /* LTE */
GT = 309, /* GT */
LT = 310, /* LT */
L_NEG = 311, /* L_NEG */
L_AND = 312, /* L_AND */
L_OR = 313, /* L_OR */
C_EQ = 314, /* C_EQ */
L_EQ = 315, /* L_EQ */
C_NEQ = 316, /* C_NEQ */
L_NEQ = 317, /* L_NEQ */
B_NEG = 318, /* B_NEG */
B_AND = 319, /* B_AND */
B_OR = 320, /* B_OR */
B_XOR = 321, /* B_XOR */
B_EQU = 322, /* B_EQU */
B_NAND = 323, /* B_NAND */
B_NOR = 324, /* B_NOR */
TERNARY = 325, /* TERNARY */
UNARY_OP = 326, /* UNARY_OP */
MACRO_TEXT = 327, /* MACRO_TEXT */
MACRO_IDENTIFIER = 328, /* MACRO_IDENTIFIER */
KW_ALWAYS = 329, /* KW_ALWAYS */
KW_AND = 330, /* KW_AND */
KW_ASSIGN = 331, /* KW_ASSIGN */
KW_AUTOMATIC = 332, /* KW_AUTOMATIC */
KW_BEGIN = 333, /* KW_BEGIN */
KW_BUF = 334, /* KW_BUF */
KW_BUFIF0 = 335, /* KW_BUFIF0 */
KW_BUFIF1 = 336, /* KW_BUFIF1 */
KW_CASE = 337, /* KW_CASE */
KW_CASEX = 338, /* KW_CASEX */
KW_CASEZ = 339, /* KW_CASEZ */
KW_CELL = 340, /* KW_CELL */
KW_CMOS = 341, /* KW_CMOS */
KW_CONFIG = 342, /* KW_CONFIG */
KW_DEASSIGN = 343, /* KW_DEASSIGN */
KW_DEFAULT = 344, /* KW_DEFAULT */
KW_DEFPARAM = 345, /* KW_DEFPARAM */
KW_DESIGN = 346, /* KW_DESIGN */
KW_DISABLE = 347, /* KW_DISABLE */
KW_EDGE = 348, /* KW_EDGE */
KW_ELSE = 349, /* KW_ELSE */
KW_END = 350, /* KW_END */
KW_ENDCASE = 351, /* KW_ENDCASE */
KW_ENDCONFIG = 352, /* KW_ENDCONFIG */
KW_ENDFUNCTION = 353, /* KW_ENDFUNCTION */
KW_ENDGENERATE = 354, /* KW_ENDGENERATE */
KW_ENDMODULE = 355, /* KW_ENDMODULE */
KW_ENDPRIMITIVE = 356, /* KW_ENDPRIMITIVE */
KW_ENDSPECIFY = 357, /* KW_ENDSPECIFY */
KW_ENDTABLE = 358, /* KW_ENDTABLE */
KW_ENDTASK = 359, /* KW_ENDTASK */
KW_EVENT = 360, /* KW_EVENT */
KW_FOR = 361, /* KW_FOR */
KW_FORCE = 362, /* KW_FORCE */
KW_FOREVER = 363, /* KW_FOREVER */
KW_FORK = 364, /* KW_FORK */
KW_FUNCTION = 365, /* KW_FUNCTION */
KW_GENERATE = 366, /* KW_GENERATE */
KW_GENVAR = 367, /* KW_GENVAR */
KW_HIGHZ0 = 368, /* KW_HIGHZ0 */
KW_HIGHZ1 = 369, /* KW_HIGHZ1 */
KW_IF = 370, /* KW_IF */
KW_IFNONE = 371, /* KW_IFNONE */
KW_INCDIR = 372, /* KW_INCDIR */
KW_INCLUDE = 373, /* KW_INCLUDE */
KW_INITIAL = 374, /* KW_INITIAL */
KW_INOUT = 375, /* KW_INOUT */
KW_INPUT = 376, /* KW_INPUT */
KW_INSTANCE = 377, /* KW_INSTANCE */
KW_INTEGER = 378, /* KW_INTEGER */
KW_JOIN = 379, /* KW_JOIN */
KW_LARGE = 380, /* KW_LARGE */
KW_LIBLIST = 381, /* KW_LIBLIST */
KW_LIBRARY = 382, /* KW_LIBRARY */
KW_LOCALPARAM = 383, /* KW_LOCALPARAM */
KW_MACROMODULE = 384, /* KW_MACROMODULE */
KW_MEDIUM = 385, /* KW_MEDIUM */
KW_MODULE = 386, /* KW_MODULE */
KW_NAN = 387, /* KW_NAN */
KW_NEGEDGE = 388, /* KW_NEGEDGE */
KW_NMOS = 389, /* KW_NMOS */
KW_NOR = 390, /* KW_NOR */
KW_NOSHOWCANCELLED = 391, /* KW_NOSHOWCANCELLED */
KW_NOT = 392, /* KW_NOT */
KW_NOTIF0 = 393, /* KW_NOTIF0 */
KW_NOTIF1 = 394, /* KW_NOTIF1 */
KW_OR = 395, /* KW_OR */
KW_OUTPUT = 396, /* KW_OUTPUT */
KW_PARAMETER = 397, /* KW_PARAMETER */
KW_PATHPULSE = 398, /* KW_PATHPULSE */
KW_PMOS = 399, /* KW_PMOS */
KW_POSEDGE = 400, /* KW_POSEDGE */
KW_PRIMITIVE = 401, /* KW_PRIMITIVE */
KW_PULL0 = 402, /* KW_PULL0 */
KW_PULL1 = 403, /* KW_PULL1 */
KW_PULLDOWN = 404, /* KW_PULLDOWN */
KW_PULLUP = 405, /* KW_PULLUP */
KW_PULSESTYLE_ONEVENT = 406, /* KW_PULSESTYLE_ONEVENT */
KW_PULSESTYLE_ONDETECT = 407, /* KW_PULSESTYLE_ONDETECT */
KW_RCMOS = 408, /* KW_RCMOS */
KW_REAL = 409, /* KW_REAL */
KW_REALTIME = 410, /* KW_REALTIME */
KW_REG = 411, /* KW_REG */
KW_RELEASE = 412, /* KW_RELEASE */
KW_REPEAT = 413, /* KW_REPEAT */
KW_RNMOS = 414, /* KW_RNMOS */
KW_RPMOS = 415, /* KW_RPMOS */
KW_RTRAN = 416, /* KW_RTRAN */
KW_RTRANIF0 = 417, /* KW_RTRANIF0 */
KW_RTRANIF1 = 418, /* KW_RTRANIF1 */
KW_SCALARED = 419, /* KW_SCALARED */
KW_SHOWCANCELLED = 420, /* KW_SHOWCANCELLED */
KW_SIGNED = 421, /* KW_SIGNED */
KW_SMALL = 422, /* KW_SMALL */
KW_SPECIFY = 423, /* KW_SPECIFY */
KW_SPECPARAM = 424, /* KW_SPECPARAM */
KW_STRONG0 = 425, /* KW_STRONG0 */
KW_STRONG1 = 426, /* KW_STRONG1 */
KW_SUPPLY0 = 427, /* KW_SUPPLY0 */
KW_SUPPLY1 = 428, /* KW_SUPPLY1 */
KW_TABLE = 429, /* KW_TABLE */
KW_TASK = 430, /* KW_TASK */
KW_TIME = 431, /* KW_TIME */
KW_TRAN = 432, /* KW_TRAN */
KW_TRANIF0 = 433, /* KW_TRANIF0 */
KW_TRANIF1 = 434, /* KW_TRANIF1 */
KW_TRI = 435, /* KW_TRI */
KW_TRI0 = 436, /* KW_TRI0 */
KW_TRI1 = 437, /* KW_TRI1 */
KW_TRIAND = 438, /* KW_TRIAND */
KW_TRIOR = 439, /* KW_TRIOR */
KW_TRIREG = 440, /* KW_TRIREG */
KW_UNSIGNED = 441, /* KW_UNSIGNED */
KW_USE = 442, /* KW_USE */
KW_VECTORED = 443, /* KW_VECTORED */
KW_WAIT = 444, /* KW_WAIT */
KW_WAND = 445, /* KW_WAND */
KW_WEAK0 = 446, /* KW_WEAK0 */
KW_WEAK1 = 447, /* KW_WEAK1 */
KW_WHILE = 448, /* KW_WHILE */
KW_WIRE = 449, /* KW_WIRE */
KW_WOR = 450, /* KW_WOR */
KW_XNOR = 451, /* KW_XNOR */
KW_XOR = 452, /* KW_XOR */
KW_NAND = 453 /* KW_NAND */
};
typedef enum yytokentype yytoken_kind_t;
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 35 "verilog_parser.y"
HOBJECT treenode;
char * string;
int token;
int operator;
IDListVar list;
#line 282 "verilog_parser.tab.h"
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_VERILOG_PARSER_TAB_H_INCLUDED */
此差异已折叠。
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#define IMPLEMENT_GUID
#include "verilog_parsetree.h"
#undef IMPLEMENT_GUID
#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);
}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); \
static const IVerilogNode _obj##_verilognode_interface = { \
INTERFACE_HEADER(_obj, IVerilogNode, _localstruct) \
_obj##_verilognode_dump, \
};
typedef struct sIVerilogRoot {
OBJECT_INTERFACE
int (*add_module)(HOBJECT object, HOBJECT module);
int (*add_primitive)(HOBJECT object, HOBJECT udp);
}IVerilogRoot;
#define VERILOGROOT_VARDECLARE
#define VERILOGROOT_VARINIT(_objptr, _clsid)
#define VERILOGROOT_FUNCDECLARE(_obj, _clsid, _localstruct) \
static int _obj##_verilogroot_add_module(HOBJECT object, HOBJECT module); \
static int _obj##_verilogroot_add_primitive(HOBJECT object, HOBJECT udp); \
static const IVerilogRoot _obj##_verilogroot_interface = { \
INTERFACE_HEADER(_obj, IVerilogRoot, _localstruct) \
_obj##_verilogroot_add_module, \
_obj##_verilogroot_add_primitive, \
};
#endif
#ifdef __cplusplus
}
#endif
#endif
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "verilog_parsetree.h"
#define IMPLEMENT_GUID
#include "verilog_root.h"
#undef IMPLEMENT_GUID
typedef struct _sVerilogRoot {
OBJECT_HEADER
INTERFACE_DECLARE(IVerilogRoot)
VERILOGROOT_VARDECLARE
INTERFACE_DECLARE(IVerilogNode)
VERILOGNODE_VARDECLARE
IDListVar modules;
IDListVar primitives;
IDListVar configs;
IDListVar libraries;
}sVerilogRoot;
OBJECT_FUNCDECLARE(verilogroot, CLSID_VERILOG_ROOT);
VERILOGROOT_FUNCDECLARE(verilogroot, CLSID_VERILOG_ROOT, sVerilogRoot);
VERILOGNODE_FUNCDECLARE(verilogroot, CLSID_VERILOG_ROOT, sVerilogRoot);
OBJECT_FUNCIMPL(verilogroot, sVerilogRoot, CLSID_VERILOG_ROOT);
QUERYINTERFACE_BEGIN(verilogroot, CLSID_VERILOG_ROOT)
QUERYINTERFACE_ITEM(IID_VERILOG_ROOT, IVerilogRoot, sVerilogRoot)
QUERYINTERFACE_ITEM(IID_VERILOG_NODE, IVerilogNode, sVerilogRoot)
QUERYINTERFACE_END
static const char *verilogrootModuleInfo()
{
return "1.0.0-20210427.1702 Verilog parse tree root";
}
static int verilogrootCreate(const PARAMITEM * pParams, int paramcount, HOBJECT * pObject)
{
sVerilogRoot * pobj;
pobj = (sVerilogRoot *)malloc(sizeof(sVerilogRoot));
if (pobj == NULL)
return -1;
dlistInit(&pobj->modules);
dlistInit(&pobj->primitives);
dlistInit(&pobj->configs);
dlistInit(&pobj->libraries);
*pObject = 0;
VERILOGROOT_VARINIT(pobj, CLSID_VERILOG_ROOT);
VERILOGNODE_VARINIT(pobj, CLSID_VERILOG_ROOT);
INTERFACE_INIT(IVerilogRoot, pobj, verilogroot, verilogroot);
INTERFACE_INIT(IVerilogNode, pobj, verilogroot, verilognode);
/*返回生成的对象*/
OBJECT_RETURN_GEN(verilogroot, pobj, pObject, CLSID_VERILOG_ROOT);
return EIID_OK;
}
static void verilogrootDestroy(HOBJECT object)
{
sVerilogRoot * pTree;
pTree = (sVerilogRoot *)objectThis(object);
free(pTree);
}
/*
功能:判断对象是否是一个有效对象
参数:
object -- 对象数据指针
返回值:
0 -- 对象是无效的
1 -- 对象是有效的
*/
static int verilogrootValid(HOBJECT object)
{
return 1;
}
static int verilogroot_verilogroot_add_module(HOBJECT object, HOBJECT module)
{
sVerilogRoot * pTree;
pTree = (sVerilogRoot *)objectThis(object);
return 0;
}
static int verilogroot_verilogroot_add_primitive(HOBJECT object, HOBJECT module)
{
sVerilogRoot * pTree;
pTree = (sVerilogRoot *)objectThis(object);
return 0;
}
static int verilogroot_verilognode_dump(HOBJECT object, FILE * pFile, int opt)
{
sVerilogRoot * pTree;
pTree = (sVerilogRoot *)objectThis(object);
return 0;
}
static IVerilogRoot ** pVerilogRoot = NULL;
IVerilogRoot ** getVerilogRoot()
{
if (pVerilogRoot == NULL) {
A_u_t_o_registor_verilogroot();
objectCreateEx(CLSID_VERILOG_ROOT, NULL, 0, IID_VERILOG_ROOT, (const void **)&pVerilogRoot);
}
return pVerilogRoot;
}
#ifndef __VERILOG_ROOT_H
#define __VERILOG_ROOT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ASMLANGUAGE
#include "guid.h"
DEFINE_GUID(CLSID_VERILOG_ROOT, 0x5d3cde51, 0xdb70, 0x4283, 0x95, 0xe1, 0x0, 0xd3, 0xbf, 0x61, 0x12, 0x36);
IVerilogRoot ** getVerilogRoot();
#endif
#ifdef __cplusplus
}
#endif
#endif
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -3,7 +3,7 @@
#
cmake_minimum_required (VERSION 3.8)
add_library (preprocess STATIC
add_library (verilog_preprocess STATIC
"include/filestack.h"
"src/preprocess.c"
"include/preprocess.h"
......
cmake_minimum_required (VERSION 3.8)
add_executable (testpreprocess "testpreprocess.c")
target_link_libraries(testpreprocess preprocess lcom)
target_link_libraries(testpreprocess verilog_preprocess lcom)
include_directories("../../lcom/include")
include_directories("../preprocess/include")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册