Commit 90cbaa29 by Chris Manghane Committed by Ian Lance Taylor

go-gcc.cc: #include "langhooks.h".

	* go-gcc.cc: #include "langhooks.h".
	(Gcc_backend::Gcc_backend): Add constructor.
	(Gcc_backend::lookup_function): New function.
	(Gcc_backend::define_builtin): New private function.
	(Gcc_backend::gcc_backend): Remove.
	(go_get_backend): Use new to create new Gcc_backend.

From-SVN: r209941
parent 66574871
2014-04-30 Chris Manghane <cmang@google.com>
* go-gcc.cc: #include "langhooks.h".
(Gcc_backend::Gcc_backend): Add constructor.
(Gcc_backend::lookup_function): New function.
(Gcc_backend::define_builtin): New private function.
(Gcc_backend::gcc_backend): Remove.
(go_get_backend): Use new to create new Gcc_backend.
2014-04-25 Chris Manghane <cmang@google.com>
* go-gcc.cc: Include "cgraph.h" and "gimplify.h".
......
......@@ -660,6 +660,11 @@ class Backend
virtual bool
function_set_body(Bfunction* function, Bstatement* code_stmt) = 0;
// Look up a named built-in function in the current backend implementation.
// Returns NULL if no built-in function by that name exists.
virtual Bfunction*
lookup_builtin(const std::string&) = 0;
// Utility.
// Write the definitions for all TYPE_DECLS, CONSTANT_DECLS,
......
......@@ -34,9 +34,6 @@ go_create_gogo(int int_type_size, int pointer_size, const char *pkgpath,
if (relative_import_path != NULL)
::gogo->set_relative_import_path(relative_import_path);
// FIXME: This should be in the gcc dependent code.
::gogo->define_builtin_function_trees();
}
// Parse the input files.
......
......@@ -4855,6 +4855,66 @@ Function::get_or_make_decl(Gogo* gogo, Named_object* no)
return this->fndecl_;
}
// Get the backend representation.
Bfunction*
Function_declaration::get_or_make_decl(Gogo* gogo, Named_object* no)
{
if (this->fndecl_ == NULL)
{
// Let Go code use an asm declaration to pick up a builtin
// function.
if (!this->asm_name_.empty())
{
Bfunction* builtin_decl =
gogo->backend()->lookup_builtin(this->asm_name_);
if (builtin_decl != NULL)
{
this->fndecl_ = builtin_decl;
return this->fndecl_;
}
}
std::string asm_name;
if (this->asm_name_.empty())
{
asm_name = (no->package() == NULL
? gogo->pkgpath_symbol()
: no->package()->pkgpath_symbol());
asm_name.append(1, '.');
asm_name.append(Gogo::unpack_hidden_name(no->name()));
if (this->fntype_->is_method())
{
asm_name.append(1, '.');
Type* rtype = this->fntype_->receiver()->type();
asm_name.append(rtype->mangled_name(gogo));
}
}
Btype* functype = this->fntype_->get_backend_fntype(gogo);
this->fndecl_ =
gogo->backend()->function(functype, no->get_id(gogo), asm_name,
true, true, true, false, false,
this->location());
}
return this->fndecl_;
}
// Build the descriptor for a function declaration. This won't
// necessarily happen if the package has just a declaration for the
// function and no other reference to it, but we may still need the
// descriptor for references from other packages.
void
Function_declaration::build_backend_descriptor(Gogo* gogo)
{
if (this->descriptor_ != NULL)
{
Translate_context context(gogo, NULL, NULL, NULL);
this->descriptor_->get_tree(&context);
}
}
// Return the function's decl after it has been built.
Bfunction*
......
......@@ -575,35 +575,10 @@ class Gogo
void
write_globals();
// Create trees for implicit builtin functions.
void
define_builtin_function_trees();
// Build a call to a builtin function. PDECL should point to a NULL
// initialized static pointer which will hold the fndecl. NAME is
// the name of the function. NARGS is the number of arguments.
// RETTYPE is the return type. It is followed by NARGS pairs of
// type and argument (both trees).
static tree
call_builtin(tree* pdecl, Location, const char* name, int nargs,
tree rettype, ...);
// Build a call to the runtime error function.
Expression*
runtime_error(int code, Location);
// Mark a function declaration as a builtin library function.
static void
mark_fndecl_as_builtin_library(tree fndecl);
// Build a constructor for a slice. SLICE_TYPE_TREE is the type of
// the slice. VALUES points to the values. COUNT is the size,
// CAPACITY is the capacity. If CAPACITY is NULL, it is set to
// COUNT.
static tree
slice_constructor(tree slice_type_tree, tree values, tree count,
tree capacity);
// Build required interface method tables.
void
build_interface_method_tables();
......
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