aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-base.cc22
-rw-r--r--gcc/rust/backend/rust-compile-base.h4
-rw-r--r--gcc/rust/rust-backend.h6
-rw-r--r--gcc/rust/rust-gcc.cc24
4 files changed, 24 insertions, 32 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 85d85b9..9f936d2 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -445,8 +445,26 @@ HIRCompileBase::compile_constant_item (
folded_expr = ConstCtx::fold (call);
}
- return ctx->get_backend ()->named_constant_expression (const_type, ident,
- folded_expr, locus);
+ return named_constant_expression (const_type, ident, folded_expr, locus);
+}
+
+tree
+HIRCompileBase::named_constant_expression (tree type_tree,
+ const std::string &name,
+ tree const_val, Location location)
+{
+ if (type_tree == error_mark_node || const_val == error_mark_node)
+ return error_mark_node;
+
+ tree name_tree = get_identifier_with_length (name.data (), name.length ());
+ tree decl
+ = build_decl (location.gcc_location (), CONST_DECL, name_tree, type_tree);
+ DECL_INITIAL (decl) = const_val;
+ TREE_CONSTANT (decl) = 1;
+ TREE_READONLY (decl) = 1;
+
+ rust_preserve_from_gc (decl);
+ return decl;
}
} // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 17e889c..a52886c 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -96,6 +96,10 @@ protected:
compile_constant_item (Context *ctx, TyTy::BaseType *resolved_type,
const Resolver::CanonicalPath *canonical_path,
HIR::Expr *const_value_expr, Location locus);
+
+ static tree named_constant_expression (tree type_tree,
+ const std::string &name,
+ tree const_val, Location location);
};
} // namespace Compile
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 56e15a3..fe809c9 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -186,12 +186,6 @@ public:
Location)
= 0;
- // Return an expression that declares a constant named NAME with the
- // constant value VAL in BTYPE.
- virtual tree named_constant_expression (tree btype, const std::string &name,
- tree val, Location)
- = 0;
-
// Return an expression for the multi-precision integer VAL in BTYPE.
virtual tree integer_constant_expression (tree btype, mpz_t val) = 0;
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index cc5f4a90..812fd55 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -195,9 +195,6 @@ public:
tree indirect_expression (tree, tree expr, bool known_valid, Location);
- tree named_constant_expression (tree type, const std::string &name, tree val,
- Location);
-
tree integer_constant_expression (tree type, mpz_t val);
tree float_constant_expression (tree type, mpfr_t val);
@@ -1096,27 +1093,6 @@ Gcc_backend::indirect_expression (tree type_tree, tree expr_tree,
return ret;
}
-// Return an expression that declares a constant named NAME with the
-// constant value VAL in BTYPE.
-
-tree
-Gcc_backend::named_constant_expression (tree type_tree, const std::string &name,
- tree const_val, Location location)
-{
- if (type_tree == error_mark_node || const_val == error_mark_node)
- return error_mark_node;
-
- tree name_tree = get_identifier_from_string (name);
- tree decl
- = build_decl (location.gcc_location (), CONST_DECL, name_tree, type_tree);
- DECL_INITIAL (decl) = const_val;
- TREE_CONSTANT (decl) = 1;
- TREE_READONLY (decl) = 1;
-
- rust_preserve_from_gc (decl);
- return decl;
-}
-
// Return a typed value as a constant integer.
tree