Skip to main content

pliron_op

Attribute Macro pliron_op 

Source
#[pliron_op]
Expand description

#[pliron_op(...)]: Unified macro for defining IR operations.

This macro provides a simplified, unified syntax for defining IR operations by expanding into the existing operation definition macros. It supports the following configuration options:

  • name = "dialect.op_name": The fully qualified name of the operation (required).
    Expands to def_op.
  • format = "format_string": Custom format string for printing/parsing (optional).
    Expands to format_op.
  • interfaces = [Interface1, Interface2, ...]: List of interfaces to implement (optional).
    Expands to derive_op_interface_impl.
  • attributes = (attr_name: AttrType, ...): List of attributes with their types (optional).
    Expands to derive_attr_get_set, generating getter and setter methods.
  • verifier = "succ": Verifier implementation, currently only “succ” is supported (optional).
    Expands to verify_succ.

§Examples

§Basic operation definition:

use pliron::derive::pliron_op;

#[pliron_op(name = "test.my_op", format, verifier = "succ")]
struct MyOp;

§Operation with custom format and interfaces:

use pliron::derive::pliron_op;
use pliron::builtin::op_interfaces::NRegionsInterface;

#[pliron_op(
    name = "test.if_op",
    format = "`(`$0`)` region($0)",
    interfaces = [ NRegionsInterface<1> ],
    verifier = "succ"
)]
struct IfOp;

§Operation with attributes:

use pliron::derive::pliron_op;
use pliron::builtin::attributes::{UnitAttr, IntegerAttr};

#[pliron_op(
    name = "dialect.test",
    format,
    attributes = (attr1: UnitAttr, attr2: IntegerAttr),
    verifier = "succ"
)]
struct CallOp;

The attributes parameter generates getter and setter methods for each attribute, equivalent to using #[derive_attr_get_set(...)].