diff options
author | Nilay Vaish <nilay@cs.wisc.edu> | 2012-10-15 17:27:16 -0500 |
---|---|---|
committer | Nilay Vaish <nilay@cs.wisc.edu> | 2012-10-15 17:27:16 -0500 |
commit | 3e607f146f4c8acac6b42e61a0e6295f52f408a4 (patch) | |
tree | e0274a4eab977e9662a9dc22126f726518d8213f /src/mem/slicc/ast | |
parent | c7b0901b97a86eb2d61e4ddd96a73a9d777a57c1 (diff) | |
download | gem5-3e607f146f4c8acac6b42e61a0e6295f52f408a4.tar.xz |
ruby: allow function definition in slicc structs
This patch adds support for function definitions to appear in slicc structs.
This is required for supporting functional accesses for different types of
messages. Subsequent patches will use this to development.
Diffstat (limited to 'src/mem/slicc/ast')
-rw-r--r-- | src/mem/slicc/ast/EnumDeclAST.py | 2 | ||||
-rw-r--r-- | src/mem/slicc/ast/FuncDeclAST.py | 13 | ||||
-rw-r--r-- | src/mem/slicc/ast/InPortDeclAST.py | 6 | ||||
-rw-r--r-- | src/mem/slicc/ast/MachineAST.py | 2 | ||||
-rw-r--r-- | src/mem/slicc/ast/StateDeclAST.py | 4 | ||||
-rw-r--r-- | src/mem/slicc/ast/TypeFieldEnumAST.py | 2 | ||||
-rw-r--r-- | src/mem/slicc/ast/TypeFieldMemberAST.py | 2 | ||||
-rw-r--r-- | src/mem/slicc/ast/TypeFieldMethodAST.py | 6 | ||||
-rw-r--r-- | src/mem/slicc/ast/TypeFieldStateAST.py | 2 |
9 files changed, 24 insertions, 15 deletions
diff --git a/src/mem/slicc/ast/EnumDeclAST.py b/src/mem/slicc/ast/EnumDeclAST.py index da07a0165..acddcb91f 100644 --- a/src/mem/slicc/ast/EnumDeclAST.py +++ b/src/mem/slicc/ast/EnumDeclAST.py @@ -67,5 +67,5 @@ class EnumDeclAST(DeclAST): pairs = { "external" : "yes" } func = Func(self.symtab, func_id, self.location, self.symtab.find("std::string", Type), [ t ], [], "", - pairs, None) + pairs) self.symtab.newSymbol(func) diff --git a/src/mem/slicc/ast/FuncDeclAST.py b/src/mem/slicc/ast/FuncDeclAST.py index 54b0f2c59..1d7e2c3ff 100644 --- a/src/mem/slicc/ast/FuncDeclAST.py +++ b/src/mem/slicc/ast/FuncDeclAST.py @@ -43,7 +43,7 @@ class FuncDeclAST(DeclAST): def files(self, parent=None): return set() - def generate(self): + def generate(self, parent = None): types = [] params = [] void_type = self.symtab.find("void", Type) @@ -71,9 +71,16 @@ class FuncDeclAST(DeclAST): machine = self.state_machine func = Func(self.symtab, self.ident, self.location, return_type, - types, params, str(body), self.pairs, machine) + types, params, str(body), self.pairs) - if machine is not None: + if parent is not None: + if not parent.addFunc(func): + self.error("Duplicate method: %s:%s()" % (parent, self.ident)) + func.class_name = parent.c_ident + + elif machine is not None: machine.addFunc(func) + func.isInternalMachineFunc = True + func.class_name = "%s_Controller" % machine else: self.symtab.newSymbol(func) diff --git a/src/mem/slicc/ast/InPortDeclAST.py b/src/mem/slicc/ast/InPortDeclAST.py index c6fadb9e7..376315eed 100644 --- a/src/mem/slicc/ast/InPortDeclAST.py +++ b/src/mem/slicc/ast/InPortDeclAST.py @@ -91,7 +91,7 @@ class InPortDeclAST(DeclAST): # Add the trigger method - FIXME, this is a bit dirty pairs = { "external" : "yes" } func = Func(self.symtab, "trigger", self.location, void_type, - param_types, [], "", pairs, None) + param_types, [], "", pairs) symtab.newSymbol(func) param_types = [] @@ -117,13 +117,13 @@ class InPortDeclAST(DeclAST): # checks before calling double trigger to ensure that won't # happen func = Func(self.symtab, "doubleTrigger", self.location, void_type, - param_types, [], "", pairs, None) + param_types, [], "", pairs) symtab.newSymbol(func) # Add the continueProcessing method - this hack supports # messages that don't trigger events func = Func(self.symtab, "continueProcessing", self.location, - void_type, [], [], "", pairs, None) + void_type, [], [], "", pairs) symtab.newSymbol(func) if self.statements is not None: diff --git a/src/mem/slicc/ast/MachineAST.py b/src/mem/slicc/ast/MachineAST.py index 6cefe8374..c48d2aef1 100644 --- a/src/mem/slicc/ast/MachineAST.py +++ b/src/mem/slicc/ast/MachineAST.py @@ -76,7 +76,7 @@ class MachineAST(DeclAST): def findMachines(self): # Add to MachineType enumeration machine_type = self.symtab.find("MachineType", Type) - if not machine_type.enumAdd(self.ident, self.pairs_ast.pairs): + if not machine_type.addEnum(self.ident, self.pairs_ast.pairs): self.error("Duplicate machine name: %s:%s" % (machine_type, self.ident)) diff --git a/src/mem/slicc/ast/StateDeclAST.py b/src/mem/slicc/ast/StateDeclAST.py index a1bbd74ae..2bca54d09 100644 --- a/src/mem/slicc/ast/StateDeclAST.py +++ b/src/mem/slicc/ast/StateDeclAST.py @@ -66,7 +66,7 @@ class StateDeclAST(DeclAST): pairs = { "external" : "yes" } func = Func(self.symtab, func_id, self.location, self.symtab.find("std::string", Type), [ t ], [], "", - pairs, None) + pairs) self.symtab.newSymbol(func) # Add the State_to_permission method @@ -75,5 +75,5 @@ class StateDeclAST(DeclAST): pairs = { "external" : "yes" } func = Func(self.symtab, func_id, self.location, self.symtab.find("AccessPermission", Type), [ t ], [], "", - pairs, None) + pairs) self.symtab.newSymbol(func) diff --git a/src/mem/slicc/ast/TypeFieldEnumAST.py b/src/mem/slicc/ast/TypeFieldEnumAST.py index 1255c972a..5ebb516d3 100644 --- a/src/mem/slicc/ast/TypeFieldEnumAST.py +++ b/src/mem/slicc/ast/TypeFieldEnumAST.py @@ -43,7 +43,7 @@ class TypeFieldEnumAST(TypeFieldAST): self.error("States must in a State Declaration, not a normal enum.") # Add enumeration - if not type.enumAdd(self.field_id, self.pairs_ast.pairs): + if not type.addEnum(self.field_id, self.pairs_ast.pairs): self.error("Duplicate enumeration: %s:%s" % (type, self.field_id)) # Fill machine info diff --git a/src/mem/slicc/ast/TypeFieldMemberAST.py b/src/mem/slicc/ast/TypeFieldMemberAST.py index a60153664..26d3ab2c6 100644 --- a/src/mem/slicc/ast/TypeFieldMemberAST.py +++ b/src/mem/slicc/ast/TypeFieldMemberAST.py @@ -51,7 +51,7 @@ class TypeFieldMemberAST(TypeFieldAST): (field_type, rvalue_type)) # Add data member to the parent type - if not type.dataMemberAdd(self.field_id, field_type, self.pairs, + if not type.addDataMember(self.field_id, field_type, self.pairs, init_code): self.error("Duplicate data member: %s:%s" % (type_ptr, field_id)) diff --git a/src/mem/slicc/ast/TypeFieldMethodAST.py b/src/mem/slicc/ast/TypeFieldMethodAST.py index 2c8cf3f7b..b89f7f97e 100644 --- a/src/mem/slicc/ast/TypeFieldMethodAST.py +++ b/src/mem/slicc/ast/TypeFieldMethodAST.py @@ -28,12 +28,14 @@ from slicc.ast.TypeFieldAST import TypeFieldAST class TypeFieldMethodAST(TypeFieldAST): - def __init__(self, slicc, return_type_ast, ident, type_asts, pairs): + def __init__(self, slicc, return_type_ast, ident, type_asts, pairs, + statements = None): super(TypeFieldMethodAST, self).__init__(slicc, pairs) self.return_type_ast = return_type_ast self.ident = ident self.type_asts = type_asts + self.statements = statements def __repr__(self): return "" @@ -46,5 +48,5 @@ class TypeFieldMethodAST(TypeFieldAST): types = [ t.type for t in self.type_asts ] # Add method - if not type.methodAdd(self.ident, return_type, types): + if not type.addMethod(self.ident, return_type, types): self.error("Duplicate method: %s:%s()" % (type, self.ident)) diff --git a/src/mem/slicc/ast/TypeFieldStateAST.py b/src/mem/slicc/ast/TypeFieldStateAST.py index aafa241dd..d2b253218 100644 --- a/src/mem/slicc/ast/TypeFieldStateAST.py +++ b/src/mem/slicc/ast/TypeFieldStateAST.py @@ -45,7 +45,7 @@ class TypeFieldStateAST(TypeFieldAST): self.error("State Declaration must be of type State.") # Add enumeration - if not type.enumAdd(self.field_id, self.pairs_ast.pairs): + if not type.addEnum(self.field_id, self.pairs_ast.pairs): self.error("Duplicate enumeration: %s:%s" % (type, self.field_id)) # Fill machine info |