Ejemplo n.º 1
0
    def generate(self):
        ident = str(self.type_ast)

        # Make the new type
        t = Type(self.symtab, ident, self.location, self.pairs,
                 self.state_machine)
        self.symtab.newSymbol(t)

        # Add all of the states of the type to it
        for state in self.states:
            state.generate(t)

        # Add the implicit State_to_string method - FIXME, this is a bit dirty
        func_id = "%s_to_string" % t.c_ident

        pairs = {"external": "yes"}
        func = Func(self.symtab, func_id + "_" + t.ident,
                    func_id, self.location,
                    self.symtab.find("std::string", Type), [t], [], "", pairs)
        self.symtab.newSymbol(func)

        # Add the State_to_permission method
        func_id = "%s_to_permission" % t.c_ident

        pairs = {"external": "yes"}
        func = Func(self.symtab, func_id + "_" + t.ident, func_id,
                    self.location, self.symtab.find("AccessPermission",
                                                    Type), [t], [], "", pairs)
        self.symtab.newSymbol(func)
Ejemplo n.º 2
0
    def generate(self, parent=None, **kwargs):
        types = []
        params = []
        void_type = self.symtab.find("void", Type)

        # Generate definition code
        self.symtab.pushFrame()

        # Lookup return type
        return_type = self.return_type.type

        # Generate function header
        for formal in self.formals:
            # Lookup parameter types
            try:
                type, ident = formal.generate()
                types.append(type)
                params.append(ident)

            except AttributeError:
                types.append(formal.type)
                params.append(None)

        body = self.slicc.codeFormatter()
        if self.statements is None:
            self["external"] = "yes"
        else:
            rtype = self.statements.generate(body, return_type)

        self.symtab.popFrame()

        func_name_args = self.ident

        if parent is None:
            for arg in self.formals:
                from slicc.ast import FormalParamAST
                if isinstance(arg, FormalParamAST):
                    arg_name = arg.type_ast.ident
                else:
                    arg_name = arg
                func_name_args += "_" + str(arg_name)

        machine = self.state_machine
        func = Func(self.symtab, func_name_args, self.ident, self.location,
                    return_type, types, params, str(body), self.pairs)

        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)
Ejemplo n.º 3
0
    def generate(self, parent = None):
        types = []
        params = []
        void_type = self.symtab.find("void", Type)

        # Generate definition code
        self.symtab.pushFrame()

        # Lookup return type
        return_type = self.return_type.type

        # Generate function header
        for formal in self.formals:
            # Lookup parameter types
            try:
                type, ident = formal.generate()
                types.append(type)
                params.append(ident)

            except AttributeError:
                types.append(formal.type)
                params.append(None)

        body = self.slicc.codeFormatter()
        if self.statements is None:
            self["external"] = "yes"
        else:
            rtype = self.statements.generate(body, return_type)

        self.symtab.popFrame()

        func_name_args = self.ident

        if parent is None:
            for arg in self.formals:
                from slicc.ast import FormalParamAST
                if isinstance(arg, FormalParamAST):
                    arg_name = arg.type_ast.ident
                else:
                    arg_name = arg
                func_name_args += "_" + str(arg_name)

        machine = self.state_machine
        func = Func(self.symtab, func_name_args, self.ident, self.location,
                    return_type, types, params, str(body), self.pairs)

        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)
Ejemplo n.º 4
0
    def generate(self):
        types = []
        params = []
        void_type = self.symtab.find("void", Type)

        # Generate definition code
        self.symtab.pushFrame()

        # Lookup return type
        return_type = self.return_type.type

        # Generate function header
        for formal in self.formals:
            # Lookup parameter types
            type, ident = formal.generate()
            types.append(type)
            params.append(ident)

        body = self.slicc.codeFormatter()
        if self.statements is None:
            self["external"] = "yes"
        else:
            rtype = self.statements.generate(body, return_type)

        self.symtab.popFrame()

        machine = self.state_machine
        func = Func(self.symtab, self.ident, self.location, return_type, types,
                    params, str(body), self.pairs, machine)

        if machine is not None:
            machine.addFunc(func)
        else:
            self.symtab.newSymbol(func)
Ejemplo n.º 5
0
    def generate(self, parent = None):
        types = []
        params = []
        void_type = self.symtab.find("void", Type)
	print "FuncDeclAST.py generate" #Urmish
	print void_type #Urmish
        # Generate definition code
        self.symtab.pushFrame()

        # Lookup return type
        return_type = self.return_type.type

        # Generate function header
        for formal in self.formals:
            # Lookup parameter types
            try:
                type, ident = formal.generate()
                types.append(type)
                params.append(ident)

            except AttributeError:
                types.append(formal.type)
                params.append(None)

        body = self.slicc.codeFormatter()
        if self.statements is None:
            self["external"] = "yes"
        else:
            rtype = self.statements.generate(body, return_type)

        self.symtab.popFrame()

        machine = self.state_machine
        func = Func(self.symtab, self.ident, self.location, return_type,
                    types, params, str(body), self.pairs)

        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)
    def generate(self, parent = None):
        types = []
        params = []
        void_type = self.symtab.find("void", Type)

        # Generate definition code
        self.symtab.pushFrame()

        # Lookup return type
        return_type = self.return_type.type

        # Generate function header
        for formal in self.formals:
            # Lookup parameter types
            type, ident = formal.generate()
            types.append(type)
            params.append(ident)

        body = self.slicc.codeFormatter()
        if self.statements is None:
            self["external"] = "yes"
        else:
            rtype = self.statements.generate(body, return_type)

        self.symtab.popFrame()

        machine = self.state_machine
        func = Func(self.symtab, self.ident, self.location, return_type,
                    types, params, str(body), self.pairs)

        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)
Ejemplo n.º 7
0
    def generate(self):
        ident = str(self.type_ast)

        # Make the new type
        t = Type(self.symtab, ident, self.location, self.pairs,
                 self.state_machine)
        self.symtab.newSymbol(t)

        # Add all of the fields of the type to it
        for field in self.fields:
            field.generate(t)

        # Add the implicit State_to_string method - FIXME, this is a bit dirty
        func_id = "%s_to_string" % t.c_ident

        pairs = {"external": "yes"}
        func = Func(self.symtab, func_id, self.location,
                    self.symtab.find("std::string", Type), [t], [], "", pairs,
                    None)
        self.symtab.newSymbol(func)
Ejemplo n.º 8
0
    def generate(self):
        symtab = self.symtab
        void_type = symtab.find("void", Type)

        machine = symtab.state_machine
        if machine is None:
            self.error("InPort declaration not part of a machine.")

        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' " + \
                       "attribute.  Type '%s' does not have this attribute.",
                       queue_type)

        type = self.queue_type.type
        in_port = Var(self.symtab, self.ident, self.location, type, str(code),
                      self.pairs, machine, self.var_expr)
        symtab.newSymbol(in_port)

        symtab.pushFrame()
        param_types = []

        # Check for Event
        type = symtab.find("Event", Type)
        if type is None:
            self.error("in_port decls require 'Event' enumeration defined")
        param_types.append(type)

        # Check for Address
        type = symtab.find("Addr", Type)
        if type is None:
            self.error("in_port decls require 'Addr' type to be defined")

        param_types.append(type)

        if machine.EntryType != None:
            param_types.append(machine.EntryType)
        if machine.TBEType != None:
            param_types.append(machine.TBEType)

        # Add the trigger method - FIXME, this is a bit dirty
        pairs = {"external": "yes"}
        trigger_func_name = "trigger"
        for param in param_types:
            trigger_func_name += "_" + param.ident
        func = Func(self.symtab, trigger_func_name, "trigger", self.location,
                    void_type, param_types, [], "", pairs)
        symtab.newSymbol(func)

        # Add the stallPort method - this hacks reschedules the controller
        # for stalled messages that don't trigger events
        func = Func(self.symtab, "stallPort", "stallPort", self.location,
                    void_type, [], [], "", pairs)
        symtab.newSymbol(func)

        param_types = []
        # Check for Event2
        type = symtab.find("Event", Type)
        if type is None:
            self.error("in_port decls require 'Event' enumeration")

        param_types.append(type)

        # Check for Address2
        type = symtab.find("Addr", Type)
        if type is None:
            self.error("in_port decls require 'Addr' type to be defined")

        param_types.append(type)

        if self.statements is not None:
            rcode = self.slicc.codeFormatter()
            rcode.indent()
            rcode.indent()
            self.statements.generate(rcode, None)
            in_port["c_code_in_port"] = str(rcode)

        symtab.popFrame()

        # Add port to state machine
        machine.addInPort(in_port)
Ejemplo n.º 9
0
    def generate(self):
        symtab = self.symtab
        void_type = symtab.find("void", Type)

        machine = symtab.state_machine
        if machine is None:
            self.error("InPort declaration not part of a machine.")

        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' " + \
                       "attribute.  Type '%s' does not have this attribute.",
                       queue_type)

        type = self.queue_type.type
        in_port = Var(self.symtab, self.ident, self.location, type, str(code),
                      self.pairs)
        symtab.newSymbol(in_port)

        symtab.pushFrame()
        param_types = []

        # Check for Event
        type = symtab.find("Event", Type)
        if type is None:
            self.error("in_port decls require 'Event' enumeration defined")
        param_types.append(type)

        # Check for Address
        type = symtab.find("Address", Type)
        if type is None:
            self.error("in_port decls require 'Address' type to be defined")

        param_types.append(type)

        if machine.EntryType != None:
            param_types.append(machine.EntryType)
        if machine.TBEType != None:
            param_types.append(machine.TBEType)

        # 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)
        symtab.newSymbol(func)

        param_types = []
        # Check for Event2
        type = symtab.find("Event", Type)
        if type is None:
            self.error("in_port decls require 'Event' enumeration")

        param_types.append(type)

        # Check for Address2
        type = symtab.find("Address", Type)
        if type is None:
            self.error("in_port decls require 'Address' type to be defined")

        param_types.append(type)

        # Add the doubleTrigger method - this hack supports tiggering
        # two simulateous events
        #
        # The key is that the second transistion cannot fail because
        # the first event cannot be undone therefore you must do some
        # checks before calling double trigger to ensure that won't
        # happen
        func = Func(self.symtab, "doubleTrigger", self.location, void_type,
                    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)
        symtab.newSymbol(func)

        if self.statements is not None:
            rcode = self.slicc.codeFormatter()
            rcode.indent()
            rcode.indent()
            self.statements.generate(rcode, None)
            in_port["c_code_in_port"] = str(rcode)

        symtab.popFrame()

        # Add port to state machine
        machine.addInPort(in_port)

        # Include max_rank to be used by StateMachine.py
        in_port["max_port_rank"] = InPortDeclAST.max_port_rank
Ejemplo n.º 10
0
    def generate(self):
        symtab = self.symtab
        void_type = symtab.find("void", Type)

        machine = symtab.state_machine
        if machine is None:
            self.error("InPort declaration not part of a machine.")

        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' " + \
                       "attribute.  Type '%s' does not have this attribute.",
                       queue_type)

        type = self.queue_type.type
        in_port = Var(self.symtab, self.ident, self.location, type, str(code),
                      self.pairs)
        symtab.newSymbol(in_port)

        symtab.pushFrame()
        param_types = []

        # Check for Event
        type = symtab.find("Event", Type)
        if type is None:
            self.error("in_port decls require 'Event' enumeration defined")
        param_types.append(type)

        # Check for Address
        type = symtab.find("Address", Type)
        if type is None:
            self.error("in_port decls require 'Address' type to be defined")

        param_types.append(type)

        if machine.EntryType != None:
            param_types.append(machine.EntryType)
        if machine.TBEType != None:
            param_types.append(machine.TBEType)

        # 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)
        symtab.newSymbol(func)

        param_types = []
        # Check for Event2
        type = symtab.find("Event", Type)
        if type is None:
            self.error("in_port decls require 'Event' enumeration")

        param_types.append(type)

        # Check for Address2
        type = symtab.find("Address", Type)
        if type is None:
            self.error("in_port decls require 'Address' type to be defined")

        param_types.append(type)

        if self.statements is not None:
            rcode = self.slicc.codeFormatter()
            rcode.indent()
            rcode.indent()
            self.statements.generate(rcode, None)
            in_port["c_code_in_port"] = str(rcode)

        symtab.popFrame()

        # Add port to state machine
        machine.addInPort(in_port)

        # Include max_rank to be used by StateMachine.py
        in_port["max_port_rank"] = InPortDeclAST.max_port_rank