From: Jayant Chauhan <[email protected]>
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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/c9980b8356b3eb98947366da01d5b0554827ab03
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4397
gcc/rust/backend/rust-compile-asm.cc | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/gcc/rust/backend/rust-compile-asm.cc
b/gcc/rust/backend/rust-compile-asm.cc
index b7143a817..be0305a6e 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -5,6 +5,14 @@
namespace Rust {
namespace Compile {
+static tree
+chain_asm_operand (tree head, const char *constraint, tree value)
+{
+ auto name = build_string (strlen (constraint) + 1, constraint);
+ return chainon (head,
+ build_tree_list (build_tree_list (NULL_TREE, name), value));
+}
+
CompileAsm::CompileAsm (Context *ctx) : HIRCompileBase (ctx) {}
tree
@@ -110,13 +118,7 @@ CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
tree out_tree = CompileExpr::Compile (*out_expr, this->ctx);
// expects a tree list
// TODO: This assumes that the output is a register
- std::string expr_name = "=r";
- auto name = build_string (expr_name.size () + 1, expr_name.c_str ());
- head = chainon (head, build_tree_list (build_tree_list (NULL_TREE, name),
- out_tree));
-
- /*Backend::debug (head);*/
- /*head = chainon (head, out_tree);*/
+ head = chain_asm_operand (head, "=r", out_tree);
}
return head;
}
@@ -156,12 +158,7 @@ CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
tree in_tree = CompileExpr::Compile (*in_expr, this->ctx);
// expects a tree list
// TODO: This assumes that the input is a register
- std::string expr_name = "r";
- auto name = build_string (expr_name.size () + 1, expr_name.c_str ());
- head = chainon (head, build_tree_list (build_tree_list (NULL_TREE, name),
- in_tree));
-
- /*head = chainon (head, out_tree);*/
+ head = chain_asm_operand (head, "r", in_tree);
}
return head;
}
base-commit: fccde896e5c095449d1df0594d82ffa3b95798d8
--
2.52.0