Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Sep 27, 2024
1 parent 9323a46 commit f59fd54
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/dialect/llvmir/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ impl Attribute for LinkageAttr {
value: value.to_string(),
}
}
fn name(&self) -> String {
self.name.clone()
}
fn parse<T: Parse>(parser: &mut Parser<T>, name: &str) -> Option<Self> {
let next = parser.peek();
if next.lexeme == "internal" {
Expand Down
25 changes: 18 additions & 7 deletions src/dialect/llvmir/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use crate::ir::AnyAttr;
use crate::ir::Block;
use crate::ir::Op;
use crate::ir::Operation;
use crate::ir::OperationAttributes;
use crate::ir::StrAttr;
use crate::parser::Parser;
use crate::parser::TokenKind;
use crate::Attribute;
use crate::Parse;
use anyhow::Result;
use std::collections::HashMap;
use std::fmt::Formatter;
use std::sync::Arc;
use std::sync::RwLock;
Expand All @@ -36,11 +38,11 @@ impl Op for GlobalOp {
fn display(&self, f: &mut Formatter<'_>, _indent: i32) -> std::fmt::Result {
write!(f, "{} ", Self::operation_name().name())?;
let operation = self.operation().read().unwrap();
for attribute in operation.attributes() {
for (name, attribute) in operation.attributes().read().unwrap().iter() {
write!(f, "{}", attribute)?;
if attribute.name() == "symbol_name" {
if name == "symbol_name" {
write!(f, "(")?;
} else if attribute.name() == "value" {
} else if name == "value" {
} else {
write!(f, " ")?;
}
Expand All @@ -57,10 +59,13 @@ impl Parse for GlobalOp {
) -> Result<Arc<RwLock<dyn Op>>> {
let _operation_name = parser.advance();
let name = GlobalOp::operation_name();
let mut attributes: Vec<Arc<dyn Attribute>> = vec![];
let attributes: OperationAttributes = Arc::new(RwLock::new(HashMap::new()));
if parser.check(TokenKind::BareIdentifier) {
if let Some(attribute) = LinkageAttr::parse(parser, "linkage") {
attributes.push(Arc::new(attribute));
attributes
.write()
.unwrap()
.insert("linkage".to_string(), Arc::new(attribute));
}
}
let symbol_name = parser.peek();
Expand All @@ -71,12 +76,18 @@ impl Parse for GlobalOp {
));
}
if let Some(attribute) = StrAttr::parse(parser, "symbol_name") {
attributes.push(Arc::new(attribute));
attributes
.write()
.unwrap()
.insert("symbol_name".to_string(), Arc::new(attribute));
}
if parser.check(TokenKind::LParen) {
parser.advance();
if let Some(attribute) = AnyAttr::parse(parser, "value") {
attributes.push(Arc::new(attribute));
attributes
.write()
.unwrap()
.insert("value".to_string(), Arc::new(attribute));
}
}
println!("{:?}", parser.advance());
Expand Down
1 change: 1 addition & 0 deletions src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub use crate::ir::module::ModuleOp;
pub use crate::ir::op::Op;
pub use crate::ir::operation::Operation;
pub use crate::ir::operation::OperationArguments;
pub use crate::ir::operation::OperationAttributes;
pub use crate::ir::operation::OperationName;
pub use crate::ir::operation::OperationOperands;
pub use crate::ir::region::Region;
Expand Down

0 comments on commit f59fd54

Please sign in to comment.