aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/import.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-06-05 21:05:38 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-06-05 21:05:38 +0000
commit5a9422664e8646313278d50666e2e4c8427cd5df (patch)
treed2b034aeb5116f43b6724b61e017131a3bc64a9c /gcc/go/gofrontend/import.cc
parent388aa75412ffd1d4cd10dd53d012fdcc1ed47f67 (diff)
downloadgcc-5a9422664e8646313278d50666e2e4c8427cd5df.zip
gcc-5a9422664e8646313278d50666e2e4c8427cd5df.tar.gz
gcc-5a9422664e8646313278d50666e2e4c8427cd5df.tar.bz2
compiler: inline call expressions and function references
Scan inlinable methods for references to global variables and functions (forgot to do that earlier). Track all packages mentioned by exports (that should have been done earlier too). Record assembler name in export data, so that we can inline calls to non-Go functions. Modify gccgoimporter code to skip assembler name. This increases the number of inlinable functions in the standard library from 215 to 439. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/180677 From-SVN: r271976
Diffstat (limited to 'gcc/go/gofrontend/import.cc')
-rw-r--r--gcc/go/gofrontend/import.cc34
1 files changed, 30 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc
index ff92b82..1c3f4a4 100644
--- a/gcc/go/gofrontend/import.cc
+++ b/gcc/go/gofrontend/import.cc
@@ -757,10 +757,11 @@ Import::import_func(Package* package)
Typed_identifier_list* results;
bool is_varargs;
bool nointerface;
+ std::string asm_name;
std::string body;
if (!Function::import_func(this, &name, &fpkg, &is_exported, &receiver,
&parameters, &results, &is_varargs, &nointerface,
- &body))
+ &asm_name, &body))
return;
if (fpkg == NULL)
fpkg = package;
@@ -802,12 +803,14 @@ Import::import_func(Package* package)
else
{
no = fpkg->add_function_declaration(name, fntype, loc);
- if (this->add_to_globals_)
+ if (this->add_to_globals_ && fpkg == package)
this->gogo_->add_dot_import_object(no);
}
if (nointerface)
no->func_declaration_value()->set_nointerface();
+ if (!asm_name.empty())
+ no->func_declaration_value()->set_asm_name(asm_name);
if (!body.empty() && !no->func_declaration_value()->has_imported_body())
no->func_declaration_value()->set_imported_body(this, body);
}
@@ -1231,6 +1234,12 @@ Import::register_builtin_type(Gogo* gogo, const char* name, Builtin_code code)
this->builtin_types_[index] = named_object->type_value();
}
+// Characters that stop read_identifier. We base this on the
+// characters that stop an identifier, without worrying about
+// characters that are permitted in an identifier. That lets us skip
+// UTF-8 parsing.
+static const char * const identifier_stop = " \n;,()[]";
+
// Read an identifier from the stream.
std::string
@@ -1242,8 +1251,14 @@ Import::read_identifier()
while (true)
{
c = stream->peek_char();
- if (c == -1 || c == ' ' || c == '\n' || c == ';' || c == ')')
+ if (c == -1 || strchr(identifier_stop, c) != NULL)
break;
+
+ // FIXME: Probably we shouldn't accept '.', but that might break
+ // some existing imports.
+ if (c == '.' && stream->match_c_string("..."))
+ break;
+
ret += c;
stream->advance(1);
}
@@ -1521,7 +1536,18 @@ Import_function_body::read_identifier()
for (size_t i = start; i < this->body_.length(); i++)
{
int c = static_cast<unsigned char>(this->body_[i]);
- if (c == ' ' || c == '\n' || c == ';' || c == ')')
+ if (strchr(identifier_stop, c) != NULL)
+ {
+ this->off_ = i;
+ return this->body_.substr(start, i - start);
+ }
+
+ // FIXME: Probably we shouldn't accept '.', but that might break
+ // some existing imports.
+ if (c == '.'
+ && i + 2 < this->body_.length()
+ && this->body_[i + 1] == '.'
+ && this->body_[i + 2] == '.')
{
this->off_ = i;
return this->body_.substr(start, i - start);