Skip to content

Commit

Permalink
feat: Check min_avm_version of intrinsic ops against target avm versi…
Browse files Browse the repository at this point in the history
…on for compiler
  • Loading branch information
tristanmenzel authored and achidlow committed Feb 1, 2024
1 parent be62082 commit 2b3dea0
Show file tree
Hide file tree
Showing 53 changed files with 210 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/amm/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/auction/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/calculator/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/global_state/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/hello_world/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/local_state/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/voting/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions scripts/generate_avm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def generate_op_node(
immediate_types=immediate_types,
signature=signature,
cost=cost,
min_avm_version=op.min_avm_version,
)
yield f"{op_name} = {data!r}"
if op.doc:
Expand Down Expand Up @@ -212,6 +213,7 @@ class AVMOp(enum.StrEnum):
immediate_types: Sequence[ImmediateKind]
_signature: OpSignature | DynamicSignatures
cost: int | None
min_avm_version: int
def __new__(cls, data: AVMOpData | str) -> "AVMOp":
# the weird union type on data && then assert,
Expand All @@ -225,6 +227,7 @@ def __new__(cls, data: AVMOpData | str) -> "AVMOp":
obj.immediate_types = tuple(data.immediate_types)
obj._signature = data.signature # noqa: SLF001
obj.cost = data.cost
obj.min_avm_version = data.min_avm_version
return obj
def get_signature(self, immediates: Sequence[str | int]) -> OpSignature:
Expand Down
1 change: 1 addition & 0 deletions src/puya/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def main() -> None:
type=LogLevel.from_string,
choices=list(LogLevel),
)
parser.add_argument("--target-avm-version", type=int, choices=[8, 9, 10])

parser.add_argument("paths", type=Path, nargs="+", metavar="PATH")
options = PuyaOptions()
Expand Down
8 changes: 8 additions & 0 deletions src/puya/codegen/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from puya.codegen.teal_writer import emit_memory_ir_as_teal
from puya.context import CompileContext
from puya.errors import CodeError
from puya.ir import models
from puya.ir.types_ import AVMBytesEncoding
from puya.ir.visitor import IRVisitor
Expand Down Expand Up @@ -150,6 +151,13 @@ def visit_phi_argument(self, arg: models.PhiArgument) -> None:
raise NotImplementedError

def visit_intrinsic_op(self, intrinsic: models.Intrinsic) -> None:
if intrinsic.op.min_avm_version > self.context.options.target_avm_version:
raise CodeError(
f"Opcode {intrinsic.op.code} requires a min avm version of "
f"{intrinsic.op.min_avm_version} but the target avm version is"
f" {self.context.options.target_avm_version}",
intrinsic.source_location,
)
for arg in intrinsic.args:
arg.accept(self)
self._add_op(
Expand Down
2 changes: 1 addition & 1 deletion src/puya/codegen/teal_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def emit_memory_ir_as_teal(
annotater.header(writer)

writer.new_line()
writer.append_line("#pragma version 8")
writer.append_line(f"#pragma version {context.options.target_avm_version}")
writer.new_line()

for subroutine in subroutines:
Expand Down
Loading

0 comments on commit 2b3dea0

Please sign in to comment.