Skip to content

Commit

Permalink
Got AST::Fragment to be created from InlineAsm
Browse files Browse the repository at this point in the history
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
  • Loading branch information
badumbatish committed May 30, 2024
1 parent 347d10d commit fedb5ed
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 10 deletions.
129 changes: 125 additions & 4 deletions gcc/rust/ast/rust-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "rust-path.h"
#include "rust-macro.h"
#include "rust-operators.h"
#include <memory>

namespace Rust {
namespace AST {
Expand Down Expand Up @@ -4620,6 +4621,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
Expand Down Expand Up @@ -4664,20 +4682,79 @@ 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
{
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
{
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
Expand All @@ -4686,6 +4763,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
Expand All @@ -4696,6 +4800,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;

Expand All @@ -4706,6 +4822,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;
};

Expand Down Expand Up @@ -4739,7 +4861,7 @@ struct TupleTemplateStr
};

// Inline Assembly Node
class InlineAsm : private ExprWithoutBlock
class InlineAsm : public ExprWithoutBlock
{
private:
location_t locus;
Expand Down Expand Up @@ -4775,10 +4897,9 @@ class InlineAsm : private ExprWithoutBlock

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);
}
};

Expand Down
31 changes: 25 additions & 6 deletions gcc/rust/expand/rust-macro-builtins-asm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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

0 comments on commit fedb5ed

Please sign in to comment.