Commit 0aa5e7f2 by Evan Shaw Committed by Ian Lance Taylor

Use backend interface for basic types

	* 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
parent 5157a881
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.
......
......@@ -52,7 +52,7 @@ class Gcc_tree
{ }
tree
get_tree()
get_tree() const
{ return this->t_; }
private:
......@@ -133,25 +133,29 @@ class Gcc_backend : public Backend
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 */,
const Btypes* /* results */)
......@@ -283,6 +287,11 @@ class Gcc_backend : public Backend
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.
......@@ -293,6 +302,97 @@ get_identifier_from_string(const std::string& str)
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*
......@@ -867,6 +967,12 @@ tree_to_block(tree t)
}
tree
type_to_tree(Btype* bt)
{
return bt->get_tree();
}
tree
expr_to_tree(Bexpression* be)
{
return be->get_tree();
......
......@@ -73,10 +73,18 @@ class Backend
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.
......@@ -299,6 +307,7 @@ extern Bexpression* tree_to_expr(tree);
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*);
......
......@@ -31,6 +31,7 @@ extern "C"
#include "statements.h"
#include "export.h"
#include "import.h"
#include "backend.h"
#include "types.h"
// Class Type.
......@@ -1622,8 +1623,11 @@ class Void_type : public 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)
......@@ -1660,8 +1664,11 @@ class Boolean_type : public Type
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)
......@@ -1806,36 +1813,10 @@ Integer_type::do_get_tree(Gogo*)
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
......@@ -1968,19 +1949,8 @@ Float_type::do_hash_for_method(Gogo*) const
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.
......@@ -2124,19 +2094,8 @@ Complex_type::do_hash_for_method(Gogo*) const
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.
......@@ -3136,7 +3095,9 @@ Pointer_type::do_hash_for_method(Gogo* gogo) const
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment