コード例 #1
0
ファイル: goto_next_line.py プロジェクト: NoamSheffer/WazeWP7
			  [{"class" : Goto},
			   {"class" : Label},
			   ]
			  )

    def match(self, fn, items):
	if items[0].target != items[1].name:
	    return False
	return True

    # The action here is simple - just remove the instruction
    def execute(self, fn, items):
	items[0] = Nop()
	return items # Keep the label

addTemplate(MatchClass())

#	goto LABEL
#LABEL2:
#LABEL:
#->
#LABEL2:
#LABEL:
class MatchClass2(Template):
    def __init__(self):
	Template.__init__(self,
			  [{"class" : Goto},
			   {"class" : Label},
			   {"class" : Label},
			   ]
			  )
コード例 #2
0
#       aload $Y
#	const xx
#	store $N
class MatchClass(Template):
    def __init__(self):
        Template.__init__(self, [
            {
                "class": Const
            },
            {
                "class": Istore
            },
            {
                "class": Aload
            },
        ])

    def match(self, fn, items):
        return True

    def execute(self, fn, items):
        tmp = items[0]
        tmp2 = items[1]
        items[0] = items[2]
        items[1] = tmp
        items[2] = tmp2
        return items


addTemplate(MatchClass())
コード例 #3
0
ファイル: double_stores.py プロジェクト: glennneiger/WazeWP7
    def match(self, fn, items):
        return False # FIXME: Disabled for now - causes problems
	N = items[0].targetLocal
	if N == items[1].sourceLocal:
	    return False
	if N != items[2].sourceLocal:
	    return False
	for item in items[3:-1]:
	    if not midInstructionValid(N, item):
		return False
	return True

    # Remove the istore/iload
    def execute(self, fn, items):
	items[0] = Nop()
	items[2] = Swap()
	return items

for n in range(0, 1):
    for m in range(0, 6):
	addTemplate(MatchStoreLoadStore(n, m))
for i in range(0, 6):
    addTemplate(MatchStoreStore(i))
addTemplate(MatchStoreLoadIreturn())
addTemplate(MatchStoreLoad())
addTemplate(MatchDupIstoreIreturn())
addTemplate(MatchStorePutstaticLoadIreturn())
addTemplate(MatchSwap())
addTemplate(MatchSwapDup())
コード例 #4
0
ファイル: jal_arguments.py プロジェクト: glennneiger/WazeWP7
    def match(self, fn, items):
        if not items[-2].sourceLocal == "3" or not items[
                -3].sourceLocal == "2" or not items[
                    -4].sourceLocal == "1" or not items[-5].sourceLocal == "0":
            return False
        for p in range(1, self.n + 1):
            if items[p * 2 -
                     2].sourceLocal and int(items[p * 2 - 2].sourceLocal) <= 3:
                return False
            if int(items[p * 2 - 1].targetLocal) > 3:
                return False
        return True

    def execute(self, fn, items):
        for p in range(1, self.n + 1):
            reg = int(items[p * 2 - 1].targetLocal)
            items[-5 + reg] = items[p * 2 - 2]
            items[p * 2 - 2] = Nop()
            items[p * 2 - 1] = Nop()
        return items


addTemplate(MatchBase(4))
addTemplate(MatchBase(3))
addTemplate(MatchBase(2))
addTemplate(MatchBase(1))

addTemplate(MatchBase2(3))
addTemplate(MatchBase2(2))
addTemplate(MatchBase2(1))
コード例 #5
0
ファイル: jal_arguments.py プロジェクト: NoamSheffer/WazeWP7
			   ]
			  )
	self.n = n

    def match(self, fn, items):
	if not items[-2].sourceLocal=="3" or not items[-3].sourceLocal=="2" or not items[-4].sourceLocal=="1" or not items[-5].sourceLocal=="0":
	    return False
	for p in range(1,self.n+1):
	    if items[p*2-2].sourceLocal and int(items[p*2-2].sourceLocal)<=3:
	        return False	
	    if int(items[p*2-1].targetLocal)>3:
	        return False
	return True

    def execute(self, fn, items):
	for p in range(1,self.n+1):
	    reg = int(items[p*2-1].targetLocal)
	    items[-5 + reg] = items[p*2-2]
	    items[p*2-2] = Nop()
	    items[p*2-1] = Nop()
	return items

addTemplate(MatchBase(4))
addTemplate(MatchBase(3))
addTemplate(MatchBase(2))
addTemplate(MatchBase(1))

addTemplate(MatchBase2(3))
addTemplate(MatchBase2(2))
addTemplate(MatchBase2(1))
コード例 #6
0
    def __init__(self):
	Template.__init__(self,
			  [{"class" : Const},
			   {"class" : Pop},
			   ]
			  )

    def match(self, fn, items):
	return True

    # make the iinc a nop and replace the const
    def execute(self, fn, items):
	items[0] = Nop()
	items[1] = Nop()
	return items


#	iload  $X
#	pop
#->
class IloadMatchClass(MatchClass):
    def __init__(self):
	Template.__init__(self,
			  [{"class" : Iload},
			   {"class" : Pop},
			   ]
			  )

addTemplate(MatchClass())
addTemplate(IloadMatchClass())
コード例 #7
0
    def match(self, fn, items):
	return True

    # make the iinc a nop and replace the const
    def execute(self, fn, items):
	items[0] = Nop()
	items[1] = Nop()
	return items

#	getstatic
#	pop2
#->
#       pop
class MatchPop2(Template):
    def __init__(self):
	Template.__init__(self,
			  [{"class" : Getstatic},
			   {"class" : Pop2},
			   ]
			  )

    # make the iinc a nop and replace the const
    def execute(self, fn, items):
	items[0] = Nop()
	items[1] = Pop()
	return items

addTemplate(MatchPop())
addTemplate(MatchPop2())
コード例 #8
0
    def execute(self, fn, items):
        items[0] = Nop()
        items[1] = Nop()
        return items


#	getstatic
#	pop2
#->
#       pop
class MatchPop2(Template):
    def __init__(self):
        Template.__init__(self, [
            {
                "class": Getstatic
            },
            {
                "class": Pop2
            },
        ])

    # make the iinc a nop and replace the const
    def execute(self, fn, items):
        items[0] = Nop()
        items[1] = Pop()
        return items


addTemplate(MatchPop())
addTemplate(MatchPop2())
コード例 #9
0
ファイル: jal_return.py プロジェクト: NoamSheffer/WazeWP7
			   {"class" : Istore},
			   {"class" : Istore},
			   ] + [{"class" : PushInstruction}, {"class" : PopInstruction}] * n + [{"class" : PushInstruction}] * m + [
			   {"class" : Invokestatic},
			   {"class" : Getstatic},
			   {"class" : Istore},
			   {"class" : Istore},
			   ]
			  )

    def match(self, fn, items):
      regs = [items[1].targetLocal, items[2].targetLocal]
      if not items[-1].targetLocal in regs or not items[-2].targetLocal in regs:
        return False
      i = 3
      while not isinstance(items[i], Getstatic):
          if items[i].sourceLocal and items[i].sourceLocal in regs:
              return False
          i += 1
      return True

    def execute(self, fn, items):
        items[0] = Nop()
        items[1] = Nop()
        items[2] = Pop()
        return items

for n in range(0, 5):
    for m in range(3, 6):
        addTemplate(MatchJalReturn(n, m))
コード例 #10
0
ファイル: jal_return.py プロジェクト: glennneiger/WazeWP7
            {
                "class": Istore
            },
            {
                "class": Istore
            },
        ])

    def match(self, fn, items):
        regs = [items[1].targetLocal, items[2].targetLocal]
        if not items[-1].targetLocal in regs or not items[
                -2].targetLocal in regs:
            return False
        i = 3
        while not isinstance(items[i], Getstatic):
            if items[i].sourceLocal and items[i].sourceLocal in regs:
                return False
            i += 1
        return True

    def execute(self, fn, items):
        items[0] = Nop()
        items[1] = Nop()
        items[2] = Pop()
        return items


for n in range(0, 5):
    for m in range(3, 6):
        addTemplate(MatchJalReturn(n, m))