Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-context-to-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Peefy authored Aug 25, 2024
2 parents 2dfb480 + 91a2270 commit 4cc7e64
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions melior/src/ir/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod result;
pub use self::{
builder::OperationBuilder, printing_flags::OperationPrintingFlags, result::OperationResult,
};
use super::{Attribute, AttributeLike, BlockRef, Identifier, RegionRef, Value};
use super::{Attribute, AttributeLike, BlockRef, Identifier, Location, RegionRef, Value};
use crate::{
context::{Context, ContextRef},
utility::{print_callback, print_string_callback},
Expand All @@ -20,12 +20,12 @@ use core::{
use mlir_sys::{
mlirOperationClone, mlirOperationDestroy, mlirOperationDump, mlirOperationEqual,
mlirOperationGetAttribute, mlirOperationGetAttributeByName, mlirOperationGetBlock,
mlirOperationGetContext, mlirOperationGetName, mlirOperationGetNextInBlock,
mlirOperationGetNumAttributes, mlirOperationGetNumOperands, mlirOperationGetNumRegions,
mlirOperationGetNumResults, mlirOperationGetNumSuccessors, mlirOperationGetOperand,
mlirOperationGetParentOperation, mlirOperationGetRegion, mlirOperationGetResult,
mlirOperationGetSuccessor, mlirOperationPrint, mlirOperationPrintWithFlags,
mlirOperationRemoveAttributeByName, mlirOperationRemoveFromParent,
mlirOperationGetContext, mlirOperationGetLocation, mlirOperationGetName,
mlirOperationGetNextInBlock, mlirOperationGetNumAttributes, mlirOperationGetNumOperands,
mlirOperationGetNumRegions, mlirOperationGetNumResults, mlirOperationGetNumSuccessors,
mlirOperationGetOperand, mlirOperationGetParentOperation, mlirOperationGetRegion,
mlirOperationGetResult, mlirOperationGetSuccessor, mlirOperationPrint,
mlirOperationPrintWithFlags, mlirOperationRemoveAttributeByName, mlirOperationRemoveFromParent,
mlirOperationSetAttributeByName, mlirOperationVerify, MlirOperation,
};
use std::{
Expand Down Expand Up @@ -130,6 +130,11 @@ impl<'c> Operation<'c> {
(0..self.region_count()).map(|index| self.region(index).expect("valid result index"))
}

/// Gets the location of the operation.
pub fn location(&self) -> Location<'c> {
unsafe { Location::from_raw(mlirOperationGetLocation(self.raw)) }
}

/// Returns the number of successors.
pub fn successor_count(&self) -> usize {
unsafe { mlirOperationGetNumSuccessors(self.raw) as usize }
Expand Down Expand Up @@ -644,6 +649,20 @@ mod tests {
);
}

#[test]
fn location() {
let context = create_test_context();
context.set_allow_unregistered_dialects(true);
let location = Location::new(&context, "test", 1, 1);

let operation = OperationBuilder::new("foo", location)
.add_regions([Region::new()])
.build()
.unwrap();

assert_eq!(operation.location(), location);
}

#[test]
fn attribute() {
let context = create_test_context();
Expand Down

0 comments on commit 4cc7e64

Please sign in to comment.