📄 oaverilogscanner.lpp
字号:
* (the closing delimeter). */ (*YYLVAL.oaStringStype()) += " "; yy_pop_state(); YYRULE_RETURN_ACTION(YYESCAPED_IDENTIFIER); }<MODULE,UDP,SPECIFY>PATHPULSE\$ { CONSTANT_TOKEN_ACTION; YYRULE_RETURN_ACTION(YYPATHPULSE); }<MODULE,UDP,SPECIFY>\" { yy_push_state(QSTRING); CONSTANT_TOKEN_ACTION; break; }<QSTRING>\\n { yymore(); break; }<QSTRING>\\t { yymore(); break; }<QSTRING>\\\\ { yymore(); break; }<QSTRING>\\\" { yymore(); break; }<QSTRING>\\{OctalDigit}{1,3} { yymore(); break; }<QSTRING>\" { VARIABLE_TOKEN_ACTION; yy_pop_state(); YYRULE_RETURN_ACTION(YYSTRING); }<QSTRING>[^\\\n\"]+ { yymore(); break; }<QSTRING>{Newline} { fatalUnexpectedToken("Unterminated string constant"); break; }<QSTRING>. { yymore(); break; }<MODULE,UDP,SPECIFY>{BinBase} { VARIABLE_TOKEN_ACTION; yy_push_state(NUMBER_B); YYRULE_RETURN_ACTION(YYBINARY_BASE); }<MODULE,UDP,SPECIFY>{HexBase} { VARIABLE_TOKEN_ACTION; yy_push_state(NUMBER_H); YYRULE_RETURN_ACTION(YYHEX_BASE); }<MODULE,UDP,SPECIFY>{DecBase} { VARIABLE_TOKEN_ACTION; YYRULE_RETURN_ACTION(YYDECIMAL_BASE); }<MODULE,UDP,SPECIFY>{OctBase} { VARIABLE_TOKEN_ACTION; yy_push_state(NUMBER_O); YYRULE_RETURN_ACTION(YYOCTAL_BASE); }<NUMBER_B>{BinaryValue} { /* remove any '_' chars */ NUMBER_TOKEN_ACTION; yy_pop_state(); YYRULE_RETURN_ACTION(YYBINARY_VALUE); }<NUMBER_B>. { fatalExpectedNumber(yytext); break; }<NUMBER_O>{OctalValue} { /* remove any '_' chars */ NUMBER_TOKEN_ACTION; yy_pop_state(); YYRULE_RETURN_ACTION(YYOCTAL_VALUE); }<NUMBER_O>. { fatalExpectedNumber(yytext); break; }<NUMBER_H>{HexValue} { /* remove any '_' chars */ NUMBER_TOKEN_ACTION; yy_pop_state(); YYRULE_RETURN_ACTION(YYHEX_VALUE); }<NUMBER_H>. { fatalExpectedNumber(yytext); break; }<MODULE,UDP,SPECIFY>{FloatValue} { /* remove any '_' chars */ NUMBER_TOKEN_ACTION; YYRULE_RETURN_ACTION(YYFLOAT_VALUE); }<MODULE,UDP,SPECIFY>{DecimalValue} { /* remove any '_' chars */ NUMBER_TOKEN_ACTION; YYRULE_RETURN_ACTION(YYDECIMAL_VALUE); }<MODULE,UDP,SPECIFY>{DigitDC} { NUMBER_TOKEN_ACTION; YYRULE_RETURN_ACTION(YYX_DIGIT); }<MODULE,UDP,SPECIFY>{DigitHI} { NUMBER_TOKEN_ACTION; YYRULE_RETURN_ACTION(YYZ_DIGIT); }<INITIAL,SPECIFY,MODULE,UDP>`include { /* Here is where the parser would open and start parsing a new file */ /* include_compiler_directive ::= include "filename" */ /* NOTE Implementations may limit the maximum number of levels to * which include files can be nested,but the limit * shall be at least 15. */ yy_push_state(TIC_INCLUDE); break; }<TIC_INCLUDE>[^\t\n]+ { if (includeStackPtr >= OAVLI_MAX_INCLUDE_DEPTH) { sprintf(errorMessage, "Error: Includes nested too deeply Max depth:%d", OAVLI_MAX_INCLUDE_DEPTH); YY_FATAL_ERROR(errorMessage); } includeStack[includeStackPtr++] = YY_CURRENT_BUFFER; yyin = fopen(yytext, "r"); if (!yyin) { throw Error(OpenFailed, NULL, yytext); } fileLineNumber[includeStackPtr] = 1; fileName[includeStackPtr] = yytext; yy_switch_to_buffer( yy_create_buffer( yyin, YY_BUF_SIZE ) ); yy_pop_state(); break; }<INITIAL,SPECIFY,MODULE,UDP>`line { /* line_compiler_directive ::= `line number "filename" level */ yy_push_state(TIC_LINE_NUMBER); break; }<TIC_LINE_LEVEL,TIC_LINE_FILE,TIC_LINE_NUMBER>{Newline} { fileLineNumber[includeStackPtr]++; yy_pop_state(); break; }<TIC_LINE_NUMBER>DecimalDigit+ { int temp = atoi(yytext); if ( temp >= 1) { fileLineNumber[includeStackPtr] = temp; } yy_pop_state(); yy_push_state(TIC_LINE_FILE); break; }<TIC_LINE_NUMBER>[^\t\n]+ { fatalExpectedNumber(yytext); break; }<TIC_LINE_FILE>[^\t\n]+ { fileName[OAVLI_MAX_INCLUDE_DEPTH] = yytext; yy_pop_state(); yy_push_state(TIC_LINE_LEVEL); break; }<TIC_LINE_LEVEL>DecimalDigit+ { yy_pop_state(); break; }<TIC_LINE_LEVEL>[^\t\n]+ { fatalExpectedNumber(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`celldefine { /* The directives celldefine and endcelldefine tag modules as cell * modules. Cells are used by certain PLI routines for applications, * such as delay calculations. It is advisable to pair each * celldefine with an endcell- define .More than one of these pairs * may appear in a single source description. These directives may * appear anywhere in the source description,but it is recommended * that the directives be specified outside the module definition. * The resetall directive includes the effects of a * endcelldefine directive. */ fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`endcelldefine { fatalUnexpectedToken(yytext); break; }<INITIAL>`default_nettype { /* The directive default_nettype controls the net type created for * implicit net declarations (see 3.5).It can be used only outside of * module definitions.It affects all modules that follow the directive, * even across source file boundaries.Multiple default_nettype directives * are allowed.The latest occurrence of this directive in the source * controls the type of nets that will be implicitly declared.Syntax 19-1 * contains the syntax of the directive. */ /* default_nettype_compiler_directive ::= default_nettype net_type net_type ::=wire |tri |tri0 |wand |triand |wor |trior |trireg |none */ /* When no default_nettype directive is present or if the * resetall directive is specified,implicit nets are of type wire. * When the default_nettype is set to none ,all nets must be * explicitly declared.If a net is not explicitly declared,an * error is generated. */ fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`define { /* here is where the macro would be added to defined macros */ fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`undef { yy_push_state(UNDEF); break; }<UNDEF>{Newline} { fileLineNumber[includeStackPtr]++; yy_pop_state(); break;}<UNDEF>{AlphaU}{AlphaNumUD}* { yy_pop_state(); break; }<INITIAL,SPECIFY,MODULE,UDP>`ifdef { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`ifndef { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`else { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`elsif { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`endif { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`resetall { break; }<INITIAL,SPECIFY,MODULE,UDP>`timescale[^\n]* { /* Treat this as a single line comment */ /* timescale_compiler_directive ::= timescale time_unit / time_precision Arguments of time_precision s seconds ms milliseconds us microseconds ns nanoseconds ps picoseconds fs femtoseconds Example: `timescale 1 ns / 1 ps */ CONSTANT_TOKEN_ACTION; break; }<INITIAL,SPECIFY,MODULE,UDP>`unconnedted_drive { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`nounconnedted_drive { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP>`{AlphaU}{AlphaNumUD}* { fatalUnexpectedToken(yytext); break; }<INITIAL,SPECIFY,MODULE,UDP,TABLE,CONFIG>{AlphaU}{AlphaNumUD}* { VARIABLE_TOKEN_ACTION; YYRULE_RETURN_ACTION(YYSIMPLE_IDENTIFIER); }<INITIAL,SPECIFY,MODULE,UDP,CONFIG>\\{Allchar}+ { /*----------------------------------------------- * Identifiers may use any character by escaping * with a "\" at the beginning of the identifier * and ending with a whitespace. *----------------------------------------------- */ VARIABLE_TOKEN_ACTION; /* * Keep the escape char and append whitespace * (the closing delimeter). */ (*YYLVAL.oaStringStype()) += " "; YYRULE_RETURN_ACTION(YYESCAPED_IDENTIFIER); }<INITIAL,SPECIFY,MODULE,UDP>\${AlphaU}{AlphaNumUD}* { /*----------------------------------------------- * System Identifiers begin with a '$' char * at the beginning of the identifier *----------------------------------------------- */ VARIABLE_TOKEN_ACTION; /* remove the $ sign char */ oaUInt4 len = (*YYLVAL.oaStringStype()).getLength(); for (oaUInt4 i = 1; i < len; i++) { (*YYLVAL.oaStringStype())[i-1] = (*YYLVAL.oaStringStype())[i]; } YYRULE_RETURN_ACTION(YYSYSTEM_IDENTIFIER); }<INITIAL,SPECIFY,MODULE,UDP,TABLE,CONFIG>. { CONSTANT_TOKEN_ACTION; YYRULE_RETURN_TEXT_ACTION(yytext[0]); }<<EOF>> { if (--includeStackPtr < 0) { yyterminate(); } else { yy_delete_buffer(YY_CURRENT_BUFFER); yy_switch_to_buffer(includeStack[includeStackPtr]); } }%%BEGIN_VERILOG_NAMESPACE// *****************************************************************************// Scanner::init()//// This function initializes the scanner for reading the given file. The // scanner stack and states are re-initialized for re-entrant behavior and the// first Verilog input file is pushed onto the include stack. The input stream// is intialized with this file and the scanner is placed into the INITIAL// state.// *****************************************************************************voidScanner::init(StringList *fileNames){ if (yy_start_stack) { yy_flex_free(yy_start_stack); yy_start_stack = NULL; yy_start_stack_depth = 0; yy_start_stack_ptr = 0; } files = fileNames; fileIter = files->begin(); clearStack(); includeStackPtr = 0; fileName[includeStackPtr] = **fileIter++; if (TranslatorOptions::useStdio(fileName[includeStackPtr])) { yyin = stdin; fileName[includeStackPtr] = "stdin"; } else { yyin = fopen((const char*) fileName[includeStackPtr], "r"); } if (!yyin) { throw Error(OpenFailed, NULL, (const char*) fileName[includeStackPtr]); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); BEGIN(INITIAL);}// *****************************************************************************// Scanner::clearStack()//// This function clears the scanner's file buffer stack.// *****************************************************************************voidScanner::clearStack(){ includeStackPtr = 0; for(oaUInt4 i = 0; i < OAVLI_MAX_INCLUDE_DEPTH; i++) { includeStack[i] = (YY_BUFFER_STATE)0; fileLineNumber[i] = 0; } fileLineNumber[0] = 1; defaultNettype[0] = '\0'; errorMessage[0] = '\0';}// *****************************************************************************// Scanner::vliYYwrap()//// This function is called when the current file ends. If yywrap() returns// zero then yyin will point to a new input file and scanning will continue.// If the yywrap() returns non-zero then the scanning terminates and the scanner// will return 0 to the caller.// *****************************************************************************intScanner::yywrap(){ yy_delete_buffer(yy_current_buffer); if (fileIter != files->end()) { if (yyin && yyin != stdin) { fclose(yyin); } fileName[includeStackPtr] = **fileIter++; fileLineNumber[includeStackPtr] = 0; if (TranslatorOptions::useStdio(fileName[includeStackPtr])) { yyin = stdin; fileName[includeStackPtr] = "stdin"; } else { yyin = fopen((const char*) fileName[includeStackPtr], "r"); } if (!yyin) { throw Error(OpenFailed, NULL, (const char*) fileName[includeStackPtr]); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); return 0; } return 1;}// *****************************************************************************// oaVerilogInScanner::fatalExpectedNumber//// This function handles the situation where a number is expected in the input// stream but some other token was read.// *****************************************************************************void Scanner::fatalExpectedNumber(yyconst char text[]){ sprintf(errorMessage, "Expected a number but found '%s'\n", text); YY_FATAL_ERROR(errorMessage);}// *****************************************************************************// oaVerilogInScanner::fatalUnexpectedToken//// This function handles unexpected tokens in the input stream.// *****************************************************************************void Scanner::fatalUnexpectedToken(yyconst char text[]){ sprintf(errorMessage, "Unexpected token found '%s'\n", text); YY_FATAL_ERROR(errorMessage);}// *****************************************************************************// oaVerilogInScanner::cleanNumber//// This function removes all the underscore ('_') characters from the given// string.// *****************************************************************************oaString *vliYYFlexLexer::cleanNumber(yyconst char *text){ oaUInt4 endOfString = strlen(text); oaString *numberText = new oaString(endOfString+1); oaUInt4 j = 0; for (oaUInt4 i = 0; i < endOfString; i++) { if (text[i] != '_') { (*numberText)[j++] = text[i]; } } (*numberText)[j] = '\0'; return (numberText);}END_VERILOG_NAMESPACE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -