diff options
Diffstat (limited to 'src/mem/slicc/parser')
-rw-r--r-- | src/mem/slicc/parser/lexer.ll | 9 | ||||
-rw-r--r-- | src/mem/slicc/parser/parser.py | 128 | ||||
-rw-r--r-- | src/mem/slicc/parser/parser.yy | 24 |
3 files changed, 89 insertions, 72 deletions
diff --git a/src/mem/slicc/parser/lexer.ll b/src/mem/slicc/parser/lexer.ll index a4af2ac51..b2d36855b 100644 --- a/src/mem/slicc/parser/lexer.ll +++ b/src/mem/slicc/parser/lexer.ll @@ -1,3 +1,4 @@ + /* * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood * All rights reserved. @@ -26,11 +27,15 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * $Id$ + */ + %{ #include <assert.h> #include "mem/slicc/ast/ASTs.hh" -#include "mem/slicc/parser/parser.hh" +#include "parser.hh" #include <string> extern "C" int yylex(); @@ -76,6 +81,7 @@ return { return RETURN; } THIS { return THIS; } CHIP { return CHIP; } void { yylval.str_ptr = new string(yytext); return VOID; } +new { return NEW; } == { yylval.str_ptr = new string(yytext); return EQ; } != { yylval.str_ptr = new string(yytext); return NE; } @@ -108,6 +114,7 @@ void { yylval.str_ptr = new string(yytext); return VOID; } [0-9]*[.][0-9]* { yylval.str_ptr = new string(yytext); return FLOATNUMBER; } [0-9]* { yylval.str_ptr = new string(yytext); return NUMBER; } + [a-zA-Z_][a-zA-Z_0-9]{0,50} { yylval.str_ptr = new string(yytext); return IDENT; } \"[^"\n]*\" { yytext[strlen(yytext)-1] = '\0'; yylval.str_ptr = new string(yytext+1); return STRING; } \'[^'\n]*\' { yytext[strlen(yytext)-1] = '\0'; yylval.str_ptr = new string(yytext+1); return STRING; } diff --git a/src/mem/slicc/parser/parser.py b/src/mem/slicc/parser/parser.py index ac2dd294a..1c7d582ec 100644 --- a/src/mem/slicc/parser/parser.py +++ b/src/mem/slicc/parser/parser.py @@ -66,6 +66,7 @@ reserved = { 'THIS' : 'THIS', 'CHIP' : 'CHIP', 'void' : 'VOID', + 'new' : 'NEW', } literals = ':[]{}(),=' @@ -75,7 +76,7 @@ tokens = [ 'EQ', 'NE', 'LT', 'GT', 'LE', 'GE', 'NOT', 'AND', 'OR', 'PLUS', 'DASH', 'STAR', 'SLASH', 'DOUBLE_COLON', 'SEMICOLON', - 'ASSIGN', 'DOT', + 'ASSIGN', 'DOT', 'LATENCY', 'IDENT', 'LIT_BOOL', 'FLOATNUMBER', 'NUMBER', 'STRING' ] tokens += reserved.values() @@ -117,6 +118,10 @@ def t_IDENT(t): t.value = False return t + if t.value.startswith('LATENCY_'): + t.type = 'LATENCY' + return t + t.type = reserved.get(t.value, 'IDENT') # Check for reserved words return t @@ -185,9 +190,25 @@ def p_decl(p): | d_func_def""" p[0] = p[1] +def p_latency(p): + """latency : LATENCY""" + pass + +def p_latencies(p): + """latencies : latency latencies + | empty""" + return [] + def p_d_machine(p): - "d_machine : MACHINE '(' ident pair_l ')' '{' decl_l '}'" - decls = [ x for x in p[7] if x is not None ] + """d_machine : MACHINE '(' ident pair_l ')' '{' decl_l '}' + | MACHINE '(' ident pair_l ')' ':' type_members '{' decl_l '}' + | MACHINE '(' ident pair_l ')' ':' latencies '{' decl_l '}'""" + + if len(p) == 9: + decl_l = p[7] + elif len(p) == 11: + decl_l = p[9] + decls = [ x for x in decl_l if x is not None ] p[0] = Machine(p[3], decls) def p_d_action(p): @@ -391,6 +412,7 @@ def p_expr(p): | literal | enumeration | ident '(' expr_l ')' + | NEW type | THIS DOT var '[' expr ']' DOT var DOT ident '(' expr_l ')' | THIS DOT var '[' expr ']' DOT var DOT ident | CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT ident '(' expr_l ')' @@ -436,72 +458,12 @@ lex.lex() yacc.yacc(write_tables=0) slicc_generated_cc = set([ - 'AccessModeType.cc', - 'AccessPermission.cc', - 'AccessType.cc', - 'AllocationStrategy.cc', - 'CacheMsg.cc', - 'CacheRequestType.cc', - 'Chip.cc', - 'CoherenceRequestType.cc', - 'DetermGETXGeneratorStatus.cc', - 'DetermInvGeneratorStatus.cc', - 'DetermSeriesGETSGeneratorStatus.cc', - 'GenericMachineType.cc', - 'GenericRequestType.cc', - 'LinkType.cc', - 'LockStatus.cc', - 'MachineType.cc', - 'MaskPredictorIndex.cc', - 'MaskPredictorTraining.cc', - 'MaskPredictorType.cc', - 'MemoryMsg.cc', - 'MemoryRequestType.cc', - 'MessageSizeType.cc', - 'PrefetchBit.cc', - 'Protocol.cc', - 'RequestGeneratorStatus.cc', - 'SearchMechanism.cc', - 'SequencerStatus.cc', - 'SpecifiedGeneratorType.cc', - 'TesterStatus.cc', - 'TopologyType.cc', - 'TransientRequestType.cc', - 'TransitionResult.cc']) + 'ControllerFactory.cc', + 'MachineType.cc']) slicc_generated_hh = set([ - 'AccessType.hh', - 'AccessModeType.hh', - 'AccessPermission.hh', - 'AllocationStrategy.hh', - 'CacheMsg.hh', - 'CacheRequestType.hh', - 'Chip.hh', - 'CoherenceRequestType.hh', - 'DetermGETXGeneratorStatus.hh', - 'DetermInvGeneratorStatus.hh', - 'DetermSeriesGETSGeneratorStatus.hh', - 'GenericMachineType.hh', - 'GenericRequestType.hh', - 'LinkType.hh', - 'LockStatus.hh', + 'ControllerFactory.hh', 'MachineType.hh', - 'MaskPredictorIndex.hh', - 'MaskPredictorTraining.hh', - 'MaskPredictorType.hh', - 'MemoryMsg.hh', - 'MemoryRequestType.hh', - 'MessageSizeType.hh', - 'PrefetchBit.hh', - 'Protocol.hh', - 'RequestGeneratorStatus.hh', - 'SearchMechanism.hh', - 'SequencerStatus.hh', - 'SpecifiedGeneratorType.hh', - 'TesterStatus.hh', - 'TopologyType.hh', - 'TransientRequestType.hh', - 'TransitionResult.hh', 'Types.hh', 'protocol_name.hh' ]) @@ -544,7 +506,9 @@ class InPort(Declaration): pass class OutPort(Declaration): pass class Transition(Declaration): pass class Extern(Declaration): pass -class Global(Declaration): pass +class Global(Declaration): + hh = True + cc = True class Struct(Declaration): hh = True cc = True @@ -555,6 +519,22 @@ class Object(Declaration): pass class Function(Declaration): cc = True +def read_slicc(sources): + if not isinstance(sources, (list,tuple)): + sources = [ sources ] + + sm_files = [] + for source in sources: + for sm_file in file(source, "r"): + sm_file = sm_file.strip() + if not sm_file: + continue + if sm_file.startswith("#"): + continue + sm_files.append(sm_file) + + return sm_files + def scan(filenames): hh = slicc_generated_hh.copy() cc = slicc_generated_cc.copy() @@ -570,3 +550,17 @@ def scan(filenames): result.add(hh, cc) return list(hh), list(cc) + +if __name__ == '__main__': + import sys + + hh, cc = scan(read_slicc(sys.argv[1:])) + hh.sort() + cc.sort() + print 'Headers:' + for i in hh: + print ' %s' % i + + print 'Sources:' + for i in cc: + print ' %s' % i diff --git a/src/mem/slicc/parser/parser.yy b/src/mem/slicc/parser/parser.yy index 724184665..fa5a3b355 100644 --- a/src/mem/slicc/parser/parser.yy +++ b/src/mem/slicc/parser/parser.yy @@ -1,3 +1,4 @@ + /* * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood * All rights reserved. @@ -26,11 +27,17 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * $Id$ + * + * */ + %{ #include <string> #include <stdio.h> #include <assert.h> #include "mem/slicc/ast/ASTs.hh" +#include <vector> #define YYMAXDEPTH 100000 #define YYERROR_VERBOSE @@ -45,6 +52,7 @@ extern "C" int yylex(); %union { string* str_ptr; Vector<string>* string_vector_ptr; + std::vector<string*>* stdstring_vector_ptr; // Decls DeclAST* decl_ptr; @@ -103,6 +111,8 @@ extern "C" int yylex(); %type <expr_ptr> expr literal enumeration %type <expr_vector_ptr> expr_list +%type <stdstring_vector_ptr> myrule + %type <pair_ptr> pair %type <pair_list_ptr> pair_list pairs @@ -115,7 +125,7 @@ extern "C" int yylex(); //%token DEQUEUE REMOVE_EARLY SKIP_EARLY PEEK_EARLY %token DEBUG_EXPR_TOKEN DEBUG_MSG_TOKEN %token ACTION_DECL TRANSITION_DECL TYPE_DECL STRUCT_DECL EXTERN_TYPE_DECL ENUM_DECL -%token TYPE_FIELD OTHER IF ELSE RETURN +%token TYPE_FIELD OTHER IF ELSE RETURN NEW %token <str_ptr> EQ NE '<' '>' LE GE NOT AND OR PLUS DASH STAR SLASH RIGHTSHIFT LEFTSHIFT @@ -138,7 +148,9 @@ decls: decl decls { $2->insertAtTop($1); $$ = $2; } | { $$ = new Vector<DeclAST*>; } ; -decl: MACHINE_DECL '(' ident pair_list ')' '{' decl_list '}' { $$ = new MachineAST($3, $4, $7); } +decl: MACHINE_DECL '(' ident pair_list ')' ':' myrule '{' decl_list '}' { $$ = new MachineAST($3, $4, NULL, $7, $9); } +// | MACHINE_DECL '(' ident pair_list ')' ':' type_members '{' decl_list '}' { $$ = new MachineAST($3, $4, $7, string_vector, $9); } + | MACHINE_DECL '(' ident pair_list ')' '{' decl_list '}' { $$ = new MachineAST($3, $4, NULL, new vector<string*>(), $7); } | ACTION_DECL '(' ident pair_list ')' statement_list { $$ = new ActionDeclAST($3, $4, $6); } | IN_PORT_DECL '(' ident ',' type ',' var pair_list ')' statement_list { $$ = new InPortDeclAST($3, $5, $7, $8, $10); } | OUT_PORT_DECL '(' ident ',' type ',' var pair_list ')' SEMICOLON { $$ = new OutPortDeclAST($3, $5, $7, $8); } @@ -214,7 +226,7 @@ formal_param : type ident { $$ = new FormalParamAST($1, $2); } ; // Idents and lists -ident: IDENT { $$ = $1; } ; +ident: IDENT { $$ = $1; }; ident_list: '{' idents '}' { $$ = $2; } | ident { $$ = new Vector<string>; $$->insertAtTop(*($1)); delete $1; } @@ -274,7 +286,7 @@ expr: var { $$ = $1; } | literal { $$ = $1; } | enumeration { $$ = $1; } | ident '(' expr_list ')' { $$ = new FuncCallExprAST($1, $3); } - + | NEW type { $$ = new NewExprAST($2); } // globally access a local chip component and call a method | THIS DOT var '[' expr ']' DOT var DOT ident '(' expr_list ')' { $$ = new ChipComponentAccessAST($3, $5, $8, $10, $12 ); } @@ -324,6 +336,10 @@ var: ident { $$ = new VarExprAST($1); } field: ident { $$ = $1; } ; +myrule: myrule IDENT { $1->push_back($2); } + | IDENT { $$ = new vector<string*>(1, $1); } + ; + %% extern FILE *yyin; |