diff options
author | jjasmine <tanghocle456@gmail.com> | 2024-05-31 14:55:45 -0700 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:44 +0100 |
commit | bfc249cc179ab1097598bcc5baa726768f5c39c0 (patch) | |
tree | b3392f9326c3ce2ca44ff86da23c3c86287e8568 /gcc | |
parent | a030a5295ea7b840b6696b7ff83ad2870e34cba7 (diff) | |
download | gcc-bfc249cc179ab1097598bcc5baa726768f5c39c0.zip gcc-bfc249cc179ab1097598bcc5baa726768f5c39c0.tar.gz gcc-bfc249cc179ab1097598bcc5baa726768f5c39c0.tar.bz2 |
gccrs: Add support for AST to HIR inline asm translation
gcc/rust/ChangeLog:
* ast/rust-expr.h:
Add support for AST to HIR inline asm translation
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* hir/tree/rust-hir-expr.h (class InlineAsm): Likewise.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 10 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-base.cc | 5 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-base.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.cc | 14 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 60 |
6 files changed, 89 insertions, 2 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index ad742bf..cc8c6ea 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -4994,6 +4994,16 @@ public: void set_outer_attrs (std::vector<Attribute> v) override { outer_attrs = v; } + std::vector<InlineAsmTemplatePiece> get_template_ () { return template_; } + + std::vector<TupleTemplateStr> get_template_strs () { return template_strs; } + + std::vector<InlineAsmOperand> get_operands () { return operands; } + + std::vector<TupleClobber> get_clobber_abi () { return clobber_abi; } + + std::set<InlineAsmOption> get_options () { return options; } + InlineAsm *clone_expr_without_block_impl () const override { return new InlineAsm (*this); diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 9696978..0f928a4 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -248,6 +248,11 @@ ASTLoweringBase::visit (AST::IfLetExpr &) void ASTLoweringBase::visit (AST::IfLetExprConseqElse &) {} + +void +ASTLoweringBase::visit (AST::InlineAsm &) +{} + // void ASTLoweringBase::visit(MatchCasematch_case) {} // void ASTLoweringBase:: (AST::MatchCaseBlockExpr &) {} // void ASTLoweringBase:: (AST::MatchCaseExpr &) {} diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index 94e0e48..1bd1343 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -148,6 +148,7 @@ public: virtual void visit (AST::IfExprConseqElse &expr); virtual void visit (AST::IfLetExpr &expr); virtual void visit (AST::IfLetExprConseqElse &expr); + virtual void visit (AST::InlineAsm &expr); // virtual void visit(MatchCase& match_case); // virtual void visit (AST::MatchCaseBlockExpr &match_case); // virtual void visit (AST::MatchCaseExpr &match_case); diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index a0eb5e3..be7ff41 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -830,6 +830,20 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr) } void +ASTLoweringExpr::visit (AST::InlineAsm &expr) +{ + auto crate_num = mappings.get_current_crate (); + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), + mappings.get_next_hir_id (crate_num), + mappings.get_next_localdef_id (crate_num)); + + translated + = new HIR::InlineAsm (expr.get_locus (), expr.is_global_asm, + expr.get_template_ (), expr.get_template_strs (), + expr.get_operands (), expr.get_clobber_abi (), + expr.get_options (), mapping); +} +void ASTLoweringExpr::visit (AST::FormatArgs &fmt) { rust_sorry_at (fmt.get_locus (), diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index cd7b74a..fc53786 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -122,6 +122,7 @@ public: void visit (AST::RangeFromToInclExpr &expr) override; void visit (AST::ClosureExprInner &expr) override; void visit (AST::ClosureExprInnerTyped &expr) override; + void visit (AST::InlineAsm &expr) override; // Extra visitor for FormatArgs nodes void visit (AST::FormatArgs &fmt) override; diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 686c731..a0858a3 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -24,7 +24,7 @@ #include "rust-hir.h" #include "rust-hir-path.h" #include "rust-operators.h" - +#include "rust-expr.h" namespace Rust { namespace HIR { @@ -3865,13 +3865,69 @@ struct InlineAsmRegOrRegClass class InlineAsm : public ExprWithoutBlock { NodeId id; + location_t locus; public: + bool is_global_asm; + std::vector<AST::InlineAsmTemplatePiece> template_; std::vector<AST::TupleTemplateStr> template_strs; std::vector<AST::InlineAsmOperand> operands; - AST::InlineAsmOption options; + std::vector<AST::TupleClobber> clobber_abi; + std::set<AST::InlineAsmOption> options; + std::vector<location_t> line_spans; + + void accept_vis (HIRExpressionVisitor &vis) override{}; + + void accept_vis (HIRFullVisitor &vis) override{}; + + std::string as_string () const override { return "InlineAsm HIR Node"; } + + location_t get_locus () const override { return locus; } + + InlineAsm *clone_expr_without_block_impl () const override + { + return new InlineAsm (*this); + } + + ExprType get_expression_type () const final override + { + // TODO: Not sure if this expression type is UnsafeBlock or not. + return ExprType::UnsafeBlock; + } + std::vector<AST::InlineAsmTemplatePiece> get_template_ () + { + return template_; + } + + std::vector<AST::TupleTemplateStr> get_template_strs () + { + return template_strs; + } + + std::vector<AST::InlineAsmOperand> get_operands () { return operands; } + + std::vector<AST::TupleClobber> get_clobber_abi () { return clobber_abi; } + + std::set<AST::InlineAsmOption> get_options () { return options; } + + InlineAsm (location_t locus, bool is_global_asm, + std::vector<AST::InlineAsmTemplatePiece> template_, + std::vector<AST::TupleTemplateStr> template_strs, + std::vector<AST::InlineAsmOperand> operands, + std::vector<AST::TupleClobber> clobber_abi, + std::set<AST::InlineAsmOption> options, + Analysis::NodeMapping mappings, + AST::AttrVec outer_attribs = AST::AttrVec ()) + : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)), + locus (locus), is_global_asm (is_global_asm), + template_ (std::move (template_)), + template_strs (std::move (template_strs)), + operands (std::move (operands)), clobber_abi (std::move (clobber_abi)), + options (std::move (options)) + + {} }; } // namespace HIR } // namespace Rust |