aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-asm.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2025-04-15 11:38:29 +0200
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2025-04-17 18:05:17 +0000
commit3e8955884cd816e43a52a0dda31399c01d2d8761 (patch)
tree6eae6fa978d9cabc0f4e6a41aa33d47a3feb8ccf /gcc/rust/backend/rust-compile-asm.cc
parent435b346f47ffa467bb6cfa1717ab9f2283b18d46 (diff)
downloadgcc-3e8955884cd816e43a52a0dda31399c01d2d8761.zip
gcc-3e8955884cd816e43a52a0dda31399c01d2d8761.tar.gz
gcc-3e8955884cd816e43a52a0dda31399c01d2d8761.tar.bz2
Parse and lower llvm asm node
Add a new HIR LlvmInlineAsm HIR node as well as some structures to represent it's options and operands. Lower AST::LlvmInlineAsm node to it and then create a tree from that node. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove unreachable code. * ast/rust-expr.h (struct LlvmOperand): Add LlvmOperand struct to represent input and outputs. (class LlvmInlineAsm): Add input, output and clobber operands. (struct TupleTemplateStr): Add locus getter. * backend/rust-compile-block.h: Add visit for LlvmInlineAsm. * backend/rust-compile-expr.cc (CompileExpr::visit): Add llvm inline asm stmt compilation. * backend/rust-compile-expr.h: Add function prototype. * backend/rust-compile-asm.h (class CompileLlvmAsm): Add llvm asm hir not to gimple. * backend/rust-compile-asm.cc (CompileLlvmAsm::CompileLlvmAsm): Add constructor. (CompileLlvmAsm::construct_operands): Add function to construct operand tree. (CompileLlvmAsm::construct_clobbers): Add function to construct clobber tree. (CompileLlvmAsm::tree_codegen_asm): Generate the whole tree for a given llvm inline assembly node. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Add visit function. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Add function prototype. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Add visit function. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Add visit function prototype. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Add visit function. * checks/errors/rust-const-checker.h: Add visit function prototype. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Add visit function. * checks/errors/rust-hir-pattern-analysis.h: Add visit function prototype. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Add visit function. * checks/errors/rust-unsafe-checker.h: Add function prototype. * expand/rust-macro-builtins-asm.cc (parse_llvm_templates): Parse templates. (parse_llvm_arguments): Add function to parse non template tokens. (parse_llvm_operands): Add function to parse operands, either input or output. (parse_llvm_outputs): Add function to parse and collect llvm asm outputs. (parse_llvm_inputs): Likewise with inputs. (parse_llvm_clobbers): Add function to parse llvm asm clobbers. (parse_llvm_options): Add function to parse llvm asm options. (parse_llvm_asm): Add function to parse llvm asm. * expand/rust-macro-builtins-asm.h (class LlvmAsmContext): Add context for llvm asm parser. (parse_llvm_outputs): Add function prototype. (parse_llvm_inputs): Likewise. (parse_llvm_clobbers): Likewise. (parse_llvm_options): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower AST llvm asm node to HIR. * hir/rust-ast-lower-expr.h: Add function prototype. * hir/rust-hir-dump.cc (Dump::visit): Add visit function. * hir/rust-hir-dump.h: Add function prototype. * hir/tree/rust-hir-expr-abstract.h: Add HIR llvm asm node kind. * hir/tree/rust-hir-expr.h (struct LlvmOperand): Add LlvmOperand type to represent input and outputs. (class LlvmInlineAsm): Add LlvmInlineAsm hir node. * hir/tree/rust-hir-full-decls.h (class LlvmInlineAsm): Add LlvmInlineAsm hir node forward declaration. * hir/tree/rust-hir-visitor.h: Add visit functions for LlvmInlineAsm hir node. * hir/tree/rust-hir.cc (LlvmInlineAsm::accept_vis): Add hir node visitor related functions. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Type check input and output operands. * typecheck/rust-hir-type-check-expr.h: Add function prototype. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit input and output operand expressions. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve input and output expressions. * resolve/rust-ast-resolve-expr.h: Add function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-asm.cc')
-rw-r--r--gcc/rust/backend/rust-compile-asm.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-asm.cc b/gcc/rust/backend/rust-compile-asm.cc
index 3a22658..f04a03e 100644
--- a/gcc/rust/backend/rust-compile-asm.cc
+++ b/gcc/rust/backend/rust-compile-asm.cc
@@ -1,5 +1,7 @@
#include "rust-compile-asm.h"
#include "rust-compile-expr.h"
+#include "rust-system.h"
+
namespace Rust {
namespace Compile {
@@ -141,5 +143,57 @@ CompileAsm::asm_construct_label_tree (HIR::InlineAsm &expr)
return NULL_TREE;
}
+CompileLlvmAsm::CompileLlvmAsm (Context *ctx) : HIRCompileBase (ctx) {}
+
+tree
+CompileLlvmAsm::construct_operands (std::vector<HIR::LlvmOperand> operands)
+{
+ tree head = NULL_TREE;
+ for (auto &operand : operands)
+ {
+ tree t = CompileExpr::Compile (*operand.expr, this->ctx);
+ auto name = build_string (operand.constraint.size () + 1,
+ operand.constraint.c_str ());
+ head = chainon (head,
+ build_tree_list (build_tree_list (NULL_TREE, name), t));
+ }
+ return head;
+}
+
+tree
+CompileLlvmAsm::construct_clobbers (std::vector<AST::TupleClobber> clobbers)
+{
+ tree head = NULL_TREE;
+ for (auto &clobber : clobbers)
+ {
+ auto name
+ = build_string (clobber.symbol.size () + 1, clobber.symbol.c_str ());
+ head = chainon (head, build_tree_list (NULL_TREE, name));
+ }
+ return head;
+}
+
+tree
+CompileLlvmAsm::tree_codegen_asm (HIR::LlvmInlineAsm &expr)
+{
+ tree ret = make_node (ASM_EXPR);
+ TREE_TYPE (ret) = void_type_node;
+ SET_EXPR_LOCATION (ret, expr.get_locus ());
+ ASM_VOLATILE_P (ret) = expr.options.is_volatile;
+
+ std::stringstream ss;
+ for (const auto &template_str : expr.templates)
+ {
+ ss << template_str.symbol << "\n";
+ }
+
+ ASM_STRING (ret) = Backend::string_constant_expression (ss.str ());
+ ASM_INPUTS (ret) = construct_operands (expr.inputs);
+ ASM_OUTPUTS (ret) = construct_operands (expr.outputs);
+ ASM_CLOBBERS (ret) = construct_clobbers (expr.get_clobbers ());
+
+ return ret;
+}
+
} // namespace Compile
} // namespace Rust