Skip to content

Commit

Permalink
Scaffolding new compile-asm files
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* Make-lang.in:
	Scaffolding new compile-asm files
	* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise
	* hir/tree/rust-hir-expr.h: Likewise
	* backend/rust-compile-asm.cc: New file. Likewise
	* backend/rust-compile-asm.h: New file. Likewise
  • Loading branch information
badumbatish committed Jul 1, 2024
1 parent 3906eec commit 2855b64
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 40 deletions.
1 change: 1 addition & 0 deletions gcc/rust/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ GRS_OBJS = \
rust/rust-compile-item.o \
rust/rust-compile-implitem.o \
rust/rust-compile-stmt.o \
rust/rust-compile-asm.o \
rust/rust-compile-expr.o \
rust/rust-compile-type.o \
rust/rust-compile-block.o \
Expand Down
80 changes: 80 additions & 0 deletions gcc/rust/backend/rust-compile-asm.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "rust-compile-asm.h"

#include "rust-tree.h"
#include "rust-system.h"
namespace Rust {
namespace Compile {

tree
CompileAsm::asm_build_expr (HIR::InlineAsm &expr)
{
return NULL_TREE;
// return build_asm_expr (CompileAsm::asm_get_locus (expr),
// CompileAsm::asm_construct_string_tree (expr),
// CompileAsm::asm_construct_outputs (expr),
// CompileAsm::asm_construct_inputs (expr),
// CompileAsm::asm_construct_clobber_tree (expr),
// CompileAsm::asm_construct_label_tree (expr),
// CompileAsm::asm_is_simple (expr),
// CompileAsm::asm_is_inline (expr));
}

location_t
CompileAsm::asm_get_locus (HIR::InlineAsm &expr)
{
return expr.get_locus ();
}
tree
CompileAsm::asm_construct_string_tree (HIR::InlineAsm &expr)
{
if (expr.template_strs.empty ())
return build_string (1, "");
// Initialize to NULL_TREE
tree string_chain = NULL_TREE;

for (const auto &template_str : expr.template_strs)
{
auto str = template_str.symbol;
auto string_tree = build_string (str.size () + 1, str.c_str ());

string_chain = tree_cons (NULL_TREE, string_tree, string_chain);
}
// Reverse the chain before returning
return nreverse (string_chain);
}
tree
CompileAsm::asm_construct_outputs (HIR::InlineAsm &expr)
{
return NULL_TREE;
}

tree
CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
{
return NULL_TREE;
}

tree
CompileAsm::asm_construct_clobber_tree (HIR::InlineAsm &expr)
{
return NULL_TREE;
}
tree
CompileAsm::asm_construct_label_tree (HIR::InlineAsm &expr)
{
return NULL_TREE;
}

bool
CompileAsm::asm_is_simple (HIR::InlineAsm &expr)
{
return true;
}

bool
CompileAsm::asm_is_inline (HIR::InlineAsm &expr)
{
return true;
}
} // namespace Compile
} // namespace Rust
46 changes: 46 additions & 0 deletions gcc/rust/backend/rust-compile-asm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

// Copyright (C) 2020-2024 Free Software Foundation, Inc.

// This file is part of GCC.

// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.

// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.

// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.

#ifndef RUST_COMPILE_ASM
#define RUST_COMPILE_ASM

#include "rust-compile-base.h"
#include "rust-hir-visitor.h"

namespace Rust {
namespace Compile {

class CompileAsm
{
public:
static tree asm_build_expr (HIR::InlineAsm &);
static location_t asm_get_locus (HIR::InlineAsm &);
static tree asm_construct_string_tree (HIR::InlineAsm &);
static tree asm_construct_outputs (HIR::InlineAsm &);
static tree asm_construct_inputs (HIR::InlineAsm &);
static tree asm_construct_clobber_tree (HIR::InlineAsm &);
static tree asm_construct_label_tree (HIR::InlineAsm &);

static bool asm_is_simple (HIR::InlineAsm &);

static bool asm_is_inline (HIR::InlineAsm &);
};
} // namespace Compile
} // namespace Rust
#endif // RUST_COMPILE_ASM
9 changes: 4 additions & 5 deletions gcc/rust/backend/rust-compile-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "rust-constexpr.h"
#include "rust-compile-type.h"
#include "rust-gcc.h"

#include "rust-compile-asm.h"
#include "fold-const.h"
#include "realmpfr.h"
#include "convert.h"
Expand Down Expand Up @@ -321,10 +321,9 @@ CompileExpr::visit (HIR::IfExpr &expr)
void
CompileExpr::visit (HIR::InlineAsm &expr)
{
// translated = build_asm_expr()(expr.get_locus(),
// expr.construct_string_tree(), expr.construct_outputs(),
// expr.construct_inputs(), expr.construct_clobber_tree(),
// expr.construct_label_tree(), expr.is_simple(), expr.is_inline_asm());
// translated = build_asm_expr (0, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
// NULL_TREE, true, true);
// CompileAsm::asm_build_expr (expr);
}

void
Expand Down
35 changes: 0 additions & 35 deletions gcc/rust/hir/tree/rust-hir-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3928,41 +3928,6 @@ class InlineAsm : public ExprWithoutBlock
options (std::move (options))

{}

tree construct_string_tree ()
{
if (template_strs.empty ())
return build_string (1, "");
// Initialize to NULL_TREE
tree string_chain = NULL_TREE;

for (const auto &template_str : template_strs)
{
auto str = template_str.symbol;
auto string_tree = build_string (str.size () + 1, str.c_str ());

string_chain = tree_cons (NULL_TREE, string_tree, string_chain);
}
// Reverse the chain before returning
return nreverse (string_chain);
}

tree construct_clobber_tree () { return NULL_TREE; }
tree construct_label_tree () { return NULL_TREE; }
tree construct_inputs () { return NULL_TREE; }
tree construct_outputs () { return NULL_TREE; }
// This function checks if the assembly macro is "simple" or not, according to
// the tree defition (tree.h) of the

// SIMPLE indicates whether there was anything at all after the
// string in the asm expression
bool is_simple ()
{
return operands.size () == 0 && clobber_abi.size () == 0
&& options.size () == 0;
}

bool is_inline_asm () { return !is_global_asm; }
};
} // namespace HIR
} // namespace Rust
Expand Down

0 comments on commit 2855b64

Please sign in to comment.