1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 19 unchanged lines hidden (view full) --- 28from m5.util import code_formatter 29 30from slicc.generate import html 31from slicc.symbols.StateMachine import StateMachine 32from slicc.symbols.Type import Type 33from slicc.util import Location 34 35class SymbolTable(object): |
36 def __init__(self, slicc): 37 self.slicc = slicc 38 |
39 self.sym_vec = [] 40 self.sym_map_vec = [ {} ] 41 self.machine_components = {} 42 43 pairs = {} 44 pairs["enumeration"] = "yes" 45 MachineType = Type(self, "MachineType", Location("init", 0), pairs) 46 self.newSymbol(MachineType) 47 48 pairs = {} 49 pairs["primitive"] = "yes" 50 pairs["external"] = "yes" 51 void = Type(self, "void", Location("init", 0), pairs) 52 self.newSymbol(void) 53 54 def __repr__(self): 55 return "[SymbolTable]" # FIXME 56 |
57 def codeFormatter(self, *args, **kwargs): 58 return self.slicc.codeFormatter(*args, **kwargs) 59 |
60 def newSymbol(self, sym): 61 self.registerSym(str(sym), sym) 62 self.sym_vec.append(sym) 63 64 def registerSym(self, id, sym): 65 # Check for redeclaration (in the current frame only) 66 if id in self.sym_map_vec[-1]: 67 sym.error("Symbol '%s' redeclared in same scope.", id) --- 50 unchanged lines hidden (view full) --- 118 self.sym_map_vec[0][ident] = symbol 119 120 def getAllType(self, type): 121 for symbol in self.sym_vec: 122 if isinstance(symbol, type): 123 yield symbol 124 125 def writeCodeFiles(self, path): |
126 code = self.codeFormatter() |
127 code(''' 128/** Auto generated C++ code started by $__file__:$__line__ */ 129 130#include "mem/ruby/slicc_interface/RubySlicc_includes.hh" 131''') 132 for symbol in self.sym_vec: 133 if isinstance(symbol, Type) and not symbol.isPrimitive: 134 code('#include "mem/protocol/${{symbol.c_ident}}.hh"') --- 5 unchanged lines hidden (view full) --- 140 141 def writeHTMLFiles(self, path): 142 machines = list(self.getAllType(StateMachine)) 143 if len(machines) > 1: 144 name = "%s_table.html" % machines[0].ident 145 else: 146 name = "empty.html" 147 |
148 code = self.codeFormatter() |
149 code(''' 150<html> 151<head> 152<title>$path</title> 153</head> 154<frameset rows="*,30"> 155 <frame name="Table" src="$name"> 156 <frame name="Status" src="empty.html"> 157</frameset> 158</html> 159''') 160 code.write(path, "index.html") 161 |
162 code = self.codeFormatter() |
163 code("<HTML></HTML>") 164 code.write(path, "empty.html") 165 166 for symbol in self.sym_vec: 167 symbol.writeHTMLFiles(path) 168 169__all__ = [ "SymbolTable" ] |