
# Autogenerated by mlir-tblgen; don't manually edit.

from ._ods_common import _cext as _ods_cext
from ._ods_common import (
    equally_sized_accessor as _ods_equally_sized_accessor,
    get_default_loc_context as _ods_get_default_loc_context,
    get_op_results_or_values as _get_op_results_or_values,
    segmented_accessor as _ods_segmented_accessor,
)
_ods_ir = _ods_cext.ir
_ods_cext.globals.register_traceback_file_exclusion(__file__)

import builtins
from typing import Any as _Any, Sequence as _Sequence, Union as _Union, Optional as _Optional
import sys as _sys
if _sys.version_info >= (3, 12):
  from collections.abc import Buffer as _Buffer  # pytype: disable=not-supported-yet
else:
  try:
    from typing_extensions import Buffer as _Buffer
  except ImportError:
    _Buffer = _Any


from ._transform_ops_gen import _Dialect

@_ods_cext.register_operation(_Dialect)
class EmitParamAsRemarkOp(_ods_ir.OpView):
  r"""
  This operation emits a diagnostic remark containing the string form of the
  attributes associated with the parameter provided as attribute. It takes
  as optional arguments:
    - an additional message text to prepend;
    - a handle pointing to operations the location of which will be used to
      emit the diagnostic; if multiple operations are associated, the
      diagnostic is emitted for all of their respective locations.
  
  This operation always succeeds.
  """

  OPERATION_NAME = "transform.debug.emit_param_as_remark"

  _ODS_REGIONS = (0, True)

  def __init__(self, param: _ods_ir.Value, *, anchor: _Optional[_ods_ir.Value] = None, message: _Optional[_Union[str, _ods_ir.StringAttr]] = None, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None):
    operands = []
    attributes = {}
    regions = None
    operands.append(param)
    if anchor is not None: operands.append(anchor)
    _ods_context = _ods_get_default_loc_context(loc)
    if message is not None: attributes["message"] = (message if (
        isinstance(message, _ods_ir.Attribute) or
        not _ods_ir.AttrBuilder.contains('StrAttr')) else
          _ods_ir.AttrBuilder.get('StrAttr')(message, context=_ods_context))
    results = []
    _ods_successors = None
    super().__init__(self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS, attributes=attributes, results=results, operands=operands, successors=_ods_successors, regions=regions, loc=loc, ip=ip)

  @builtins.property
  def param(self) -> _ods_ir.Value:
    return self.operation.operands[0]

  @builtins.property
  def anchor(self) -> _Optional[_ods_ir.Value]:
    return None if len(self.operation.operands) < 2 else self.operation.operands[1]

  @builtins.property
  def message(self) -> _Optional[_ods_ir.StringAttr]:
    if "message" not in self.operation.attributes:
      return None
    return self.operation.attributes["message"]

  @message.setter
  def message(self, value: _Optional[_ods_ir.StringAttr]):
    if value is not None:
      self.operation.attributes["message"] = value
    elif "message" in self.operation.attributes:
      del self.operation.attributes["message"]

  @message.deleter
  def message(self):
    del self.operation.attributes["message"]

@_ods_cext.register_op_adaptor(EmitParamAsRemarkOp)
class EmitParamAsRemarkOpAdaptor(_ods_ir.OpAdaptor):
  OPERATION_NAME = "transform.debug.emit_param_as_remark"

  @builtins.property
  def param(self) -> _ods_ir.Value:
    return self.operands[0]

  @builtins.property
  def anchor(self) -> _Optional[_ods_ir.Value]:
    return None if len(self.operands) < 2 else self.operands[1]

  @builtins.property
  def message(self) -> _Optional[_ods_ir.StringAttr]:
    if "message" not in self.attributes:
      return None
    return self.attributes["message"]

def debug_emit_param_as_remark(param: _ods_ir.Value, *, anchor: _Optional[_ods_ir.Value] = None, message: _Optional[_Union[str, _ods_ir.StringAttr]] = None, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None) -> EmitParamAsRemarkOp:
  return EmitParamAsRemarkOp(param=param, anchor=anchor, message=message, loc=loc, ip=ip)

@_ods_cext.register_operation(_Dialect)
class EmitRemarkAtOp(_ods_ir.OpView):
  r"""
  This operation emits a diagnostic remark with the given message at the
  location of each payload object associated with the argument. The argument
  may be an operation or a value handle.
  
  This operation always succeeds.
  """

  OPERATION_NAME = "transform.debug.emit_remark_at"

  _ODS_REGIONS = (0, True)

  def __init__(self, at: _ods_ir.Value, message: _Union[str, _ods_ir.StringAttr], *, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None):
    operands = []
    attributes = {}
    regions = None
    operands.append(at)
    _ods_context = _ods_get_default_loc_context(loc)
    attributes["message"] = (message if (
    isinstance(message, _ods_ir.Attribute) or
    not _ods_ir.AttrBuilder.contains('StrAttr')) else
      _ods_ir.AttrBuilder.get('StrAttr')(message, context=_ods_context))
    results = []
    _ods_successors = None
    super().__init__(self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS, attributes=attributes, results=results, operands=operands, successors=_ods_successors, regions=regions, loc=loc, ip=ip)

  @builtins.property
  def at(self) -> _ods_ir.Value:
    return self.operation.operands[0]

  @builtins.property
  def message(self) -> _ods_ir.StringAttr:
    return self.operation.attributes["message"]

  @message.setter
  def message(self, value: _ods_ir.StringAttr):
    if value is None:
      raise ValueError("'None' not allowed as value for mandatory attributes")
    self.operation.attributes["message"] = value

@_ods_cext.register_op_adaptor(EmitRemarkAtOp)
class EmitRemarkAtOpAdaptor(_ods_ir.OpAdaptor):
  OPERATION_NAME = "transform.debug.emit_remark_at"

  @builtins.property
  def at(self) -> _ods_ir.Value:
    return self.operands[0]

  @builtins.property
  def message(self) -> _ods_ir.StringAttr:
    return self.attributes["message"]

def debug_emit_remark_at(at: _ods_ir.Value, message: _Union[str, _ods_ir.StringAttr], *, loc: _Optional[_ods_ir.Location] = None, ip: _Optional[_ods_ir.InsertionPoint] = None) -> EmitRemarkAtOp:
  return EmitRemarkAtOp(at=at, message=message, loc=loc, ip=ip)
