* go-gcc.c (class Gcc_tree): Make get_tree const.
(Gcc_backend::void_type): Implement.
(Gcc_backend::bool_type): Implement.
(Gcc_backend::integer_type): Implement.
(Gcc_backend::float_type): Implement.
(Gcc_backend::complex_type): New function.
(Gcc_backend::pointer_type): New function.
(Gcc_backend::make_type): New function.
(type_to_tree): New function.
From-SVN: r172931
+2011-04-25 Evan Shaw <edsrzf@gmail.com>
+
+ * go-gcc.c (class Gcc_tree): Make get_tree const.
+ (Gcc_backend::void_type): Implement.
+ (Gcc_backend::bool_type): Implement.
+ (Gcc_backend::integer_type): Implement.
+ (Gcc_backend::float_type): Implement.
+ (Gcc_backend::complex_type): New function.
+ (Gcc_backend::pointer_type): New function.
+ (Gcc_backend::make_type): New function.
+ (type_to_tree): New function.
+
2011-04-21 Ian Lance Taylor <iant@google.com>
* go-system.h (go_assert, go_unreachable): Define.
{ }
tree
- get_tree()
+ get_tree() const
{ return this->t_; }
private:
Btype*
void_type()
- { gcc_unreachable(); }
+ { return this->make_type(void_type_node); }
Btype*
bool_type()
- { gcc_unreachable(); }
+ { return this->make_type(boolean_type_node); }
Btype*
- integer_type(bool /* is_unsigned */, int /* bits */)
- { gcc_unreachable(); }
+ integer_type(bool, int);
Btype*
- float_type(int /* bits */)
- { gcc_unreachable(); }
+ float_type(int);
+
+ Btype*
+ complex_type(int);
Btype*
string_type()
{ gcc_unreachable(); }
+ Btype*
+ pointer_type(const Btype*);
+
Btype*
function_type(const Function_type*, Btype* /* receiver */,
const Btypes* /* parameters */,
Bstatement*
make_statement(tree t)
{ return new Bstatement(t); }
+
+ // Make a Btype from a tree.
+ Btype*
+ make_type(tree t)
+ { return new Btype(t); }
};
// A helper function.
return get_identifier_with_length(str.data(), str.length());
}
+// Get an unnamed integer type.
+
+Btype*
+Gcc_backend::integer_type(bool is_unsigned, int bits)
+{
+ tree type;
+ if (is_unsigned)
+ {
+ if (bits == INT_TYPE_SIZE)
+ type = unsigned_type_node;
+ else if (bits == CHAR_TYPE_SIZE)
+ type = unsigned_char_type_node;
+ else if (bits == SHORT_TYPE_SIZE)
+ type = short_unsigned_type_node;
+ else if (bits == LONG_TYPE_SIZE)
+ type = long_unsigned_type_node;
+ else if (bits == LONG_LONG_TYPE_SIZE)
+ type = long_long_unsigned_type_node;
+ else
+ type = make_unsigned_type(bits);
+ }
+ else
+ {
+ if (bits == INT_TYPE_SIZE)
+ type = integer_type_node;
+ else if (bits == CHAR_TYPE_SIZE)
+ type = signed_char_type_node;
+ else if (bits == SHORT_TYPE_SIZE)
+ type = short_integer_type_node;
+ else if (bits == LONG_TYPE_SIZE)
+ type = long_integer_type_node;
+ else if (bits == LONG_LONG_TYPE_SIZE)
+ type = long_long_integer_type_node;
+ else
+ type = make_signed_type(bits);
+ }
+ return this->make_type(type);
+}
+
+// Get an unnamed float type.
+
+Btype*
+Gcc_backend::float_type(int bits)
+{
+ tree type;
+ if (bits == FLOAT_TYPE_SIZE)
+ type = float_type_node;
+ else if (bits == DOUBLE_TYPE_SIZE)
+ type = double_type_node;
+ else if (bits == LONG_DOUBLE_TYPE_SIZE)
+ type = long_double_type_node;
+ else
+ {
+ type = make_node(REAL_TYPE);
+ TYPE_PRECISION(type) = bits;
+ layout_type(type);
+ }
+ return this->make_type(type);
+}
+
+// Get an unnamed complex type.
+
+Btype*
+Gcc_backend::complex_type(int bits)
+{
+ tree type;
+ if (bits == FLOAT_TYPE_SIZE * 2)
+ type = complex_float_type_node;
+ else if (bits == DOUBLE_TYPE_SIZE * 2)
+ type = complex_double_type_node;
+ else if (bits == LONG_DOUBLE_TYPE_SIZE * 2)
+ type = complex_long_double_type_node;
+ else
+ {
+ type = make_node(REAL_TYPE);
+ TYPE_PRECISION(type) = bits / 2;
+ layout_type(type);
+ type = build_complex_type(type);
+ }
+ return this->make_type(type);
+}
+
+// Get a pointer type.
+
+Btype*
+Gcc_backend::pointer_type(const Btype* to_type)
+{
+ tree type = build_pointer_type(to_type->get_tree());
+ return this->make_type(type);
+}
+
// An expression as a statement.
Bstatement*
return new Bblock(t);
}
+tree
+type_to_tree(Btype* bt)
+{
+ return bt->get_tree();
+}
+
tree
expr_to_tree(Bexpression* be)
{
virtual Btype*
float_type(int bits) = 0;
+ // Get an unnamed complex type with the given number of bits.
+ virtual Btype*
+ complex_type(int bits) = 0;
+
// Get the unnamed string type.
virtual Btype*
string_type() = 0;
+ // Get a pointer type.
+ virtual Btype*
+ pointer_type(const Btype* to_type) = 0;
+
// 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.
extern Bstatement* tree_to_stat(tree);
extern Bfunction* tree_to_function(tree);
extern Bblock* tree_to_block(tree);
+extern tree type_to_tree(Btype*);
extern tree expr_to_tree(Bexpression*);
extern tree stat_to_tree(Bstatement*);
extern tree block_to_tree(Bblock*);
#include "statements.h"
#include "export.h"
#include "import.h"
+#include "backend.h"
#include "types.h"
// Class Type.
protected:
tree
- do_get_tree(Gogo*)
- { return void_type_node; }
+ do_get_tree(Gogo* gogo)
+ {
+ Btype* btype = gogo->backend()->void_type();
+ return type_to_tree(btype);
+ }
tree
do_get_init_tree(Gogo*, tree, bool)
protected:
tree
- do_get_tree(Gogo*)
- { return boolean_type_node; }
+ do_get_tree(Gogo* gogo)
+ {
+ Btype* btype = gogo->backend()->bool_type();
+ return type_to_tree(btype);
+ }
tree
do_get_init_tree(Gogo*, tree type_tree, bool is_clear)
return error_mark_node;
}
- if (this->is_unsigned_)
- {
- if (this->bits_ == INT_TYPE_SIZE)
- return unsigned_type_node;
- else if (this->bits_ == CHAR_TYPE_SIZE)
- return unsigned_char_type_node;
- else if (this->bits_ == SHORT_TYPE_SIZE)
- return short_unsigned_type_node;
- else if (this->bits_ == LONG_TYPE_SIZE)
- return long_unsigned_type_node;
- else if (this->bits_ == LONG_LONG_TYPE_SIZE)
- return long_long_unsigned_type_node;
- else
- return make_unsigned_type(this->bits_);
- }
- else
- {
- if (this->bits_ == INT_TYPE_SIZE)
- return integer_type_node;
- else if (this->bits_ == CHAR_TYPE_SIZE)
- return signed_char_type_node;
- else if (this->bits_ == SHORT_TYPE_SIZE)
- return short_integer_type_node;
- else if (this->bits_ == LONG_TYPE_SIZE)
- return long_integer_type_node;
- else if (this->bits_ == LONG_LONG_TYPE_SIZE)
- return long_long_integer_type_node;
- else
- return make_signed_type(this->bits_);
- }
+ // FIXME: GOGO can be NULL when called from go_type_for_size, so call
+ // go_get_backend() instead of gogo->backend().
+ Btype* btype = go_get_backend()->integer_type(this->is_unsigned_, this->bits_);
+ return type_to_tree(btype);
}
tree
tree
Float_type::type_tree() const
{
- if (this->bits_ == FLOAT_TYPE_SIZE)
- return float_type_node;
- else if (this->bits_ == DOUBLE_TYPE_SIZE)
- return double_type_node;
- else if (this->bits_ == LONG_DOUBLE_TYPE_SIZE)
- return long_double_type_node;
- else
- {
- tree ret = make_node(REAL_TYPE);
- TYPE_PRECISION(ret) = this->bits_;
- layout_type(ret);
- return ret;
- }
+ Btype* btype = go_get_backend()->float_type(this->bits_);
+ return type_to_tree(btype);
}
// Get a tree.
tree
Complex_type::type_tree() const
{
- if (this->bits_ == FLOAT_TYPE_SIZE * 2)
- return complex_float_type_node;
- else if (this->bits_ == DOUBLE_TYPE_SIZE * 2)
- return complex_double_type_node;
- else if (this->bits_ == LONG_DOUBLE_TYPE_SIZE * 2)
- return complex_long_double_type_node;
- else
- {
- tree ret = make_node(REAL_TYPE);
- TYPE_PRECISION(ret) = this->bits_ / 2;
- layout_type(ret);
- return build_complex_type(ret);
- }
+ Btype* btype = go_get_backend()->complex_type(this->bits_);
+ return type_to_tree(btype);
}
// Get a tree.
tree
Pointer_type::do_get_tree(Gogo* gogo)
{
- return build_pointer_type(this->to_type_->get_tree(gogo));
+ Btype* to_btype = tree_to_type(this->to_type_->get_tree(gogo));
+ Btype* btype = gogo->backend()->pointer_type(to_btype);
+ return type_to_tree(btype);
}
// Initialize a pointer type.