Skip to content
Snippets Groups Projects
Commit e39f5eb9 authored by Martin Teichmann's avatar Martin Teichmann
Browse files

augmented assignment is no special case anymore

parent 0bcc66a5
No related branches found
No related tags found
No related merge requests found
......@@ -87,18 +87,6 @@ class OpcodeFlags:
class AssembleError(Exception):
pass
def augassign(opcode):
def ret(self, value):
if isinstance(value, int):
return Instruction(opcode + Opcode.LONG * self.long, self.no,
0, 0, value)
elif isinstance(value, Register) and self.long == value.long:
return Instruction(opcode + Opcode.REG + Opcode.LONG * self.long,
self.no, value.no, 0, 0)
else:
return NotImplemented
return ret
def comparison(uposop, unegop, sposop=None, snegop=None):
if sposop is None:
......@@ -400,27 +388,6 @@ class Register(Expression):
self.long = long
self.signed = signed
__iadd__ = augassign(Opcode.ADD)
__isub__ = augassign(Opcode.SUB)
__imul__ = augassign(Opcode.MUL)
__itruediv__ = augassign(Opcode.DIV)
__ior__ = augassign(Opcode.OR)
__iand__ = augassign(Opcode.AND)
__ilshift__ = augassign(Opcode.LSH)
__imod__ = augassign(Opcode.MOD)
__ixor__ = augassign(Opcode.XOR)
def __irshift__(self, value):
opcode = Opcode.ARSH if self.signed else Opcode.RSH
if isinstance(value, int):
return Instruction(opcode + Opcode.LONG * self.long, self.no,
0, 0, value)
elif isinstance(value, Register) and self.long == value.long:
return Instruction(opcode + Opcode.REG + Opcode.LONG * self.long,
self.no, value.no, 0, 0)
else:
return NotImplemented
def __add__(self, value):
if isinstance(value, int) and self.long:
return Sum(self.ebpf, self, value)
......
......@@ -44,6 +44,7 @@ class Tests(TestCase):
def test_word(self):
e = EBPF()
e.owners |= {6}
e.w3 = 7
e.w4 = e.w1
e.w2 += 3
......@@ -56,6 +57,7 @@ class Tests(TestCase):
def test_augassign(self):
e = EBPF()
e.owners |= {4, 6, 7}
e.r5 += 7
e.r3 += e.r6
e.r4 -= 3
......@@ -82,7 +84,7 @@ class Tests(TestCase):
self.assertEqual(e.opcodes,
[Instruction(opcode=7, dst=5, src=0, off=0, imm=7),
Instruction(opcode=15, dst=3, src=6, off=0, imm=0),
Instruction(opcode=0x17, dst=4, src=0, off=0, imm=3),
Instruction(opcode=7, dst=4, src=0, off=0, imm=-3),
Instruction(opcode=0x1f, dst=4, src=7, off=0, imm=0),
Instruction(opcode=0x27, dst=4, src=0, off=0, imm=3),
Instruction(opcode=0x2f, dst=4, src=7, off=0, imm=0),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment