diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 749fdc05f2ba..438d3d3b86eb 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -4771,7 +4771,7 @@ struct InlineAsmRegOrRegClass class InlineAsmOperand { public: - enum RegisterType + enum class RegisterType { In, Out, @@ -4782,8 +4782,24 @@ class InlineAsmOperand Label, }; - struct In + class Register { + public: + Register () {} + virtual ~Register () = default; + + std::unique_ptr clone () const + { + return std::unique_ptr (clone_impl ()); + } + + protected: + virtual Register *clone_impl () const = 0; + }; + + class In : public Register + { + public: tl::optional reg; std::unique_ptr expr; @@ -4808,10 +4824,14 @@ class InlineAsmOperand return *this; } + + private: + In *clone_impl () const { return new In (*this); } }; - struct Out + class Out : public Register { + public: tl::optional reg; bool late; std::unique_ptr expr; // can be null @@ -4837,10 +4857,14 @@ class InlineAsmOperand expr = other.expr->clone_expr (); return *this; } + + private: + Out *clone_impl () const { return new Out (*this); } }; - struct InOut + class InOut : public Register { + public: tl::optional reg; bool late; std::unique_ptr expr; // this can't be null @@ -4867,10 +4891,14 @@ class InlineAsmOperand return *this; } + + private: + InOut *clone_impl () const { return new InOut (*this); } }; - struct SplitInOut + class SplitInOut : public Register { + public: tl::optional reg; bool late; std::unique_ptr in_expr; @@ -4902,15 +4930,23 @@ class InlineAsmOperand return *this; } + + private: + SplitInOut *clone_impl () const { return new SplitInOut (*this); } }; - struct Const + class Const : public Register { + public: AnonConst anon_const; + + private: + Const *clone_impl () const { return new Const (*this); } }; - struct Sym + class Sym : public Register { + public: std::unique_ptr expr; Sym (std::unique_ptr expr) : expr (std::move (expr)) @@ -4927,10 +4963,14 @@ class InlineAsmOperand expr = std::unique_ptr (other.expr->clone_expr ()); return *this; } + + private: + Sym *clone_impl () const { return new Sym (*this); } }; - struct Label + class Label : public Register { + public: std::string label_name; std::unique_ptr expr; @@ -4951,27 +4991,37 @@ class InlineAsmOperand expr = std::unique_ptr (other.expr->clone_expr ()); return *this; } + + private: + Label *clone_impl () const { return new Label (*this); } }; InlineAsmOperand (const InlineAsmOperand &other) - : register_type (other.register_type), in (other.in), out (other.out), - in_out (other.in_out), split_in_out (other.split_in_out), - cnst (other.cnst), sym (other.sym) + : register_type (other.register_type), locus (other.locus), + reg (other.reg->clone ()) {} - InlineAsmOperand (const struct In ®) : register_type (In), in (reg) {} - InlineAsmOperand (const struct Out ®) : register_type (Out), out (reg) {} - InlineAsmOperand (const struct InOut ®) - : register_type (InOut), in_out (reg) + InlineAsmOperand (const In ®, location_t locus) + : register_type (RegisterType::In), locus (locus), reg (new In (reg)) + {} + InlineAsmOperand (const Out ®, location_t locus) + : register_type (RegisterType::Out), locus (locus), reg (new Out (reg)) + {} + InlineAsmOperand (const InOut ®, location_t locus) + : register_type (RegisterType::InOut), locus (locus), reg (new InOut (reg)) + {} + InlineAsmOperand (const SplitInOut ®, location_t locus) + : register_type (RegisterType::SplitInOut), locus (locus), + reg (new SplitInOut (reg)) {} - InlineAsmOperand (const struct SplitInOut ®) - : register_type (SplitInOut), split_in_out (reg) + InlineAsmOperand (const Const ®, location_t locus) + : register_type (RegisterType::Const), locus (locus), reg (new Const (reg)) {} - InlineAsmOperand (const struct Const ®) : register_type (Const), cnst (reg) + InlineAsmOperand (const Sym ®, location_t locus) + : register_type (RegisterType::Sym), locus (locus), reg (new Sym (reg)) {} - InlineAsmOperand (const struct Sym ®) : register_type (Sym), sym (reg) {} - InlineAsmOperand (const struct Label ®) - : register_type (Label), label (reg) + InlineAsmOperand (const Label ®, location_t locus) + : register_type (RegisterType::Label), locus (locus), reg (new Label (reg)) {} location_t get_locus () const { return locus; } @@ -4980,25 +5030,88 @@ class InlineAsmOperand // Potentially fail immediately if you don't use get_register_type() to // inspect the RegisterType first before calling the following functions Check // first - struct In get_in () const { return in.value (); } - struct Out get_out () const { return out.value (); } - struct InOut get_in_out () const { return in_out.value (); } - struct SplitInOut get_split_in_out () const { return split_in_out.value (); } - struct Const get_const () const { return cnst.value (); } - struct Sym get_sym () const { return sym.value (); } - struct Label get_label () const { return label.value (); } + In &get_in () + { + rust_assert (register_type == RegisterType::In); + return static_cast (*reg); + } + const In &get_in () const + { + rust_assert (register_type == RegisterType::In); + return static_cast (*reg); + } + + Out &get_out () + { + rust_assert (register_type == RegisterType::Out); + return static_cast (*reg); + } + const Out &get_out () const + { + rust_assert (register_type == RegisterType::Out); + return static_cast (*reg); + } + + InOut &get_in_out () + { + rust_assert (register_type == RegisterType::InOut); + return static_cast (*reg); + } + const InOut &get_in_out () const + { + rust_assert (register_type == RegisterType::InOut); + return static_cast (*reg); + } + + SplitInOut &get_split_in_out () + { + rust_assert (register_type == RegisterType::SplitInOut); + return static_cast (*reg); + } + const SplitInOut &get_split_in_out () const + { + rust_assert (register_type == RegisterType::SplitInOut); + return static_cast (*reg); + } + + Const &get_const () + { + rust_assert (register_type == RegisterType::Const); + return static_cast (*reg); + } + const Const &get_const () const + { + rust_assert (register_type == RegisterType::Const); + return static_cast (*reg); + } + + Sym &get_sym () + { + rust_assert (register_type == RegisterType::Sym); + return static_cast (*reg); + } + const Sym &get_sym () const + { + rust_assert (register_type == RegisterType::Sym); + return static_cast (*reg); + } + + Label &get_label () + { + rust_assert (register_type == RegisterType::Label); + return static_cast