parser.py (9104:27d56b644e78) | parser.py (9219:258753d3bc47) |
---|---|
1# Copyright (c) 2009 The Hewlett-Packard Development Company 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 24 unchanged lines hidden (view full) --- 33from m5.util import code_formatter 34from m5.util.grammar import Grammar, ParseError 35 36import slicc.ast as ast 37import slicc.util as util 38from slicc.symbols import SymbolTable 39 40class SLICC(Grammar): | 1# Copyright (c) 2009 The Hewlett-Packard Development Company 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 24 unchanged lines hidden (view full) --- 33from m5.util import code_formatter 34from m5.util.grammar import Grammar, ParseError 35 36import slicc.ast as ast 37import slicc.util as util 38from slicc.symbols import SymbolTable 39 40class SLICC(Grammar): |
41 def __init__(self, filename, verbose=False, traceback=False, **kwargs): | 41 def __init__(self, filename, base_dir, verbose=False, traceback=False, **kwargs): |
42 self.protocol = None 43 self.traceback = traceback 44 self.verbose = verbose 45 self.symtab = SymbolTable(self) | 42 self.protocol = None 43 self.traceback = traceback 44 self.verbose = verbose 45 self.symtab = SymbolTable(self) |
46 self.base_dir = base_dir |
|
46 47 try: 48 self.decl_list = self.parse_file(filename, **kwargs) 49 except ParseError, e: 50 if not self.traceback: 51 sys.exit(str(e)) 52 raise 53 --- 5 unchanged lines hidden (view full) --- 59 code = code_formatter(*args, **kwargs) 60 code['protocol'] = self.protocol 61 return code 62 63 def process(self): 64 self.decl_list.findMachines() 65 self.decl_list.generate() 66 | 47 48 try: 49 self.decl_list = self.parse_file(filename, **kwargs) 50 except ParseError, e: 51 if not self.traceback: 52 sys.exit(str(e)) 53 raise 54 --- 5 unchanged lines hidden (view full) --- 60 code = code_formatter(*args, **kwargs) 61 code['protocol'] = self.protocol 62 return code 63 64 def process(self): 65 self.decl_list.findMachines() 66 self.decl_list.generate() 67 |
67 def writeCodeFiles(self, code_path): 68 self.symtab.writeCodeFiles(code_path) | 68 def writeCodeFiles(self, code_path, includes): 69 self.symtab.writeCodeFiles(code_path, includes) |
69 70 def writeHTMLFiles(self, html_path): 71 self.symtab.writeHTMLFiles(html_path) 72 73 def files(self): 74 f = set([ 75 'MachineType.cc', 76 'MachineType.hh', --- 167 unchanged lines hidden (view full) --- 244 (self.current_source, self.current_line) 245 raise ParseError(msg) 246 self.protocol = p[2] 247 p[0] = None 248 249 def p_decl__include(self, p): 250 "decl : INCLUDE STRING SEMI" 251 dirname = os.path.dirname(self.current_source) | 70 71 def writeHTMLFiles(self, html_path): 72 self.symtab.writeHTMLFiles(html_path) 73 74 def files(self): 75 f = set([ 76 'MachineType.cc', 77 'MachineType.hh', --- 167 unchanged lines hidden (view full) --- 245 (self.current_source, self.current_line) 246 raise ParseError(msg) 247 self.protocol = p[2] 248 p[0] = None 249 250 def p_decl__include(self, p): 251 "decl : INCLUDE STRING SEMI" 252 dirname = os.path.dirname(self.current_source) |
252 filename = os.path.join(dirname, p[2]) | 253 if os.path.exists(os.path.join(dirname, p[2])): 254 filename = os.path.join(dirname, p[2]) 255 else: 256 filename = os.path.join(self.base_dir, p[2]) |
253 p[0] = self.parse_file(filename) 254 255 def p_decl__machine(self, p): 256 "decl : MACHINE '(' ident pairs ')' ':' params '{' decls '}'" 257 p[0] = ast.MachineAST(self, p[3], p[4], p[7], p[9]) 258 259 def p_decl__action(self, p): 260 "decl : ACTION '(' ident pairs ')' statements" --- 460 unchanged lines hidden --- | 257 p[0] = self.parse_file(filename) 258 259 def p_decl__machine(self, p): 260 "decl : MACHINE '(' ident pairs ')' ':' params '{' decls '}'" 261 p[0] = ast.MachineAST(self, p[3], p[4], p[7], p[9]) 262 263 def p_decl__action(self, p): 264 "decl : ACTION '(' ident pairs ')' statements" --- 460 unchanged lines hidden --- |