diff options
author | Chris Manghane <cmang@google.com> | 2014-04-17 20:42:31 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-04-17 20:42:31 +0000 |
commit | e85baec793f3560bdace25d061dd05874ff5cd2f (patch) | |
tree | 0f0a7fc9a1aefaaab07c083ef183efc2a474f3d5 /gcc/go/go-gcc.cc | |
parent | be7341a882e4ee6d493b2b2940f9cbb37b15d515 (diff) | |
download | gcc-e85baec793f3560bdace25d061dd05874ff5cd2f.zip gcc-e85baec793f3560bdace25d061dd05874ff5cd2f.tar.gz gcc-e85baec793f3560bdace25d061dd05874ff5cd2f.tar.bz2 |
compiler: Use backend interface for constant expressions.
* go-gcc.cc (Gcc_backend::named_constant_expression): New
function.
From-SVN: r209495
Diffstat (limited to 'gcc/go/go-gcc.cc')
-rw-r--r-- | gcc/go/go-gcc.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index 3abefae..1af639e 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -227,6 +227,10 @@ class Gcc_backend : public Backend indirect_expression(Bexpression* expr, bool known_valid, Location); Bexpression* + named_constant_expression(Btype* btype, const std::string& name, + Bexpression* val, Location); + + Bexpression* integer_constant_expression(Btype* btype, mpz_t val); Bexpression* @@ -962,6 +966,29 @@ Gcc_backend::indirect_expression(Bexpression* expr, bool known_valid, return tree_to_expr(ret); } +// Return an expression that declares a constant named NAME with the +// constant value VAL in BTYPE. + +Bexpression* +Gcc_backend::named_constant_expression(Btype* btype, const std::string& name, + Bexpression* val, Location location) +{ + tree type_tree = btype->get_tree(); + tree const_val = val->get_tree(); + if (type_tree == error_mark_node || const_val == error_mark_node) + return this->error_expression(); + + 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; + + go_preserve_from_gc(decl); + return this->make_expression(decl); +} + // Return a typed value as a constant integer. Bexpression* |