Skip to content

Commit c9980b8

Browse files
Pasta-coderCohenArthur
authored andcommitted
backend: Factor out asm operand chaining
This patch introduces a static helper in . This removes code duplication when building tree lists for assembly inputs and outputs. It also removes commented-out debug code to clean up the file. gcc/rust/ChangeLog: * backend/rust-compile-asm.cc (chain_asm_operand): New helper. (CompileAsm::asm_construct_outputs): Use helper and remove dead code. (CompileAsm::asm_construct_inputs): Use helper and remove dead code. Signed-off-by: Jayant Chauhan <[email protected]>
1 parent fccde89 commit c9980b8

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

gcc/rust/backend/rust-compile-asm.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
namespace Rust {
66
namespace Compile {
77

8+
static tree
9+
chain_asm_operand (tree head, const char *constraint, tree value)
10+
{
11+
auto name = build_string (strlen (constraint) + 1, constraint);
12+
return chainon (head,
13+
build_tree_list (build_tree_list (NULL_TREE, name), value));
14+
}
15+
816
CompileAsm::CompileAsm (Context *ctx) : HIRCompileBase (ctx) {}
917

1018
tree
@@ -110,13 +118,7 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
110118
tree out_tree = CompileExpr::Compile (*out_expr, this->ctx);
111119
// expects a tree list
112120
// TODO: This assumes that the output is a register
113-
std::string expr_name = "=r";
114-
auto name = build_string (expr_name.size () + 1, expr_name.c_str ());
115-
head = chainon (head, build_tree_list (build_tree_list (NULL_TREE, name),
116-
out_tree));
117-
118-
/*Backend::debug (head);*/
119-
/*head = chainon (head, out_tree);*/
121+
head = chain_asm_operand (head, "=r", out_tree);
120122
}
121123
return head;
122124
}
@@ -156,12 +158,7 @@ CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
156158
tree in_tree = CompileExpr::Compile (*in_expr, this->ctx);
157159
// expects a tree list
158160
// TODO: This assumes that the input is a register
159-
std::string expr_name = "r";
160-
auto name = build_string (expr_name.size () + 1, expr_name.c_str ());
161-
head = chainon (head, build_tree_list (build_tree_list (NULL_TREE, name),
162-
in_tree));
163-
164-
/*head = chainon (head, out_tree);*/
161+
head = chain_asm_operand (head, "r", in_tree);
165162
}
166163
return head;
167164
}

0 commit comments

Comments
 (0)