Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryenAddFunctionImport lost internalName on export, is this intentional? #7272

Open
primstar-cool opened this issue Feb 3, 2025 · 0 comments

Comments

@primstar-cool
Copy link

 BinaryenAddFunctionImport(module, internalName, "env", "externalBaseName", params, result);
BinaryenFunctionRef func = BinaryenGetFunction(module, ret);
func->setExplicitName(internalName);

i think add and Get , It's a bit wasteful. why not return BinaryenFunctionRef on BinaryenAddFunctionImport?
i find that, BinaryenAddFunction directly setExplicitName. why not BinaryenAddFunctionImport?

void BinaryenAddFunctionImport(BinaryenModuleRef module,
                               const char* internalName,
                               const char* externalModuleName,
                               const char* externalBaseName,
                               BinaryenType params,
                               BinaryenType results) {
  auto* func = ((Module*)module)->getFunctionOrNull(internalName);
  if (func == nullptr) {
    auto func = std::make_unique<Function>();
    if (internalName)
      func->setExplicitName(internalName); 
    func->name = internalName;
    func->module = externalModuleName;
    func->base = externalBaseName;
    // TODO: Take a HeapType rather than params and results.
    func->type = Signature(Type(params), Type(results));
    ((Module*)module)->addFunction(std::move(func));
  } else {
    // already exists so just set module and base
    func->module = externalModuleName;
    func->base = externalBaseName;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant