Skip to content

Commit

Permalink
Use bison for ilasm parser generator (#101415)
Browse files Browse the repository at this point in the history
* Use bison for ilasm parser generator

* Bring back asmparse.grammar
  • Loading branch information
hez2010 committed May 14, 2024
1 parent ed339b3 commit 714a442
Show file tree
Hide file tree
Showing 4 changed files with 7,848 additions and 3,917 deletions.
14 changes: 7 additions & 7 deletions src/coreclr/ilasm/asmparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
};

/* These are returned by the LEXER and have values */
%token ERROR_ BAD_COMMENT_ BAD_LITERAL_ /* bad strings, */
%token BAD_COMMENT_ BAD_LITERAL_ /* bad strings, */
%token <string> ID /* testing343 */
%token <string> DOTTEDNAME /* System.Object */
%token <binstr> QSTRING /* "Hello World\n" */
%token <string> SQSTRING /* 'Hello World\n' */
%token <int32> INT32 /* 3425 0x34FA 0352 */
%token <int64> INT64 /* 342534523534534 0x34FA434644554 */
%token <int32> INT32_V /* 3425 0x34FA 0352 */
%token <int64> INT64_V /* 342534523534534 0x34FA434644554 */
%token <float64> FLOAT64 /* -334234 24E-34 */
%token <int32> HEXBYTE /* 05 1A FA */
%token <tdd> TYPEDEF_T
Expand Down Expand Up @@ -96,7 +96,7 @@
%token _CLASS _NAMESPACE _METHOD _FIELD _DATA _THIS _BASE _NESTER
%token _EMITBYTE _TRY _MAXSTACK _LOCALS _ENTRYPOINT _ZEROINIT
%token _EVENT _ADDON _REMOVEON _FIRE _OTHER
%token _PROPERTY _SET _GET DEFAULT_
%token _PROPERTY _SET _GET
%token _PERMISSION _PERMISSIONSET

/* security actions */
Expand Down Expand Up @@ -259,11 +259,11 @@ dottedName : id { $$ = $1; }
| dottedName '.' dottedName { $$ = newStringWDel($1, '.', $3); }
;

int32 : INT32 { $$ = $1; }
int32 : INT32_V { $$ = $1; }
;

int64 : INT64 { $$ = $1; }
| INT32 { $$ = neg ? new __int64($1) : new __int64((unsigned)$1); }
int64 : INT64_V { $$ = $1; }
| INT32_V { $$ = neg ? new __int64($1) : new __int64((unsigned)$1); }
;

float64 : FLOAT64 { $$ = $1; }
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/ilasm/grammar_after.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,13 +1209,13 @@ int yylex()
if ((i64 & mask64) && (i64 != largestNegVal32))
{
yylval.int64 = new __int64(i64);
tok = INT64;
tok = INT64_V;
if (neg) *yylval.int64 = -*yylval.int64;
}
else
{
yylval.int32 = (__int32)i64;
tok = INT32;
tok = INT32_V;
if(neg) yylval.int32 = -yylval.int32;
}
}
Expand Down Expand Up @@ -1280,7 +1280,7 @@ int yylex()
}
dbprintf((" Line %d token %d (%c) val = %s\n", PENV->curLine, tok,
(tok < 128 && isprint(tok)) ? tok : ' ',
(tok > 255 && tok != INT32 && tok != INT64 && tok!= FLOAT64) ? yylval.string : ""));
(tok > 255 && tok != INT32_V && tok != INT64_V && tok!= FLOAT64) ? yylval.string : ""));

PENV->curPos = curPos;
PENV->curTok = curTok;
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/ilasm/grammar_before.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ static char* newString(_In_ __nullterminated const char* str1);
static void corEmitInt(BinStr* buff, unsigned data);
static void AppendStringWithLength(BinStr* pbs, _In_ __nullterminated char* sz);
static void AppendFieldToCustomBlob(BinStr* pBlob, _In_ BinStr* pField);
static unsigned corCountArgs(BinStr* args);
Instr* SetupInstr(unsigned short);
void yyerror(_In_ __nullterminated const char*);
int yylex();
bool bParsingByteArray = FALSE;
int iOpcodeLen = 0;
int iCallConv = 0;
Expand Down
Loading

0 comments on commit 714a442

Please sign in to comment.