Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Dec 20, 2024
1 parent a5e72c2 commit 7eb608b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
21 changes: 7 additions & 14 deletions xrcf/src/ir/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,12 @@ impl Operation {
}
/// Add a new op result with given name.
pub fn add_new_op_result(&self, name: &str, typ: Arc<RwLock<dyn Type>>) -> UnsetOpResult {
let results = self.results();
let vec = results.vec();
let mut vec = vec.try_write().unwrap();

let mut result = OpResult::default();
result.set_name(name);
result.set_typ(typ);
let op_result = Value::OpResult(result);
let op_result = Shared::new(op_result.into());
vec.push(op_result.clone());
self.results().vec().wr().push(op_result.clone());
UnsetOpResult::new(op_result)
}
pub fn set_region(&mut self, region: Option<Arc<RwLock<Region>>>) {
Expand All @@ -395,14 +391,12 @@ impl Operation {
let mut out = Vec::new();
let results = self.results().vec();
let results = results.rd();
let defines_result = results.len() > 0;
let defines_result = results.len() != 0;
if !defines_result {
return Users::HasNoOpResults;
}
for result in results.iter() {
let result = result.rd();
let result_users = result.users();
match result_users {
match result.rd().users() {
Users::OpOperands(users) => {
for usage in users.iter() {
out.push(usage.clone());
Expand All @@ -414,8 +408,7 @@ impl Operation {
Users::OpOperands(out)
}
pub fn display(&self, f: &mut Formatter<'_>, indent: i32) -> std::fmt::Result {
let spaces = crate::ir::spaces(indent);
write!(f, "{spaces}")?;
write!(f, "{}", crate::ir::spaces(indent))?;
if !self.results().is_empty() {
write!(f, "{} = ", self.results())?;
}
Expand All @@ -425,10 +418,10 @@ impl Operation {
write!(f, " {}", operands)?;
}
write!(f, "{}", self.attributes())?;
let result_types = self.results().types();
if !result_types.vec().is_empty() {
let result_types = self.results().types().into_iter();
if result_types.len() != 0 {
write!(f, " :")?;
for result_type in result_types.vec().iter() {
for result_type in result_types {
write!(f, " {}", result_type.rd())?;
}
}
Expand Down
8 changes: 8 additions & 0 deletions xrcf/src/ir/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ pub struct Types {
types: Vec<Arc<RwLock<dyn Type>>>,
}

impl IntoIterator for Types {
type Item = Arc<RwLock<dyn Type>>;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.types.into_iter()
}
}

impl Types {
pub fn from_vec(types: Vec<Arc<RwLock<dyn Type>>>) -> Self {
Self { types }
Expand Down

0 comments on commit 7eb608b

Please sign in to comment.