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

202105291616

上级 9b59ec71
......@@ -7,9 +7,10 @@ project ("hdl4se")
# 包含子项目。
add_subdirectory ("preprocess")
# add_subdirectory ("parser")
add_subdirectory ("testpreprocess")
# add_subdirectory ("testparser")
add_subdirectory ("parser")
add_subdirectory ("testscanner")
add_subdirectory ("testparser")
add_subdirectory ("hdl4secell")
add_subdirectory ("hdl4sesim")
add_subdirectory ("bignumber")
......
......@@ -114,6 +114,7 @@ static struct s_key_word_list {
DEFKEYWORD(OR ,"or"),
DEFKEYWORD(OUTPUT ,"output"),
DEFKEYWORD(PARAMETER ,"parameter"),
DEFKEYWORD(PATHPULSE ,"PATHPULSE$"),
DEFKEYWORD(PMOS ,"pmos"),
DEFKEYWORD(POSEDGE ,"posedge"),
DEFKEYWORD(PRIMITIVE ,"primitive"),
......@@ -168,6 +169,19 @@ static struct s_key_word_list {
DEFKEYWORD(WOR ,"wor"),
DEFKEYWORD(XNOR ,"xnor"),
DEFKEYWORD(XOR ,"xor"),
DEFKEYWORD(SYS_SETUP ,"$setup"),
DEFKEYWORD(SYS_HOLD ,"$hold"),
DEFKEYWORD(SYS_SETUPHOLD ,"$setuphold"),
DEFKEYWORD(SYS_RECOVERY ,"$recovery"),
DEFKEYWORD(SYS_REMOVAL ,"$removal"),
DEFKEYWORD(SYS_RECREM ,"$recrem"),
DEFKEYWORD(SYS_SKEW ,"$skew"),
DEFKEYWORD(SYS_TIMESKEW ,"$timeskew"),
DEFKEYWORD(SYS_FULLSKEW ,"$fullskew"),
DEFKEYWORD(SYS_SKEW ,"$skew"),
DEFKEYWORD(SYS_PERIOD ,"$period"),
DEFKEYWORD(SYS_WIDTH ,"$width"),
DEFKEYWORD(SYS_NOCHANGE ,"$nochange")
};
int verilog_find_reserved_word(const char * ident)
......
此差异已折叠。
/* 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_D_GITWORK_HDL4SE_PARSER_VERILOG_PARSER_H_INCLUDED
# define YY_YY_D_GITWORK_HDL4SE_PARSER_VERILOG_PARSER_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* "%code requires" blocks. */
#line 24 "D:/gitwork/hdl4se/parser/verilog_parser.y"
#include "stdio.h"
#include "object.h"
#include "dlist.h"
#include "verilog_parsetree.h"
#include "verilog_root.h"
#include "verilog_module.h"
#include "verilog_keyword.h"
#line 60 "D:/gitwork/hdl4se/parser/verilog_parser.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 */
BIN_VALUE = 263, /* BIN_VALUE */
OCT_VALUE = 264, /* OCT_VALUE */
HEX_VALUE = 265, /* HEX_VALUE */
DEC_VALUE = 266, /* DEC_VALUE */
DEC_BASE = 267, /* DEC_BASE */
BIN_BASE = 268, /* BIN_BASE */
OCT_BASE = 269, /* OCT_BASE */
HEX_BASE = 270, /* HEX_BASE */
NUM_REAL = 271, /* NUM_REAL */
NUM_SIZE = 272, /* NUM_SIZE */
UNSIGNED_NUMBER = 273, /* UNSIGNED_NUMBER */
SYSTEM_ID = 274, /* SYSTEM_ID */
SIMPLE_ID = 275, /* SIMPLE_ID */
ESCAPED_ID = 276, /* ESCAPED_ID */
DEFINE_ID = 277, /* DEFINE_ID */
STRING = 278, /* STRING */
ATTRIBUTE_START = 279, /* ATTRIBUTE_START */
ATTRIBUTE_END = 280, /* ATTRIBUTE_END */
ASL = 281, /* ASL */
ASR = 282, /* ASR */
LSL = 283, /* LSL */
LSR = 284, /* LSR */
GTE = 285, /* GTE */
LTE = 286, /* LTE */
L_AND = 287, /* L_AND */
L_OR = 288, /* L_OR */
L_EQ = 289, /* L_EQ */
C_EQ = 290, /* C_EQ */
L_NEQ = 291, /* L_NEQ */
C_NEQ = 292, /* C_NEQ */
B_EQU = 293, /* B_EQU */
B_NAND = 294, /* B_NAND */
B_NOR = 295, /* B_NOR */
IDX_PRT_SEL = 296, /* IDX_PRT_SEL */
KW_ALWAYS = 297, /* KW_ALWAYS */
KW_AND = 298, /* KW_AND */
KW_ASSIGN = 299, /* KW_ASSIGN */
KW_AUTOMATIC = 300, /* KW_AUTOMATIC */
KW_BEGIN = 301, /* KW_BEGIN */
KW_BUF = 302, /* KW_BUF */
KW_BUFIF0 = 303, /* KW_BUFIF0 */
KW_BUFIF1 = 304, /* KW_BUFIF1 */
KW_CASE = 305, /* KW_CASE */
KW_CASEX = 306, /* KW_CASEX */
KW_CASEZ = 307, /* KW_CASEZ */
KW_CELL = 308, /* KW_CELL */
KW_CMOS = 309, /* KW_CMOS */
KW_CONFIG = 310, /* KW_CONFIG */
KW_DEASSIGN = 311, /* KW_DEASSIGN */
KW_DEFAULT = 312, /* KW_DEFAULT */
KW_DEFPARAM = 313, /* KW_DEFPARAM */
KW_DESIGN = 314, /* KW_DESIGN */
KW_DISABLE = 315, /* KW_DISABLE */
KW_EDGE = 316, /* KW_EDGE */
KW_ELSE = 317, /* KW_ELSE */
KW_END = 318, /* KW_END */
KW_ENDCASE = 319, /* KW_ENDCASE */
KW_ENDCONFIG = 320, /* KW_ENDCONFIG */
KW_ENDFUNCTION = 321, /* KW_ENDFUNCTION */
KW_ENDGENERATE = 322, /* KW_ENDGENERATE */
KW_ENDMODULE = 323, /* KW_ENDMODULE */
KW_ENDPRIMITIVE = 324, /* KW_ENDPRIMITIVE */
KW_ENDSPECIFY = 325, /* KW_ENDSPECIFY */
KW_ENDTABLE = 326, /* KW_ENDTABLE */
KW_ENDTASK = 327, /* KW_ENDTASK */
KW_EVENT = 328, /* KW_EVENT */
KW_FOR = 329, /* KW_FOR */
KW_FORCE = 330, /* KW_FORCE */
KW_FOREVER = 331, /* KW_FOREVER */
KW_FORK = 332, /* KW_FORK */
KW_FUNCTION = 333, /* KW_FUNCTION */
KW_GENERATE = 334, /* KW_GENERATE */
KW_GENVAR = 335, /* KW_GENVAR */
KW_HIGHZ0 = 336, /* KW_HIGHZ0 */
KW_HIGHZ1 = 337, /* KW_HIGHZ1 */
KW_IF = 338, /* KW_IF */
KW_IFNONE = 339, /* KW_IFNONE */
KW_INCDIR = 340, /* KW_INCDIR */
KW_INCLUDE = 341, /* KW_INCLUDE */
KW_INITIAL = 342, /* KW_INITIAL */
KW_INOUT = 343, /* KW_INOUT */
KW_INPUT = 344, /* KW_INPUT */
KW_INSTANCE = 345, /* KW_INSTANCE */
KW_INTEGER = 346, /* KW_INTEGER */
KW_JOIN = 347, /* KW_JOIN */
KW_LARGE = 348, /* KW_LARGE */
KW_LIBLIST = 349, /* KW_LIBLIST */
KW_LIBRARY = 350, /* KW_LIBRARY */
KW_LOCALPARAM = 351, /* KW_LOCALPARAM */
KW_MACROMODULE = 352, /* KW_MACROMODULE */
KW_MEDIUM = 353, /* KW_MEDIUM */
KW_MODULE = 354, /* KW_MODULE */
KW_NAN = 355, /* KW_NAN */
KW_NEGEDGE = 356, /* KW_NEGEDGE */
KW_NMOS = 357, /* KW_NMOS */
KW_NOR = 358, /* KW_NOR */
KW_NOSHOWCANCELLED = 359, /* KW_NOSHOWCANCELLED */
KW_NOT = 360, /* KW_NOT */
KW_NOTIF0 = 361, /* KW_NOTIF0 */
KW_NOTIF1 = 362, /* KW_NOTIF1 */
KW_OR = 363, /* KW_OR */
KW_OUTPUT = 364, /* KW_OUTPUT */
KW_PARAMETER = 365, /* KW_PARAMETER */
KW_PATHPULSE = 366, /* KW_PATHPULSE */
KW_PMOS = 367, /* KW_PMOS */
KW_POSEDGE = 368, /* KW_POSEDGE */
KW_PRIMITIVE = 369, /* KW_PRIMITIVE */
KW_PULL0 = 370, /* KW_PULL0 */
KW_PULL1 = 371, /* KW_PULL1 */
KW_PULLDOWN = 372, /* KW_PULLDOWN */
KW_PULLUP = 373, /* KW_PULLUP */
KW_PULSESTYLE_ONEVENT = 374, /* KW_PULSESTYLE_ONEVENT */
KW_PULSESTYLE_ONDETECT = 375, /* KW_PULSESTYLE_ONDETECT */
KW_RCMOS = 376, /* KW_RCMOS */
KW_REAL = 377, /* KW_REAL */
KW_REALTIME = 378, /* KW_REALTIME */
KW_REG = 379, /* KW_REG */
KW_RELEASE = 380, /* KW_RELEASE */
KW_REPEAT = 381, /* KW_REPEAT */
KW_RNMOS = 382, /* KW_RNMOS */
KW_RPMOS = 383, /* KW_RPMOS */
KW_RTRAN = 384, /* KW_RTRAN */
KW_RTRANIF0 = 385, /* KW_RTRANIF0 */
KW_RTRANIF1 = 386, /* KW_RTRANIF1 */
KW_SCALARED = 387, /* KW_SCALARED */
KW_SHOWCANCELLED = 388, /* KW_SHOWCANCELLED */
KW_SIGNED = 389, /* KW_SIGNED */
KW_SMALL = 390, /* KW_SMALL */
KW_SPECIFY = 391, /* KW_SPECIFY */
KW_SPECPARAM = 392, /* KW_SPECPARAM */
KW_STRONG0 = 393, /* KW_STRONG0 */
KW_STRONG1 = 394, /* KW_STRONG1 */
KW_SUPPLY0 = 395, /* KW_SUPPLY0 */
KW_SUPPLY1 = 396, /* KW_SUPPLY1 */
KW_TABLE = 397, /* KW_TABLE */
KW_TASK = 398, /* KW_TASK */
KW_TIME = 399, /* KW_TIME */
KW_TRAN = 400, /* KW_TRAN */
KW_TRANIF0 = 401, /* KW_TRANIF0 */
KW_TRANIF1 = 402, /* KW_TRANIF1 */
KW_TRI = 403, /* KW_TRI */
KW_TRI0 = 404, /* KW_TRI0 */
KW_TRI1 = 405, /* KW_TRI1 */
KW_TRIAND = 406, /* KW_TRIAND */
KW_TRIOR = 407, /* KW_TRIOR */
KW_TRIREG = 408, /* KW_TRIREG */
KW_UNSIGNED = 409, /* KW_UNSIGNED */
KW_USE = 410, /* KW_USE */
KW_VECTORED = 411, /* KW_VECTORED */
KW_WAIT = 412, /* KW_WAIT */
KW_WAND = 413, /* KW_WAND */
KW_WEAK0 = 414, /* KW_WEAK0 */
KW_WEAK1 = 415, /* KW_WEAK1 */
KW_WHILE = 416, /* KW_WHILE */
KW_WIRE = 417, /* KW_WIRE */
KW_WOR = 418, /* KW_WOR */
KW_XNOR = 419, /* KW_XNOR */
KW_XOR = 420, /* KW_XOR */
KW_NAND = 421, /* KW_NAND */
KW_UWIRE = 422, /* KW_UWIRE */
KW_SYS_SETUP = 423, /* KW_SYS_SETUP */
KW_SYS_HOLD = 424, /* KW_SYS_HOLD */
KW_SYS_SETUPHOLD = 425, /* KW_SYS_SETUPHOLD */
KW_SYS_RECOVERY = 426, /* KW_SYS_RECOVERY */
KW_SYS_REMOVAL = 427, /* KW_SYS_REMOVAL */
KW_SYS_RECREM = 428, /* KW_SYS_RECREM */
KW_SYS_SKEW = 429, /* KW_SYS_SKEW */
KW_SYS_TIMESKEW = 430, /* KW_SYS_TIMESKEW */
KW_SYS_FULLSKEW = 431, /* KW_SYS_FULLSKEW */
KW_SYS_PERIOD = 432, /* KW_SYS_PERIOD */
KW_SYS_WIDTH = 433, /* KW_SYS_WIDTH */
KW_SYS_NOCHANGE = 434, /* KW_SYS_NOCHANGE */
POW = 435 /* POW */
};
typedef enum yytokentype yytoken_kind_t;
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 36 "D:/gitwork/hdl4se/parser/verilog_parser.y"
HOBJECT treenode;
char * string;
int token;
int operator;
int ival;
IDListVar list;
#line 266 "D:/gitwork/hdl4se/parser/verilog_parser.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_D_GITWORK_HDL4SE_PARSER_VERILOG_PARSER_H_INCLUDED */
此差异已折叠。
此差异已折叠。
......@@ -67,9 +67,11 @@ NUM_UNSIGNED {DIGIT_DECIMAL}({UNDERSCORE}|{DIGIT_DECIMAL})*
/* Identifiers */
WRITE_SPACE " "|"\n"|"\t"
SYSTEM_ID \$[a-zA-Z0-9_\$]+
SIMPLE_ID [a-zA-Z_][a-zA-Z0-9_$]*
ESCAPED_ID \\{SIMPLE_ID}
ESCAPED_ID \\.*WRITE_SPACE
/* Strings */
......@@ -139,8 +141,7 @@ B_NOR "~|"
"~^" {EMIT_TOKEN(B_EQU);}
"~&" {EMIT_TOKEN(B_NAND);}
"~|" {EMIT_TOKEN(B_NOR);}
"+:" {EMIT_TOKEN(IDX_PRT_SEL);}
"-:" {EMIT_TOKEN(IDX_PRT_SEL);}
{BASE_DECIMAL} {BEGIN(in_dec_val); EMIT_TOKEN(DEC_BASE);}
{BASE_HEX} {BEGIN(in_hex_val); EMIT_TOKEN(HEX_BASE);}
......@@ -159,18 +160,22 @@ B_NOR "~|"
EMIT_TOKEN(UNSIGNED_NUMBER);
}
{SYSTEM_ID} {
/*yylval.identifier = ast_new_identifier(yytext,yylineno);*/
{SYSTEM_ID} {
yylval.string=_strdup(yytext);
EMIT_TOKEN(SYSTEM_ID);
if (objectCall0(preprocess, SymbolEmitEnabled)) {
int id = verilog_find_reserved_word(yytext);
if (id == -1) {
EMIT_TOKEN(SYSTEM_ID);
} else {
EMIT_TOKEN(id);
}
}
}
{ESCAPED_ID} {
/*yylval.identifier = ast_new_identifier(yytext,yylineno);*/
yylval.string=_strdup(yytext);
EMIT_TOKEN(ESCAPED_ID);
}
{SIMPLE_ID} {
/*yylval.identifier = ast_new_identifier(yytext,yylineno);*/
yylval.string=_strdup(yytext);
if (objectCall0(preprocess, SymbolEmitEnabled)) {
int id = verilog_find_reserved_word(yytext);
......
此差异已折叠。
......@@ -40,7 +40,11 @@
#include "string.h"
#include "stdlib.h"
#define PRINTF printf
int my_printf(char* fmt, ...) {
return 0;
}
#define PRINTF my_printf
#define IMPLEMENT_GUID
#include "verilog_preprocess.h"
......@@ -1479,8 +1483,8 @@ static int verilog_preprocess_state_macro(sVerilogPreprocess * pPreprocess, int
pPreprocess->tokenstate = TOKEN_COMMENT_START;
pPreprocess->lastch = '/';
} else {
verilog_preprocess_preprocess_PreAction(pPreprocess, PA_MACRO, pPreprocess->macro_name, "");
pPreprocess->file_stack_top->ungetch = ch;
verilog_preprocess_preprocess_PreAction(pPreprocess, PA_MACRO, pPreprocess->macro_name, "");
pPreprocess->state = STATE_INITIAL;
pPreprocess->tokenstate = TOKEN_NONE;
pPreprocess->tokentype = TT_NONE;
......@@ -2015,12 +2019,16 @@ static int verilog_preprocess_preprocess_PreAction(HOBJECT object, int action, c
stringitem * pItem;
char * macroexpand;
pItem = stringlistfindkey(&pPreprocess->macro_list, name);
if (pItem == NULL)
return -1;
macroexpand = verilog_preprocess_expand_macro(pPreprocess, &pItem->string[strlen(name)+1]);
if (macroexpand != NULL) {
pPreprocess->file_stack_top = filestack_push_string(&pPreprocess->file_stack, macroexpand, 0, 0, 0);
free(macroexpand);
if (pItem != NULL) {
macroexpand = verilog_preprocess_expand_macro(pPreprocess, &pItem->string[strlen(name) + 1]);
if (macroexpand != NULL) {
pPreprocess->file_stack_top = filestack_push_string(&pPreprocess->file_stack, macroexpand, 0, 0, 0);
free(macroexpand);
}
}
else {
/* macro not defined, same as it is a blank */
pPreprocess->file_stack_top = filestack_push_string(&pPreprocess->file_stack, " ", 0, 0, 0);
}
}
break;
......
......@@ -43,15 +43,18 @@
int main(int argc, char* argv[])
{
char buf[8192];
char buf[100];
int len;
IPreprocess ** p;
preprocessVerilogCreate(&p);
objectCall1(p, AddIncludePath, "c:/tools/");
objectCall2(p, SetFile, argv[1], 0);
if (argc == 1)
objectCall2(p, SetFile, "d:/TestDriver.v", 0);
else
objectCall2(p, SetFile, argv[1], 0);
do {
len = objectCall2(p, GetText, buf, 8191);
len = objectCall2(p, GetText, buf, 90);
if (len > 0)
printf(buf);
} while (len > 0);
......
cmake_minimum_required (VERSION 3.8)
add_executable (testscanner "main.c")
target_link_libraries(testscanner verilog_preprocess verilog_parser lcom)
include_directories("../../lcom/include")
include_directories("../preprocess/include")
include_directories("../parser")
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include "object.h"
#include "preprocess.h"
#include "verilog_preprocess.h"
#include "string.h"
int SetPreProcess(HOBJECT object);
int yylex();
char* yytext;
int main(int argc, char* argv[])
{
int token;
IPreprocess** p;
preprocessVerilogCreate(&p);
objectCall1(p, AddIncludePath, "c:/tools/");
SetPreProcess(p);
if (argc == 1)
objectCall2(p, SetFile, "d:/TestDriver.v", 0);
else
objectCall2(p, SetFile, argv[1], 0);
do {
token = yylex();
if (token > 0)
printf("token %d: %s\n", token, yytext);
} while (token > 0);
objectRelease(p);
return 0;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册