slicc: have a central mechanism for creating a code_formatter.
This makes it easier to add global variables like protocol
This commit is contained in:
parent
1068ca85d0
commit
cf86532857
20 changed files with 59 additions and 73 deletions
|
@ -63,8 +63,9 @@ def slicc_scanner(node, env, path):
|
||||||
env.Append(SCANNERS=Scanner(function=slicc_scanner,skeys=['.slicc']))
|
env.Append(SCANNERS=Scanner(function=slicc_scanner,skeys=['.slicc']))
|
||||||
|
|
||||||
def slicc_emitter(target, source, env):
|
def slicc_emitter(target, source, env):
|
||||||
|
protocol = source[0].get_contents()
|
||||||
files = [s.srcnode().abspath for s in source[1:]]
|
files = [s.srcnode().abspath for s in source[1:]]
|
||||||
slicc = SLICC(debug=True)
|
slicc = SLICC(protocol, debug=True)
|
||||||
print "SLICC parsing..."
|
print "SLICC parsing..."
|
||||||
for name in slicc.load(files, verbose=True):
|
for name in slicc.load(files, verbose=True):
|
||||||
print " %s" % name
|
print " %s" % name
|
||||||
|
@ -104,7 +105,7 @@ def slicc_action(target, source, env):
|
||||||
if not isdir(hdir):
|
if not isdir(hdir):
|
||||||
os.mkdir(hdir)
|
os.mkdir(hdir)
|
||||||
|
|
||||||
slicc = SLICC(debug=True)
|
slicc = SLICC(protocol, debug=True)
|
||||||
files = [str(s) for s in source[1:]]
|
files = [str(s) for s in source[1:]]
|
||||||
slicc.load(files, verbose=False)
|
slicc.load(files, verbose=False)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
from m5.util import code_formatter
|
|
||||||
|
|
||||||
from slicc.util import PairContainer, Location
|
from slicc.util import PairContainer, Location
|
||||||
|
|
||||||
class AST(PairContainer):
|
class AST(PairContainer):
|
||||||
|
@ -54,7 +52,7 @@ class AST(PairContainer):
|
||||||
def embedError(self, message, *args):
|
def embedError(self, message, *args):
|
||||||
if args:
|
if args:
|
||||||
message = message % args
|
message = message % args
|
||||||
code = code_formatter()
|
code = self.slicc.codeFormatter()
|
||||||
code('''
|
code('''
|
||||||
cerr << "Runtime Error at ${{self.location}}, Ruby Time: " << g_eventQueue_ptr->getTime() << ": "<< $message << ", PID: " << getpid() << endl;
|
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();
|
char c; cerr << "press return to continue." << endl; cin.get(c); abort();
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.DeclAST import DeclAST
|
||||||
from slicc.symbols import Action, Type, Var
|
from slicc.symbols import Action, Type, Var
|
||||||
|
|
||||||
|
@ -55,7 +53,7 @@ class ActionDeclAST(DeclAST):
|
||||||
self.symtab.newSymbol(var)
|
self.symtab.newSymbol(var)
|
||||||
|
|
||||||
# Do not allows returns in actions
|
# Do not allows returns in actions
|
||||||
code = code_formatter()
|
code = self.slicc.codeFormatter()
|
||||||
self.statement_list.generate(code, None)
|
self.statement_list.generate(code, None)
|
||||||
self.pairs["c_code"] = str(code)
|
self.pairs["c_code"] = str(code)
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.ast.StatementAST import StatementAST
|
||||||
|
|
||||||
class AssignStatementAST(StatementAST):
|
class AssignStatementAST(StatementAST):
|
||||||
|
@ -39,8 +37,8 @@ class AssignStatementAST(StatementAST):
|
||||||
return "[AssignStatementAST: %r := %r]" % (self.lvalue, self.rvalue)
|
return "[AssignStatementAST: %r := %r]" % (self.lvalue, self.rvalue)
|
||||||
|
|
||||||
def generate(self, code, return_type):
|
def generate(self, code, return_type):
|
||||||
lcode = code_formatter()
|
lcode = self.slicc.codeFormatter()
|
||||||
rcode = code_formatter()
|
rcode = self.slicc.codeFormatter()
|
||||||
|
|
||||||
ltype = self.lvalue.generate(lcode)
|
ltype = self.lvalue.generate(lcode)
|
||||||
rtype = self.rvalue.generate(rcode)
|
rtype = self.rvalue.generate(rcode)
|
||||||
|
|
|
@ -45,7 +45,7 @@ class CheckStopSlotsStatementAST(StatementAST):
|
||||||
var = self.variable.var
|
var = self.variable.var
|
||||||
assert var not in self.resources
|
assert var not in self.resources
|
||||||
|
|
||||||
check_code = code_formatter()
|
check_code = self.slicc.codeFormatter()
|
||||||
if self.condStr == "((*in_msg_ptr)).m_isOnChipSearch":
|
if self.condStr == "((*in_msg_ptr)).m_isOnChipSearch":
|
||||||
check_code('''
|
check_code('''
|
||||||
const Response9Msg* in_msg_ptr =
|
const Response9Msg* in_msg_ptr =
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
from m5.util import code_formatter
|
|
||||||
|
|
||||||
from slicc.ast.AST import AST
|
from slicc.ast.AST import AST
|
||||||
|
|
||||||
class ExprAST(AST):
|
class ExprAST(AST):
|
||||||
|
@ -37,7 +35,7 @@ class ExprAST(AST):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def inline(self, get_type=False):
|
def inline(self, get_type=False):
|
||||||
code = code_formatter(fix_newlines=False)
|
code = self.slicc.codeFormatter(fix_newlines=False)
|
||||||
return_type = self.generate(code)
|
return_type = self.generate(code)
|
||||||
if get_type:
|
if get_type:
|
||||||
return return_type, code
|
return return_type, code
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.ast.StatementAST import StatementAST
|
||||||
from slicc.symbols import Type
|
from slicc.symbols import Type
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.ast.DeclAST import DeclAST
|
||||||
from slicc.symbols import Func, Type
|
from slicc.symbols import Func, Type
|
||||||
|
|
||||||
|
@ -70,7 +68,7 @@ class FuncDeclAST(DeclAST):
|
||||||
types.append(type)
|
types.append(type)
|
||||||
params.append(ident)
|
params.append(ident)
|
||||||
|
|
||||||
body = code_formatter()
|
body = self.slicc.codeFormatter()
|
||||||
if self.statements is None:
|
if self.statements is None:
|
||||||
self["external"] = "yes"
|
self["external"] = "yes"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.ast.StatementAST import StatementAST
|
||||||
from slicc.symbols import Type
|
from slicc.symbols import Type
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ class IfStatementAST(StatementAST):
|
||||||
return "[IfStatement: %r%r%r]" % (self.cond, self.then, self.else_)
|
return "[IfStatement: %r%r%r]" % (self.cond, self.then, self.else_)
|
||||||
|
|
||||||
def generate(self, code, return_type):
|
def generate(self, code, return_type):
|
||||||
cond_code = code_formatter()
|
cond_code = self.slicc.codeFormatter()
|
||||||
cond_type = self.cond.generate(cond_code)
|
cond_type = self.cond.generate(cond_code)
|
||||||
|
|
||||||
if cond_type != self.symtab.find("bool", Type):
|
if cond_type != self.symtab.find("bool", Type):
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.DeclAST import DeclAST
|
||||||
from slicc.ast.TypeAST import TypeAST
|
from slicc.ast.TypeAST import TypeAST
|
||||||
from slicc.symbols import Func, Type, Var
|
from slicc.symbols import Func, Type, Var
|
||||||
|
@ -48,7 +46,7 @@ class InPortDeclAST(DeclAST):
|
||||||
symtab = self.symtab
|
symtab = self.symtab
|
||||||
void_type = symtab.find("void", Type)
|
void_type = symtab.find("void", Type)
|
||||||
|
|
||||||
code = code_formatter()
|
code = self.slicc.codeFormatter()
|
||||||
queue_type = self.var_expr.generate(code)
|
queue_type = self.var_expr.generate(code)
|
||||||
if not queue_type.isInPort:
|
if not queue_type.isInPort:
|
||||||
self.error("The inport queue's type must have the 'inport' " + \
|
self.error("The inport queue's type must have the 'inport' " + \
|
||||||
|
@ -115,7 +113,7 @@ class InPortDeclAST(DeclAST):
|
||||||
symtab.newSymbol(func)
|
symtab.newSymbol(func)
|
||||||
|
|
||||||
if self.statements is not None:
|
if self.statements is not None:
|
||||||
rcode = code_formatter()
|
rcode = self.slicc.codeFormatter()
|
||||||
rcode.indent()
|
rcode.indent()
|
||||||
rcode.indent()
|
rcode.indent()
|
||||||
self.statements.generate(rcode, None)
|
self.statements.generate(rcode, None)
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.ast.ExprAST import ExprAST
|
||||||
from slicc.symbols import Type
|
from slicc.symbols import Type
|
||||||
|
|
||||||
|
@ -42,8 +40,8 @@ class InfixOperatorExprAST(ExprAST):
|
||||||
return "[InfixExpr: %r %s %r]" % (self.left, self.op, self.right)
|
return "[InfixExpr: %r %s %r]" % (self.left, self.op, self.right)
|
||||||
|
|
||||||
def generate(self, code):
|
def generate(self, code):
|
||||||
lcode = code_formatter()
|
lcode = self.slicc.codeFormatter()
|
||||||
rcode = code_formatter()
|
rcode = self.slicc.codeFormatter()
|
||||||
|
|
||||||
ltype = self.left.generate(lcode)
|
ltype = self.left.generate(lcode)
|
||||||
rtype = self.right.generate(rcode)
|
rtype = self.right.generate(rcode)
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.ast.ExprAST import ExprAST
|
||||||
|
|
||||||
class MemberExprAST(ExprAST):
|
class MemberExprAST(ExprAST):
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.ast.ExprAST import ExprAST
|
||||||
|
|
||||||
class MethodCallExprAST(ExprAST):
|
class MethodCallExprAST(ExprAST):
|
||||||
|
@ -36,7 +34,7 @@ class MethodCallExprAST(ExprAST):
|
||||||
self.expr_ast_vec = expr_ast_vec
|
self.expr_ast_vec = expr_ast_vec
|
||||||
|
|
||||||
def generate(self, code):
|
def generate(self, code):
|
||||||
tmp = code_formatter()
|
tmp = self.slicc.codeFormatter()
|
||||||
paramTypes = []
|
paramTypes = []
|
||||||
for expr_ast in self.expr_ast_vec:
|
for expr_ast in self.expr_ast_vec:
|
||||||
return_type = expr_ast.generate(tmp)
|
return_type = expr_ast.generate(tmp)
|
||||||
|
@ -91,7 +89,7 @@ class MemberMethodCallExprAST(MethodCallExprAST):
|
||||||
self.obj_expr_ast,
|
self.obj_expr_ast,
|
||||||
self.expr_ast_vec)
|
self.expr_ast_vec)
|
||||||
def generate_prefix(self, paramTypes):
|
def generate_prefix(self, paramTypes):
|
||||||
code = code_formatter()
|
code = self.slicc.codeFormatter()
|
||||||
|
|
||||||
# member method call
|
# member method call
|
||||||
obj_type = self.obj_expr_ast.generate(code)
|
obj_type = self.obj_expr_ast.generate(code)
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.DeclAST import DeclAST
|
||||||
from slicc.ast.TypeAST import TypeAST
|
from slicc.ast.TypeAST import TypeAST
|
||||||
from slicc.symbols import Var
|
from slicc.symbols import Var
|
||||||
|
@ -45,7 +43,7 @@ class OutPortDeclAST(DeclAST):
|
||||||
return "[OutPortDecl: %r]" % self.ident
|
return "[OutPortDecl: %r]" % self.ident
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
code = code_formatter(newlines=False)
|
code = self.slicc.codeFormatter(newlines=False)
|
||||||
|
|
||||||
queue_type = self.var_expr.generate(code)
|
queue_type = self.var_expr.generate(code)
|
||||||
if not queue_type.isOutPort:
|
if not queue_type.isOutPort:
|
||||||
|
|
|
@ -30,6 +30,7 @@ import os.path
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from m5.util import code_formatter
|
||||||
from m5.util.grammar import Grammar, TokenError, ParseError
|
from m5.util.grammar import Grammar, TokenError, ParseError
|
||||||
|
|
||||||
import slicc.ast as ast
|
import slicc.ast as ast
|
||||||
|
@ -50,11 +51,17 @@ def read_slicc(sources):
|
||||||
yield sm_file
|
yield sm_file
|
||||||
|
|
||||||
class SLICC(Grammar):
|
class SLICC(Grammar):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, protocol, **kwargs):
|
||||||
super(SLICC, self).__init__(**kwargs)
|
super(SLICC, self).__init__(**kwargs)
|
||||||
self.decl_list_vec = []
|
self.decl_list_vec = []
|
||||||
self.current_file = None
|
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):
|
def parse(self, filename):
|
||||||
self.current_file = filename
|
self.current_file = filename
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.Symbol import Symbol
|
||||||
from slicc.symbols.Type import Type
|
from slicc.symbols.Type import Type
|
||||||
|
|
||||||
|
@ -71,7 +69,7 @@ class Func(Symbol):
|
||||||
if "external" in self:
|
if "external" in self:
|
||||||
return
|
return
|
||||||
|
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
code('''
|
code('''
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.Symbol import Symbol
|
||||||
from slicc.symbols.Var import Var
|
from slicc.symbols.Var import Var
|
||||||
|
@ -150,7 +150,7 @@ class StateMachine(Symbol):
|
||||||
func.writeCodeFiles(path)
|
func.writeCodeFiles(path)
|
||||||
|
|
||||||
def printControllerPython(self, path):
|
def printControllerPython(self, path):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
ident = self.ident
|
ident = self.ident
|
||||||
py_ident = "%s_Controller" % ident
|
py_ident = "%s_Controller" % ident
|
||||||
c_ident = "%s_Controller" % self.ident
|
c_ident = "%s_Controller" % self.ident
|
||||||
|
@ -180,7 +180,7 @@ class $py_ident(RubyController):
|
||||||
|
|
||||||
def printControllerHH(self, path):
|
def printControllerHH(self, path):
|
||||||
'''Output the method declarations for the class declaration'''
|
'''Output the method declarations for the class declaration'''
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
ident = self.ident
|
ident = self.ident
|
||||||
c_ident = "%s_Controller" % self.ident
|
c_ident = "%s_Controller" % self.ident
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ static int m_num_controllers;
|
||||||
def printControllerCC(self, path):
|
def printControllerCC(self, path):
|
||||||
'''Output the actions for performing the actions'''
|
'''Output the actions for performing the actions'''
|
||||||
|
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
ident = self.ident
|
ident = self.ident
|
||||||
c_ident = "%s_Controller" % self.ident
|
c_ident = "%s_Controller" % self.ident
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ void $c_ident::${{action.ident}}(const Address& addr)
|
||||||
def printCWakeup(self, path):
|
def printCWakeup(self, path):
|
||||||
'''Output the wakeup loop for the events'''
|
'''Output the wakeup loop for the events'''
|
||||||
|
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
ident = self.ident
|
ident = self.ident
|
||||||
|
|
||||||
code('''
|
code('''
|
||||||
|
@ -696,7 +696,7 @@ void ${ident}_Controller::wakeup()
|
||||||
def printCSwitch(self, path):
|
def printCSwitch(self, path):
|
||||||
'''Output switch statement for transition table'''
|
'''Output switch statement for transition table'''
|
||||||
|
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
ident = self.ident
|
ident = self.ident
|
||||||
|
|
||||||
code('''
|
code('''
|
||||||
|
@ -778,7 +778,7 @@ TransitionResult ${ident}_Controller::doTransitionWorker(${ident}_Event event, $
|
||||||
case_string = "%s_State_%s, %s_Event_%s" % \
|
case_string = "%s_State_%s, %s_Event_%s" % \
|
||||||
(self.ident, trans.state.ident, self.ident, trans.event.ident)
|
(self.ident, trans.state.ident, self.ident, trans.event.ident)
|
||||||
|
|
||||||
case = code_formatter()
|
case = self.symtab.codeFormatter()
|
||||||
# Only set next_state if it changes
|
# Only set next_state if it changes
|
||||||
if trans.state != trans.nextState:
|
if trans.state != trans.nextState:
|
||||||
ns_ident = trans.nextState.ident
|
ns_ident = trans.nextState.ident
|
||||||
|
@ -853,7 +853,7 @@ if (!%s.areNSlotsAvailable(%s)) {
|
||||||
code.write(path, "%s_Transitions.cc" % self.ident)
|
code.write(path, "%s_Transitions.cc" % self.ident)
|
||||||
|
|
||||||
def printProfilerHH(self, path):
|
def printProfilerHH(self, path):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
ident = self.ident
|
ident = self.ident
|
||||||
|
|
||||||
code('''
|
code('''
|
||||||
|
@ -888,7 +888,7 @@ class ${ident}_Profiler {
|
||||||
code.write(path, "%s_Profiler.hh" % self.ident)
|
code.write(path, "%s_Profiler.hh" % self.ident)
|
||||||
|
|
||||||
def printProfilerCC(self, path):
|
def printProfilerCC(self, path):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
ident = self.ident
|
ident = self.ident
|
||||||
|
|
||||||
code('''
|
code('''
|
||||||
|
@ -967,7 +967,7 @@ void ${ident}_Profiler::dumpStats(ostream& out) const
|
||||||
# **************************
|
# **************************
|
||||||
def frameRef(self, click_href, click_target, over_href, over_target_num,
|
def frameRef(self, click_href, click_target, over_href, over_target_num,
|
||||||
text):
|
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>""")
|
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)
|
return str(code)
|
||||||
|
|
||||||
|
@ -998,7 +998,7 @@ void ${ident}_Profiler::dumpStats(ostream& out) const
|
||||||
code.write(path, name)
|
code.write(path, name)
|
||||||
|
|
||||||
def printHTMLTransitions(self, path, active_state):
|
def printHTMLTransitions(self, path, active_state):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
|
|
||||||
code('''
|
code('''
|
||||||
<HTML><BODY link="blue" vlink="blue">
|
<HTML><BODY link="blue" vlink="blue">
|
||||||
|
|
|
@ -33,7 +33,9 @@ from slicc.symbols.Type import Type
|
||||||
from slicc.util import Location
|
from slicc.util import Location
|
||||||
|
|
||||||
class SymbolTable(object):
|
class SymbolTable(object):
|
||||||
def __init__(self):
|
def __init__(self, slicc):
|
||||||
|
self.slicc = slicc
|
||||||
|
|
||||||
self.sym_vec = []
|
self.sym_vec = []
|
||||||
self.sym_map_vec = [ {} ]
|
self.sym_map_vec = [ {} ]
|
||||||
self.machine_components = {}
|
self.machine_components = {}
|
||||||
|
@ -52,6 +54,9 @@ class SymbolTable(object):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "[SymbolTable]" # FIXME
|
return "[SymbolTable]" # FIXME
|
||||||
|
|
||||||
|
def codeFormatter(self, *args, **kwargs):
|
||||||
|
return self.slicc.codeFormatter(*args, **kwargs)
|
||||||
|
|
||||||
def newSymbol(self, sym):
|
def newSymbol(self, sym):
|
||||||
self.registerSym(str(sym), sym)
|
self.registerSym(str(sym), sym)
|
||||||
self.sym_vec.append(sym)
|
self.sym_vec.append(sym)
|
||||||
|
@ -118,7 +123,7 @@ class SymbolTable(object):
|
||||||
yield symbol
|
yield symbol
|
||||||
|
|
||||||
def writeCodeFiles(self, path):
|
def writeCodeFiles(self, path):
|
||||||
code = code_formatter()
|
code = self.codeFormatter()
|
||||||
code('''
|
code('''
|
||||||
/** Auto generated C++ code started by $__file__:$__line__ */
|
/** Auto generated C++ code started by $__file__:$__line__ */
|
||||||
|
|
||||||
|
@ -140,7 +145,7 @@ class SymbolTable(object):
|
||||||
else:
|
else:
|
||||||
name = "empty.html"
|
name = "empty.html"
|
||||||
|
|
||||||
code = code_formatter()
|
code = self.codeFormatter()
|
||||||
code('''
|
code('''
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -154,7 +159,7 @@ class SymbolTable(object):
|
||||||
''')
|
''')
|
||||||
code.write(path, "index.html")
|
code.write(path, "index.html")
|
||||||
|
|
||||||
code = code_formatter()
|
code = self.codeFormatter()
|
||||||
code("<HTML></HTML>")
|
code("<HTML></HTML>")
|
||||||
code.write(path, "empty.html")
|
code.write(path, "empty.html")
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# 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.util import PairContainer
|
||||||
from slicc.symbols.Symbol import Symbol
|
from slicc.symbols.Symbol import Symbol
|
||||||
|
@ -191,7 +191,7 @@ class Type(Symbol):
|
||||||
self.printTypeCC(path)
|
self.printTypeCC(path)
|
||||||
|
|
||||||
def printTypeHH(self, path):
|
def printTypeHH(self, path):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
code('''
|
code('''
|
||||||
/** \\file ${{self.c_ident}}.hh
|
/** \\file ${{self.c_ident}}.hh
|
||||||
*
|
*
|
||||||
|
@ -375,7 +375,7 @@ ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj)
|
||||||
code.write(path, "%s.hh" % self.c_ident)
|
code.write(path, "%s.hh" % self.c_ident)
|
||||||
|
|
||||||
def printTypeCC(self, path):
|
def printTypeCC(self, path):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
|
|
||||||
code('''
|
code('''
|
||||||
/** \\file ${{self.c_ident}}.cc
|
/** \\file ${{self.c_ident}}.cc
|
||||||
|
@ -412,7 +412,7 @@ void ${{self.c_ident}}::print(ostream& out) const
|
||||||
code.write(path, "%s.cc" % self.c_ident)
|
code.write(path, "%s.cc" % self.c_ident)
|
||||||
|
|
||||||
def printEnumHH(self, path):
|
def printEnumHH(self, path):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
code('''
|
code('''
|
||||||
/** \\file ${{self.c_ident}}.hh
|
/** \\file ${{self.c_ident}}.hh
|
||||||
*
|
*
|
||||||
|
@ -470,7 +470,7 @@ ostream& operator<<(ostream& out, const ${{self.c_ident}}& obj);
|
||||||
code.write(path, "%s.hh" % self.c_ident)
|
code.write(path, "%s.hh" % self.c_ident)
|
||||||
|
|
||||||
def printEnumCC(self, path):
|
def printEnumCC(self, path):
|
||||||
code = code_formatter()
|
code = self.symtab.codeFormatter()
|
||||||
code('''
|
code('''
|
||||||
/** \\file ${{self.c_ident}}.hh
|
/** \\file ${{self.c_ident}}.hh
|
||||||
*
|
*
|
||||||
|
|
|
@ -55,13 +55,12 @@ class lookup(object):
|
||||||
if item == '__line__':
|
if item == '__line__':
|
||||||
return self.frame.f_lineno
|
return self.frame.f_lineno
|
||||||
|
|
||||||
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:
|
if self.formatter.locals and item in self.frame.f_locals:
|
||||||
return self.frame.f_locals[item]
|
return self.frame.f_locals[item]
|
||||||
|
|
||||||
|
if item in self.dict:
|
||||||
|
return self.dict[item]
|
||||||
|
|
||||||
if self.formatter.globals and item in self.frame.f_globals:
|
if self.formatter.globals and item in self.frame.f_globals:
|
||||||
return self.frame.f_globals[item]
|
return self.frame.f_globals[item]
|
||||||
|
|
||||||
|
@ -124,7 +123,7 @@ class code_formatter(object):
|
||||||
self._dict = {}
|
self._dict = {}
|
||||||
self._indent_level = 0
|
self._indent_level = 0
|
||||||
self._indent_spaces = 4
|
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.locals = kwargs.pop('locals', type(self).locals)
|
||||||
self._fix_newlines = \
|
self._fix_newlines = \
|
||||||
kwargs.pop('fix_newlines', type(self).fix_newlines)
|
kwargs.pop('fix_newlines', type(self).fix_newlines)
|
||||||
|
|
Loading…
Reference in a new issue