Skip to content

Commit

Permalink
Use ';' as separator b/w Operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vaivaswatha committed Oct 24, 2023
1 parent dbae825 commit c297c16
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ impl Printable for BasicBlock {
f,
"{}{}",
indented_nl(state),
self.iter(ctx).iprint(ctx, state, ListSeparator::Newline)
self.iter(ctx)
.iprint(ctx, state, ListSeparator::CharNewline(';'))
)?;
});

Expand Down
11 changes: 3 additions & 8 deletions src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ fn get_name_from_attr_map(
// dict\[[DEBUG_INFO_NAME]\] is a [VecAttr] with [UnitAttr] entries
// for unknown names and [StringAttr] for known names. The length of
// this array is always the same as the number of results.
pub fn set_operation_result_name(
ctx: &mut Context,
op: Ptr<Operation>,
res_idx: usize,
name: String,
) {
pub fn set_operation_result_name(ctx: &Context, op: Ptr<Operation>, res_idx: usize, name: String) {
let op = &mut *op.deref_mut(ctx);
let num_results = op.get_num_results();
assert!(res_idx < num_results);
Expand All @@ -86,7 +81,7 @@ pub fn set_operation_result_name(
}

/// Get name for a result in an [Operation].
// See [get_operation_result_name] for attribute storage convention.
// See [set_operation_result_name] for attribute storage convention.
pub fn get_operation_result_name(
ctx: &Context,
op: Ptr<Operation>,
Expand All @@ -105,7 +100,7 @@ pub fn get_operation_result_name(
// dict\[[DEBUG_INFO_NAME]\] is a [VecAttr] with [UnitAttr] entries
// for unknown names and [StringAttr] for known names. The length of
// this array is always the same as the number of arguments.
pub fn set_block_arg_name(ctx: &mut Context, block: Ptr<BasicBlock>, arg_idx: usize, name: String) {
pub fn set_block_arg_name(ctx: &Context, block: Ptr<BasicBlock>, arg_idx: usize, name: String) {
let block = &mut *block.deref_mut(ctx);
let num_args = block.get_num_arguments();
assert!(arg_idx < num_args);
Expand Down
2 changes: 1 addition & 1 deletion src/dialects/llvm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl Printable for StructType {
"{{ {} }}",
self.fields
.iter()
.iprint(ctx, state, printable::ListSeparator::SpacedChar(','))
.iprint(ctx, state, printable::ListSeparator::CharSpace(','))
)?;

// Done processing this struct. Remove it from the stack.
Expand Down
10 changes: 8 additions & 2 deletions src/printable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ impl<'a, T: Printable> Printable for &'a T {
pub enum ListSeparator {
/// Newline
Newline,
/// Character followed by a newline.
CharNewline(char),
/// Single character
Char(char),
/// Single character followed by a space
SpacedChar(char),
CharSpace(char),
}

/// Iterate over [Item](Iterator::Item)s in an [Iterator] and print them.
Expand All @@ -193,10 +195,14 @@ where
ListSeparator::Newline => {
fmt_indented_newline(state, f)?;
}
ListSeparator::CharNewline(c) => {
write!(f, "{}", c)?;
fmt_indented_newline(state, f)?;
}
ListSeparator::Char(c) => {
write!(f, "{}", c)?;
}
ListSeparator::SpacedChar(c) => {
ListSeparator::CharSpace(c) => {
write!(f, "{} ", c)?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn const_ret_in_mod(ctx: &mut Context) -> Result<(ModuleOp, FuncOp, Constant
block_0_0():
builtin.func @foo: builtin.function <() -> (builtin.integer <si64>)> {
entry():
c0 = builtin.constant 0x0: builtin.integer <si64>
c0 = builtin.constant 0x0: builtin.integer <si64>;
llvm.return c0
}
}"#]]
Expand Down
6 changes: 3 additions & 3 deletions tests/ir_construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ fn replace_c0_with_c1_operand() -> Result<()> {
block_0_0():
builtin.func @foo: builtin.function <() -> (builtin.integer <si64>)> {
entry():
c0 = builtin.constant 0x0: builtin.integer <si64>
c1 = builtin.constant 0x1: builtin.integer <si64>
c0 = builtin.constant 0x0: builtin.integer <si64>;
c1 = builtin.constant 0x1: builtin.integer <si64>;
llvm.return c0
}
}"#]]
Expand All @@ -106,7 +106,7 @@ fn replace_c0_with_c1_operand() -> Result<()> {
block_0_0():
builtin.func @foo: builtin.function <() -> (builtin.integer <si64>)> {
entry():
c1 = builtin.constant 0x1: builtin.integer <si64>
c1 = builtin.constant 0x1: builtin.integer <si64>;
llvm.return c1
}
}"#]]
Expand Down

0 comments on commit c297c16

Please sign in to comment.