diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-04-23 04:58:00 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-04-23 04:58:00 +0000 |
commit | 0e94da57dc1e5712c60a876545a0c09a4d672002 (patch) | |
tree | 2cfb99ced2bf497d3daed25f022fed99a6e01693 /gcc/go/gofrontend/runtime.cc | |
parent | 216f7526fef4db4a7f6510f4d48827bb4c55fc64 (diff) | |
download | gcc-0e94da57dc1e5712c60a876545a0c09a4d672002.zip gcc-0e94da57dc1e5712c60a876545a0c09a4d672002.tar.gz gcc-0e94da57dc1e5712c60a876545a0c09a4d672002.tar.bz2 |
compiler: Expose runtime code through Func_expression.
Enables us to easily check if a Call_expression is a call to a runtime
function and, if so, which runtime function is corresponds to.
This will be used during escape analysis.
Reviewed-on: https://go-review.googlesource.com/18544
From-SVN: r235383
Diffstat (limited to 'gcc/go/gofrontend/runtime.cc')
-rw-r--r-- | gcc/go/gofrontend/runtime.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/runtime.cc b/gcc/go/gofrontend/runtime.cc index de68f64..6492025 100644 --- a/gcc/go/gofrontend/runtime.cc +++ b/gcc/go/gofrontend/runtime.cc @@ -402,3 +402,39 @@ Runtime::map_iteration_type() Linemap::predeclared_location()); return Type::make_array_type(runtime_function_type(RFT_POINTER), iexpr); } + + +// Get the runtime code for a named builtin function. This is used as a helper +// when creating function references for call expressions. Every reference to +// a builtin runtime function should have the associated runtime code. If the +// name is ambiguous and can refer to many runtime codes, return +// NUMBER_OF_FUNCTIONS. + +Runtime::Function +Runtime::name_to_code(const std::string& name) +{ + Function code = Runtime::NUMBER_OF_FUNCTIONS; + + // Aliases seen in function declaration code. + // TODO(cmang): Add other aliases. + if (name == "new") + code = Runtime::NEW; + else if (name == "close") + code = Runtime::CLOSE; + else if (name == "copy") + code = Runtime::COPY; + else if (name == "append") + code = Runtime::APPEND; + else if (name == "delete") + code = Runtime::MAPDELETE; + else + { + // Look through the known names for a match. + for (size_t i = 0; i < Runtime::NUMBER_OF_FUNCTIONS; i++) + { + if (strcmp(runtime_functions[i].name, name.c_str()) == 0) + code = static_cast<Runtime::Function>(i); + } + } + return code; +} |