aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorjjasmine <tanghocle456@gmail.com>2024-05-28 21:56:19 -0700
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:43 +0100
commit256bb62f995625ff32748e479b371c20082189ba (patch)
treefcbee9189caa2ed95855d87e9f5272eaef8aa824 /gcc/rust
parent5d2d1a2d9818bcde16e0c41df450e2537fb1fee4 (diff)
downloadgcc-256bb62f995625ff32748e479b371c20082189ba.zip
gcc-256bb62f995625ff32748e479b371c20082189ba.tar.gz
gcc-256bb62f995625ff32748e479b371c20082189ba.tar.bz2
gccrs: Got AST::Fragment to be created from InlineAsm
gcc/rust/ChangeLog: * ast/rust-expr.h (struct AnonConst): Got AST::Fragment to be created from InlineAsm. (struct InlineAsmOperand): Likewise. (class InlineAsm): Likewise. * expand/rust-macro-builtins-asm.cc (parse_reg_operand): Likewise. (parse_asm): likewise
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/ast/rust-expr.h129
-rw-r--r--gcc/rust/expand/rust-macro-builtins-asm.cc31
2 files changed, 150 insertions, 10 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 76e5fa7..1284c73 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -6,6 +6,7 @@
#include "rust-path.h"
#include "rust-macro.h"
#include "rust-operators.h"
+#include <memory>
namespace Rust {
namespace AST {
@@ -4723,6 +4724,23 @@ struct AnonConst
{
NodeId id;
std::unique_ptr<Expr> value;
+ AnonConst () {}
+ AnonConst (const AnonConst &other)
+ {
+ id = other.id;
+ value = other.value == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.value->clone_expr ());
+ }
+
+ AnonConst operator= (const AnonConst &other)
+ {
+ id = other.id;
+ value = other.value == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.value->clone_expr ());
+ return *this;
+ }
};
struct InlineAsmRegOrRegClass
@@ -4767,6 +4785,25 @@ struct InlineAsmOperand
{
InlineAsmRegOrRegClass reg;
std::unique_ptr<Expr> expr;
+
+ In () {}
+ In (const struct In &other)
+ {
+ reg = other.reg;
+ expr = other.expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.expr->clone_expr ());
+ }
+
+ In operator= (const struct In &other)
+ {
+ reg = other.reg;
+ expr = other.expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.expr->clone_expr ());
+
+ return *this;
+ }
};
struct Out
@@ -4774,6 +4811,26 @@ struct InlineAsmOperand
InlineAsmRegOrRegClass reg;
bool late;
std::unique_ptr<Expr> expr; // can be null
+
+ Out () {}
+ Out (const struct Out &other)
+ {
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.expr->clone_expr ());
+ }
+
+ Out operator= (const struct Out &other)
+ {
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.expr->clone_expr ());
+ return *this;
+ }
};
struct InOut
@@ -4781,6 +4838,26 @@ struct InlineAsmOperand
InlineAsmRegOrRegClass reg;
bool late;
std::unique_ptr<Expr> expr; // this can't be null
+
+ InOut () {}
+ InOut (const struct InOut &other)
+ {
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.expr->clone_expr ());
+ }
+
+ InOut operator= (const struct InOut &other)
+ {
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.expr->clone_expr ());
+ return *this;
+ }
};
struct SplitInOut
@@ -4789,6 +4866,33 @@ struct InlineAsmOperand
bool late;
std::unique_ptr<Expr> in_expr;
std::unique_ptr<Expr> out_expr; // could be null
+
+ SplitInOut () {}
+ SplitInOut (const struct SplitInOut &other)
+ {
+ reg = other.reg;
+ late = other.late;
+ in_expr = other.in_expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.in_expr->clone_expr ());
+ out_expr = other.out_expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.out_expr->clone_expr ());
+ }
+
+ SplitInOut operator= (const struct SplitInOut &other)
+ {
+ reg = other.reg;
+ late = other.late;
+ in_expr = other.in_expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.in_expr->clone_expr ());
+ out_expr = other.out_expr == nullptr
+ ? nullptr
+ : std::unique_ptr<Expr> (other.out_expr->clone_expr ());
+
+ return *this;
+ }
};
struct Const
@@ -4799,6 +4903,18 @@ struct InlineAsmOperand
struct Sym
{
std::unique_ptr<Expr> sym;
+
+ Sym () {}
+ Sym (const struct Sym &other)
+ {
+ sym = std::unique_ptr<Expr> (other.sym->clone_expr ());
+ }
+
+ Sym operator= (const struct Sym &other)
+ {
+ sym = std::unique_ptr<Expr> (other.sym->clone_expr ());
+ return *this;
+ }
};
RegisterType registerType;
@@ -4809,6 +4925,12 @@ struct InlineAsmOperand
struct Const cnst;
struct Sym sym;
+ InlineAsmOperand () {}
+ InlineAsmOperand (const InlineAsmOperand &other)
+ : in (other.in), out (other.out), inOut (other.inOut),
+ splitInOut (other.splitInOut), cnst (other.cnst), sym (other.sym)
+ {}
+
location_t locus;
};
@@ -4842,7 +4964,7 @@ struct TupleTemplateStr
};
// Inline Assembly Node
-class InlineAsm : private ExprWithoutBlock
+class InlineAsm : public ExprWithoutBlock
{
private:
location_t locus;
@@ -4878,10 +5000,9 @@ public:
void set_outer_attrs (std::vector<Attribute> v) override { outer_attrs = v; }
- ExprWithoutBlock *clone_expr_without_block_impl () const override
+ InlineAsm *clone_expr_without_block_impl () const override
{
- rust_unreachable ();
- return nullptr;
+ return new InlineAsm (*this);
}
};
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 9e02400..ee57f7f 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -220,27 +220,40 @@ parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
bool is_explicit_reg = false;
bool is_global_asm = inlineAsm.is_global_asm;
if (!is_global_asm && check_identifier (parser, "in"))
- {}
+ {
+ return tl::nullopt;
+ }
else if (!is_global_asm && check_identifier (parser, "out"))
- {}
+ {
+ return tl::nullopt;
+ }
else if (!is_global_asm && check_identifier (parser, "lateout"))
- {}
+ {
+ return tl::nullopt;
+ }
else if (!is_global_asm && check_identifier (parser, "inout"))
- {}
+ {
+ return tl::nullopt;
+ }
else if (!is_global_asm && check_identifier (parser, "inlateout"))
- {}
+ {
+ return tl::nullopt;
+ }
else if (parser.peek_current_token ()->get_id () == CONST)
{
rust_unreachable ();
// todo: Please handle const
+ return tl::nullopt;
}
else if (false && check_identifier (parser, "sym"))
{
// todo: Please handle sym
+ return tl::nullopt;
}
else if (false && check_identifier (parser, "label"))
{
// todo: Please handle label
+ return tl::nullopt;
}
else
{
@@ -518,7 +531,13 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
// operands stream, also handles the optional ","
parse_asm_arg (parser, last_token_id, inlineAsmCtx);
- return tl::nullopt;
+ AST::SingleASTNode single
+ = AST::SingleASTNode (inlineAsmCtx.inlineAsm.clone_expr_without_block ());
+ std::vector<AST::SingleASTNode> single_vec = {single};
+
+ AST::Fragment fragment_ast
+ = AST::Fragment (single_vec, std::vector<std::unique_ptr<AST::Token>> ());
+ return fragment_ast;
}
} // namespace Rust