env.Append(SCANNERS=Scanner(function=slicc_scanner,skeys=['.slicc']))
def slicc_emitter(target, source, env):
+ protocol = source[0].get_contents()
files = [s.srcnode().abspath for s in source[1:]]
- slicc = SLICC(debug=True)
+ slicc = SLICC(protocol, debug=True)
print "SLICC parsing..."
for name in slicc.load(files, verbose=True):
print " %s" % name
if not isdir(hdir):
os.mkdir(hdir)
- slicc = SLICC(debug=True)
+ slicc = SLICC(protocol, debug=True)
files = [str(s) for s in source[1:]]
slicc.load(files, verbose=False)
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.util import PairContainer, Location
class AST(PairContainer):
def embedError(self, message, *args):
if args:
message = message % args
- code = code_formatter()
+ code = self.slicc.codeFormatter()
code('''
cerr << "Runtime Error at ${{self.location}}, Ruby Time: " << g_eventQueue_ptr->getTime() << ": "<< $message << ", PID: " << getpid() << endl;
char c; cerr << "press return to continue." << endl; cin.get(c); abort();
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.DeclAST import DeclAST
from slicc.symbols import Action, Type, Var
self.symtab.newSymbol(var)
# Do not allows returns in actions
- code = code_formatter()
+ code = self.slicc.codeFormatter()
self.statement_list.generate(code, None)
self.pairs["c_code"] = str(code)
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.StatementAST import StatementAST
class AssignStatementAST(StatementAST):
return "[AssignStatementAST: %r := %r]" % (self.lvalue, self.rvalue)
def generate(self, code, return_type):
- lcode = code_formatter()
- rcode = code_formatter()
+ lcode = self.slicc.codeFormatter()
+ rcode = self.slicc.codeFormatter()
ltype = self.lvalue.generate(lcode)
rtype = self.rvalue.generate(rcode)
var = self.variable.var
assert var not in self.resources
- check_code = code_formatter()
+ check_code = self.slicc.codeFormatter()
if self.condStr == "((*in_msg_ptr)).m_isOnChipSearch":
check_code('''
const Response9Msg* in_msg_ptr =
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.AST import AST
class ExprAST(AST):
pass
def inline(self, get_type=False):
- code = code_formatter(fix_newlines=False)
+ code = self.slicc.codeFormatter(fix_newlines=False)
return_type = self.generate(code)
if get_type:
return return_type, code
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.StatementAST import StatementAST
from slicc.symbols import Type
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util.code_formatter import code_formatter
-
from slicc.ast.DeclAST import DeclAST
from slicc.symbols import Func, Type
types.append(type)
params.append(ident)
- body = code_formatter()
+ body = self.slicc.codeFormatter()
if self.statements is None:
self["external"] = "yes"
else:
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.StatementAST import StatementAST
from slicc.symbols import Type
return "[IfStatement: %r%r%r]" % (self.cond, self.then, self.else_)
def generate(self, code, return_type):
- cond_code = code_formatter()
+ cond_code = self.slicc.codeFormatter()
cond_type = self.cond.generate(cond_code)
if cond_type != self.symtab.find("bool", Type):
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.DeclAST import DeclAST
from slicc.ast.TypeAST import TypeAST
from slicc.symbols import Func, Type, Var
symtab = self.symtab
void_type = symtab.find("void", Type)
- code = code_formatter()
+ code = self.slicc.codeFormatter()
queue_type = self.var_expr.generate(code)
if not queue_type.isInPort:
self.error("The inport queue's type must have the 'inport' " + \
symtab.newSymbol(func)
if self.statements is not None:
- rcode = code_formatter()
+ rcode = self.slicc.codeFormatter()
rcode.indent()
rcode.indent()
self.statements.generate(rcode, None)
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.ExprAST import ExprAST
from slicc.symbols import Type
return "[InfixExpr: %r %s %r]" % (self.left, self.op, self.right)
def generate(self, code):
- lcode = code_formatter()
- rcode = code_formatter()
+ lcode = self.slicc.codeFormatter()
+ rcode = self.slicc.codeFormatter()
ltype = self.left.generate(lcode)
rtype = self.right.generate(rcode)
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.ExprAST import ExprAST
class MemberExprAST(ExprAST):
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.ExprAST import ExprAST
class MethodCallExprAST(ExprAST):
self.expr_ast_vec = expr_ast_vec
def generate(self, code):
- tmp = code_formatter()
+ tmp = self.slicc.codeFormatter()
paramTypes = []
for expr_ast in self.expr_ast_vec:
return_type = expr_ast.generate(tmp)
self.obj_expr_ast,
self.expr_ast_vec)
def generate_prefix(self, paramTypes):
- code = code_formatter()
+ code = self.slicc.codeFormatter()
# member method call
obj_type = self.obj_expr_ast.generate(code)
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.ast.DeclAST import DeclAST
from slicc.ast.TypeAST import TypeAST
from slicc.symbols import Var
return "[OutPortDecl: %r]" % self.ident
def generate(self):
- code = code_formatter(newlines=False)
+ code = self.slicc.codeFormatter(newlines=False)
queue_type = self.var_expr.generate(code)
if not queue_type.isOutPort:
import re
import sys
+from m5.util import code_formatter
from m5.util.grammar import Grammar, TokenError, ParseError
import slicc.ast as ast
yield sm_file
class SLICC(Grammar):
- def __init__(self, **kwargs):
+ def __init__(self, protocol, **kwargs):
super(SLICC, self).__init__(**kwargs)
self.decl_list_vec = []
self.current_file = None
- self.symtab = SymbolTable()
+ self.protocol = protocol
+ self.symtab = SymbolTable(self)
+
+ def codeFormatter(self, *args, **kwargs):
+ code = code_formatter(*args, **kwargs)
+ code['protocol'] = self.protocol
+ return code
def parse(self, filename):
self.current_file = filename
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter
-
from slicc.symbols.Symbol import Symbol
from slicc.symbols.Type import Type
if "external" in self:
return
- code = code_formatter()
+ code = self.symtab.codeFormatter()
# Header
code('''
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter, orderdict
+from m5.util import orderdict
from slicc.symbols.Symbol import Symbol
from slicc.symbols.Var import Var
func.writeCodeFiles(path)
def printControllerPython(self, path):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
ident = self.ident
py_ident = "%s_Controller" % ident
c_ident = "%s_Controller" % self.ident
def printControllerHH(self, path):
'''Output the method declarations for the class declaration'''
- code = code_formatter()
+ code = self.symtab.codeFormatter()
ident = self.ident
c_ident = "%s_Controller" % self.ident
def printControllerCC(self, path):
'''Output the actions for performing the actions'''
- code = code_formatter()
+ code = self.symtab.codeFormatter()
ident = self.ident
c_ident = "%s_Controller" % self.ident
def printCWakeup(self, path):
'''Output the wakeup loop for the events'''
- code = code_formatter()
+ code = self.symtab.codeFormatter()
ident = self.ident
code('''
def printCSwitch(self, path):
'''Output switch statement for transition table'''
- code = code_formatter()
+ code = self.symtab.codeFormatter()
ident = self.ident
code('''
case_string = "%s_State_%s, %s_Event_%s" % \
(self.ident, trans.state.ident, self.ident, trans.event.ident)
- case = code_formatter()
+ case = self.symtab.codeFormatter()
# Only set next_state if it changes
if trans.state != trans.nextState:
ns_ident = trans.nextState.ident
code.write(path, "%s_Transitions.cc" % self.ident)
def printProfilerHH(self, path):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
ident = self.ident
code('''
code.write(path, "%s_Profiler.hh" % self.ident)
def printProfilerCC(self, path):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
ident = self.ident
code('''
# **************************
def frameRef(self, click_href, click_target, over_href, over_target_num,
text):
- code = code_formatter(fix_newlines=False)
+ code = self.symtab.codeFormatter(fix_newlines=False)
code("""<A href=\"$click_href\" target=\"$click_target\" onMouseOver=\"if (parent.frames[$over_target_num].location != parent.location + '$over_href') { parent.frames[$over_target_num].location='$over_href' }\" >${{html.formatShorthand(text)}}</A>""")
return str(code)
code.write(path, name)
def printHTMLTransitions(self, path, active_state):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
code('''
<HTML><BODY link="blue" vlink="blue">
from slicc.util import Location
class SymbolTable(object):
- def __init__(self):
+ def __init__(self, slicc):
+ self.slicc = slicc
+
self.sym_vec = []
self.sym_map_vec = [ {} ]
self.machine_components = {}
def __repr__(self):
return "[SymbolTable]" # FIXME
+ def codeFormatter(self, *args, **kwargs):
+ return self.slicc.codeFormatter(*args, **kwargs)
+
def newSymbol(self, sym):
self.registerSym(str(sym), sym)
self.sym_vec.append(sym)
yield symbol
def writeCodeFiles(self, path):
- code = code_formatter()
+ code = self.codeFormatter()
code('''
/** Auto generated C++ code started by $__file__:$__line__ */
else:
name = "empty.html"
- code = code_formatter()
+ code = self.codeFormatter()
code('''
<html>
<head>
''')
code.write(path, "index.html")
- code = code_formatter()
+ code = self.codeFormatter()
code("<HTML></HTML>")
code.write(path, "empty.html")
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from m5.util import code_formatter, orderdict
+from m5.util import orderdict
from slicc.util import PairContainer
from slicc.symbols.Symbol import Symbol
self.printTypeCC(path)
def printTypeHH(self, path):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
code('''
/** \\file ${{self.c_ident}}.hh
*
code.write(path, "%s.hh" % self.c_ident)
def printTypeCC(self, path):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
code('''
/** \\file ${{self.c_ident}}.cc
code.write(path, "%s.cc" % self.c_ident)
def printEnumHH(self, path):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
code('''
/** \\file ${{self.c_ident}}.hh
*
code.write(path, "%s.hh" % self.c_ident)
def printEnumCC(self, path):
- code = code_formatter()
+ code = self.symtab.codeFormatter()
code('''
/** \\file ${{self.c_ident}}.hh
*
if item == '__line__':
return self.frame.f_lineno
+ if self.formatter.locals and item in self.frame.f_locals:
+ return self.frame.f_locals[item]
+
if item in self.dict:
return self.dict[item]
- if self.formatter.locals or self.formatter.globals:
- if self.formatter.locals and item in self.frame.f_locals:
- return self.frame.f_locals[item]
-
- if self.formatter.globals and item in self.frame.f_globals:
- return self.frame.f_globals[item]
+ if self.formatter.globals and item in self.frame.f_globals:
+ return self.frame.f_globals[item]
if item in __builtin__.__dict__:
return __builtin__.__dict__[item]
self._dict = {}
self._indent_level = 0
self._indent_spaces = 4
- self.globals = kwargs.pop('globals',type(self).globals)
+ self.globals = kwargs.pop('globals', type(self).globals)
self.locals = kwargs.pop('locals', type(self).locals)
self._fix_newlines = \
kwargs.pop('fix_newlines', type(self).fix_newlines)