aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2021-11-15 10:12:20 -0800
committerDavid Faust <david.faust@oracle.com>2021-11-16 13:15:54 -0800
commita4e5aee5863c7d898ee640296bc837e0baa8e796 (patch)
treef40c90287ae41fa3689cdc38d4bb021fb6cc8394 /gcc
parent95048daaffa5e16df4d663702fe80294eac7b85e (diff)
downloadgcc-a4e5aee5863c7d898ee640296bc837e0baa8e796.zip
gcc-a4e5aee5863c7d898ee640296bc837e0baa8e796.tar.gz
gcc-a4e5aee5863c7d898ee640296bc837e0baa8e796.tar.bz2
Replace Bblock with GCC tree
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-block.h4
-rw-r--r--gcc/rust/backend/rust-compile-context.h8
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc2
-rw-r--r--gcc/rust/backend/rust-compile-expr.h16
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h8
-rw-r--r--gcc/rust/backend/rust-compile-item.h4
-rw-r--r--gcc/rust/backend/rust-compile.cc28
-rw-r--r--gcc/rust/rust-backend.h22
-rw-r--r--gcc/rust/rust-gcc.cc52
9 files changed, 60 insertions, 84 deletions
diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h
index 0e631e1..af90671 100644
--- a/gcc/rust/backend/rust-compile-block.h
+++ b/gcc/rust/backend/rust-compile-block.h
@@ -30,7 +30,7 @@ class CompileBlock : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bblock *compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result)
+ static tree compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result)
{
CompileBlock compiler (ctx, result);
expr->accept_vis (compiler);
@@ -44,7 +44,7 @@ private:
: HIRCompileBase (ctx), translated (nullptr), result (result)
{}
- Bblock *translated;
+ tree translated;
Bvariable *result;
};
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 4c8f722..1fe67d2 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -112,13 +112,13 @@ public:
Analysis::Mappings *get_mappings () { return mappings; }
ConstFold::Context *get_const_ctx () { return const_ctx; }
- void push_block (Bblock *scope)
+ void push_block (tree scope)
{
scope_stack.push_back (scope);
statements.push_back ({});
}
- Bblock *pop_block ()
+ tree pop_block ()
{
auto block = scope_stack.back ();
scope_stack.pop_back ();
@@ -131,7 +131,7 @@ public:
return block;
}
- Bblock *peek_enclosing_scope ()
+ tree peek_enclosing_scope ()
{
if (scope_stack.size () == 0)
return nullptr;
@@ -323,7 +323,7 @@ private:
std::map<HirId, tree> compiled_consts;
std::map<HirId, ::Blabel *> compiled_labels;
std::vector<::std::vector<tree>> statements;
- std::vector<::Bblock *> scope_stack;
+ std::vector<tree> scope_stack;
std::vector<::Bvariable *> loop_value_stack;
std::vector<::Blabel *> loop_begin_labels;
std::map<const TyTy::BaseType *, std::pair<HirId, ::tree >> mono;
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 8b1da22..fb01d8d 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -176,7 +176,7 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn,
fn_vtable_access, expr_locus);
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
bool is_address_taken = false;
tree ret_var_stmt = NULL_TREE;
Bvariable *fn_convert_expr_tmp
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index f739273..52cc58a 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -514,7 +514,7 @@ public:
if (needs_temp)
{
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
@@ -551,7 +551,7 @@ public:
if (needs_temp)
{
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
tree block_type = TyTyResolveCompile::compile (ctx, if_type);
bool is_address_taken = false;
@@ -587,7 +587,7 @@ public:
if (needs_temp)
{
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
@@ -740,7 +740,7 @@ public:
bool needs_temp = !block_tyty->is_unit ();
if (needs_temp)
{
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
bool is_address_taken = false;
@@ -773,7 +773,7 @@ public:
ctx->add_statement (loop_begin_label_decl);
ctx->push_loop_begin_label (loop_begin_label);
- Bblock *code_block
+ tree code_block
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
tree loop_expr
= ctx->get_backend ()->loop_expression (code_block, expr.get_locus ());
@@ -811,8 +811,8 @@ public:
Location start_location = expr.get_loop_block ()->get_locus ();
Location end_location = expr.get_loop_block ()->get_locus (); // FIXME
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Bblock *loop_block
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree loop_block
= ctx->get_backend ()->block (fnctx.fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (loop_block);
@@ -832,7 +832,7 @@ public:
= ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
ctx->add_statement (break_stmt);
- Bblock *code_block
+ tree code_block
= CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
tree code_block_stmt = ctx->get_backend ()->block_statement (code_block);
ctx->add_statement (code_block_stmt);
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 23b10d6..7b41226 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -262,12 +262,12 @@ public:
ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = NULL;
+ tree enclosing_scope = NULL_TREE;
HIR::BlockExpr *function_body = function.get_definition ().get ();
Location start_location = function_body->get_locus ();
Location end_location = function_body->get_closing_locus ();
- Bblock *code_block
+ tree code_block
= ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (code_block);
@@ -522,12 +522,12 @@ public:
ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = NULL;
+ tree enclosing_scope = NULL_TREE;
HIR::BlockExpr *function_body = func.get_block_expr ().get ();
Location start_location = function_body->get_locus ();
Location end_location = function_body->get_closing_locus ();
- Bblock *code_block
+ tree code_block
= ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (code_block);
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 94a313e..5af9ab3 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -261,12 +261,12 @@ public:
ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = NULL;
+ tree enclosing_scope = NULL_TREE;
HIR::BlockExpr *function_body = function.get_definition ().get ();
Location start_location = function_body->get_locus ();
Location end_location = function_body->get_closing_locus ();
- Bblock *code_block
+ tree code_block
= ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
start_location, end_location);
ctx->push_block (code_block);
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 71435f3..579b323 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -338,10 +338,9 @@ CompileBlock::visit (HIR::BlockExpr &expr)
bool ok = compile_locals_for_block (*rib, fndecl, locals);
rust_assert (ok);
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Bblock *new_block
- = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
- start_location, end_location);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree new_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
+ start_location, end_location);
ctx->push_block (new_block);
for (auto &s : expr.get_statements ())
@@ -395,8 +394,7 @@ CompileConditionalBlocks::visit (HIR::IfExpr &expr)
fncontext fnctx = ctx->peek_fn ();
tree fndecl = fnctx.fndecl;
tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
- Bblock *then_block
- = CompileBlock::compile (expr.get_if_block (), ctx, result);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
translated
= ctx->get_backend ()->if_statement (fndecl, condition_expr, then_block,
@@ -409,10 +407,8 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr)
fncontext fnctx = ctx->peek_fn ();
tree fndecl = fnctx.fndecl;
tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
- Bblock *then_block
- = CompileBlock::compile (expr.get_if_block (), ctx, result);
- Bblock *else_block
- = CompileBlock::compile (expr.get_else_block (), ctx, result);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
+ tree else_block = CompileBlock::compile (expr.get_else_block (), ctx, result);
translated
= ctx->get_backend ()->if_statement (fndecl, condition_expr, then_block,
@@ -425,17 +421,15 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqIf &expr)
fncontext fnctx = ctx->peek_fn ();
tree fndecl = fnctx.fndecl;
tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx);
- Bblock *then_block
- = CompileBlock::compile (expr.get_if_block (), ctx, result);
+ tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result);
// else block
std::vector<Bvariable *> locals;
Location start_location = expr.get_conseq_if_expr ()->get_locus ();
Location end_location = expr.get_conseq_if_expr ()->get_locus (); // FIXME
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Bblock *else_block
- = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
- start_location, end_location);
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
+ tree else_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
+ start_location, end_location);
ctx->push_block (else_block);
tree else_stmt_decl
@@ -610,7 +604,7 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
locus);
fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ tree enclosing_scope = ctx->peek_enclosing_scope ();
bool is_address_taken = false;
tree ret_var_stmt = NULL_TREE;
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 836f519..d4d2b89 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -41,9 +41,6 @@ saw_errors (void);
// frontend, and passed back to the backend. The types must be
// defined by the backend using these names.
-// The backend representation of a block.
-class Bblock;
-
// The backend representation of a variable.
class Bvariable;
@@ -78,7 +75,6 @@ public:
// debug
virtual void debug (tree) = 0;
- virtual void debug (Bblock *) = 0;
virtual void debug (Bvariable *) = 0;
virtual void debug (Blabel *) = 0;
@@ -409,12 +405,12 @@ public:
virtual tree return_statement (tree, const std::vector<tree> &, Location) = 0;
// Create an if statement within a function. ELSE_BLOCK may be NULL.
- virtual tree if_statement (tree, tree condition, Bblock *then_block,
- Bblock *else_block, Location)
+ virtual tree if_statement (tree, tree condition, tree then_block,
+ tree else_block, Location)
= 0;
// infinite loop expressions
- virtual tree loop_expression (Bblock *body, Location) = 0;
+ virtual tree loop_expression (tree body, Location) = 0;
// exit expressions
virtual tree exit_expression (tree condition, Location) = 0;
@@ -458,20 +454,20 @@ public:
// the initial curly brace. END_LOCATION is the location of the end
// of the block, more or less the location of the final curly brace.
// The statements will be added after the block is created.
- virtual Bblock *block (tree function, Bblock *enclosing,
- const std::vector<Bvariable *> &vars,
- Location start_location, Location end_location)
+ virtual tree block (tree function, tree enclosing,
+ const std::vector<Bvariable *> &vars,
+ Location start_location, Location end_location)
= 0;
// Add the statements to a block. The block is created first. Then
// the statements are created. Then the statements are added to the
// block. This will called exactly once per block. The vector may
// be empty if there are no statements.
- virtual void block_add_statements (Bblock *, const std::vector<tree> &) = 0;
+ virtual void block_add_statements (tree, const std::vector<tree> &) = 0;
// Return the block as a statement. This is used to include a block
// in a list of statements.
- virtual tree block_statement (Bblock *) = 0;
+ virtual tree block_statement (tree) = 0;
// Variables.
@@ -546,7 +542,7 @@ public:
// variable, and may not be very useful. This function should
// return a variable which can be referenced later and should set
// *PSTATEMENT to a statement which initializes the variable.
- virtual Bvariable *temporary_variable (tree, Bblock *, tree, tree init,
+ virtual Bvariable *temporary_variable (tree, tree, tree, tree init,
bool address_is_taken,
Location location, tree *pstatement)
= 0;
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 7308353..0fa07d9 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -70,12 +70,6 @@ private:
// In gcc, types, expressions, and statements are all trees.
-class Bblock : public Gcc_tree
-{
-public:
- Bblock (tree t) : Gcc_tree (t) {}
-};
-
class Blabel : public Gcc_tree
{
public:
@@ -137,7 +131,6 @@ public:
Gcc_backend ();
void debug (tree t) { debug_tree (t); };
- void debug (Bblock *t) { debug_tree (t->get_tree ()); };
void debug (Bvariable *t) { debug_tree (t->get_decl ()); };
void debug (Blabel *t) { debug_tree (t->get_tree ()); };
@@ -343,8 +336,8 @@ public:
tree return_statement (tree, const std::vector<tree> &, Location);
- tree if_statement (tree, tree condition, Bblock *then_block,
- Bblock *else_block, Location);
+ tree if_statement (tree, tree condition, tree then_block, tree else_block,
+ Location);
tree switch_statement (tree function, tree value,
const std::vector<std::vector<tree>> &cases,
@@ -357,18 +350,17 @@ public:
tree exception_handler_statement (tree bstat, tree except_stmt,
tree finally_stmt, Location);
- tree loop_expression (Bblock *body, Location);
+ tree loop_expression (tree body, Location);
tree exit_expression (tree condition, Location);
// Blocks.
- Bblock *block (tree, Bblock *, const std::vector<Bvariable *> &, Location,
- Location);
+ tree block (tree, tree, const std::vector<Bvariable *> &, Location, Location);
- void block_add_statements (Bblock *, const std::vector<tree> &);
+ void block_add_statements (tree, const std::vector<tree> &);
- tree block_statement (Bblock *);
+ tree block_statement (tree);
// Variables.
@@ -389,7 +381,7 @@ public:
Bvariable *static_chain_variable (tree, const std::string &, tree, Location);
- Bvariable *temporary_variable (tree, Bblock *, tree, tree, bool, Location,
+ Bvariable *temporary_variable (tree, tree, tree, tree, bool, Location,
tree *);
Bvariable *implicit_variable (const std::string &, const std::string &,
@@ -2194,11 +2186,9 @@ Gcc_backend::exception_handler_statement (tree try_stmt, tree except_stmt,
// If.
tree
-Gcc_backend::if_statement (tree, tree cond_tree, Bblock *then_block,
- Bblock *else_block, Location location)
+Gcc_backend::if_statement (tree, tree cond_tree, tree then_tree, tree else_tree,
+ Location location)
{
- tree then_tree = then_block->get_tree ();
- tree else_tree = else_block == NULL ? NULL_TREE : else_block->get_tree ();
if (cond_tree == error_mark_node || then_tree == error_mark_node
|| else_tree == error_mark_node)
return this->error_statement ();
@@ -2210,10 +2200,10 @@ Gcc_backend::if_statement (tree, tree cond_tree, Bblock *then_block,
// Loops
tree
-Gcc_backend::loop_expression (Bblock *body, Location locus)
+Gcc_backend::loop_expression (tree body, Location locus)
{
return fold_build1_loc (locus.gcc_location (), LOOP_EXPR, void_type_node,
- body->get_tree ());
+ body);
}
tree
@@ -2329,8 +2319,8 @@ Gcc_backend::statement_list (const std::vector<tree> &statements)
// BIND_EXPR node points to the BLOCK node, we store the BIND_EXPR in
// the Bblock.
-Bblock *
-Gcc_backend::block (tree fndecl, Bblock *enclosing,
+tree
+Gcc_backend::block (tree fndecl, tree enclosing,
const std::vector<Bvariable *> &vars,
Location start_location, Location)
{
@@ -2359,8 +2349,7 @@ Gcc_backend::block (tree fndecl, Bblock *enclosing,
}
else
{
- tree superbind_tree = enclosing->get_tree ();
- tree superblock_tree = BIND_EXPR_BLOCK (superbind_tree);
+ tree superblock_tree = BIND_EXPR_BLOCK (enclosing);
gcc_assert (TREE_CODE (superblock_tree) == BLOCK);
BLOCK_SUPERCONTEXT (block_tree) = superblock_tree;
@@ -2387,13 +2376,13 @@ Gcc_backend::block (tree fndecl, Bblock *enclosing,
= build3_loc (start_location.gcc_location (), BIND_EXPR, void_type_node,
BLOCK_VARS (block_tree), NULL_TREE, block_tree);
TREE_SIDE_EFFECTS (bind_tree) = 1;
- return new Bblock (bind_tree);
+ return bind_tree;
}
// Add statements to a block.
void
-Gcc_backend::block_add_statements (Bblock *bblock,
+Gcc_backend::block_add_statements (tree bind_tree,
const std::vector<tree> &statements)
{
tree stmt_list = NULL_TREE;
@@ -2405,7 +2394,6 @@ Gcc_backend::block_add_statements (Bblock *bblock,
append_to_statement_list (s, &stmt_list);
}
- tree bind_tree = bblock->get_tree ();
gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR);
BIND_EXPR_BODY (bind_tree) = stmt_list;
}
@@ -2413,9 +2401,8 @@ Gcc_backend::block_add_statements (Bblock *bblock,
// Return a block as a statement.
tree
-Gcc_backend::block_statement (Bblock *bblock)
+Gcc_backend::block_statement (tree bind_tree)
{
- tree bind_tree = bblock->get_tree ();
gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR);
return bind_tree;
}
@@ -2659,7 +2646,7 @@ Gcc_backend::static_chain_variable (tree fndecl, const std::string &name,
// Make a temporary variable.
Bvariable *
-Gcc_backend::temporary_variable (tree fndecl, Bblock *bblock, tree type_tree,
+Gcc_backend::temporary_variable (tree fndecl, tree bind_tree, tree type_tree,
tree init_tree, bool is_address_taken,
Location location, tree *pstatement)
{
@@ -2685,7 +2672,7 @@ Gcc_backend::temporary_variable (tree fndecl, Bblock *bblock, tree type_tree,
}
else
{
- gcc_assert (bblock != NULL);
+ gcc_assert (bind_tree != NULL_TREE);
var = build_decl (location.gcc_location (), VAR_DECL,
create_tmp_var_name ("RUSTTMP"), type_tree);
DECL_ARTIFICIAL (var) = 1;
@@ -2694,7 +2681,6 @@ Gcc_backend::temporary_variable (tree fndecl, Bblock *bblock, tree type_tree,
DECL_CONTEXT (var) = fndecl;
// We have to add this variable to the BLOCK and the BIND_EXPR.
- tree bind_tree = bblock->get_tree ();
gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR);
tree block_tree = BIND_EXPR_BLOCK (bind_tree);
gcc_assert (TREE_CODE (block_tree) == BLOCK);