]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Convert class Backend into namespace
authorOwen Avery <powerboat9.gamer@gmail.com>
Mon, 4 Sep 2023 20:13:31 +0000 (16:13 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:04:35 +0000 (19:04 +0100)
gcc/rust/ChangeLog:

* rust-backend.h
(class Backend): Convert to ...
(namespace Backend): ... namespace.
* rust-gcc.cc
(Backend::Backend): Rename to ...
(Backend::init): ... here.
(rust_get_backend): Remove.

* rust-session-manager.cc
(rust_get_backend): Remove.
(Session::init): Use Backend::init instead of rust_get_backend.
(Session::compile_crate):
Initialize Context without pointer to Backend.
* rust-session-manager.h
(Session::backend): Remove.
* backend/rust-compile-context.cc
(Context::Context): Remove pointer to Backend.
* backend/rust-compile-context.h
(class Context): Remove pointer to Backend, update function calls.

* backend/rust-compile-base.cc: Update function calls.
* backend/rust-compile-block.cc: Likewise.
* backend/rust-compile-expr.cc: Likewise.
* backend/rust-compile-extern.h: Likewise.
* backend/rust-compile-fnparam.cc: Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-item.cc: Likewise.
* backend/rust-compile-pattern.cc: Likewise.
* backend/rust-compile-resolve-path.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* backend/rust-compile-var-decl.h: Likewise.
* backend/rust-compile.cc: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 files changed:
gcc/rust/backend/rust-compile-base.cc
gcc/rust/backend/rust-compile-block.cc
gcc/rust/backend/rust-compile-context.cc
gcc/rust/backend/rust-compile-context.h
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/backend/rust-compile-extern.h
gcc/rust/backend/rust-compile-fnparam.cc
gcc/rust/backend/rust-compile-intrinsic.cc
gcc/rust/backend/rust-compile-item.cc
gcc/rust/backend/rust-compile-pattern.cc
gcc/rust/backend/rust-compile-resolve-path.cc
gcc/rust/backend/rust-compile-type.cc
gcc/rust/backend/rust-compile-var-decl.h
gcc/rust/backend/rust-compile.cc
gcc/rust/rust-backend.h
gcc/rust/rust-gcc.cc
gcc/rust/rust-session-manager.cc
gcc/rust/rust-session-manager.h

index c11b6cca52a84fd192286217598e0e9daa6075fe..02d45571b9bae9755beabcfae24f759f46ae7625 100644 (file)
@@ -517,8 +517,7 @@ HIRCompileBase::compile_function_body (tree fndecl,
                                        lvalue_locus, rvalue_locus);
 
          tree return_stmt
-           = ctx->get_backend ()->return_statement (fndecl, return_value,
-                                                    locus);
+           = Backend::return_statement (fndecl, return_value, locus);
          ctx->add_statement (return_stmt);
        }
       else
@@ -529,7 +528,7 @@ HIRCompileBase::compile_function_body (tree fndecl,
          // now just return unit expression
          tree unit_expr = unit_expression (ctx, locus);
          tree return_stmt
-           = ctx->get_backend ()->return_statement (fndecl, unit_expr, locus);
+           = Backend::return_statement (fndecl, unit_expr, locus);
          ctx->add_statement (return_stmt);
        }
     }
@@ -540,7 +539,7 @@ HIRCompileBase::compile_function_body (tree fndecl,
       location_t locus = function_body.get_locus ();
       tree return_value = unit_expression (ctx, locus);
       tree return_stmt
-       = ctx->get_backend ()->return_statement (fndecl, return_value, locus);
+       = Backend::return_statement (fndecl, return_value, locus);
       ctx->add_statement (return_stmt);
     }
 }
@@ -562,8 +561,8 @@ HIRCompileBase::compile_function (
   std::string asm_name = fn_name;
 
   unsigned int flags = 0;
-  tree fndecl = ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
-                                              "" /* asm_name */, flags, locus);
+  tree fndecl = Backend::function (compiled_fn_type, ir_symbol_name,
+                                  "" /* asm_name */, flags, locus);
 
   setup_fndecl (fndecl, is_main_fn, fntype->has_subsititions_defined (),
                visibility, qualifiers, outer_attrs);
@@ -620,7 +619,7 @@ HIRCompileBase::compile_function (
                            compiled_param_var);
     }
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   // lookup locals
@@ -637,8 +636,8 @@ HIRCompileBase::compile_function (
   location_t start_location = function_body->get_locus ();
   location_t end_location = function_body->get_end_locus ();
 
-  tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
-                                               start_location, end_location);
+  tree code_block = Backend::block (fndecl, enclosing_scope, locals,
+                                   start_location, end_location);
   ctx->push_block (code_block);
 
   Bvariable *return_address = nullptr;
@@ -647,9 +646,8 @@ HIRCompileBase::compile_function (
   bool address_is_taken = false;
   tree ret_var_stmt = NULL_TREE;
   return_address
-    = ctx->get_backend ()->temporary_variable (fndecl, code_block, return_type,
-                                              NULL, address_is_taken, locus,
-                                              &ret_var_stmt);
+    = Backend::temporary_variable (fndecl, code_block, return_type, NULL,
+                                  address_is_taken, locus, &ret_var_stmt);
 
   ctx->add_statement (ret_var_stmt);
 
@@ -688,11 +686,10 @@ HIRCompileBase::compile_constant_item (
   // make a _fake_ function with a block so it can hold onto temps then
   // use our constexpr code to fold it completely or error_mark_node
   Backend::typed_identifier receiver;
-  tree compiled_fn_type = ctx->get_backend ()->function_type (
+  tree compiled_fn_type = Backend::function_type (
     receiver, {}, {Backend::typed_identifier ("_", const_type, locus)}, NULL,
     locus);
-  tree fndecl
-    = ctx->get_backend ()->function (compiled_fn_type, ident, "", 0, locus);
+  tree fndecl = Backend::function (compiled_fn_type, ident, "", 0, locus);
   TREE_READONLY (fndecl) = 1;
 
   std::vector<Bvariable *> locals;
@@ -714,16 +711,15 @@ HIRCompileBase::compile_constant_item (
       locals = compile_locals_for_block (ctx, *rib, fndecl);
     }
 
-  tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
-                                               start_location, end_location);
+  tree code_block = Backend::block (fndecl, enclosing_scope, locals,
+                                   start_location, end_location);
   ctx->push_block (code_block);
 
   bool address_is_taken = false;
   tree ret_var_stmt = NULL_TREE;
   Bvariable *return_address
-    = ctx->get_backend ()->temporary_variable (fndecl, code_block, const_type,
-                                              NULL, address_is_taken, locus,
-                                              &ret_var_stmt);
+    = Backend::temporary_variable (fndecl, code_block, const_type, NULL,
+                                  address_is_taken, locus, &ret_var_stmt);
 
   ctx->add_statement (ret_var_stmt);
   ctx->push_fn (fndecl, return_address, resolved_type);
@@ -738,8 +734,9 @@ HIRCompileBase::compile_constant_item (
     {
       tree value = CompileExpr::Compile (const_value_expr, ctx);
 
-      tree return_expr = ctx->get_backend ()->return_statement (
-       fndecl, value, const_value_expr->get_locus ());
+      tree return_expr
+       = Backend::return_statement (fndecl, value,
+                                    const_value_expr->get_locus ());
       ctx->add_statement (return_expr);
     }
 
@@ -908,8 +905,7 @@ tree
 HIRCompileBase::unit_expression (Context *ctx, location_t locus)
 {
   tree unit_type = TyTyResolveCompile::get_unit_type (ctx);
-  return ctx->get_backend ()->constructor_expression (unit_type, false, {}, -1,
-                                                     locus);
+  return Backend::constructor_expression (unit_type, false, {}, -1, locus);
 }
 
 } // namespace Compile
index 709be0ed8288278b833ee5e2f4332de939371690..83ecc6725928324f3b2006ced81789761dbf5213 100644 (file)
@@ -55,8 +55,8 @@ CompileBlock::visit (HIR::BlockExpr &expr)
     = compile_locals_for_block (ctx, *rib, fndecl);
 
   tree enclosing_scope = ctx->peek_enclosing_scope ();
-  tree new_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
-                                              start_location, end_location);
+  tree new_block = Backend::block (fndecl, enclosing_scope, locals,
+                                  start_location, end_location);
   ctx->push_block (new_block);
 
   for (auto &s : expr.get_statements ())
@@ -75,13 +75,11 @@ CompileBlock::visit (HIR::BlockExpr &expr)
       if (result != nullptr)
        {
          location_t locus = expr.get_final_expr ()->get_locus ();
-         tree result_reference
-           = ctx->get_backend ()->var_expression (result, locus);
+         tree result_reference = Backend::var_expression (result, locus);
 
          tree assignment
-           = ctx->get_backend ()->assignment_statement (result_reference,
-                                                        compiled_expr,
-                                                        expr.get_locus ());
+           = Backend::assignment_statement (result_reference, compiled_expr,
+                                            expr.get_locus ());
          ctx->add_statement (assignment);
        }
     }
@@ -89,13 +87,11 @@ CompileBlock::visit (HIR::BlockExpr &expr)
     {
       location_t locus = expr.get_locus ();
       tree compiled_expr = unit_expression (ctx, expr.get_locus ());
-      tree result_reference
-       = ctx->get_backend ()->var_expression (result, locus);
+      tree result_reference = Backend::var_expression (result, locus);
 
       tree assignment
-       = ctx->get_backend ()->assignment_statement (result_reference,
-                                                    compiled_expr,
-                                                    expr.get_locus ());
+       = Backend::assignment_statement (result_reference, compiled_expr,
+                                        expr.get_locus ());
       ctx->add_statement (assignment);
     }
 
@@ -113,9 +109,8 @@ CompileConditionalBlocks::visit (HIR::IfExpr &expr)
   tree then_block
     = CompileBlock::compile (expr.get_if_block ().get (), ctx, result);
 
-  translated
-    = ctx->get_backend ()->if_statement (fndecl, condition_expr, then_block,
-                                        NULL, expr.get_locus ());
+  translated = Backend::if_statement (fndecl, condition_expr, then_block, NULL,
+                                     expr.get_locus ());
 }
 
 void
@@ -133,8 +128,8 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr)
   location_t start_location = expr.get_else_block ()->get_locus ();
   location_t end_location = expr.get_else_block ()->get_locus (); // FIXME
   tree enclosing_scope = ctx->peek_enclosing_scope ();
-  tree else_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
-                                               start_location, end_location);
+  tree else_block = Backend::block (fndecl, enclosing_scope, locals,
+                                   start_location, end_location);
   ctx->push_block (else_block);
 
   tree else_stmt_decl
@@ -145,9 +140,8 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr)
 
   ctx->pop_block ();
 
-  translated
-    = ctx->get_backend ()->if_statement (fndecl, condition_expr, then_block,
-                                        else_block, expr.get_locus ());
+  translated = Backend::if_statement (fndecl, condition_expr, then_block,
+                                     else_block, expr.get_locus ());
 }
 
 } // namespace Compile
index 6c1a1f95ad83f5a2e6560cf6a113d3fa75f280dd..e9d44f9725d9b90d82d1d09ee0a0fff6b9c3e873 100644 (file)
@@ -22,8 +22,8 @@
 namespace Rust {
 namespace Compile {
 
-Context::Context (::Backend *backend)
-  : backend (backend), resolver (Resolver::Resolver::get ()),
+Context::Context ()
+  : resolver (Resolver::Resolver::get ()),
     tyctx (Resolver::TypeCheckContext::get ()),
     mappings (Analysis::Mappings::get ()), mangler (Mangler ())
 {
index 095d2a0cf6d8d97051fbe9fc0e6836bdd2bc08ce..63e50ac33df7b6679afd68a6ac85ef6fe4f64c0d 100644 (file)
@@ -41,7 +41,7 @@ struct fncontext
 class Context
 {
 public:
-  Context (::Backend *backend);
+  Context ();
 
   void setup_builtins ();
 
@@ -79,7 +79,6 @@ public:
     return type;
   }
 
-  ::Backend *get_backend () { return backend; }
   Resolver::Resolver *get_resolver () { return resolver; }
   Resolver::TypeCheckContext *get_tyctx () { return tyctx; }
   Analysis::Mappings *get_mappings () { return mappings; }
@@ -98,7 +97,7 @@ public:
     auto stmts = statements.back ();
     statements.pop_back ();
 
-    backend->block_add_statements (block, stmts);
+    Backend::block_add_statements (block, stmts);
 
     return block;
   }
@@ -290,7 +289,7 @@ public:
 
   void write_to_backend ()
   {
-    backend->write_global_definitions (type_decls, const_decls, func_decls,
+    Backend::write_global_definitions (type_decls, const_decls, func_decls,
                                       var_decls);
   }
 
@@ -359,7 +358,6 @@ public:
   static hashval_t type_hasher (tree type);
 
 private:
-  ::Backend *backend;
   Resolver::Resolver *resolver;
   Resolver::TypeCheckContext *tyctx;
   Analysis::Mappings *mappings;
index 0e2d92b3fb70585e089f4775fc6d243d6db6121a..2c8ed0282a8727dd8e12ab5a992e589188d0c0b6 100644 (file)
@@ -68,8 +68,7 @@ CompileExpr::visit (HIR::TupleIndexExpr &expr)
     }
 
   translated
-    = ctx->get_backend ()->struct_field_expression (receiver_ref, index,
-                                                   expr.get_locus ());
+    = Backend::struct_field_expression (receiver_ref, index, expr.get_locus ());
 }
 
 void
@@ -101,9 +100,8 @@ CompileExpr::visit (HIR::TupleExpr &expr)
       vals.push_back (e);
     }
 
-  translated
-    = ctx->get_backend ()->constructor_expression (tuple_type, false, vals, -1,
-                                                  expr.get_locus ());
+  translated = Backend::constructor_expression (tuple_type, false, vals, -1,
+                                               expr.get_locus ());
 }
 
 void
@@ -133,9 +131,8 @@ CompileExpr::visit (HIR::ReturnExpr &expr)
                                    lvalue_locus, rvalue_locus);
     }
 
-  tree return_stmt
-    = ctx->get_backend ()->return_statement (fncontext.fndecl, return_value,
-                                            expr.get_locus ());
+  tree return_stmt = Backend::return_statement (fncontext.fndecl, return_value,
+                                               expr.get_locus ());
   ctx->add_statement (return_stmt);
 }
 
@@ -164,21 +161,22 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
     {
       auto receiver_tmp = NULL_TREE;
       auto receiver
-       = ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl,
-                                                  NULL_TREE, TREE_TYPE (lhs),
-                                                  lhs, true, expr.get_locus (),
-                                                  &receiver_tmp);
+       = Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
+                                      TREE_TYPE (lhs), lhs, true,
+                                      expr.get_locus (), &receiver_tmp);
       auto check
-       = ctx->get_backend ()->arithmetic_or_logical_expression_checked (
-         op, lhs, rhs, expr.get_locus (), receiver);
+       = Backend::arithmetic_or_logical_expression_checked (op, lhs, rhs,
+                                                            expr.get_locus (),
+                                                            receiver);
 
       ctx->add_statement (check);
       translated = receiver->get_tree (expr.get_locus ());
     }
   else
     {
-      translated = ctx->get_backend ()->arithmetic_or_logical_expression (
-       op, lhs, rhs, expr.get_locus ());
+      translated
+       = Backend::arithmetic_or_logical_expression (op, lhs, rhs,
+                                                    expr.get_locus ());
     }
 }
 
@@ -211,22 +209,25 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
     {
       auto tmp = NULL_TREE;
       auto receiver
-       = ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl,
-                                                  NULL_TREE, TREE_TYPE (lhs),
-                                                  lhs, true, expr.get_locus (),
-                                                  &tmp);
+       = Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
+                                      TREE_TYPE (lhs), lhs, true,
+                                      expr.get_locus (), &tmp);
       auto check
-       = ctx->get_backend ()->arithmetic_or_logical_expression_checked (
-         op, lhs, rhs, expr.get_locus (), receiver);
+       = Backend::arithmetic_or_logical_expression_checked (op, lhs, rhs,
+                                                            expr.get_locus (),
+                                                            receiver);
       ctx->add_statement (check);
 
-      translated = ctx->get_backend ()->assignment_statement (
-       lhs, receiver->get_tree (expr.get_locus ()), expr.get_locus ());
+      translated
+       = Backend::assignment_statement (lhs,
+                                        receiver->get_tree (expr.get_locus ()),
+                                        expr.get_locus ());
     }
   else
     {
-      translated = ctx->get_backend ()->arithmetic_or_logical_expression (
-       op, lhs, rhs, expr.get_locus ());
+      translated
+       = Backend::arithmetic_or_logical_expression (op, lhs, rhs,
+                                                    expr.get_locus ());
     }
 }
 
@@ -251,8 +252,7 @@ CompileExpr::visit (HIR::NegationExpr &expr)
       return;
     }
 
-  translated
-    = ctx->get_backend ()->negation_expression (op, negated_expr, location);
+  translated = Backend::negation_expression (op, negated_expr, location);
 }
 
 void
@@ -263,8 +263,7 @@ CompileExpr::visit (HIR::ComparisonExpr &expr)
   auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
   auto location = expr.get_locus ();
 
-  translated
-    = ctx->get_backend ()->comparison_expression (op, lhs, rhs, location);
+  translated = Backend::comparison_expression (op, lhs, rhs, location);
 }
 
 void
@@ -275,8 +274,7 @@ CompileExpr::visit (HIR::LazyBooleanExpr &expr)
   auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx);
   auto location = expr.get_locus ();
 
-  translated
-    = ctx->get_backend ()->lazy_boolean_expression (op, lhs, rhs, location);
+  translated = Backend::lazy_boolean_expression (op, lhs, rhs, location);
 }
 
 void
@@ -340,17 +338,15 @@ CompileExpr::visit (HIR::IfExprConseqElse &expr)
 
   bool is_address_taken = false;
   tree ret_var_stmt = nullptr;
-  tmp = ctx->get_backend ()->temporary_variable (fnctx.fndecl, enclosing_scope,
-                                                block_type, NULL,
-                                                is_address_taken,
-                                                expr.get_locus (),
-                                                &ret_var_stmt);
+  tmp = Backend::temporary_variable (fnctx.fndecl, enclosing_scope, block_type,
+                                    NULL, is_address_taken, expr.get_locus (),
+                                    &ret_var_stmt);
   ctx->add_statement (ret_var_stmt);
 
   auto stmt = CompileConditionalBlocks::compile (&expr, ctx, tmp);
   ctx->add_statement (stmt);
 
-  translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
+  translated = Backend::var_expression (tmp, expr.get_locus ());
 }
 
 void
@@ -371,18 +367,16 @@ CompileExpr::visit (HIR::BlockExpr &expr)
 
   bool is_address_taken = false;
   tree ret_var_stmt = nullptr;
-  tmp = ctx->get_backend ()->temporary_variable (fnctx.fndecl, enclosing_scope,
-                                                block_type, NULL,
-                                                is_address_taken,
-                                                expr.get_locus (),
-                                                &ret_var_stmt);
+  tmp = Backend::temporary_variable (fnctx.fndecl, enclosing_scope, block_type,
+                                    NULL, is_address_taken, expr.get_locus (),
+                                    &ret_var_stmt);
   ctx->add_statement (ret_var_stmt);
 
   auto block_stmt = CompileBlock::compile (&expr, ctx, tmp);
   rust_assert (TREE_CODE (block_stmt) == BIND_EXPR);
   ctx->add_statement (block_stmt);
 
-  translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
+  translated = Backend::var_expression (tmp, expr.get_locus ());
 }
 
 void
@@ -527,9 +521,10 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
   for (auto &arg : arguments)
     ctor_arguments.push_back (arg);
 
-  translated = ctx->get_backend ()->constructor_expression (
-    compiled_adt_type, adt->is_enum (), ctor_arguments, union_disriminator,
-    struct_expr.get_locus ());
+  translated
+    = Backend::constructor_expression (compiled_adt_type, adt->is_enum (),
+                                      ctor_arguments, union_disriminator,
+                                      struct_expr.get_locus ());
 }
 
 void
@@ -585,9 +580,8 @@ CompileExpr::visit (HIR::FieldAccessExpr &expr)
       receiver_ref = indirect;
     }
 
-  translated
-    = ctx->get_backend ()->struct_field_expression (receiver_ref, field_index,
-                                                   expr.get_locus ());
+  translated = Backend::struct_field_expression (receiver_ref, field_index,
+                                                expr.get_locus ());
 }
 
 void
@@ -619,9 +613,10 @@ CompileExpr::visit (HIR::LoopExpr &expr)
 
   bool is_address_taken = false;
   tree ret_var_stmt = NULL_TREE;
-  Bvariable *tmp = ctx->get_backend ()->temporary_variable (
-    fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
-    expr.get_locus (), &ret_var_stmt);
+  Bvariable *tmp
+    = Backend::temporary_variable (fnctx.fndecl, enclosing_scope, block_type,
+                                  NULL, is_address_taken, expr.get_locus (),
+                                  &ret_var_stmt);
   ctx->add_statement (ret_var_stmt);
   ctx->push_loop_context (tmp);
 
@@ -629,30 +624,27 @@ CompileExpr::visit (HIR::LoopExpr &expr)
     {
       HIR::LoopLabel &loop_label = expr.get_loop_label ();
       tree label
-       = ctx->get_backend ()->label (fnctx.fndecl,
-                                     loop_label.get_lifetime ().get_name (),
-                                     loop_label.get_locus ());
-      tree label_decl = ctx->get_backend ()->label_definition_statement (label);
+       = Backend::label (fnctx.fndecl, loop_label.get_lifetime ().get_name (),
+                         loop_label.get_locus ());
+      tree label_decl = Backend::label_definition_statement (label);
       ctx->add_statement (label_decl);
       ctx->insert_label_decl (
        loop_label.get_lifetime ().get_mappings ().get_hirid (), label);
     }
 
-  tree loop_begin_label
-    = ctx->get_backend ()->label (fnctx.fndecl, "", expr.get_locus ());
+  tree loop_begin_label = Backend::label (fnctx.fndecl, "", expr.get_locus ());
   tree loop_begin_label_decl
-    = ctx->get_backend ()->label_definition_statement (loop_begin_label);
+    = Backend::label_definition_statement (loop_begin_label);
   ctx->add_statement (loop_begin_label_decl);
   ctx->push_loop_begin_label (loop_begin_label);
 
   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 ());
+  tree loop_expr = Backend::loop_expression (code_block, expr.get_locus ());
   ctx->add_statement (loop_expr);
 
   ctx->pop_loop_context ();
-  translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
+  translated = Backend::var_expression (tmp, expr.get_locus ());
 
   ctx->pop_loop_begin_label ();
 }
@@ -665,10 +657,9 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
     {
       HIR::LoopLabel &loop_label = expr.get_loop_label ();
       tree label
-       = ctx->get_backend ()->label (fnctx.fndecl,
-                                     loop_label.get_lifetime ().get_name (),
-                                     loop_label.get_locus ());
-      tree label_decl = ctx->get_backend ()->label_definition_statement (label);
+       = Backend::label (fnctx.fndecl, loop_label.get_lifetime ().get_name (),
+                         loop_label.get_locus ());
+      tree label_decl = Backend::label_definition_statement (label);
       ctx->add_statement (label_decl);
       ctx->insert_label_decl (
        loop_label.get_lifetime ().get_mappings ().get_hirid (), label);
@@ -679,15 +670,13 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
   location_t end_location = expr.get_loop_block ()->get_locus (); // FIXME
 
   tree enclosing_scope = ctx->peek_enclosing_scope ();
-  tree loop_block
-    = ctx->get_backend ()->block (fnctx.fndecl, enclosing_scope, locals,
-                                 start_location, end_location);
+  tree loop_block = Backend::block (fnctx.fndecl, enclosing_scope, locals,
+                                   start_location, end_location);
   ctx->push_block (loop_block);
 
-  tree loop_begin_label
-    = ctx->get_backend ()->label (fnctx.fndecl, "", expr.get_locus ());
+  tree loop_begin_label = Backend::label (fnctx.fndecl, "", expr.get_locus ());
   tree loop_begin_label_decl
-    = ctx->get_backend ()->label_definition_statement (loop_begin_label);
+    = Backend::label_definition_statement (loop_begin_label);
   ctx->add_statement (loop_begin_label_decl);
   ctx->push_loop_begin_label (loop_begin_label);
 
@@ -695,8 +684,7 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
     = CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx);
   tree exit_condition = fold_build1_loc (expr.get_locus (), TRUTH_NOT_EXPR,
                                         boolean_type_node, condition);
-  tree exit_expr
-    = ctx->get_backend ()->exit_expression (exit_condition, expr.get_locus ());
+  tree exit_expr = Backend::exit_expression (exit_condition, expr.get_locus ());
   ctx->add_statement (exit_expr);
 
   tree code_block_stmt
@@ -707,8 +695,7 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
   ctx->pop_loop_begin_label ();
   ctx->pop_block ();
 
-  tree loop_expr
-    = ctx->get_backend ()->loop_expression (loop_block, expr.get_locus ());
+  tree loop_expr = Backend::loop_expression (loop_block, expr.get_locus ());
   ctx->add_statement (loop_expr);
 }
 
@@ -721,13 +708,12 @@ CompileExpr::visit (HIR::BreakExpr &expr)
 
       Bvariable *loop_result_holder = ctx->peek_loop_context ();
       tree result_reference
-       = ctx->get_backend ()->var_expression (loop_result_holder,
-                                              expr.get_expr ()->get_locus ());
+       = Backend::var_expression (loop_result_holder,
+                                  expr.get_expr ()->get_locus ());
 
       tree assignment
-       = ctx->get_backend ()->assignment_statement (result_reference,
-                                                    compiled_expr,
-                                                    expr.get_locus ());
+       = Backend::assignment_statement (result_reference, compiled_expr,
+                                        expr.get_locus ());
       ctx->add_statement (assignment);
     }
 
@@ -759,15 +745,14 @@ CompileExpr::visit (HIR::BreakExpr &expr)
          return;
        }
 
-      tree goto_label
-       = ctx->get_backend ()->goto_statement (label, expr.get_locus ());
+      tree goto_label = Backend::goto_statement (label, expr.get_locus ());
       ctx->add_statement (goto_label);
     }
   else
     {
-      tree exit_expr = ctx->get_backend ()->exit_expression (
-       ctx->get_backend ()->boolean_constant_expression (true),
-       expr.get_locus ());
+      tree exit_expr
+       = Backend::exit_expression (Backend::boolean_constant_expression (true),
+                                   expr.get_locus ());
       ctx->add_statement (exit_expr);
     }
 }
@@ -804,7 +789,7 @@ CompileExpr::visit (HIR::ContinueExpr &expr)
        }
     }
 
-  translated = ctx->get_backend ()->goto_statement (label, expr.get_locus ());
+  translated = Backend::goto_statement (label, expr.get_locus ());
 }
 
 void
@@ -933,8 +918,7 @@ CompileExpr::visit (HIR::AssignmentExpr &expr)
   // debug_tree (lvalue);
 
   tree assignment
-    = ctx->get_backend ()->assignment_statement (lvalue, rvalue,
-                                                expr.get_locus ());
+    = Backend::assignment_statement (lvalue, rvalue, expr.get_locus ());
 
   ctx->add_statement (assignment);
 }
@@ -1333,29 +1317,28 @@ CompileExpr::visit (HIR::MatchExpr &expr)
 
   bool is_address_taken = false;
   tree ret_var_stmt = nullptr;
-  tmp = ctx->get_backend ()->temporary_variable (fnctx.fndecl, enclosing_scope,
-                                                block_type, NULL,
-                                                is_address_taken,
-                                                expr.get_locus (),
-                                                &ret_var_stmt);
+  tmp = Backend::temporary_variable (fnctx.fndecl, enclosing_scope, block_type,
+                                    NULL, is_address_taken, expr.get_locus (),
+                                    &ret_var_stmt);
   ctx->add_statement (ret_var_stmt);
 
   // lets compile the scrutinee expression
   tree match_scrutinee_rval
     = CompileExpr::Compile (expr.get_scrutinee_expr ().get (), ctx);
 
-  Bvariable *match_scrutinee_tmp_var = ctx->get_backend ()->temporary_variable (
-    fnctx.fndecl, enclosing_scope, TREE_TYPE (match_scrutinee_rval), NULL,
-    is_address_taken, expr.get_locus (), &ret_var_stmt);
+  Bvariable *match_scrutinee_tmp_var
+    = Backend::temporary_variable (fnctx.fndecl, enclosing_scope,
+                                  TREE_TYPE (match_scrutinee_rval), NULL,
+                                  is_address_taken, expr.get_locus (),
+                                  &ret_var_stmt);
   ctx->add_statement (ret_var_stmt);
 
   tree match_scrutinee_expr = match_scrutinee_tmp_var->get_tree (
     expr.get_scrutinee_expr ()->get_locus ());
 
   tree assignment
-    = ctx->get_backend ()->assignment_statement (match_scrutinee_expr,
-                                                match_scrutinee_rval,
-                                                expr.get_locus ());
+    = Backend::assignment_statement (match_scrutinee_expr, match_scrutinee_rval,
+                                    expr.get_locus ());
   ctx->add_statement (assignment);
 
   tree match_scrutinee_expr_qualifier_expr;
@@ -1369,13 +1352,11 @@ CompileExpr::visit (HIR::MatchExpr &expr)
       // would be DECL_QUALIFIER i think. For now this will just access the
       // first record field and its respective qualifier because it will always
       // be set because this is all a big special union
-      tree scrutinee_first_record_expr
-       = ctx->get_backend ()->struct_field_expression (
-         match_scrutinee_expr, 0, expr.get_scrutinee_expr ()->get_locus ());
-      match_scrutinee_expr_qualifier_expr
-       = ctx->get_backend ()->struct_field_expression (
-         scrutinee_first_record_expr, 0,
-         expr.get_scrutinee_expr ()->get_locus ());
+      tree scrutinee_first_record_expr = Backend::struct_field_expression (
+       match_scrutinee_expr, 0, expr.get_scrutinee_expr ()->get_locus ());
+      match_scrutinee_expr_qualifier_expr = Backend::struct_field_expression (
+       scrutinee_first_record_expr, 0,
+       expr.get_scrutinee_expr ()->get_locus ());
     }
   else if (scrutinee_kind == TyTy::TypeKind::REF)
     {
@@ -1433,11 +1414,11 @@ CompileExpr::visit (HIR::MatchExpr &expr)
                // because it will always be set because this is all a big
                // special union
                tree scrutinee_first_record_expr
-                 = ctx->get_backend ()->struct_field_expression (
+                 = Backend::struct_field_expression (
                    match_scrutinee_expr, 0,
                    expr.get_scrutinee_expr ()->get_locus ());
                match_scrutinee_expr_qualifier_expr
-                 = ctx->get_backend ()->struct_field_expression (
+                 = Backend::struct_field_expression (
                    scrutinee_first_record_expr, 0,
                    expr.get_scrutinee_expr ()->get_locus ());
              }
@@ -1469,18 +1450,16 @@ CompileExpr::visit (HIR::MatchExpr &expr)
   tree fndecl = fnctx.fndecl;
   location_t end_label_locus = expr.get_locus (); // FIXME
   tree end_label
-    = ctx->get_backend ()->label (fndecl,
-                                 "" /* empty creates an artificial label */,
-                                 end_label_locus);
+    = Backend::label (fndecl, "" /* empty creates an artificial label */,
+                     end_label_locus);
   tree end_label_decl_statement
-    = ctx->get_backend ()->label_definition_statement (end_label);
+    = Backend::label_definition_statement (end_label);
 
   // setup the switch-body-block
   location_t start_location = UNKNOWN_LOCATION; // FIXME
   location_t end_location = UNKNOWN_LOCATION;  // FIXME
-  tree switch_body_block
-    = ctx->get_backend ()->block (fndecl, enclosing_scope, {}, start_location,
-                                 end_location);
+  tree switch_body_block = Backend::block (fndecl, enclosing_scope, {},
+                                          start_location, end_location);
   ctx->push_block (switch_body_block);
 
   for (auto &kase : expr.get_match_cases ())
@@ -1491,8 +1470,9 @@ CompileExpr::visit (HIR::MatchExpr &expr)
 
       // generate implicit label
       location_t arm_locus = kase_arm.get_locus ();
-      tree case_label = ctx->get_backend ()->label (
-       fndecl, "" /* empty creates an artificial label */, arm_locus);
+      tree case_label
+       = Backend::label (fndecl, "" /* empty creates an artificial label */,
+                         arm_locus);
 
       // setup the bindings for the block
       for (auto &kase_pattern : kase_arm.get_patterns ())
@@ -1508,11 +1488,10 @@ CompileExpr::visit (HIR::MatchExpr &expr)
 
       // compile the expr and setup the assignment if required when tmp != NULL
       tree kase_expr_tree = CompileExpr::Compile (kase.get_expr ().get (), ctx);
-      tree result_reference
-       = ctx->get_backend ()->var_expression (tmp, arm_locus);
+      tree result_reference = Backend::var_expression (tmp, arm_locus);
       tree assignment
-       = ctx->get_backend ()->assignment_statement (result_reference,
-                                                    kase_expr_tree, arm_locus);
+       = Backend::assignment_statement (result_reference, kase_expr_tree,
+                                        arm_locus);
       ctx->add_statement (assignment);
 
       // go to end label
@@ -1530,7 +1509,7 @@ CompileExpr::visit (HIR::MatchExpr &expr)
   ctx->add_statement (match_expr_stmt);
   ctx->add_statement (end_label_decl_statement);
 
-  translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
+  translated = Backend::var_expression (tmp, expr.get_locus ());
 }
 
 void
@@ -1617,9 +1596,10 @@ CompileExpr::visit (HIR::CallExpr &expr)
       for (auto &arg : arguments)
        ctor_arguments.push_back (arg);
 
-      translated = ctx->get_backend ()->constructor_expression (
-       compiled_adt_type, adt->is_enum (), ctor_arguments, union_disriminator,
-       expr.get_locus ());
+      translated
+       = Backend::constructor_expression (compiled_adt_type, adt->is_enum (),
+                                          ctor_arguments, union_disriminator,
+                                          expr.get_locus ());
 
       return;
     }
@@ -1709,8 +1689,8 @@ CompileExpr::visit (HIR::CallExpr &expr)
     }
 
   // must be a regular call to a function
-  translated = ctx->get_backend ()->call_expression (fn_address, args, nullptr,
-                                                    expr.get_locus ());
+  translated
+    = Backend::call_expression (fn_address, args, nullptr, expr.get_locus ());
 }
 
 void
@@ -1806,8 +1786,8 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
       args.push_back (rvalue);
     }
 
-  translated = ctx->get_backend ()->call_expression (fn_expr, args, nullptr,
-                                                    expr.get_locus ());
+  translated
+    = Backend::call_expression (fn_expr, args, nullptr, expr.get_locus ());
 }
 
 tree
@@ -1841,8 +1821,7 @@ CompileExpr::get_fn_addr_from_dyn (const TyTy::DynamicObjectType *dyn,
   tree idx = build_int_cst (size_type_node, offs);
 
   tree vtable_ptr
-    = ctx->get_backend ()->struct_field_expression (receiver_ref, 1,
-                                                   expr_locus);
+    = Backend::struct_field_expression (receiver_ref, 1, expr_locus);
   tree vtable_array_access
     = build4_loc (expr_locus, ARRAY_REF, TREE_TYPE (TREE_TYPE (vtable_ptr)),
                  vtable_ptr, idx, NULL_TREE, NULL_TREE);
@@ -1860,8 +1839,7 @@ CompileExpr::get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn,
                                    location_t expr_locus)
 {
   // access the offs + 1 for the fnptr and offs=0 for the reciever obj
-  return ctx->get_backend ()->struct_field_expression (receiver_ref, 0,
-                                                      expr_locus);
+  return Backend::struct_field_expression (receiver_ref, 0, expr_locus);
 }
 
 tree
@@ -1906,8 +1884,7 @@ CompileExpr::resolve_operator_overload (
   if (rhs != nullptr)   // can be null for negation_expr (unary ones)
     args.push_back (rhs);
 
-  return ctx->get_backend ()->call_expression (fn_expr, args, nullptr,
-                                              expr.get_locus ());
+  return Backend::call_expression (fn_expr, args, nullptr, expr.get_locus ());
 }
 
 tree
@@ -1918,7 +1895,7 @@ CompileExpr::compile_bool_literal (const HIR::LiteralExpr &expr,
 
   const auto literal_value = expr.get_literal ();
   bool bval = literal_value.as_string ().compare ("true") == 0;
-  return ctx->get_backend ()->boolean_constant_expression (bval);
+  return Backend::boolean_constant_expression (bval);
 }
 
 tree
@@ -2009,7 +1986,7 @@ CompileExpr::compile_char_literal (const HIR::LiteralExpr &expr,
 
   // FIXME needs wchar_t
   char c = literal_value.as_string ().c_str ()[0];
-  return ctx->get_backend ()->wchar_constant_expression (c);
+  return Backend::wchar_constant_expression (c);
 }
 
 tree
@@ -2033,8 +2010,7 @@ CompileExpr::compile_string_literal (const HIR::LiteralExpr &expr,
   rust_assert (expr.get_lit_type () == HIR::Literal::STRING);
   const auto literal_value = expr.get_literal ();
 
-  auto base = ctx->get_backend ()->string_constant_expression (
-    literal_value.as_string ());
+  auto base = Backend::string_constant_expression (literal_value.as_string ());
   tree data = address_expression (base, expr.get_locus ());
 
   TyTy::BaseType *usize = nullptr;
@@ -2044,9 +2020,8 @@ CompileExpr::compile_string_literal (const HIR::LiteralExpr &expr,
 
   tree size = build_int_cstu (type, literal_value.as_string ().size ());
 
-  return ctx->get_backend ()->constructor_expression (fat_pointer, false,
-                                                     {data, size}, -1,
-                                                     expr.get_locus ());
+  return Backend::constructor_expression (fat_pointer, false, {data, size}, -1,
+                                         expr.get_locus ());
 }
 
 tree
@@ -2068,16 +2043,15 @@ CompileExpr::compile_byte_string_literal (const HIR::LiteralExpr &expr,
   for (size_t i = 0; i < value_str.size (); i++)
     {
       char b = value_str.at (i);
-      tree bb = ctx->get_backend ()->char_constant_expression (b);
+      tree bb = Backend::char_constant_expression (b);
       vals.push_back (bb);
       indexes.push_back (i);
     }
 
   tree array_type = TyTyResolveCompile::compile (ctx, array_tyty);
   tree constructed
-    = ctx->get_backend ()->array_constructor_expression (array_type, indexes,
-                                                        vals,
-                                                        expr.get_locus ());
+    = Backend::array_constructor_expression (array_type, indexes, vals,
+                                            expr.get_locus ());
 
   return address_expression (constructed, expr.get_locus ());
 }
@@ -2090,7 +2064,7 @@ CompileExpr::type_cast_expression (tree type_to_cast_to, tree expr_tree,
       || TREE_TYPE (expr_tree) == error_mark_node)
     return error_mark_node;
 
-  if (ctx->get_backend ()->type_size (type_to_cast_to) == 0
+  if (Backend::type_size (type_to_cast_to) == 0
       || TREE_TYPE (expr_tree) == void_type_node)
     {
       // Do not convert zero-sized types.
@@ -2151,8 +2125,7 @@ CompileExpr::type_cast_expression (tree type_to_cast_to, tree expr_tree,
 
       // this is returning the direct raw pointer of the slice an assumes a very
       // specific layout
-      return ctx->get_backend ()->struct_field_expression (expr_tree, 0,
-                                                          location);
+      return Backend::struct_field_expression (expr_tree, 0, location);
     }
 
   return fold_convert_loc (location, type_to_cast_to, expr_tree);
@@ -2215,9 +2188,8 @@ CompileExpr::array_value_expr (location_t expr_locus,
       indexes.push_back (i++);
     }
 
-  return ctx->get_backend ()->array_constructor_expression (array_type, indexes,
-                                                           constructor,
-                                                           expr_locus);
+  return Backend::array_constructor_expression (array_type, indexes,
+                                               constructor, expr_locus);
 }
 
 tree
@@ -2276,10 +2248,8 @@ CompileExpr::array_copied_expr (location_t expr_locus,
          indexes.push_back (idx++);
        }
 
-      return ctx->get_backend ()->array_constructor_expression (array_type,
-                                                               indexes,
-                                                               constructor,
-                                                               expr_locus);
+      return Backend::array_constructor_expression (array_type, indexes,
+                                                   constructor, expr_locus);
     }
 
   else
@@ -2291,24 +2261,21 @@ CompileExpr::array_copied_expr (location_t expr_locus,
 
       std::vector<Bvariable *> locals;
       tree enclosing_scope = ctx->peek_enclosing_scope ();
-      tree init_block
-       = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
-                                     expr_locus, expr_locus);
+      tree init_block = Backend::block (fndecl, enclosing_scope, locals,
+                                       expr_locus, expr_locus);
       ctx->push_block (init_block);
 
       tree tmp;
-      tree stmts
-       = ctx->get_backend ()->array_initializer (fndecl, init_block,
-                                                 array_type, capacity_expr,
-                                                 translated_expr, &tmp,
-                                                 expr_locus);
+      tree stmts = Backend::array_initializer (fndecl, init_block, array_type,
+                                              capacity_expr, translated_expr,
+                                              &tmp, expr_locus);
       ctx->add_statement (stmts);
 
       tree block = ctx->pop_block ();
 
       // The result is a compound expression which creates a temporary array,
       // initializes all the elements in a loop, and then yeilds the array.
-      return ctx->get_backend ()->compound_expression (block, tmp, expr_locus);
+      return Backend::compound_expression (block, tmp, expr_locus);
     }
 }
 
@@ -2374,8 +2341,8 @@ HIRCompileBase::resolve_deref_adjustment (Resolver::Adjustment &adjustment,
     }
 
   // make the call
-  return ctx->get_backend ()->call_expression (fn_address, {adjusted_argument},
-                                              nullptr, locus);
+  return Backend::call_expression (fn_address, {adjusted_argument}, nullptr,
+                                  locus);
 }
 
 tree
@@ -2434,8 +2401,8 @@ HIRCompileBase::resolve_unsized_slice_adjustment (
        .to_uhwi ();
   tree size = build_int_cstu (size_type_node, array_size);
 
-  return ctx->get_backend ()->constructor_expression (fat_pointer, false,
-                                                     {data, size}, -1, locus);
+  return Backend::constructor_expression (fat_pointer, false, {data, size}, -1,
+                                         locus);
 }
 
 tree
@@ -2476,9 +2443,8 @@ CompileExpr::visit (HIR::RangeFromToExpr &expr)
   tree adt = TyTyResolveCompile::compile (ctx, tyty);
 
   // make the constructor
-  translated
-    = ctx->get_backend ()->constructor_expression (adt, false, {from, to}, -1,
-                                                  expr.get_locus ());
+  translated = Backend::constructor_expression (adt, false, {from, to}, -1,
+                                               expr.get_locus ());
 }
 
 void
@@ -2499,9 +2465,8 @@ CompileExpr::visit (HIR::RangeFromExpr &expr)
   tree adt = TyTyResolveCompile::compile (ctx, tyty);
 
   // make the constructor
-  translated
-    = ctx->get_backend ()->constructor_expression (adt, false, {from}, -1,
-                                                  expr.get_locus ());
+  translated = Backend::constructor_expression (adt, false, {from}, -1,
+                                               expr.get_locus ());
 }
 
 void
@@ -2523,8 +2488,7 @@ CompileExpr::visit (HIR::RangeToExpr &expr)
 
   // make the constructor
   translated
-    = ctx->get_backend ()->constructor_expression (adt, false, {to}, -1,
-                                                  expr.get_locus ());
+    = Backend::constructor_expression (adt, false, {to}, -1, expr.get_locus ());
 }
 
 void
@@ -2536,8 +2500,8 @@ CompileExpr::visit (HIR::RangeFullExpr &expr)
   rust_assert (ok);
 
   tree adt = TyTyResolveCompile::compile (ctx, tyty);
-  translated = ctx->get_backend ()->constructor_expression (adt, false, {}, -1,
-                                                           expr.get_locus ());
+  translated
+    = Backend::constructor_expression (adt, false, {}, -1, expr.get_locus ());
 }
 
 void
@@ -2559,9 +2523,8 @@ CompileExpr::visit (HIR::RangeFromToInclExpr &expr)
   tree adt = TyTyResolveCompile::compile (ctx, tyty);
 
   // make the constructor
-  translated
-    = ctx->get_backend ()->constructor_expression (adt, false, {from, to}, -1,
-                                                  expr.get_locus ());
+  translated = Backend::constructor_expression (adt, false, {from, to}, -1,
+                                               expr.get_locus ());
 }
 
 void
@@ -2613,9 +2576,8 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr)
        = indirect_expression (array_reference, expr.get_locus ());
     }
 
-  translated
-    = ctx->get_backend ()->array_index_expression (array_reference, index,
-                                                  expr.get_locus ());
+  translated = Backend::array_index_expression (array_reference, index,
+                                               expr.get_locus ());
 }
 
 void
@@ -2659,9 +2621,8 @@ CompileExpr::visit (HIR::ClosureExpr &expr)
       vals.push_back (val);
     }
 
-  translated
-    = ctx->get_backend ()->constructor_expression (compiled_closure_tyty, false,
-                                                  vals, -1, expr.get_locus ());
+  translated = Backend::constructor_expression (compiled_closure_tyty, false,
+                                               vals, -1, expr.get_locus ());
 }
 
 tree
@@ -2685,9 +2646,8 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
   std::string asm_name = ctx->mangle_item (&closure_tyty, path);
 
   unsigned int flags = 0;
-  tree fndecl
-    = ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name, asm_name,
-                                    flags, expr.get_locus ());
+  tree fndecl = Backend::function (compiled_fn_type, ir_symbol_name, asm_name,
+                                  flags, expr.get_locus ());
 
   // insert into the context
   ctx->insert_function_decl (fn_tyty, fndecl);
@@ -2698,9 +2658,8 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
 
   // closure self
   Bvariable *self_param
-    = ctx->get_backend ()->parameter_variable (fndecl, "$closure",
-                                              compiled_closure_tyty,
-                                              expr.get_locus ());
+    = Backend::parameter_variable (fndecl, "$closure", compiled_closure_tyty,
+                                  expr.get_locus ());
   DECL_ARTIFICIAL (self_param->get_decl ()) = 1;
   param_vars.push_back (self_param);
 
@@ -2717,8 +2676,9 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
       rust_assert (ok);
 
       // get the assessor
-      tree binding = ctx->get_backend ()->struct_field_expression (
-       self_param->get_tree (expr.get_locus ()), idx, expr.get_locus ());
+      tree binding = Backend::struct_field_expression (self_param->get_tree (
+                                                        expr.get_locus ()),
+                                                      idx, expr.get_locus ());
       tree indirection = indirect_expression (binding, expr.get_locus ());
 
       // insert bindings
@@ -2732,8 +2692,8 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
   tree args_type
     = TyTyResolveCompile::compile (ctx, &closure_tyty.get_parameters ());
   Bvariable *args_param
-    = ctx->get_backend ()->parameter_variable (fndecl, "args", args_type,
-                                              expr.get_locus ());
+    = Backend::parameter_variable (fndecl, "args", args_type,
+                                  expr.get_locus ());
   param_vars.push_back (args_param);
 
   // setup the implicit mappings for the arguments. Since argument passing to
@@ -2746,15 +2706,16 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
   size_t i = 0;
   for (auto &closure_param : expr.get_params ())
     {
-      tree compiled_param_var = ctx->get_backend ()->struct_field_expression (
-       args_param_expr, i, closure_param.get_locus ());
+      tree compiled_param_var
+       = Backend::struct_field_expression (args_param_expr, i,
+                                           closure_param.get_locus ());
 
       CompilePatternBindings::Compile (closure_param.get_pattern ().get (),
                                       compiled_param_var, ctx);
       i++;
     }
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     {
       ctx->pop_closure_context ();
       return error_mark_node;
@@ -2788,8 +2749,8 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
       end_location = body->get_end_locus ();
     }
 
-  tree code_block = ctx->get_backend ()->block (fndecl, enclosing_scope, locals,
-                                               start_location, end_location);
+  tree code_block = Backend::block (fndecl, enclosing_scope, locals,
+                                   start_location, end_location);
   ctx->push_block (code_block);
 
   TyTy::BaseType *tyret = &closure_tyty.get_result_type ();
@@ -2800,10 +2761,9 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
   tree ret_var_stmt = NULL_TREE;
 
   return_address
-    = ctx->get_backend ()->temporary_variable (fndecl, code_block, return_type,
-                                              NULL, address_is_taken,
-                                              expr.get_locus (),
-                                              &ret_var_stmt);
+    = Backend::temporary_variable (fndecl, code_block, return_type, NULL,
+                                  address_is_taken, expr.get_locus (),
+                                  &ret_var_stmt);
 
   ctx->add_statement (ret_var_stmt);
 
@@ -2818,8 +2778,8 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
     {
       tree value = CompileExpr::Compile (function_body, ctx);
       tree return_expr
-       = ctx->get_backend ()->return_statement (fndecl, value,
-                                                function_body->get_locus ());
+       = Backend::return_statement (fndecl, value,
+                                    function_body->get_locus ());
       ctx->add_statement (return_expr);
     }
 
@@ -2931,9 +2891,8 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
   tree tuple_args_tyty = TREE_VALUE (tuple_args_tyty_chain);
 
   tree tuple_args
-    = ctx->get_backend ()->constructor_expression (tuple_args_tyty, false,
-                                                  tuple_arg_vals, -1,
-                                                  expr.get_locus ());
+    = Backend::constructor_expression (tuple_args_tyty, false, tuple_arg_vals,
+                                      -1, expr.get_locus ());
 
   // args are always self, and the tuple of the args we are passing where
   // self is the path of the call-expr in this case the fn_address
@@ -2942,9 +2901,9 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
   args.push_back (tuple_args);
 
   tree call_address = address_expression (function, expr.get_locus ());
-  *result = ctx->get_backend ()->call_expression (call_address, args,
-                                                 nullptr /* static chain ?*/,
-                                                 expr.get_locus ());
+  *result
+    = Backend::call_expression (call_address, args, nullptr /* static chain ?*/,
+                               expr.get_locus ());
   return true;
 }
 
index 9fb2086ad2cc46e50572c662d0024d8d0c7d3135..bf17beebc9bd4a089d6b84a926fc8e4c0186b3af 100644 (file)
@@ -51,7 +51,7 @@ public:
     Bvariable *lookup = Bvariable::error_variable ();
     if (ctx->lookup_var_decl (item.get_mappings ().get_hirid (), &lookup))
       {
-       reference = ctx->get_backend ()->var_expression (lookup, ref_locus);
+       reference = Backend::var_expression (lookup, ref_locus);
        return;
       }
 
@@ -70,13 +70,12 @@ public:
     bool in_unique_section = false;
 
     Bvariable *static_global
-      = ctx->get_backend ()->global_variable (name, asm_name, type, is_external,
-                                             is_hidden, in_unique_section,
-                                             item.get_locus ());
+      = Backend::global_variable (name, asm_name, type, is_external, is_hidden,
+                                 in_unique_section, item.get_locus ());
     ctx->insert_var_decl (item.get_mappings ().get_hirid (), static_global);
     ctx->push_var (static_global);
 
-    reference = ctx->get_backend ()->var_expression (static_global, ref_locus);
+    reference = Backend::var_expression (static_global, ref_locus);
   }
 
   void visit (HIR::ExternalFunctionItem &function) override
@@ -145,9 +144,8 @@ public:
       }
 
     const unsigned int flags = Backend::function_is_declaration;
-    tree fndecl
-      = ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
-                                      asm_name, flags, function.get_locus ());
+    tree fndecl = Backend::function (compiled_fn_type, ir_symbol_name, asm_name,
+                                    flags, function.get_locus ());
     TREE_PUBLIC (fndecl) = 1;
     setup_abi_options (fndecl, fntype->get_abi ());
 
index fb6049f25d5db329ed2762ba14f922ce396c0a57..68066b8463d0635d801ca4e7bf7d7d918ff4f8fa 100644 (file)
@@ -52,19 +52,20 @@ void
 CompileFnParam::visit (HIR::IdentifierPattern &pattern)
 {
   if (!pattern.is_mut ())
-    decl_type = ctx->get_backend ()->immutable_type (decl_type);
+    decl_type = Backend::immutable_type (decl_type);
 
-  compiled_param = ctx->get_backend ()->parameter_variable (
-    fndecl, pattern.get_identifier ().as_string (), decl_type, locus);
+  compiled_param
+    = Backend::parameter_variable (fndecl,
+                                  pattern.get_identifier ().as_string (),
+                                  decl_type, locus);
 }
 
 void
 CompileFnParam::visit (HIR::WildcardPattern &pattern)
 {
-  decl_type = ctx->get_backend ()->immutable_type (decl_type);
+  decl_type = Backend::immutable_type (decl_type);
 
-  compiled_param
-    = ctx->get_backend ()->parameter_variable (fndecl, "_", decl_type, locus);
+  compiled_param = Backend::parameter_variable (fndecl, "_", decl_type, locus);
 }
 
 void
@@ -96,10 +97,9 @@ CompileSelfParam::compile (Context *ctx, tree fndecl, HIR::SelfParam &self,
     = self.get_self_kind () == HIR::SelfParam::ImplicitSelfKind::IMM
       || self.get_self_kind () == HIR::SelfParam::ImplicitSelfKind::IMM_REF;
   if (is_immutable)
-    decl_type = ctx->get_backend ()->immutable_type (decl_type);
+    decl_type = Backend::immutable_type (decl_type);
 
-  return ctx->get_backend ()->parameter_variable (fndecl, "self", decl_type,
-                                                 locus);
+  return Backend::parameter_variable (fndecl, "self", decl_type, locus);
 }
 
 tree
@@ -109,12 +109,11 @@ CompileFnParam::create_tmp_param_var (tree decl_type)
   tree tmp_ident = create_tmp_var_name ("RSTPRM");
   std::string cpp_str_identifier = std::string (IDENTIFIER_POINTER (tmp_ident));
 
-  decl_type = ctx->get_backend ()->immutable_type (decl_type);
-  compiled_param
-    = ctx->get_backend ()->parameter_variable (fndecl, cpp_str_identifier,
-                                              decl_type, locus);
+  decl_type = Backend::immutable_type (decl_type);
+  compiled_param = Backend::parameter_variable (fndecl, cpp_str_identifier,
+                                               decl_type, locus);
 
-  return ctx->get_backend ()->var_expression (compiled_param, locus);
+  return Backend::var_expression (compiled_param, locus);
 }
 
 } // namespace Compile
index f2650c98c15032020ee8bbaa11621597c2863bf6..cdb5d7616c46dec8c2b9b7cc43b5ce40fa7957fd 100644 (file)
@@ -301,9 +301,8 @@ compile_intrinsic_function (Context *ctx, TyTy::FnType *fntype)
   std::string asm_name = ctx->mangle_item (fntype, canonical_path);
 
   unsigned int flags = 0;
-  tree fndecl
-    = ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name, asm_name,
-                                    flags, fntype->get_ident ().locus);
+  tree fndecl = Backend::function (compiled_fn_type, ir_symbol_name, asm_name,
+                                  flags, fntype->get_ident ().locus);
 
   TREE_PUBLIC (fndecl) = 0;
   TREE_READONLY (fndecl) = 1;
@@ -322,8 +321,8 @@ enter_intrinsic_block (Context *ctx, tree fndecl,
   location_t start_location = UNDEF_LOCATION;
   location_t end_location = UNDEF_LOCATION;
 
-  auto block = ctx->get_backend ()->block (fndecl, enclosing_scope, vars,
-                                          start_location, end_location);
+  auto block = Backend::block (fndecl, enclosing_scope, vars, start_location,
+                              end_location);
 
   ctx->push_block (block);
 }
@@ -357,19 +356,18 @@ offset_handler (Context *ctx, TyTy::FnType *fntype)
   auto &dst_param = param_vars.at (0);
   auto &size_param = param_vars.at (1);
   rust_assert (param_vars.size () == 2);
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   enter_intrinsic_block (ctx, fndecl);
 
   // BUILTIN offset FN BODY BEGIN
-  tree dst = ctx->get_backend ()->var_expression (dst_param, UNDEF_LOCATION);
-  tree size = ctx->get_backend ()->var_expression (size_param, UNDEF_LOCATION);
+  tree dst = Backend::var_expression (dst_param, UNDEF_LOCATION);
+  tree size = Backend::var_expression (size_param, UNDEF_LOCATION);
   tree pointer_offset_expr
     = pointer_offset_expression (dst, size, BUILTINS_LOCATION);
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, pointer_offset_expr,
-                                            UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, pointer_offset_expr, UNDEF_LOCATION);
   ctx->add_statement (return_statement);
   // BUILTIN offset FN BODY END
 
@@ -403,7 +401,7 @@ sizeof_handler (Context *ctx, TyTy::FnType *fntype)
   // BUILTIN size_of FN BODY BEGIN
   tree size_expr = TYPE_SIZE_UNIT (template_parameter_type);
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, size_expr, UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, size_expr, UNDEF_LOCATION);
   ctx->add_statement (return_statement);
   // BUILTIN size_of FN BODY END
 
@@ -428,13 +426,13 @@ transmute_handler (Context *ctx, TyTy::FnType *fntype)
   std::vector<tree_node *> compiled_types;
   compile_fn_params (ctx, fntype, fndecl, &param_vars, &compiled_types);
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   // param to convert
   Bvariable *convert_me_param = param_vars.at (0);
   tree convert_me_expr
-    = ctx->get_backend ()->var_expression (convert_me_param, UNDEF_LOCATION);
+    = Backend::var_expression (convert_me_param, UNDEF_LOCATION);
 
   // check for transmute pre-conditions
   tree target_type_expr = TREE_TYPE (DECL_RESULT (fndecl));
@@ -476,8 +474,7 @@ transmute_handler (Context *ctx, TyTy::FnType *fntype)
   tree result_expr = build_fold_indirect_ref_loc (UNKNOWN_LOCATION, t);
 
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, result_expr,
-                                            UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, result_expr, UNDEF_LOCATION);
   ctx->add_statement (return_statement);
   // BUILTIN transmute FN BODY END
 
@@ -505,19 +502,18 @@ rotate_handler (Context *ctx, TyTy::FnType *fntype, tree_code op)
   auto &x_param = param_vars.at (0);
   auto &y_param = param_vars.at (1);
   rust_assert (param_vars.size () == 2);
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   enter_intrinsic_block (ctx, fndecl);
 
   // BUILTIN rotate FN BODY BEGIN
-  tree x = ctx->get_backend ()->var_expression (x_param, UNDEF_LOCATION);
-  tree y = ctx->get_backend ()->var_expression (y_param, UNDEF_LOCATION);
+  tree x = Backend::var_expression (x_param, UNDEF_LOCATION);
+  tree y = Backend::var_expression (y_param, UNDEF_LOCATION);
   tree rotate_expr
     = fold_build2_loc (BUILTINS_LOCATION, op, TREE_TYPE (x), x, y);
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, rotate_expr,
-                                            UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, rotate_expr, UNDEF_LOCATION);
   ctx->add_statement (return_statement);
   // BUILTIN rotate FN BODY END
 
@@ -548,14 +544,14 @@ wrapping_op_handler_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
   auto &lhs_param = param_vars.at (0);
   auto &rhs_param = param_vars.at (1);
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   enter_intrinsic_block (ctx, fndecl);
 
   // BUILTIN wrapping_<op> FN BODY BEGIN
-  auto lhs = ctx->get_backend ()->var_expression (lhs_param, UNDEF_LOCATION);
-  auto rhs = ctx->get_backend ()->var_expression (rhs_param, UNDEF_LOCATION);
+  auto lhs = Backend::var_expression (lhs_param, UNDEF_LOCATION);
+  auto rhs = Backend::var_expression (rhs_param, UNDEF_LOCATION);
 
   // Operations are always wrapping in Rust, as we have -fwrapv enabled by
   // default. The difference between a wrapping_{add, sub, mul} and a regular
@@ -564,7 +560,7 @@ wrapping_op_handler_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
   auto wrap_expr = build2 (op, TREE_TYPE (lhs), lhs, rhs);
 
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, wrap_expr, UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, wrap_expr, UNDEF_LOCATION);
   ctx->add_statement (return_statement);
   // BUILTIN wrapping_<op> FN BODY END
 
@@ -595,7 +591,7 @@ op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
   auto &x_param = param_vars.at (0);
   auto &y_param = param_vars.at (1);
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   rust_assert (fntype->get_num_substitutions () == 1);
@@ -607,20 +603,20 @@ op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
 
   // this should match y as well or we can take it from the TyTy structure
   tree tmp_stmt = error_mark_node;
-  Bvariable *result_variable = ctx->get_backend ()->temporary_variable (
-    fndecl, NULL_TREE, template_parameter_type, NULL_TREE,
-    true /*address_is_taken*/, UNDEF_LOCATION, &tmp_stmt);
+  Bvariable *result_variable
+    = Backend::temporary_variable (fndecl, NULL_TREE, template_parameter_type,
+                                  NULL_TREE, true /*address_is_taken*/,
+                                  UNDEF_LOCATION, &tmp_stmt);
   Bvariable *bool_variable
-    = ctx->get_backend ()->temporary_variable (fndecl, NULL_TREE,
-                                              boolean_type_node, NULL_TREE,
-                                              true /*address_is_taken*/,
-                                              UNDEF_LOCATION, &tmp_stmt);
+    = Backend::temporary_variable (fndecl, NULL_TREE, boolean_type_node,
+                                  NULL_TREE, true /*address_is_taken*/,
+                                  UNDEF_LOCATION, &tmp_stmt);
 
   enter_intrinsic_block (ctx, fndecl, {result_variable, bool_variable});
 
   // BUILTIN op_with_overflow FN BODY BEGIN
-  auto x = ctx->get_backend ()->var_expression (x_param, UNDEF_LOCATION);
-  auto y = ctx->get_backend ()->var_expression (y_param, UNDEF_LOCATION);
+  auto x = Backend::var_expression (x_param, UNDEF_LOCATION);
+  auto y = Backend::var_expression (y_param, UNDEF_LOCATION);
 
   tree overflow_builtin = error_mark_node;
   switch (op)
@@ -654,20 +650,18 @@ op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
                                           3, x, y, result_ref);
 
   tree overflow_assignment
-    = ctx->get_backend ()->assignment_statement (bool_decl, builtin_call,
-                                                BUILTINS_LOCATION);
+    = Backend::assignment_statement (bool_decl, builtin_call,
+                                    BUILTINS_LOCATION);
 
   ctx->add_statement (overflow_assignment);
 
   std::vector<tree> vals = {result_decl, bool_decl};
   tree tuple_type = TREE_TYPE (DECL_RESULT (fndecl));
-  tree result_expr
-    = ctx->get_backend ()->constructor_expression (tuple_type, false, vals, -1,
-                                                  UNDEF_LOCATION);
+  tree result_expr = Backend::constructor_expression (tuple_type, false, vals,
+                                                     -1, UNDEF_LOCATION);
 
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, result_expr,
-                                            UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, result_expr, UNDEF_LOCATION);
   ctx->add_statement (return_statement);
 
   // BUILTIN wrapping_<op> FN BODY END
@@ -700,19 +694,16 @@ copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype)
   std::vector<Bvariable *> param_vars;
   compile_fn_params (ctx, fntype, fndecl, &param_vars);
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   enter_intrinsic_block (ctx, fndecl);
 
   // BUILTIN copy_nonoverlapping BODY BEGIN
 
-  auto src
-    = ctx->get_backend ()->var_expression (param_vars[0], UNDEF_LOCATION);
-  auto dst
-    = ctx->get_backend ()->var_expression (param_vars[1], UNDEF_LOCATION);
-  auto count
-    = ctx->get_backend ()->var_expression (param_vars[2], UNDEF_LOCATION);
+  auto src = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
+  auto dst = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
+  auto count = Backend::var_expression (param_vars[2], UNDEF_LOCATION);
 
   // We want to create the following statement
   // memcpy(dst, src, size_of::<T>());
@@ -730,9 +721,8 @@ copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype)
   rust_assert (memcpy_raw);
   auto memcpy = build_fold_addr_expr_loc (UNKNOWN_LOCATION, memcpy_raw);
 
-  auto copy_call
-    = ctx->get_backend ()->call_expression (memcpy, {dst, src, size_expr},
-                                           nullptr, UNDEF_LOCATION);
+  auto copy_call = Backend::call_expression (memcpy, {dst, src, size_expr},
+                                            nullptr, UNDEF_LOCATION);
 
   ctx->add_statement (copy_call);
 
@@ -749,8 +739,7 @@ make_unsigned_long_tree (Context *ctx, unsigned long value)
   mpz_t mpz_value;
   mpz_init_set_ui (mpz_value, value);
 
-  return ctx->get_backend ()->integer_constant_expression (integer_type_node,
-                                                          mpz_value);
+  return Backend::integer_constant_expression (integer_type_node, mpz_value);
 }
 
 static tree
@@ -771,13 +760,13 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind)
   std::vector<Bvariable *> args;
   compile_fn_params (ctx, fntype, fndecl, &args);
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, args))
+  if (!Backend::function_set_parameters (fndecl, args))
     return error_mark_node;
 
   enter_intrinsic_block (ctx, fndecl);
 
-  auto addr = ctx->get_backend ()->var_expression (args[0], UNDEF_LOCATION);
-  auto locality = ctx->get_backend ()->var_expression (args[1], UNDEF_LOCATION);
+  auto addr = Backend::var_expression (args[0], UNDEF_LOCATION);
+  auto locality = Backend::var_expression (args[1], UNDEF_LOCATION);
   auto rw_flag = make_unsigned_long_tree (ctx, kind == Prefetch::Write ? 1 : 0);
 
   auto prefetch_raw = NULL_TREE;
@@ -787,8 +776,8 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind)
   auto prefetch = build_fold_addr_expr_loc (UNKNOWN_LOCATION, prefetch_raw);
 
   auto prefetch_call
-    = ctx->get_backend ()->call_expression (prefetch, {addr, rw_flag, locality},
-                                           nullptr, UNDEF_LOCATION);
+    = Backend::call_expression (prefetch, {addr, rw_flag, locality}, nullptr,
+                               UNDEF_LOCATION);
 
   TREE_READONLY (prefetch_call) = 0;
   TREE_SIDE_EFFECTS (prefetch_call) = 1;
@@ -854,17 +843,15 @@ atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering)
   std::vector<tree> types;
   compile_fn_params (ctx, fntype, fndecl, &param_vars, &types);
 
-  auto ok = ctx->get_backend ()->function_set_parameters (fndecl, param_vars);
+  auto ok = Backend::function_set_parameters (fndecl, param_vars);
   rust_assert (ok);
 
   enter_intrinsic_block (ctx, fndecl);
 
-  auto dst
-    = ctx->get_backend ()->var_expression (param_vars[0], UNDEF_LOCATION);
+  auto dst = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
   TREE_READONLY (dst) = 0;
 
-  auto value
-    = ctx->get_backend ()->var_expression (param_vars[1], UNDEF_LOCATION);
+  auto value = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
   auto memorder = make_unsigned_long_tree (ctx, ordering);
 
   auto monomorphized_type
@@ -885,9 +872,8 @@ atomic_store_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering)
     = build_fold_addr_expr_loc (UNKNOWN_LOCATION, atomic_store_raw);
 
   auto store_call
-    = ctx->get_backend ()->call_expression (atomic_store,
-                                           {dst, value, memorder}, nullptr,
-                                           UNDEF_LOCATION);
+    = Backend::call_expression (atomic_store, {dst, value, memorder}, nullptr,
+                               UNDEF_LOCATION);
   TREE_READONLY (store_call) = 0;
   TREE_SIDE_EFFECTS (store_call) = 1;
 
@@ -919,13 +905,12 @@ atomic_load_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering)
   std::vector<tree> types;
   compile_fn_params (ctx, fntype, fndecl, &param_vars, &types);
 
-  auto ok = ctx->get_backend ()->function_set_parameters (fndecl, param_vars);
+  auto ok = Backend::function_set_parameters (fndecl, param_vars);
   rust_assert (ok);
 
   enter_intrinsic_block (ctx, fndecl);
 
-  auto src
-    = ctx->get_backend ()->var_expression (param_vars[0], UNDEF_LOCATION);
+  auto src = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
   auto memorder = make_unsigned_long_tree (ctx, ordering);
 
   auto monomorphized_type
@@ -945,11 +930,10 @@ atomic_load_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering)
   auto atomic_load
     = build_fold_addr_expr_loc (UNKNOWN_LOCATION, atomic_load_raw);
 
-  auto load_call
-    = ctx->get_backend ()->call_expression (atomic_load, {src, memorder},
-                                           nullptr, UNDEF_LOCATION);
+  auto load_call = Backend::call_expression (atomic_load, {src, memorder},
+                                            nullptr, UNDEF_LOCATION);
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, load_call, UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, load_call, UNDEF_LOCATION);
 
   TREE_READONLY (load_call) = 0;
   TREE_SIDE_EFFECTS (load_call) = 1;
@@ -976,15 +960,15 @@ unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
   std::vector<Bvariable *> param_vars;
   compile_fn_params (ctx, fntype, fndecl, &param_vars);
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   enter_intrinsic_block (ctx, fndecl);
 
   // BUILTIN unchecked_<op> BODY BEGIN
 
-  auto x = ctx->get_backend ()->var_expression (param_vars[0], UNDEF_LOCATION);
-  auto y = ctx->get_backend ()->var_expression (param_vars[1], UNDEF_LOCATION);
+  auto x = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
+  auto y = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
 
   auto *monomorphized_type
     = fntype->get_substs ().at (0).get_param_ty ()->resolve ();
@@ -994,7 +978,7 @@ unchecked_op_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
 
   auto expr = build2 (op, TREE_TYPE (x), x, y);
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, expr, UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, expr, UNDEF_LOCATION);
 
   ctx->add_statement (return_statement);
 
@@ -1036,10 +1020,9 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
 
   tree tmp_stmt = error_mark_node;
   Bvariable *bvar
-    = ctx->get_backend ()->temporary_variable (fndecl, NULL_TREE, dst_type,
-                                              NULL_TREE,
-                                              true /*address_is_taken*/,
-                                              UNDEF_LOCATION, &tmp_stmt);
+    = Backend::temporary_variable (fndecl, NULL_TREE, dst_type, NULL_TREE,
+                                  true /*address_is_taken*/, UNDEF_LOCATION,
+                                  &tmp_stmt);
 
   enter_intrinsic_block (ctx, fndecl, {bvar});
 
@@ -1062,7 +1045,7 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
   ctx->add_statement (memset_call);
 
   auto return_statement
-    = ctx->get_backend ()->return_statement (fndecl, dst, UNDEF_LOCATION);
+    = Backend::return_statement (fndecl, dst, UNDEF_LOCATION);
   ctx->add_statement (return_statement);
   // BUILTIN size_of FN BODY END
 
@@ -1097,17 +1080,15 @@ move_val_init_handler (Context *ctx, TyTy::FnType *fntype)
   std::vector<Bvariable *> param_vars;
   compile_fn_params (ctx, fntype, fndecl, &param_vars);
 
-  if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
+  if (!Backend::function_set_parameters (fndecl, param_vars))
     return error_mark_node;
 
   enter_intrinsic_block (ctx, fndecl);
 
   // BUILTIN size_of FN BODY BEGIN
 
-  tree dst
-    = ctx->get_backend ()->var_expression (param_vars[0], UNDEF_LOCATION);
-  tree src
-    = ctx->get_backend ()->var_expression (param_vars[1], UNDEF_LOCATION);
+  tree dst = Backend::var_expression (param_vars[0], UNDEF_LOCATION);
+  tree src = Backend::var_expression (param_vars[1], UNDEF_LOCATION);
   tree size = TYPE_SIZE_UNIT (template_parameter_type);
 
   tree memcpy_builtin = error_mark_node;
index 3fee2b09a9cfb00233f68c52778b651471ee8bbd..90a8fa76230e2577fe73ccc2c4930abadd838a0f 100644 (file)
@@ -30,8 +30,7 @@ CompileItem::visit (HIR::StaticItem &var)
   Bvariable *static_decl_ref = nullptr;
   if (ctx->lookup_var_decl (var.get_mappings ().get_hirid (), &static_decl_ref))
     {
-      reference
-       = ctx->get_backend ()->var_expression (static_decl_ref, ref_locus);
+      reference = Backend::var_expression (static_decl_ref, ref_locus);
       return;
     }
 
@@ -61,17 +60,16 @@ CompileItem::visit (HIR::StaticItem &var)
   bool in_unique_section = true;
 
   Bvariable *static_global
-    = ctx->get_backend ()->global_variable (name, asm_name, type, is_external,
-                                           is_hidden, in_unique_section,
-                                           var.get_locus ());
+    = Backend::global_variable (name, asm_name, type, is_external, is_hidden,
+                               in_unique_section, var.get_locus ());
 
   tree init = value == error_mark_node ? error_mark_node : DECL_INITIAL (value);
-  ctx->get_backend ()->global_variable_set_init (static_global, init);
+  Backend::global_variable_set_init (static_global, init);
 
   ctx->insert_var_decl (var.get_mappings ().get_hirid (), static_global);
   ctx->push_var (static_global);
 
-  reference = ctx->get_backend ()->var_expression (static_global, ref_locus);
+  reference = Backend::var_expression (static_global, ref_locus);
 }
 
 void
index 54bfda18ddb9dc65132c0d7f3da4b4fcc519757c..38fcedb011d80d522e0aacf9cae552ea81875418 100644 (file)
@@ -218,11 +218,14 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
            for (auto &pattern : items_no_range.get_patterns ())
              {
                tree variant_accessor
-                 = ctx->get_backend ()->struct_field_expression (
-                   match_scrutinee_expr, variant_index, pattern->get_locus ());
+                 = Backend::struct_field_expression (match_scrutinee_expr,
+                                                     variant_index,
+                                                     pattern->get_locus ());
 
-               tree binding = ctx->get_backend ()->struct_field_expression (
-                 variant_accessor, tuple_field_index++, pattern->get_locus ());
+               tree binding
+                 = Backend::struct_field_expression (variant_accessor,
+                                                     tuple_field_index++,
+                                                     pattern->get_locus ());
 
                ctx->insert_pattern_binding (
                  pattern->get_pattern_mappings ().get_hirid (), binding);
@@ -235,8 +238,10 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
              {
                tree variant_accessor = match_scrutinee_expr;
 
-               tree binding = ctx->get_backend ()->struct_field_expression (
-                 variant_accessor, tuple_field_index++, pattern->get_locus ());
+               tree binding
+                 = Backend::struct_field_expression (variant_accessor,
+                                                     tuple_field_index++,
+                                                     pattern->get_locus ());
 
                ctx->insert_pattern_binding (
                  pattern->get_pattern_mappings ().get_hirid (), binding);
@@ -307,19 +312,22 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern)
            if (adt->is_enum ())
              {
                tree variant_accessor
-                 = ctx->get_backend ()->struct_field_expression (
-                   match_scrutinee_expr, variant_index, ident.get_locus ());
+                 = Backend::struct_field_expression (match_scrutinee_expr,
+                                                     variant_index,
+                                                     ident.get_locus ());
 
                // we are offsetting by + 1 here since the first field in the
                // record is always the discriminator
-               binding = ctx->get_backend ()->struct_field_expression (
-                 variant_accessor, offs + 1, ident.get_locus ());
+               binding = Backend::struct_field_expression (variant_accessor,
+                                                           offs + 1,
+                                                           ident.get_locus ());
              }
            else
              {
                tree variant_accessor = match_scrutinee_expr;
-               binding = ctx->get_backend ()->struct_field_expression (
-                 variant_accessor, offs, ident.get_locus ());
+               binding
+                 = Backend::struct_field_expression (variant_accessor, offs,
+                                                     ident.get_locus ());
              }
 
            ctx->insert_pattern_binding (ident.get_mappings ().get_hirid (),
@@ -360,14 +368,12 @@ CompilePatternLet::visit (HIR::IdentifierPattern &pattern)
       ctx->add_statement (init_expr);
 
       auto unit_type_init_expr = unit_expression (ctx, rval_locus);
-      auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var,
-                                                   unit_type_init_expr);
+      auto s = Backend::init_statement (fnctx.fndecl, var, unit_type_init_expr);
       ctx->add_statement (s);
     }
   else
     {
-      auto s
-       = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr);
+      auto s = Backend::init_statement (fnctx.fndecl, var, init_expr);
       ctx->add_statement (s);
     }
 }
@@ -378,9 +384,9 @@ CompilePatternLet::visit (HIR::WildcardPattern &pattern)
   tree init_stmt = NULL;
   tree stmt_type = TyTyResolveCompile::compile (ctx, ty);
 
-  ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
-                                          stmt_type, init_expr, false,
-                                          pattern.get_locus (), &init_stmt);
+  Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE, stmt_type,
+                              init_expr, false, pattern.get_locus (),
+                              &init_stmt);
 
   ctx->add_statement (init_stmt);
 }
@@ -393,12 +399,10 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
   tree tuple_type = TyTyResolveCompile::compile (ctx, ty);
   tree init_stmt;
   Bvariable *tmp_var
-    = ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl,
-                                              NULL_TREE, tuple_type, init_expr,
-                                              false, pattern.get_locus (),
-                                              &init_stmt);
-  tree access_expr
-    = ctx->get_backend ()->var_expression (tmp_var, pattern.get_locus ());
+    = Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
+                                  tuple_type, init_expr, false,
+                                  pattern.get_locus (), &init_stmt);
+  tree access_expr = Backend::var_expression (tmp_var, pattern.get_locus ());
   ctx->add_statement (init_stmt);
 
   switch (pattern.get_items ()->get_pattern_type ())
@@ -418,8 +422,9 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
            bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
            rust_assert (ok);
 
-           tree sub_init = ctx->get_backend ()->struct_field_expression (
-             access_expr, tuple_idx, sub->get_locus ());
+           tree sub_init
+             = Backend::struct_field_expression (access_expr, tuple_idx,
+                                                 sub->get_locus ());
            CompilePatternLet::Compile (sub.get (), sub_init, ty_sub,
                                        rval_locus, ctx);
            tuple_idx++;
@@ -436,8 +441,9 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
            bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
            rust_assert (ok);
 
-           tree sub_init = ctx->get_backend ()->struct_field_expression (
-             access_expr, tuple_idx, sub->get_locus ());
+           tree sub_init
+             = Backend::struct_field_expression (access_expr, tuple_idx,
+                                                 sub->get_locus ());
            CompilePatternLet::Compile (sub.get (), sub_init, ty_sub,
                                        rval_locus, ctx);
            tuple_idx++;
@@ -457,8 +463,9 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
            bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
            rust_assert (ok);
 
-           tree sub_init = ctx->get_backend ()->struct_field_expression (
-             access_expr, tuple_idx, sub->get_locus ());
+           tree sub_init
+             = Backend::struct_field_expression (access_expr, tuple_idx,
+                                                 sub->get_locus ());
            CompilePatternLet::Compile (sub.get (), sub_init, ty_sub,
                                        rval_locus, ctx);
            tuple_idx++;
index df2bd0d316fc1ccaf117192afa3c70bb880aa469..729a09933e2470f73c33f8bbb83fa437bb383dd8 100644 (file)
@@ -96,10 +96,9 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
       tree folded_discrim_expr = fold_expr (discrim_expr_node);
       tree qualifier = folded_discrim_expr;
 
-      return ctx->get_backend ()->constructor_expression (compiled_adt_type,
-                                                         true, {qualifier},
-                                                         union_disriminator,
-                                                         expr_locus);
+      return Backend::constructor_expression (compiled_adt_type, true,
+                                             {qualifier}, union_disriminator,
+                                             expr_locus);
     }
 
   HirId ref;
@@ -130,7 +129,7 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
   if (ctx->lookup_var_decl (ref, &var))
     {
       // TREE_USED is setup in the gcc abstraction here
-      return ctx->get_backend ()->var_expression (var, expr_locus);
+      return Backend::var_expression (var, expr_locus);
     }
 
   // might be a match pattern binding
index 1d4f3bc186118fd71e7c38548d4d770ffc11b928..0c4710228d49dbe0543dbd33c227a56e3571b2c9 100644 (file)
@@ -79,9 +79,9 @@ TyTyResolveCompile::get_implicit_enumeral_node_type (Context *ctx)
   static tree enum_node = NULL_TREE;
   if (enum_node == NULL_TREE)
     {
-      enum_node = ctx->get_backend ()->named_type (
-       "enumeral", ctx->get_backend ()->integer_type (false, 64),
-       BUILTINS_LOCATION);
+      enum_node
+       = Backend::named_type ("enumeral", Backend::integer_type (false, 64),
+                              BUILTINS_LOCATION);
     }
   return enum_node;
 }
@@ -92,9 +92,8 @@ TyTyResolveCompile::get_unit_type (Context *ctx)
   static tree unit_type;
   if (unit_type == nullptr)
     {
-      auto unit_type_node = ctx->get_backend ()->struct_type ({});
-      unit_type = ctx->get_backend ()->named_type ("()", unit_type_node,
-                                                  BUILTINS_LOCATION);
+      auto unit_type_node = Backend::struct_type ({});
+      unit_type = Backend::named_type ("()", unit_type_node, BUILTINS_LOCATION);
     }
   return unit_type;
 }
@@ -175,13 +174,13 @@ TyTyResolveCompile::visit (const TyTy::ClosureType &type)
                                                   type.get_ident ().locus));
     }
 
-  tree type_record = ctx->get_backend ()->struct_type (fields);
+  tree type_record = Backend::struct_type (fields);
   RS_CLOSURE_FLAG (type_record) = 1;
 
   std::string named_struct_str
     = type.get_ident ().path.get () + "::{{closure}}";
-  translated = ctx->get_backend ()->named_type (named_struct_str, type_record,
-                                               type.get_ident ().locus);
+  translated = Backend::named_type (named_struct_str, type_record,
+                                   type.get_ident ().locus);
 }
 
 void
@@ -220,14 +219,11 @@ TyTyResolveCompile::visit (const TyTy::FnType &type)
     }
 
   if (!type.is_varadic ())
-    translated
-      = ctx->get_backend ()->function_type (receiver, parameters, results, NULL,
-                                           type.get_ident ().locus);
+    translated = Backend::function_type (receiver, parameters, results, NULL,
+                                        type.get_ident ().locus);
   else
-    translated
-      = ctx->get_backend ()->function_type_varadic (receiver, parameters,
-                                                   results, NULL,
-                                                   type.get_ident ().locus);
+    translated = Backend::function_type_varadic (receiver, parameters, results,
+                                                NULL, type.get_ident ().locus);
 }
 
 void
@@ -244,8 +240,8 @@ TyTyResolveCompile::visit (const TyTy::FnPtr &type)
       parameters.push_back (pty);
     }
 
-  translated = ctx->get_backend ()->function_ptr_type (result_type, parameters,
-                                                      type.get_ident ().locus);
+  translated = Backend::function_ptr_type (result_type, parameters,
+                                          type.get_ident ().locus);
 }
 
 void
@@ -270,9 +266,8 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
          fields.push_back (std::move (f));
        }
 
-      type_record = type.is_union ()
-                     ? ctx->get_backend ()->union_type (fields)
-                     : ctx->get_backend ()->struct_type (fields);
+      type_record = type.is_union () ? Backend::union_type (fields)
+                                    : Backend::struct_type (fields);
     }
   else
     {
@@ -333,10 +328,10 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
              fields.push_back (std::move (f));
            }
 
-         tree variant_record = ctx->get_backend ()->struct_type (fields);
-         tree named_variant_record = ctx->get_backend ()->named_type (
-           variant->get_ident ().path.get (), variant_record,
-           variant->get_ident ().locus);
+         tree variant_record = Backend::struct_type (fields);
+         tree named_variant_record
+           = Backend::named_type (variant->get_ident ().path.get (),
+                                  variant_record, variant->get_ident ().locus);
 
          // set the qualifier to be a builtin
          DECL_ARTIFICIAL (TYPE_FIELDS (variant_record)) = 1;
@@ -362,7 +357,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
        }
 
       // finally make the union or the enum
-      type_record = ctx->get_backend ()->union_type (enum_fields);
+      type_record = Backend::union_type (enum_fields);
     }
 
   // Handle repr options
@@ -387,8 +382,8 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
 
   std::string named_struct_str
     = type.get_ident ().path.get () + type.subst_as_string ();
-  translated = ctx->get_backend ()->named_type (named_struct_str, type_record,
-                                               type.get_ident ().locus);
+  translated = Backend::named_type (named_struct_str, type_record,
+                                   type.get_ident ().locus);
 }
 
 void
@@ -419,10 +414,9 @@ TyTyResolveCompile::visit (const TyTy::TupleType &type)
       fields.push_back (std::move (f));
     }
 
-  tree struct_type_record = ctx->get_backend ()->struct_type (fields);
-  translated
-    = ctx->get_backend ()->named_type (type.as_string (), struct_type_record,
-                                      type.get_ident ().locus);
+  tree struct_type_record = Backend::struct_type (fields);
+  translated = Backend::named_type (type.as_string (), struct_type_record,
+                                   type.get_ident ().locus);
 }
 
 void
@@ -437,8 +431,7 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type)
 
   tree folded_capacity_expr = fold_expr (capacity_expr);
 
-  translated
-    = ctx->get_backend ()->array_type (element_type, folded_capacity_expr);
+  translated = Backend::array_type (element_type, folded_capacity_expr);
 }
 
 void
@@ -448,15 +441,15 @@ TyTyResolveCompile::visit (const TyTy::SliceType &type)
 
   std::string named_struct_str
     = std::string ("[") + type.get_element_type ()->get_name () + "]";
-  translated = ctx->get_backend ()->named_type (named_struct_str, type_record,
-                                               type.get_ident ().locus);
+  translated = Backend::named_type (named_struct_str, type_record,
+                                   type.get_ident ().locus);
 }
 
 void
 TyTyResolveCompile::visit (const TyTy::BoolType &)
 {
-  translated = ctx->get_backend ()->named_type ("bool", boolean_type_node,
-                                               BUILTINS_LOCATION);
+  translated
+    = Backend::named_type ("bool", boolean_type_node, BUILTINS_LOCATION);
 }
 
 void
@@ -465,32 +458,32 @@ TyTyResolveCompile::visit (const TyTy::IntType &type)
   switch (type.get_int_kind ())
     {
     case TyTy::IntType::I8:
-      translated = ctx->get_backend ()->named_type (
-       "i8", ctx->get_backend ()->integer_type (false, 8), BUILTINS_LOCATION);
+      translated = Backend::named_type ("i8", Backend::integer_type (false, 8),
+                                       BUILTINS_LOCATION);
       return;
 
     case TyTy::IntType::I16:
-      translated = ctx->get_backend ()->named_type (
-       "i16", ctx->get_backend ()->integer_type (false, 16),
-       BUILTINS_LOCATION);
+      translated
+       = Backend::named_type ("i16", Backend::integer_type (false, 16),
+                              BUILTINS_LOCATION);
       return;
 
     case TyTy::IntType::I32:
-      translated = ctx->get_backend ()->named_type (
-       "i32", ctx->get_backend ()->integer_type (false, 32),
-       BUILTINS_LOCATION);
+      translated
+       = Backend::named_type ("i32", Backend::integer_type (false, 32),
+                              BUILTINS_LOCATION);
       return;
 
     case TyTy::IntType::I64:
-      translated = ctx->get_backend ()->named_type (
-       "i64", ctx->get_backend ()->integer_type (false, 64),
-       BUILTINS_LOCATION);
+      translated
+       = Backend::named_type ("i64", Backend::integer_type (false, 64),
+                              BUILTINS_LOCATION);
       return;
 
     case TyTy::IntType::I128:
-      translated = ctx->get_backend ()->named_type (
-       "i128", ctx->get_backend ()->integer_type (false, 128),
-       BUILTINS_LOCATION);
+      translated
+       = Backend::named_type ("i128", Backend::integer_type (false, 128),
+                              BUILTINS_LOCATION);
       return;
     }
 }
@@ -501,29 +494,29 @@ TyTyResolveCompile::visit (const TyTy::UintType &type)
   switch (type.get_uint_kind ())
     {
     case TyTy::UintType::U8:
-      translated = ctx->get_backend ()->named_type (
-       "u8", ctx->get_backend ()->integer_type (true, 8), BUILTINS_LOCATION);
+      translated = Backend::named_type ("u8", Backend::integer_type (true, 8),
+                                       BUILTINS_LOCATION);
       return;
 
     case TyTy::UintType::U16:
-      translated = ctx->get_backend ()->named_type (
-       "u16", ctx->get_backend ()->integer_type (true, 16), BUILTINS_LOCATION);
+      translated = Backend::named_type ("u16", Backend::integer_type (true, 16),
+                                       BUILTINS_LOCATION);
       return;
 
     case TyTy::UintType::U32:
-      translated = ctx->get_backend ()->named_type (
-       "u32", ctx->get_backend ()->integer_type (true, 32), BUILTINS_LOCATION);
+      translated = Backend::named_type ("u32", Backend::integer_type (true, 32),
+                                       BUILTINS_LOCATION);
       return;
 
     case TyTy::UintType::U64:
-      translated = ctx->get_backend ()->named_type (
-       "u64", ctx->get_backend ()->integer_type (true, 64), BUILTINS_LOCATION);
+      translated = Backend::named_type ("u64", Backend::integer_type (true, 64),
+                                       BUILTINS_LOCATION);
       return;
 
     case TyTy::UintType::U128:
-      translated = ctx->get_backend ()->named_type (
-       "u128", ctx->get_backend ()->integer_type (true, 128),
-       BUILTINS_LOCATION);
+      translated
+       = Backend::named_type ("u128", Backend::integer_type (true, 128),
+                              BUILTINS_LOCATION);
       return;
     }
 }
@@ -534,17 +527,13 @@ TyTyResolveCompile::visit (const TyTy::FloatType &type)
   switch (type.get_float_kind ())
     {
     case TyTy::FloatType::F32:
-      translated
-       = ctx->get_backend ()->named_type ("f32",
-                                          ctx->get_backend ()->float_type (32),
-                                          BUILTINS_LOCATION);
+      translated = Backend::named_type ("f32", Backend::float_type (32),
+                                       BUILTINS_LOCATION);
       return;
 
     case TyTy::FloatType::F64:
-      translated
-       = ctx->get_backend ()->named_type ("f64",
-                                          ctx->get_backend ()->float_type (64),
-                                          BUILTINS_LOCATION);
+      translated = Backend::named_type ("f64", Backend::float_type (64),
+                                       BUILTINS_LOCATION);
       return;
     }
 }
@@ -552,30 +541,28 @@ TyTyResolveCompile::visit (const TyTy::FloatType &type)
 void
 TyTyResolveCompile::visit (const TyTy::USizeType &)
 {
-  translated = ctx->get_backend ()->named_type (
-    "usize",
-    ctx->get_backend ()->integer_type (
-      true, ctx->get_backend ()->get_pointer_size ()),
-    BUILTINS_LOCATION);
+  translated
+    = Backend::named_type ("usize",
+                          Backend::integer_type (true,
+                                                 Backend::get_pointer_size ()),
+                          BUILTINS_LOCATION);
 }
 
 void
 TyTyResolveCompile::visit (const TyTy::ISizeType &)
 {
-  translated = ctx->get_backend ()->named_type (
-    "isize",
-    ctx->get_backend ()->integer_type (
-      false, ctx->get_backend ()->get_pointer_size ()),
-    BUILTINS_LOCATION);
+  translated
+    = Backend::named_type ("isize",
+                          Backend::integer_type (false,
+                                                 Backend::get_pointer_size ()),
+                          BUILTINS_LOCATION);
 }
 
 void
 TyTyResolveCompile::visit (const TyTy::CharType &)
 {
   translated
-    = ctx->get_backend ()->named_type ("char",
-                                      ctx->get_backend ()->wchar_type (),
-                                      BUILTINS_LOCATION);
+    = Backend::named_type ("char", Backend::wchar_type (), BUILTINS_LOCATION);
 }
 
 void
@@ -591,9 +578,8 @@ TyTyResolveCompile::visit (const TyTy::ReferenceType &type)
        = std::string (type.is_mutable () ? "&mut " : "&") + "["
          + slice->get_element_type ()->get_name () + "]";
 
-      translated
-       = ctx->get_backend ()->named_type (dyn_slice_type_str, type_record,
-                                          slice->get_locus ());
+      translated = Backend::named_type (dyn_slice_type_str, type_record,
+                                       slice->get_locus ());
 
       return;
     }
@@ -603,9 +589,8 @@ TyTyResolveCompile::visit (const TyTy::ReferenceType &type)
       std::string dyn_str_type_str
        = std::string (type.is_mutable () ? "&mut " : "&") + "str";
 
-      translated
-       = ctx->get_backend ()->named_type (dyn_str_type_str, type_record,
-                                          str->get_locus ());
+      translated = Backend::named_type (dyn_str_type_str, type_record,
+                                       str->get_locus ());
 
       return;
     }
@@ -615,9 +600,8 @@ TyTyResolveCompile::visit (const TyTy::ReferenceType &type)
       std::string dyn_str_type_str
        = std::string (type.is_mutable () ? "&mut " : "& ") + dyn->get_name ();
 
-      translated
-       = ctx->get_backend ()->named_type (dyn_str_type_str, type_record,
-                                          dyn->get_locus ());
+      translated = Backend::named_type (dyn_str_type_str, type_record,
+                                       dyn->get_locus ());
 
       return;
     }
@@ -626,12 +610,12 @@ TyTyResolveCompile::visit (const TyTy::ReferenceType &type)
     = TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
   if (type.is_mutable ())
     {
-      translated = ctx->get_backend ()->reference_type (base_compiled_type);
+      translated = Backend::reference_type (base_compiled_type);
     }
   else
     {
-      auto base = ctx->get_backend ()->immutable_type (base_compiled_type);
-      translated = ctx->get_backend ()->reference_type (base);
+      auto base = Backend::immutable_type (base_compiled_type);
+      translated = Backend::reference_type (base);
     }
 }
 
@@ -648,9 +632,8 @@ TyTyResolveCompile::visit (const TyTy::PointerType &type)
        = std::string (type.is_mutable () ? "*mut " : "*const ") + "["
          + slice->get_element_type ()->get_name () + "]";
 
-      translated
-       = ctx->get_backend ()->named_type (dyn_slice_type_str, type_record,
-                                          slice->get_locus ());
+      translated = Backend::named_type (dyn_slice_type_str, type_record,
+                                       slice->get_locus ());
 
       return;
     }
@@ -660,9 +643,8 @@ TyTyResolveCompile::visit (const TyTy::PointerType &type)
       std::string dyn_str_type_str
        = std::string (type.is_mutable () ? "*mut " : "*const ") + "str";
 
-      translated
-       = ctx->get_backend ()->named_type (dyn_str_type_str, type_record,
-                                          str->get_locus ());
+      translated = Backend::named_type (dyn_str_type_str, type_record,
+                                       str->get_locus ());
 
       return;
     }
@@ -673,9 +655,8 @@ TyTyResolveCompile::visit (const TyTy::PointerType &type)
        = std::string (type.is_mutable () ? "*mut " : "*const ")
          + dyn->get_name ();
 
-      translated
-       = ctx->get_backend ()->named_type (dyn_str_type_str, type_record,
-                                          dyn->get_locus ());
+      translated = Backend::named_type (dyn_str_type_str, type_record,
+                                       dyn->get_locus ());
 
       return;
     }
@@ -684,12 +665,12 @@ TyTyResolveCompile::visit (const TyTy::PointerType &type)
     = TyTyResolveCompile::compile (ctx, type.get_base (), trait_object_mode);
   if (type.is_mutable ())
     {
-      translated = ctx->get_backend ()->pointer_type (base_compiled_type);
+      translated = Backend::pointer_type (base_compiled_type);
     }
   else
     {
-      auto base = ctx->get_backend ()->immutable_type (base_compiled_type);
-      translated = ctx->get_backend ()->pointer_type (base);
+      auto base = Backend::immutable_type (base_compiled_type);
+      translated = Backend::pointer_type (base);
     }
 }
 
@@ -697,8 +678,7 @@ void
 TyTyResolveCompile::visit (const TyTy::StrType &type)
 {
   tree raw_str = create_str_type_record (type);
-  translated
-    = ctx->get_backend ()->named_type ("str", raw_str, BUILTINS_LOCATION);
+  translated = Backend::named_type ("str", raw_str, BUILTINS_LOCATION);
 }
 
 void
@@ -712,14 +692,13 @@ TyTyResolveCompile::visit (const TyTy::DynamicObjectType &type)
 {
   if (trait_object_mode)
     {
-      translated = ctx->get_backend ()->integer_type (
-       true, ctx->get_backend ()->get_pointer_size ());
+      translated = Backend::integer_type (true, Backend::get_pointer_size ());
       return;
     }
 
   tree type_record = create_dyn_obj_record (type);
-  translated = ctx->get_backend ()->named_type (type.get_name (), type_record,
-                                               type.get_ident ().locus);
+  translated = Backend::named_type (type.get_name (), type_record,
+                                   type.get_ident ().locus);
 }
 
 tree
@@ -729,8 +708,7 @@ TyTyResolveCompile::create_dyn_obj_record (const TyTy::DynamicObjectType &type)
   auto items = type.get_object_items ();
   std::vector<Backend::typed_identifier> fields;
 
-  tree uint = ctx->get_backend ()->integer_type (
-    true, ctx->get_backend ()->get_pointer_size ());
+  tree uint = Backend::integer_type (true, Backend::get_pointer_size ());
   tree uintptr_ty = build_pointer_type (uint);
 
   Backend::typed_identifier f ("pointer", uintptr_ty,
@@ -739,13 +717,13 @@ TyTyResolveCompile::create_dyn_obj_record (const TyTy::DynamicObjectType &type)
   fields.push_back (std::move (f));
 
   tree vtable_size = build_int_cst (size_type_node, items.size ());
-  tree vtable_type = ctx->get_backend ()->array_type (uintptr_ty, vtable_size);
+  tree vtable_type = Backend::array_type (uintptr_ty, vtable_size);
   Backend::typed_identifier vtf ("vtable", vtable_type,
                                 ctx->get_mappings ()->lookup_location (
                                   type.get_ty_ref ()));
   fields.push_back (std::move (vtf));
 
-  tree record = ctx->get_backend ()->struct_type (fields);
+  tree record = Backend::struct_type (fields);
   RS_DST_FLAG (record) = 1;
   TYPE_MAIN_VARIANT (record) = ctx->insert_main_variant (record);
 
@@ -769,7 +747,7 @@ TyTyResolveCompile::create_slice_type_record (const TyTy::SliceType &type)
   tree len_field_ty = TyTyResolveCompile::compile (ctx, usize);
   Backend::typed_identifier len_field ("len", len_field_ty, type.get_locus ());
 
-  tree record = ctx->get_backend ()->struct_type ({data_field, len_field});
+  tree record = Backend::struct_type ({data_field, len_field});
   RS_DST_FLAG (record) = 1;
   TYPE_MAIN_VARIANT (record) = ctx->insert_main_variant (record);
 
@@ -795,7 +773,7 @@ TyTyResolveCompile::create_str_type_record (const TyTy::StrType &type)
   tree len_field_ty = TyTyResolveCompile::compile (ctx, usize);
   Backend::typed_identifier len_field ("len", len_field_ty, type.get_locus ());
 
-  tree record = ctx->get_backend ()->struct_type ({data_field, len_field});
+  tree record = Backend::struct_type ({data_field, len_field});
   RS_DST_FLAG (record) = 1;
   TYPE_MAIN_VARIANT (record) = ctx->insert_main_variant (record);
 
index 0378ef519a303f339347072ab7109f42e9201af4..3abff897b2eafa1f149a7237321877a35d883cee 100644 (file)
@@ -40,11 +40,12 @@ public:
   void visit (HIR::IdentifierPattern &pattern) override
   {
     if (!pattern.is_mut ())
-      translated_type = ctx->get_backend ()->immutable_type (translated_type);
+      translated_type = Backend::immutable_type (translated_type);
 
-    Bvariable *var = ctx->get_backend ()->local_variable (
-      fndecl, pattern.get_identifier ().as_string (), translated_type,
-      NULL /*decl_var*/, pattern.get_locus ());
+    Bvariable *var
+      = Backend::local_variable (fndecl, pattern.get_identifier ().as_string (),
+                                translated_type, NULL /*decl_var*/,
+                                pattern.get_locus ());
 
     HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
     ctx->insert_var_decl (stmt_id, var);
index 93f740fb8128cb6f60c46cf9637a8bec93a8c4e8..60eb81c63062651236d7b2db50af0d20761a1580 100644 (file)
@@ -218,12 +218,14 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref,
       vtable_ctor_idx.push_back (i++);
     }
 
-  tree vtable_ctor = ctx->get_backend ()->array_constructor_expression (
-    TREE_TYPE (vtable_field), vtable_ctor_idx, vtable_ctor_elems, locus);
+  tree vtable_ctor
+    = Backend::array_constructor_expression (TREE_TYPE (vtable_field),
+                                            vtable_ctor_idx, vtable_ctor_elems,
+                                            locus);
 
   std::vector<tree> dyn_ctor = {address_of_compiled_ref, vtable_ctor};
-  return ctx->get_backend ()->constructor_expression (dynamic_object, false,
-                                                     dyn_ctor, -1, locus);
+  return Backend::constructor_expression (dynamic_object, false, dyn_ctor, -1,
+                                         locus);
 }
 
 tree
index 1e2f7c155361632c3d111b711a008768e1e16816..25dd3706fd40b4f01fcb12903888a14cc880163c 100644 (file)
@@ -40,430 +40,494 @@ class Bvariable;
 // The backend interface.  This is a pure abstract class that a
 // specific backend will implement.
 
-class Backend
-{
-public:
-  Backend ();
-
-  // Name/type/location.  Used for function parameters, struct fields,
-  // interface methods.
-  struct typed_identifier
-  {
-    std::string name;
-    tree type;
-    location_t location;
-
-    typed_identifier () : name (), type (NULL_TREE), location (UNKNOWN_LOCATION)
-    {}
-
-    typed_identifier (const std::string &a_name, tree a_type,
-                     location_t a_location)
-      : name (a_name), type (a_type), location (a_location)
-    {}
-  };
-
-  // debug
-  void debug (tree);
-  void debug (Bvariable *);
-
-  tree get_identifier_node (const std::string &str);
-
-  // Types.
-
-  // Get the wchar type
-  tree wchar_type ();
-
-  // Get the Host pointer size in bits
-  int get_pointer_size ();
-
-  // Get the raw str type const char*
-  tree raw_str_type ();
-
-  // Get an unnamed integer type with the given signedness and number
-  // of bits.
-  tree integer_type (bool is_unsigned, int bits);
-
-  // Get an unnamed floating point type with the given number of bits
-  // (32 or 64).
-  tree float_type (int bits);
-
-  // Get an unnamed complex type with the given number of bits (64 or 128).
-  tree complex_type (int bits);
-
-  // Get a pointer type.
-  tree pointer_type (tree to_type);
-
-  // Get a reference type.
-  tree reference_type (tree to_type);
-
-  // make type immutable
-  tree immutable_type (tree base);
-
-  // Get a function type.  The receiver, parameter, and results are
-  // generated from the types in the Function_type.  The Function_type
-  // is provided so that the names are available.  This should return
-  // not the type of a Go function (which is a pointer to a struct)
-  // but the type of a C function pointer (which will be used as the
-  // type of the first field of the struct).  If there is more than
-  // one result, RESULT_STRUCT is a struct type to hold the results,
-  // and RESULTS may be ignored; if there are zero or one results,
-  // RESULT_STRUCT is NULL.
-  tree function_type (const typed_identifier &receiver,
-                     const std::vector<typed_identifier> &parameters,
-                     const std::vector<typed_identifier> &results,
-                     tree result_struct, location_t location);
-
-  tree function_type_varadic (const typed_identifier &receiver,
-                             const std::vector<typed_identifier> &parameters,
-                             const std::vector<typed_identifier> &results,
-                             tree result_struct, location_t location);
+namespace Backend {
 
-  tree function_ptr_type (tree result, const std::vector<tree> &praameters,
-                         location_t location);
+void
+init ();
 
-  // Get a struct type.
-  tree struct_type (const std::vector<typed_identifier> &fields);
-
-  // Get a union type.
-  tree union_type (const std::vector<typed_identifier> &fields);
-
-  // Get an array type.
-  tree array_type (tree element_type, tree length);
-
-  // Return a named version of a type.  The location is the location
-  // of the type definition.  This will not be called for a type
-  // created via placeholder_pointer_type, placeholder_struct_type, or
-  // placeholder_array_type..  (It may be called for a pointer,
-  // struct, or array type in a case like "type P *byte; type Q P".)
-  tree named_type (const std::string &name, tree, location_t);
-
-  // Return the size of a type.
-  int64_t type_size (tree);
-
-  // Return the alignment of a type.
-  int64_t type_alignment (tree);
-
-  // Return the alignment of a struct field of this type.  This is
-  // normally the same as type_alignment, but not always.
-  int64_t type_field_alignment (tree);
-
-  // Return the offset of field INDEX in a struct type.  INDEX is the
-  // entry in the FIELDS std::vector parameter of struct_type or
-  // set_placeholder_struct_type.
-  int64_t type_field_offset (tree, size_t index);
-
-  // Expressions.
-
-  // Return an expression for a zero value of the given type.  This is
-  // used for cases such as local variable initialization and
-  // converting nil to other types.
-  tree zero_expression (tree);
-
-  // Create a reference to a variable.
-  tree var_expression (Bvariable *var, location_t);
-
-  // Return an expression for the multi-precision integer VAL in BTYPE.
-  tree integer_constant_expression (tree btype, mpz_t val);
-
-  // Return an expression for the floating point value VAL in BTYPE.
-  tree float_constant_expression (tree btype, mpfr_t val);
-
-  // Return an expression for the complex value VAL in BTYPE.
-  tree complex_constant_expression (tree btype, mpc_t val);
-
-  // Return an expression for the string value VAL.
-  tree string_constant_expression (const std::string &val);
-
-  // Get a char literal
-  tree char_constant_expression (char c);
-
-  // Get a char literal
-  tree wchar_constant_expression (wchar_t c);
-
-  // Return an expression for the boolean value VAL.
-  tree boolean_constant_expression (bool val);
-
-  // Return an expression for the real part of BCOMPLEX.
-  tree real_part_expression (tree bcomplex, location_t);
-
-  // Return an expression for the imaginary part of BCOMPLEX.
-  tree imag_part_expression (tree bcomplex, location_t);
+// Name/type/location.  Used for function parameters, struct fields,
+// interface methods.
+struct typed_identifier
+{
+  std::string name;
+  tree type;
+  location_t location;
 
-  // Return an expression for the complex number (BREAL, BIMAG).
-  tree complex_expression (tree breal, tree bimag, location_t);
+  typed_identifier () : name (), type (NULL_TREE), location (UNKNOWN_LOCATION)
+  {}
 
-  // Return an expression that converts EXPR to TYPE.
-  tree convert_expression (tree type, tree expr, location_t);
-
-  // Return an expression for the field at INDEX in BSTRUCT.
-  tree struct_field_expression (tree bstruct, size_t index, location_t);
-
-  // Create an expression that executes BSTAT before BEXPR.
-  tree compound_expression (tree bstat, tree bexpr, location_t);
-
-  // Return an expression that executes THEN_EXPR if CONDITION is true, or
-  // ELSE_EXPR otherwise and returns the result as type BTYPE, within the
-  // specified function FUNCTION.  ELSE_EXPR may be NULL.  BTYPE may be NULL.
-  tree conditional_expression (tree function, tree btype, tree condition,
-                              tree then_expr, tree else_expr, location_t);
-
-  // Return an expression for the negation operation OP EXPR.
-  // Supported values of OP are enumerated in NegationOperator.
-  tree negation_expression (NegationOperator op, tree expr, location_t);
-
-  // Return an expression for the operation LEFT OP RIGHT.
-  // Supported values of OP are enumerated in ArithmeticOrLogicalOperator.
-  tree arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op,
-                                        tree left, tree right, location_t loc);
-
-  // Return an expression for the operation LEFT OP RIGHT.
-  // Supported values of OP are enumerated in ArithmeticOrLogicalOperator.
-  // This function adds overflow checking and returns a list of statements to
-  // add to the current function context. The `receiver` variable refers to the
-  // variable which will contain the result of that operation.
-  tree arithmetic_or_logical_expression_checked (ArithmeticOrLogicalOperator op,
-                                                tree left, tree right,
-                                                location_t loc,
-                                                Bvariable *receiver);
-
-  // Return an expression for the operation LEFT OP RIGHT.
-  // Supported values of OP are enumerated in ComparisonOperator.
-  tree comparison_expression (ComparisonOperator op, tree left, tree right,
-                             location_t loc);
-
-  // Return an expression for the operation LEFT OP RIGHT.
-  // Supported values of OP are enumerated in LazyBooleanOperator.
-  tree lazy_boolean_expression (LazyBooleanOperator op, tree left, tree right,
-                               location_t);
-
-  // Return an expression that constructs BTYPE with VALS.  BTYPE must be the
-  // backend representation a of struct.  VALS must be in the same order as the
-  // corresponding fields in BTYPE.
-  tree constructor_expression (tree btype, bool is_variant,
-                              const std::vector<tree> &vals, int, location_t);
-
-  // Return an expression that constructs an array of BTYPE with INDEXES and
-  // VALS.  INDEXES and VALS must have the same amount of elements. Each index
-  // in INDEXES must be in the same order as the corresponding value in VALS.
-  tree array_constructor_expression (tree btype,
-                                    const std::vector<unsigned long> &indexes,
-                                    const std::vector<tree> &vals, location_t);
-
-  tree array_initializer (tree, tree, tree, tree, tree, tree *, location_t);
-
-  // Return an expression for ARRAY[INDEX] as an l-value.  ARRAY is a valid
-  // fixed-length array, not a slice.
-  tree array_index_expression (tree array, tree index, location_t);
-
-  // Create an expression for a call to FN with ARGS, taking place within
-  // caller CALLER.
-  tree call_expression (tree fn, const std::vector<tree> &args,
-                       tree static_chain, location_t);
-
-  // Statements.
-
-  // Create a variable initialization statement in the specified
-  // function.  This initializes a local variable at the point in the
-  // program flow where it is declared.
-  tree init_statement (tree, Bvariable *var, tree init);
-
-  // Create an assignment statement within the specified function.
-  tree assignment_statement (tree lhs, tree rhs, location_t);
-
-  // Create return statement for an decl for a value (can be NULL_TREE) at a
-  // location
-  tree return_statement (tree fndecl, tree val, location_t);
-
-  // Create an if statement within a function.  ELSE_BLOCK may be NULL.
-  tree if_statement (tree, tree condition, tree then_block, tree else_block,
-                    location_t);
-
-  // infinite loop expressions
-  tree loop_expression (tree body, location_t);
-
-  // exit expressions
-  tree exit_expression (tree condition, location_t);
-
-  // Create a single statement from two statements.
-  tree compound_statement (tree, tree);
-
-  // Create a single statement from a list of statements.
-  tree statement_list (const std::vector<tree> &);
-
-  // Create a statement that attempts to execute BSTAT and calls EXCEPT_STMT if
-  // an exception occurs. EXCEPT_STMT may be NULL.  FINALLY_STMT may be NULL and
-  // if not NULL, it will always be executed.  This is used for handling defers
-  // in Go functions.  In C++, the resulting code is of this form:
-  //   try { BSTAT; } catch { EXCEPT_STMT; } finally { FINALLY_STMT; }
-  tree exception_handler_statement (tree bstat, tree except_stmt,
-                                   tree finally_stmt, location_t);
-
-  // Blocks.
-
-  // Create a block.  The frontend will call this function when it
-  // starts converting a block within a function.  FUNCTION is the
-  // current function.  ENCLOSING is the enclosing block; it will be
-  // NULL for the top-level block in a function.  VARS is the list of
-  // local variables defined within this block; each entry will be
-  // created by the local_variable function.  START_LOCATION is the
-  // location of the start of the block, more or less the location of
-  // 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.
-  tree block (tree function, tree enclosing,
-             const std::vector<Bvariable *> &vars, location_t start_location,
-             location_t end_location);
-
-  // 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.
-  void block_add_statements (tree, const std::vector<tree> &);
-
-  // Variables.
-
-  // Create a global variable. NAME is the package-qualified name of
-  // the variable.  ASM_NAME is the encoded identifier for the
-  // variable, incorporating the package, and made safe for the
-  // assembler.  BTYPE is the type of the variable.  IS_EXTERNAL is
-  // true if the variable is defined in some other package.  IS_HIDDEN
-  // is true if the variable is not exported (name begins with a lower
-  // case letter).  IN_UNIQUE_SECTION is true if the variable should
-  // be put into a unique section if possible; this is intended to
-  // permit the linker to garbage collect the variable if it is not
-  // referenced.  LOCATION is where the variable was defined.
-  Bvariable *global_variable (const std::string &name,
-                             const std::string &asm_name, tree btype,
-                             bool is_external, bool is_hidden,
-                             bool in_unique_section, location_t location);
-
-  // A global variable will 1) be initialized to zero, or 2) be
-  // initialized to a constant value, or 3) be initialized in the init
-  // function.  In case 2, the frontend will call
-  // global_variable_set_init to set the initial value.  If this is
-  // not called, the backend should initialize a global variable to 0.
-  // The init function may then assign a value to it.
-  void global_variable_set_init (Bvariable *, tree);
-
-  // Create a local variable.  The frontend will create the local
-  // variables first, and then create the block which contains them.
-  // FUNCTION is the function in which the variable is defined.  NAME
-  // is the name of the variable.  TYPE is the type.  DECL_VAR, if not
-  // null, gives the location at which the value of this variable may
-  // be found, typically used to create an inner-scope reference to an
-  // outer-scope variable, to extend the lifetime of the variable beyond
-  // the inner scope.  IS_ADDRESS_TAKEN is true if the address of this
-  // variable is taken (this implies that the address does not escape
-  // the function, as otherwise the variable would be on the heap).
-  // LOCATION is where the variable is defined.  For each local variable
-  // the frontend will call init_statement to set the initial value.
-  Bvariable *local_variable (tree function, const std::string &name, tree type,
-                            Bvariable *decl_var, location_t location);
-
-  // Create a function parameter.  This is an incoming parameter, not
-  // a result parameter (result parameters are treated as local
-  // variables).  The arguments are as for local_variable.
-  Bvariable *parameter_variable (tree function, const std::string &name,
-                                tree type, location_t location);
-
-  // Create a static chain parameter.  This is the closure parameter.
-  Bvariable *static_chain_variable (tree function, const std::string &name,
-                                   tree type, location_t location);
-
-  // Create a temporary variable.  A temporary variable has no name,
-  // just a type.  We pass in FUNCTION and BLOCK in case they are
-  // needed.  If INIT is not NULL, the variable should be initialized
-  // to that value.  Otherwise the initial value is irrelevant--the
-  // backend does not have to explicitly initialize it to zero.
-  // ADDRESS_IS_TAKEN is true if the programs needs to take the
-  // address of this temporary variable.  LOCATION is the location of
-  // the statement or expression which requires creating the temporary
-  // 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.
-  Bvariable *temporary_variable (tree fndecl, tree bind_tree, tree type,
-                                tree init, bool address_is_taken,
-                                location_t location, tree *pstatement);
-
-  // Labels.
-
-  // Create a new label.  NAME will be empty if this is a label
-  // created by the frontend for a loop construct.  The location is
-  // where the label is defined.
-  tree label (tree, const std::string &name, location_t);
-
-  // Create a statement which defines a label.  This statement will be
-  // put into the codestream at the point where the label should be
-  // defined.
-  tree label_definition_statement (tree);
-
-  // Create a goto statement to a label.
-  tree goto_statement (tree, location_t);
-
-  // Create an expression for the address of a label.  This is used to
-  // get the return address of a deferred function which may call
-  // recover.
-  tree label_address (tree, location_t);
-
-  // Functions.
-
-  // Bit flags to pass to the function method.
-
-  // Set if this is a function declaration rather than a definition;
-  // the definition will be in another compilation unit.
-  static const unsigned int function_is_declaration = 1 << 0;
-
-  // Set if the function should never be inlined because they call
-  // recover and must be visible for correct panic recovery.
-  static const unsigned int function_is_uninlinable = 1 << 1;
-
-  // Set if the function does not return.  This is set for the
-  // implementation of panic.
-  static const unsigned int function_does_not_return = 1 << 2;
-
-  // Set if the function should be put in a unique section if
-  // possible.  This is used for field tracking.
-  static const unsigned int function_in_unique_section = 1 << 3;
-
-  // Declare or define a function of FNTYPE.
-  // NAME is the Go name of the function.  ASM_NAME, if not the empty
-  // string, is the name that should be used in the symbol table; this
-  // will be non-empty if a magic extern comment is used.  FLAGS is
-  // bit flags described above.
-  tree function (tree fntype, const std::string &name,
-                const std::string &asm_name, unsigned int flags, location_t);
-
-  // Create a statement that runs all deferred calls for FUNCTION.  This should
-  // be a statement that looks like this in C++:
-  //   finish:
-  //     try { DEFER_RETURN; } catch { CHECK_DEFER; goto finish; }
-  tree function_defer_statement (tree function, tree undefer, tree check_defer,
-                                location_t);
-
-  // Record PARAM_VARS as the variables to use for the parameters of FUNCTION.
-  // This will only be called for a function definition.  Returns true on
-  // success, false on failure.
-  bool function_set_parameters (tree function,
-                               const std::vector<Bvariable *> &param_vars);
-
-  // Utility.
-
-  // Write the definitions for all TYPE_DECLS, CONSTANT_DECLS,
-  // FUNCTION_DECLS, and VARIABLE_DECLS declared globally.
-  void
-  write_global_definitions (const std::vector<tree> &type_decls,
-                           const std::vector<tree> &constant_decls,
-                           const std::vector<tree> &function_decls,
-                           const std::vector<Bvariable *> &variable_decls);
-
-protected:
-  tree fill_in_fields (tree, const std::vector<typed_identifier> &);
-
-  tree fill_in_array (tree, tree, tree);
-
-  tree non_zero_size_type (tree);
-
-  tree convert_tree (tree, tree, location_t);
+  typed_identifier (const std::string &a_name, tree a_type,
+                   location_t a_location)
+    : name (a_name), type (a_type), location (a_location)
+  {}
 };
 
+// debug
+void debug (tree);
+void
+debug (Bvariable *);
+
+tree
+get_identifier_node (const std::string &str);
+
+// Types.
+
+// Get the wchar type
+tree
+wchar_type ();
+
+// Get the Host pointer size in bits
+int
+get_pointer_size ();
+
+// Get the raw str type const char*
+tree
+raw_str_type ();
+
+// Get an unnamed integer type with the given signedness and number
+// of bits.
+tree
+integer_type (bool is_unsigned, int bits);
+
+// Get an unnamed floating point type with the given number of bits
+// (32 or 64).
+tree
+float_type (int bits);
+
+// Get an unnamed complex type with the given number of bits (64 or 128).
+tree
+complex_type (int bits);
+
+// Get a pointer type.
+tree
+pointer_type (tree to_type);
+
+// Get a reference type.
+tree
+reference_type (tree to_type);
+
+// make type immutable
+tree
+immutable_type (tree base);
+
+// Get a function type.  The receiver, parameter, and results are
+// generated from the types in the Function_type.  The Function_type
+// is provided so that the names are available.  This should return
+// not the type of a Go function (which is a pointer to a struct)
+// but the type of a C function pointer (which will be used as the
+// type of the first field of the struct).  If there is more than
+// one result, RESULT_STRUCT is a struct type to hold the results,
+// and RESULTS may be ignored; if there are zero or one results,
+// RESULT_STRUCT is NULL.
+tree
+function_type (const typed_identifier &receiver,
+              const std::vector<typed_identifier> &parameters,
+              const std::vector<typed_identifier> &results, tree result_struct,
+              location_t location);
+
+tree
+function_type_varadic (const typed_identifier &receiver,
+                      const std::vector<typed_identifier> &parameters,
+                      const std::vector<typed_identifier> &results,
+                      tree result_struct, location_t location);
+
+tree
+function_ptr_type (tree result, const std::vector<tree> &praameters,
+                  location_t location);
+
+// Get a struct type.
+tree
+struct_type (const std::vector<typed_identifier> &fields);
+
+// Get a union type.
+tree
+union_type (const std::vector<typed_identifier> &fields);
+
+// Get an array type.
+tree
+array_type (tree element_type, tree length);
+
+// Return a named version of a type.  The location is the location
+// of the type definition.  This will not be called for a type
+// created via placeholder_pointer_type, placeholder_struct_type, or
+// placeholder_array_type..  (It may be called for a pointer,
+// struct, or array type in a case like "type P *byte; type Q P".)
+tree
+named_type (const std::string &name, tree, location_t);
+
+// Return the size of a type.
+int64_t type_size (tree);
+
+// Return the alignment of a type.
+int64_t type_alignment (tree);
+
+// Return the alignment of a struct field of this type.  This is
+// normally the same as type_alignment, but not always.
+int64_t type_field_alignment (tree);
+
+// Return the offset of field INDEX in a struct type.  INDEX is the
+// entry in the FIELDS std::vector parameter of struct_type or
+// set_placeholder_struct_type.
+int64_t
+type_field_offset (tree, size_t index);
+
+// Expressions.
+
+// Return an expression for a zero value of the given type.  This is
+// used for cases such as local variable initialization and
+// converting nil to other types.
+tree zero_expression (tree);
+
+// Create a reference to a variable.
+tree
+var_expression (Bvariable *var, location_t);
+
+// Return an expression for the multi-precision integer VAL in BTYPE.
+tree
+integer_constant_expression (tree btype, mpz_t val);
+
+// Return an expression for the floating point value VAL in BTYPE.
+tree
+float_constant_expression (tree btype, mpfr_t val);
+
+// Return an expression for the complex value VAL in BTYPE.
+tree
+complex_constant_expression (tree btype, mpc_t val);
+
+// Return an expression for the string value VAL.
+tree
+string_constant_expression (const std::string &val);
+
+// Get a char literal
+tree
+char_constant_expression (char c);
+
+// Get a char literal
+tree
+wchar_constant_expression (wchar_t c);
+
+// Return an expression for the boolean value VAL.
+tree
+boolean_constant_expression (bool val);
+
+// Return an expression for the real part of BCOMPLEX.
+tree
+real_part_expression (tree bcomplex, location_t);
+
+// Return an expression for the imaginary part of BCOMPLEX.
+tree
+imag_part_expression (tree bcomplex, location_t);
+
+// Return an expression for the complex number (BREAL, BIMAG).
+tree
+complex_expression (tree breal, tree bimag, location_t);
+
+// Return an expression that converts EXPR to TYPE.
+tree
+convert_expression (tree type, tree expr, location_t);
+
+// Return an expression for the field at INDEX in BSTRUCT.
+tree
+struct_field_expression (tree bstruct, size_t index, location_t);
+
+// Create an expression that executes BSTAT before BEXPR.
+tree
+compound_expression (tree bstat, tree bexpr, location_t);
+
+// Return an expression that executes THEN_EXPR if CONDITION is true, or
+// ELSE_EXPR otherwise and returns the result as type BTYPE, within the
+// specified function FUNCTION.  ELSE_EXPR may be NULL.  BTYPE may be NULL.
+tree
+conditional_expression (tree function, tree btype, tree condition,
+                       tree then_expr, tree else_expr, location_t);
+
+// Return an expression for the negation operation OP EXPR.
+// Supported values of OP are enumerated in NegationOperator.
+tree
+negation_expression (NegationOperator op, tree expr, location_t);
+
+// Return an expression for the operation LEFT OP RIGHT.
+// Supported values of OP are enumerated in ArithmeticOrLogicalOperator.
+tree
+arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op, tree left,
+                                 tree right, location_t loc);
+
+// Return an expression for the operation LEFT OP RIGHT.
+// Supported values of OP are enumerated in ArithmeticOrLogicalOperator.
+// This function adds overflow checking and returns a list of statements to
+// add to the current function context. The `receiver` variable refers to the
+// variable which will contain the result of that operation.
+tree
+arithmetic_or_logical_expression_checked (ArithmeticOrLogicalOperator op,
+                                         tree left, tree right, location_t loc,
+                                         Bvariable *receiver);
+
+// Return an expression for the operation LEFT OP RIGHT.
+// Supported values of OP are enumerated in ComparisonOperator.
+tree
+comparison_expression (ComparisonOperator op, tree left, tree right,
+                      location_t loc);
+
+// Return an expression for the operation LEFT OP RIGHT.
+// Supported values of OP are enumerated in LazyBooleanOperator.
+tree
+lazy_boolean_expression (LazyBooleanOperator op, tree left, tree right,
+                        location_t);
+
+// Return an expression that constructs BTYPE with VALS.  BTYPE must be the
+// backend representation a of struct.  VALS must be in the same order as the
+// corresponding fields in BTYPE.
+tree
+constructor_expression (tree btype, bool is_variant,
+                       const std::vector<tree> &vals, int, location_t);
+
+// Return an expression that constructs an array of BTYPE with INDEXES and
+// VALS.  INDEXES and VALS must have the same amount of elements. Each index
+// in INDEXES must be in the same order as the corresponding value in VALS.
+tree
+array_constructor_expression (tree btype,
+                             const std::vector<unsigned long> &indexes,
+                             const std::vector<tree> &vals, location_t);
+
+tree
+array_initializer (tree, tree, tree, tree, tree, tree *, location_t);
+
+// Return an expression for ARRAY[INDEX] as an l-value.  ARRAY is a valid
+// fixed-length array, not a slice.
+tree
+array_index_expression (tree array, tree index, location_t);
+
+// Create an expression for a call to FN with ARGS, taking place within
+// caller CALLER.
+tree
+call_expression (tree fn, const std::vector<tree> &args, tree static_chain,
+                location_t);
+
+// Statements.
+
+// Create a variable initialization statement in the specified
+// function.  This initializes a local variable at the point in the
+// program flow where it is declared.
+tree
+init_statement (tree, Bvariable *var, tree init);
+
+// Create an assignment statement within the specified function.
+tree
+assignment_statement (tree lhs, tree rhs, location_t);
+
+// Create return statement for an decl for a value (can be NULL_TREE) at a
+// location
+tree
+return_statement (tree fndecl, tree val, location_t);
+
+// Create an if statement within a function.  ELSE_BLOCK may be NULL.
+tree
+if_statement (tree, tree condition, tree then_block, tree else_block,
+             location_t);
+
+// infinite loop expressions
+tree
+loop_expression (tree body, location_t);
+
+// exit expressions
+tree
+exit_expression (tree condition, location_t);
+
+// Create a single statement from two statements.
+tree compound_statement (tree, tree);
+
+// Create a single statement from a list of statements.
+tree
+statement_list (const std::vector<tree> &);
+
+// Create a statement that attempts to execute BSTAT and calls EXCEPT_STMT if
+// an exception occurs. EXCEPT_STMT may be NULL.  FINALLY_STMT may be NULL and
+// if not NULL, it will always be executed.  This is used for handling defers
+// in Go functions.  In C++, the resulting code is of this form:
+//   try { BSTAT; } catch { EXCEPT_STMT; } finally { FINALLY_STMT; }
+tree
+exception_handler_statement (tree bstat, tree except_stmt, tree finally_stmt,
+                            location_t);
+
+// Blocks.
+
+// Create a block.  The frontend will call this function when it
+// starts converting a block within a function.  FUNCTION is the
+// current function.  ENCLOSING is the enclosing block; it will be
+// NULL for the top-level block in a function.  VARS is the list of
+// local variables defined within this block; each entry will be
+// created by the local_variable function.  START_LOCATION is the
+// location of the start of the block, more or less the location of
+// 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.
+tree
+block (tree function, tree enclosing, const std::vector<Bvariable *> &vars,
+       location_t start_location, location_t end_location);
+
+// 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.
+void
+block_add_statements (tree, const std::vector<tree> &);
+
+// Variables.
+
+// Create a global variable. NAME is the package-qualified name of
+// the variable.  ASM_NAME is the encoded identifier for the
+// variable, incorporating the package, and made safe for the
+// assembler.  BTYPE is the type of the variable.  IS_EXTERNAL is
+// true if the variable is defined in some other package.  IS_HIDDEN
+// is true if the variable is not exported (name begins with a lower
+// case letter).  IN_UNIQUE_SECTION is true if the variable should
+// be put into a unique section if possible; this is intended to
+// permit the linker to garbage collect the variable if it is not
+// referenced.  LOCATION is where the variable was defined.
+Bvariable *
+global_variable (const std::string &name, const std::string &asm_name,
+                tree btype, bool is_external, bool is_hidden,
+                bool in_unique_section, location_t location);
+
+// A global variable will 1) be initialized to zero, or 2) be
+// initialized to a constant value, or 3) be initialized in the init
+// function.  In case 2, the frontend will call
+// global_variable_set_init to set the initial value.  If this is
+// not called, the backend should initialize a global variable to 0.
+// The init function may then assign a value to it.
+void
+global_variable_set_init (Bvariable *, tree);
+
+// Create a local variable.  The frontend will create the local
+// variables first, and then create the block which contains them.
+// FUNCTION is the function in which the variable is defined.  NAME
+// is the name of the variable.  TYPE is the type.  DECL_VAR, if not
+// null, gives the location at which the value of this variable may
+// be found, typically used to create an inner-scope reference to an
+// outer-scope variable, to extend the lifetime of the variable beyond
+// the inner scope.  IS_ADDRESS_TAKEN is true if the address of this
+// variable is taken (this implies that the address does not escape
+// the function, as otherwise the variable would be on the heap).
+// LOCATION is where the variable is defined.  For each local variable
+// the frontend will call init_statement to set the initial value.
+Bvariable *
+local_variable (tree function, const std::string &name, tree type,
+               Bvariable *decl_var, location_t location);
+
+// Create a function parameter.  This is an incoming parameter, not
+// a result parameter (result parameters are treated as local
+// variables).  The arguments are as for local_variable.
+Bvariable *
+parameter_variable (tree function, const std::string &name, tree type,
+                   location_t location);
+
+// Create a static chain parameter.  This is the closure parameter.
+Bvariable *
+static_chain_variable (tree function, const std::string &name, tree type,
+                      location_t location);
+
+// Create a temporary variable.  A temporary variable has no name,
+// just a type.  We pass in FUNCTION and BLOCK in case they are
+// needed.  If INIT is not NULL, the variable should be initialized
+// to that value.  Otherwise the initial value is irrelevant--the
+// backend does not have to explicitly initialize it to zero.
+// ADDRESS_IS_TAKEN is true if the programs needs to take the
+// address of this temporary variable.  LOCATION is the location of
+// the statement or expression which requires creating the temporary
+// 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.
+Bvariable *
+temporary_variable (tree fndecl, tree bind_tree, tree type, tree init,
+                   bool address_is_taken, location_t location,
+                   tree *pstatement);
+
+// Labels.
+
+// Create a new label.  NAME will be empty if this is a label
+// created by the frontend for a loop construct.  The location is
+// where the label is defined.
+tree
+label (tree, const std::string &name, location_t);
+
+// Create a statement which defines a label.  This statement will be
+// put into the codestream at the point where the label should be
+// defined.
+tree label_definition_statement (tree);
+
+// Create a goto statement to a label.
+tree goto_statement (tree, location_t);
+
+// Create an expression for the address of a label.  This is used to
+// get the return address of a deferred function which may call
+// recover.
+tree label_address (tree, location_t);
+
+// Functions.
+
+// Bit flags to pass to the function method.
+
+// Set if this is a function declaration rather than a definition;
+// the definition will be in another compilation unit.
+static const unsigned int function_is_declaration = 1 << 0;
+
+// Set if the function should never be inlined because they call
+// recover and must be visible for correct panic recovery.
+static const unsigned int function_is_uninlinable = 1 << 1;
+
+// Set if the function does not return.  This is set for the
+// implementation of panic.
+static const unsigned int function_does_not_return = 1 << 2;
+
+// Set if the function should be put in a unique section if
+// possible.  This is used for field tracking.
+static const unsigned int function_in_unique_section = 1 << 3;
+
+// Declare or define a function of FNTYPE.
+// NAME is the Go name of the function.  ASM_NAME, if not the empty
+// string, is the name that should be used in the symbol table; this
+// will be non-empty if a magic extern comment is used.  FLAGS is
+// bit flags described above.
+tree
+function (tree fntype, const std::string &name, const std::string &asm_name,
+         unsigned int flags, location_t);
+
+// Create a statement that runs all deferred calls for FUNCTION.  This should
+// be a statement that looks like this in C++:
+//   finish:
+//     try { DEFER_RETURN; } catch { CHECK_DEFER; goto finish; }
+tree
+function_defer_statement (tree function, tree undefer, tree check_defer,
+                         location_t);
+
+// Record PARAM_VARS as the variables to use for the parameters of FUNCTION.
+// This will only be called for a function definition.  Returns true on
+// success, false on failure.
+bool
+function_set_parameters (tree function,
+                        const std::vector<Bvariable *> &param_vars);
+
+// Utility.
+
+// Write the definitions for all TYPE_DECLS, CONSTANT_DECLS,
+// FUNCTION_DECLS, and VARIABLE_DECLS declared globally.
+void
+write_global_definitions (const std::vector<tree> &type_decls,
+                         const std::vector<tree> &constant_decls,
+                         const std::vector<tree> &function_decls,
+                         const std::vector<Bvariable *> &variable_decls);
+
+// TODO: make static
+
+tree
+fill_in_fields (tree, const std::vector<typed_identifier> &);
+
+tree fill_in_array (tree, tree, tree);
+
+tree non_zero_size_type (tree);
+
+tree convert_tree (tree, tree, location_t);
+
+} // namespace Backend
+
 #endif // RUST_BACKEND_H
index 083add4bcaee3533fbaa05872acd7725659e36e4..1aca71f1b6532d375b9a4eaa18988b3c398d27dc 100644 (file)
@@ -99,7 +99,8 @@ get_identifier_from_string (const std::string &str)
 
 // Define the built-in functions that are exposed to GCCRust.
 
-Backend::Backend ()
+void
+Backend::init ()
 {
   /* We need to define the fetch_and_add functions, since we use them
      for ++ and --.  */
@@ -2468,11 +2469,3 @@ Backend::write_global_definitions (
 
   delete[] defs;
 }
-
-// Return the backend generator.
-
-Backend *
-rust_get_backend ()
-{
-  return new Backend ();
-}
index 9ce2d7f29abc52444e1b102649801600b9b0361b..7c4a76fe169ce7866d5f1bef81f5b11a1abe5c7d 100644 (file)
@@ -59,9 +59,6 @@ saw_errors (void);
 extern Linemap *
 rust_get_linemap ();
 
-extern Backend *
-rust_get_backend ();
-
 namespace Rust {
 
 const char *kLexDumpFile = "gccrs.lex.dump";
@@ -167,7 +164,7 @@ Session::init ()
   linemap = rust_get_linemap ();
 
   // setup backend to GCC GIMPLE
-  backend = rust_get_backend ();
+  Backend::init ();
 
   // setup mappings class
   mappings = Analysis::Mappings::get ();
@@ -670,7 +667,7 @@ Session::compile_crate (const char *filename)
     return;
 
   // do compile to gcc generic
-  Compile::Context ctx (backend);
+  Compile::Context ctx;
   Compile::CompileCrate::Compile (hir, &ctx);
 
   // we can't do static analysis if there are errors to worry about
index 8706f7291bd4cf7da00ddbd3c0575dc4fa10c31e..75c7b3860a0a33ba647c7be08e4b4c484bed8a84 100644 (file)
@@ -344,9 +344,6 @@ struct Session
    * expansion) */
   std::vector<std::string> extra_files;
 
-  // backend wrapper to GCC GENERIC
-  Backend *backend;
-
   // backend linemap
   Linemap *linemap;