Skip to main content

def_op

Attribute Macro def_op 

Source
#[def_op]
Expand description

#[def_op(...)]: Create a new IR operation.

Note: It is suggested to use the pliron_op macro instead of using this macro directly. The documention here is useful though, because pliron_op’s name field expands to this macro.

The argument to the macro is the fully qualified name of the operation in the form of "dialect.op_name".

The macro assumes an empty struct and will add the op: Ptr<Operation> field used to access the underlying Operation in the context.

The macro will automatically derive the Clone, Copy, Hash, PartialEq and Eq traits for the new struct definition.

Note: pre-requisite traits for Op (Printable, Verify etc) must already be implemented

Usage:

use pliron::derive::{def_op, format_op, verify_succ};

#[verify_succ]
#[def_op("my_dialect.op")]
#[format_op]
pub struct MyOp;

The example will create a struct definition equivalent to:

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct MyOp {
  op: Ptr<Operation>,
}