Ejemplo n.º 1
0
    def _synthesizeAsync(self, log_function=None, completion_callback_function=None):
        """ Asynchronously call the synthesis tool.  This function will return immediately after
            spawning a subprocess.  `log_function` will be called with a string argument every time
            the subprocess generates a line of text.  `completion_callback_function` will be called
            when synthesis finishes, with two arguments: the success flags `realizable`
            and `realizableFS`. """

        # Find the synthesis tool
        cmd = self._getGROneCommand("GROneMain")
        if cmd is None:
            # No tool available
            return (False, False, "")

        # Add any extra compiler options
        if self.proj.compile_options["fastslow"]:
            cmd.append("--fastslow")

        self.realizable = False
        self.realizableFS = False

        # Define some wrappers around the callback functions so we can parse the output
        # of the synthesis tool and return it in a meaningful way.
        def onLog(text):
            """ Intercept log callbacks to check for realizability status. """

            if "Specification is realizable" in text:
                self.realizable = True
            if "Specification is realizable with slow and fast actions" in text:
                self.realizableFS = True

            # You'll pass this on, won't you
            if log_function is not None:
                log_function(text)

        # Create a flag for convenience
        self.synthesis_complete = threading.Event()

        def onSubprocessComplete():
            if completion_callback_function is not None:
                completion_callback_function(self.realizable, self.realizableFS)
            self.synthesis_complete.set()
            self.synthesis_subprocess = None

        # Kick off the subprocess
        self.synthesis_subprocess = AsynchronousProcessThread(cmd, onSubprocessComplete, onLog)
Ejemplo n.º 2
0
    def _synthesizeAsync(self,
                         log_function=None,
                         completion_callback_function=None):
        """ Asynchronously call the synthesis tool.  This function will return immediately after
            spawning a subprocess.  `log_function` will be called with a string argument every time
            the subprocess generates a line of text.  `completion_callback_function` will be called
            when synthesis finishes, with two arguments: the success flags `realizable`
            and `realizableFS`. """

        if self.proj.compile_options["synthesizer"].lower() == "jtlv":
            # Find the synthesis tool
            cmd = self._getGROneCommand("GROneMain")

            # Add any extra compiler options
            if self.proj.compile_options["fastslow"]:
                cmd.append("--fastslow")
            if self.proj.compile_options["symbolic"]:
                cmd.append("--symbolic")

            REALIZABLE_MESSAGE = "Specification is synthesizable!"
            REALIZABLE_FS_MESSAGE = "Specification is synthesizable under fast/slow!"

        elif self.proj.compile_options["synthesizer"].lower() == "slugs":
            # Find the synthesis tool
            cmd = self._getSlugsCommand()

            # Make sure flags are compatible
            if any(self.proj.compile_options[k]
                   for k in ("fastslow", "symbolic")):
                raise RuntimeError(
                    "Slugs does not currently support fast/slow or symbolic compilation options."
                )

            # Create proper input for Slugs
            logging.info("Preparing Slugs input...")
            self.prepareSlugsInput()

            REALIZABLE_MESSAGE = "RESULT: Specification is realizable"
            REALIZABLE_FS_MESSAGE = None
        else:
            raise RuntimeError("Invalid synthesizer: {!r}".format(
                self.proj.compile_options["synthesizer"]))

        self.realizable = False
        self.realizableFS = False

        # Define some wrappers around the callback functions so we can parse the output
        # of the synthesis tool and return it in a meaningful way.
        def onLog(text):
            """ Intercept log callbacks to check for realizability status. """

            if REALIZABLE_MESSAGE in text:
                self.realizable = True
            if REALIZABLE_FS_MESSAGE is not None and REALIZABLE_FS_MESSAGE in text:
                self.realizableFS = True

            # You'll pass this on, won't you
            if log_function is not None:
                log_function(text)

        # Create a flag for convenience
        self.synthesis_complete = threading.Event()

        def onSubprocessComplete():
            if completion_callback_function is not None:
                completion_callback_function(self.realizable,
                                             self.realizableFS)
            self.synthesis_complete.set()
            self.synthesis_subprocess = None

        # Kick off the subprocess
        logging.info("Synthesizing a strategy...")

        self.synthesis_subprocess = AsynchronousProcessThread(
            cmd, onSubprocessComplete, onLog)