https://gcc.gnu.org/g:bfc249cc179ab1097598bcc5baa726768f5c39c0
commit r15-8191-gbfc249cc179ab1097598bcc5baa726768f5c39c0 Author: jjasmine <tanghocle...@gmail.com> Date: Fri May 31 14:55:45 2024 -0700 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. Diff: --- gcc/rust/ast/rust-expr.h | 10 +++++++ gcc/rust/hir/rust-ast-lower-base.cc | 5 ++++ gcc/rust/hir/rust-ast-lower-base.h | 1 + gcc/rust/hir/rust-ast-lower-expr.cc | 14 +++++++++ gcc/rust/hir/rust-ast-lower-expr.h | 1 + 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 ad742bfe85d6..cc8c6ea03500 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 96969782c98f..0f928a4f4620 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 94e0e48968ca..1bd1343bd166 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 a0eb5e32f25b..be7ff413c93f 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -829,6 +829,20 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr) expr.get_locus ()); } +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) { diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index cd7b74aa7f2b..fc53786613b3 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 686c7311a4b3..a0858a36f04c 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