Skip to content

Commit 4f60c8f

Browse files
authored
Merge pull request #16 from sanchezocegueda/insts
- Modify output to include name - Add srem and urem instructions
2 parents 5d38a57 + 0a1b824 commit 4f60c8f

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

src/btoropt/parser.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,18 @@ def parse_inst(line: str, p: list[Instruction]) -> Instruction:
187187
case "output":
188188
# Sanity check: verify that instruction is well formed
189189
assert len(inst) >= 3,\
190-
"input instruction must be of the form: <lid> output <opid>. Found: " + line
190+
"output instruction must be of the form: <lid> output <opid> [name]. Found: " + line
191191

192192
# Find the op associated to this instruction
193193
out = find_inst(p, int(inst[2]))
194194

195+
if len(inst) >= 4:
196+
name = inst[3].strip()
197+
else:
198+
name = f"output_{inst[0]}"
199+
195200
# Construct instruction
196-
op = Output(lid, out)
201+
op = Output(lid, out, name)
197202

198203
case "bad":
199204
# Sanity check: verify that instruction is well formed
@@ -461,6 +466,33 @@ def parse_inst(line: str, p: list[Instruction]) -> Instruction:
461466
# Construct instruction
462467
op = Smod(lid, sort, op1, op2)
463468

469+
case "srem":
470+
# Sanity check: verify that instruction is well formed
471+
assert len(inst) >= 5,\
472+
"sort instruction must be of the form: <lid> srem <sid> <op1> <op2>. Found: " + line
473+
474+
# Find the operands associated to this instruction
475+
sort = find_inst(p, int(inst[2]))
476+
op1 = find_inst(p, int(inst[3]))
477+
op2 = find_inst(p, int(inst[4]))
478+
479+
# Construct instruction
480+
op = Srem(lid, sort, op1, op2)
481+
482+
case "urem":
483+
# Sanity check: verify that instruction is well formed
484+
assert len(inst) >= 5,\
485+
"sort instruction must be of the form: <lid> urem <sid> <op1> <op2>. Found: " + line
486+
487+
# Find the operands associated to this instruction
488+
sort = find_inst(p, int(inst[2]))
489+
op1 = find_inst(p, int(inst[3]))
490+
op2 = find_inst(p, int(inst[4]))
491+
492+
# Construct instruction
493+
op = Urem(lid, sort, op1, op2)
494+
495+
464496
case "sll":
465497
# Sanity check: verify that instruction is well formed
466498
assert len(inst) >= 5,\

src/btoropt/program.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
tags = ["sort","input", "output", "bad", "constraint", "zero",
2323
"one", "ones", "constd", "consth", "const", "state",
2424
"init", "next", "slice", "ite", "implies", "iff",
25-
"add", "sub", "mul", "sdiv", "udiv", "smod", "sll",
26-
"srl", "sra", "and", "or", "xor", "concat",
25+
"add", "sub", "mul", "sdiv", "udiv", "smod",
26+
"srem", "urem", "sll", "srl", "sra", "and",
27+
"or", "xor", "concat",
2728
# Unary operations
2829
"not", "inc", "dec", "neg", "redor", "redxor", "redand",
2930
"eq", "neq", "ugt", "sgt", "ugte", "sgte", "ult",
@@ -119,8 +120,9 @@ def serialize(self) -> str:
119120

120121

121122
class Output(Instruction):
122-
def __init__(self, lid: int, out: Instruction):
123+
def __init__(self, lid: int, out: Instruction, name: str):
123124
super().__init__(lid, "output", [out])
125+
self.name = name
124126

125127
## Unary Instructions ##
126128

@@ -285,6 +287,14 @@ class Smod(Instruction):
285287
def __init__(self, lid: int, sort: Sort, op1: Instruction, op2: Instruction):
286288
super().__init__(lid, "smod", [sort, op1, op2])
287289

290+
class Srem(Instruction):
291+
def __init__(self, lid: int, sort: Sort, op1: Instruction, op2: Instruction):
292+
super().__init__(lid, "srem", [sort, op1, op2])
293+
294+
class Urem(Instruction):
295+
def __init__(self, lid: int, sort: Sort, op1: Instruction, op2: Instruction):
296+
super().__init__(lid, "urem", [sort, op1, op2])
297+
288298
class Sll(Instruction):
289299
def __init__(self, lid: int, sort: Sort, op1: Instruction, op2: Instruction):
290300
super().__init__(lid, "sll", [sort, op1, op2])

0 commit comments

Comments
 (0)