Example #1
0
    def optimize(self, statements):
        cur_statement = GStatement()
        nstatements = [cur_statement]
        for statement in statements:
            for code in statement:
                if code.address == 'M':
                    cur_statement = GStatement()
                    nstatements.append(cur_statement)
                cur_statement.append(code)

            cur_statement = GStatement()
            nstatements.append(cur_statement)
        return nstatements
Example #2
0
    def optimize(self, statements):
        cur_statement = GStatement()
        nstatements = [cur_statement]
        last_val = None
        for statement in statements:
            for code in statement:
                if code.address == 'F':
                    if code.command != last_val:
                        s = GStatement(code)
                        nstatements.insert(-1, s)
                        last_val = code.command
                else:
                    cur_statement.append(code)

            cur_statement = GStatement()
            nstatements.append(cur_statement)
        return nstatements
Example #3
0
    def optimize(self, statements):
        cur_statement = GStatement()
        nstatements = [cur_statement]
        state = {x:None for x in self.move_desc}
        save = False
        for statement in statements:
            for code in statement:
                if code.address == 'G' and code.command in (0,1):
                    save = True
                elif code.address in ('G', 'M'):
                    state = {x:None for x in self.move_desc}
                    save = False

                if not save:
                    cur_statement.append(code)
                    continue

                if code.address in self.move_desc:
                    if code.command != state[code.address]:
                        cur_statement.append(code)
                        state[code.address] = code.command
                else:
                    cur_statement.append(code)

            cur_statement = GStatement()
            nstatements.append(cur_statement)
        return nstatements
Example #4
0
    def optimize(self, statements):
        cur_statement = GStatement()
        nstatements = [cur_statement]
        cur_code = None
        for statement in statements:
            for code in statement:
                if code.address in self.move_desc:
                    cur_statement.append(code)
                elif code == cur_code:
                    pass
                elif code.address == 'G' and code.command >= 0 and code.command <= 3:
                    cur_code = code
                    cur_statement.append(code)
                else:
                    cur_code = None
                    cur_statement.append(code)

            cur_statement = GStatement()
            nstatements.append(cur_statement)
        return nstatements