/*1Given a list of names of functions and symbols, generate C code that define functions2that when called give a pointer to each of these.34For functions, this ensures that these named functions are all placed in the WASM5function table, which makes using them many orders of magnitude faster.67For symbols, it ensures that we have access to them at all (and quickly) so that8the GOTMemHandler (global offset table memory handler) can tell dynamic libraries9where the symbols are in memory.10*/1112const MACRO = `13#ifndef WASM_EXPORT14#define WASM_EXPORT(x,y) __attribute__((visibility("default"))) void* __WASM_EXPORT__##x() { return &(y);}15#endif16`;1718export default function wasmExport(names: string[]): string {19const v = Array.from(new Set(names)).sort();20return `${MACRO}\n21${v22.filter((func) => func.trim())23.map((func) => `WASM_EXPORT(${func},${func})`)24.join("\n")}`;25}2627export function alias(name, value) {28return `WASM_EXPORT(${name},${value})\n`;29}303132