mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:19:48 +00:00
[dart2wasm] Support main taking parameters and supply dummies
Change-Id: I97d27db54413c5d752444d32467a7d33d30ac43d Cq-Include-Trybots: luci.dart.try:dart2wasm-linux-x64-d8-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255997 Reviewed-by: Joshua Litt <joshualitt@google.com> Commit-Queue: Aske Simon Christensen <askesc@google.com>
This commit is contained in:
parent
7aebb788bf
commit
f16805e072
|
@ -385,4 +385,4 @@ var asyncBridge = new WebAssembly.Function(
|
|||
// Call `main`. If tasks are placed into the event loop (by scheduling tasks
|
||||
// explicitly or awaiting Futures), these will automatically keep the script
|
||||
// alive even after `main` returns.
|
||||
dartInstance.exports.main();
|
||||
dartInstance.exports.$main();
|
||||
|
|
|
@ -365,7 +365,6 @@ class Translator {
|
|||
|
||||
functions.collectImportsAndExports();
|
||||
mainFunction = _findMainMethod(libraries.first);
|
||||
functions.addExport(mainFunction.reference, "main");
|
||||
|
||||
initFunction =
|
||||
m.addFunction(m.addFunctionType(const [], const []), "#init");
|
||||
|
@ -376,6 +375,7 @@ class Translator {
|
|||
|
||||
dispatchTable.build();
|
||||
|
||||
m.exportFunction("\$main", generateEntryFunction(mainFunction.reference));
|
||||
functions.initialize();
|
||||
while (functions.worklist.isNotEmpty) {
|
||||
Reference reference = functions.worklist.removeLast();
|
||||
|
@ -477,6 +477,44 @@ class Translator {
|
|||
}
|
||||
}
|
||||
|
||||
w.DefinedFunction generateEntryFunction(Reference mainReference) {
|
||||
final ParameterInfo paramInfo = paramInfoFor(mainReference);
|
||||
assert(paramInfo.typeParamCount == 0);
|
||||
final w.BaseFunction mainFunction = functions.getFunction(mainReference);
|
||||
final w.DefinedFunction entry =
|
||||
m.addFunction(m.addFunctionType(const [], const []), "\$main");
|
||||
final w.Instructions b = entry.body;
|
||||
|
||||
if (paramInfo.positional.isNotEmpty) {
|
||||
// Supply dummy commandline arguments
|
||||
constants.instantiateConstant(
|
||||
entry,
|
||||
b,
|
||||
ListConstant(coreTypes.stringNonNullableRawType, const []),
|
||||
mainFunction.type.inputs[0]);
|
||||
}
|
||||
if (paramInfo.positional.length > 1) {
|
||||
// Supply dummy isolate
|
||||
constants.instantiateConstant(
|
||||
entry, b, NullConstant(), mainFunction.type.inputs[1]);
|
||||
}
|
||||
for (int i = 2; i < paramInfo.positional.length; i++) {
|
||||
// Supply default values for positional parameters
|
||||
constants.instantiateConstant(
|
||||
entry, b, paramInfo.positional[i]!, mainFunction.type.inputs[i]);
|
||||
}
|
||||
for (String name in paramInfo.names) {
|
||||
// Supply default values for named parameters
|
||||
constants.instantiateConstant(entry, b, paramInfo.named[name]!,
|
||||
mainFunction.type.inputs[paramInfo.nameIndex[name]!]);
|
||||
}
|
||||
b.call(mainFunction);
|
||||
convertType(entry, outputOrVoid(mainFunction.type.outputs), voidMarker);
|
||||
b.end();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
Class classForType(DartType type) {
|
||||
return type is InterfaceType
|
||||
? type.classNode
|
||||
|
|
Loading…
Reference in a new issue