Skip to content

Commit

Permalink
Turn to switch case, use new helper functions
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-expr.cc (translate_operand_in):
	Turn to switch case, use new helper functions
	(translate_operand_out): Likewise.
	(translate_operand_inout): Likewise.
	(translate_operand_split_in_out): Likewise.
	(translate_operand_const): Likewise.
	(translate_operand_sym): Likewise.
	(translate_operand_label): Likewise.
	(from_operand): Likewise.
	(ASTLoweringExpr::visit): Likewise.
  • Loading branch information
badumbatish authored and P-E-P committed Aug 1, 2024
1 parent 78a1f76 commit e941015
Showing 1 changed file with 94 additions and 70 deletions.
164 changes: 94 additions & 70 deletions gcc/rust/hir/rust-ast-lower-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "rust-ast.h"
#include "rust-diagnostics.h"
#include "rust-system.h"
#include "tree/rust-hir-expr.h"

namespace Rust {
namespace HIR {
Expand Down Expand Up @@ -829,11 +830,86 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr)
expr.get_locus ());
}

HIR::InlineAsmOperand
translate_operand_in (const AST::InlineAsmOperand &operand)
{
auto in_value = operand.get_in ();

struct HIR::InlineAsmOperand::In in (
in_value.reg,
std::unique_ptr<Expr> (ASTLoweringExpr::translate (*in_value.expr.get ())));
return in;
}

HIR::InlineAsmOperand
translate_operand_out (const AST::InlineAsmOperand &operand)
{
auto out_value = operand.get_out ();
struct HIR::InlineAsmOperand::Out out (out_value.reg, out_value.late,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (
*out_value.expr.get ())));
return out;
}
HIR::InlineAsmOperand
translate_operand_inout (const AST::InlineAsmOperand &operand)
{
auto inout_value = operand.get_in_out ();
struct HIR::InlineAsmOperand::InOut inout (inout_value.reg, inout_value.late,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (
*inout_value.expr.get ())));
return inout;
}
HIR::InlineAsmOperand
translate_operand_split_in_out (const AST::InlineAsmOperand &operand)
{
auto split_in_out_value = operand.get_split_in_out ();
struct HIR::InlineAsmOperand::SplitInOut split_in_out (
split_in_out_value.reg, split_in_out_value.late,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (*split_in_out_value.in_expr.get ())),
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (*split_in_out_value.out_expr.get ())));
return split_in_out;
}
HIR::InlineAsmOperand
translate_operand_const (const AST::InlineAsmOperand &operand)
{
auto const_value = operand.get_const ();
struct HIR::AnonConst anon_const (const_value.anon_const.id,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (
*const_value.anon_const.expr.get ())));
struct HIR::InlineAsmOperand::Const cnst
{
anon_const
};
return cnst;
}

HIR::InlineAsmOperand
translate_operand_sym (const AST::InlineAsmOperand &operand)
{
auto sym_value = operand.get_sym ();
struct HIR::InlineAsmOperand::Sym sym (std::unique_ptr<Expr> (
ASTLoweringExpr::translate (*sym_value.expr.get ())));
return sym;
}
HIR::InlineAsmOperand
translate_operand_label (const AST::InlineAsmOperand &operand)
{
auto label_value = operand.get_label ();
struct HIR::InlineAsmOperand::Label label (label_value.label_name,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (
*label_value.expr.get ())));
return label;
}
HIR::InlineAsmOperand
from_operand (const AST::InlineAsmOperand &operand)
{
using RegisterType = AST::InlineAsmOperand::RegisterType;
using Operand = HIR::InlineAsmOperand;
auto type = operand.get_register_type ();

/*In,*/
Expand All @@ -843,75 +919,23 @@ from_operand (const AST::InlineAsmOperand &operand)
/*Const,*/
/*Sym,*/
/*Label,*/
if (type == RegisterType::In)
{
auto in_value = operand.get_in ();

struct Operand::In in (in_value.reg,
std::unique_ptr<Expr> (ASTLoweringExpr::translate (
*in_value.expr.get ())));
return in;
}
else if (type == RegisterType::Out)
{
auto out_value = operand.get_out ();
struct Operand::Out out (out_value.reg, out_value.late,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (
*out_value.expr.get ())));
return out;
}
else if (type == RegisterType::InOut)
{
auto inout_value = operand.get_in_out ();
struct Operand::InOut inout (inout_value.reg, inout_value.late,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (
*inout_value.expr.get ())));
return inout;
}
else if (type == RegisterType::SplitInOut)
{
auto split_in_out_value = operand.get_split_in_out ();
struct Operand::SplitInOut split_in_out (
split_in_out_value.reg, split_in_out_value.late,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (*split_in_out_value.in_expr.get ())),
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (*split_in_out_value.out_expr.get ())));
return split_in_out;
}
else if (type == RegisterType::Const)
{
auto const_value = operand.get_const ();
struct HIR::AnonConst anon_const (
const_value.anon_const.id,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (*const_value.anon_const.expr.get ())));
struct Operand::Const cnst
{
anon_const
};
return cnst;
}
else if (type == RegisterType::Sym)
{
auto sym_value = operand.get_sym ();
struct Operand::Sym sym (std::unique_ptr<Expr> (
ASTLoweringExpr::translate (*sym_value.expr.get ())));
return sym;
}
else if (type == RegisterType::Label)
{
auto label_value = operand.get_label ();
struct Operand::Label label (label_value.label_name,
std::unique_ptr<Expr> (
ASTLoweringExpr::translate (
*label_value.expr.get ())));
return label;
}
else
switch (type)
{
case RegisterType::In:
return translate_operand_in (operand);
case RegisterType::Out:
return translate_operand_out (operand);
case RegisterType::InOut:
return translate_operand_inout (operand);
case RegisterType::SplitInOut:
return translate_operand_split_in_out (operand);
case RegisterType::Const:
return translate_operand_const (operand);
case RegisterType::Sym:
return translate_operand_sym (operand);
case RegisterType::Label:
return translate_operand_label (operand);
default:
rust_unreachable ();
}
}
Expand All @@ -924,7 +948,7 @@ ASTLoweringExpr::visit (AST::InlineAsm &expr)
mappings.get_next_localdef_id (crate_num));

std::vector<HIR::InlineAsmOperand> hir_operands;
std::vector<AST::InlineAsmOperand> ast_operands = expr.get_operands ();
const std::vector<AST::InlineAsmOperand> &ast_operands = expr.get_operands ();
/*int ast_operands_size = ast_operands.size ();*/
for (auto &operand : ast_operands)
{
Expand Down

0 comments on commit e941015

Please sign in to comment.