diff options
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; +} |