mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
C: allow to change main function name
This commit is contained in:
parent
a65f8fdcd9
commit
aeb5f44922
|
@ -27,6 +27,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -719,7 +720,12 @@ public class CTarget implements TeaVMTarget, TeaVMCHost {
|
|||
|
||||
private void generateMain(GenerationContext context, CodeWriter writer, IncludeManager includes,
|
||||
ListableClassHolderSource classes, List<? extends ValueType> types) {
|
||||
writer.println("int main(int argc, char** argv) {").indent();
|
||||
Iterator<? extends TeaVMEntryPoint> entryPointIter = controller.getEntryPoints().values().iterator();
|
||||
String mainFunctionName = entryPointIter.hasNext() ? entryPointIter.next().getPublicName() : null;
|
||||
if (mainFunctionName == null) {
|
||||
mainFunctionName = "main";
|
||||
}
|
||||
writer.println("int " + mainFunctionName + "(int argc, char** argv) {").indent();
|
||||
|
||||
writer.println("teavm_beforeInit();");
|
||||
writer.println("teavm_initHeap(" + minHeapSize + ");");
|
||||
|
@ -832,8 +838,9 @@ public class CTarget implements TeaVMTarget, TeaVMCHost {
|
|||
|
||||
private void generateCallToMainMethod(IntrinsicContext context, InvocationExpr invocation) {
|
||||
NameProvider names = context.names();
|
||||
TeaVMEntryPoint entryPoint = controller.getEntryPoints().get("main");
|
||||
if (entryPoint != null) {
|
||||
Iterator<? extends TeaVMEntryPoint> entryPointIter = controller.getEntryPoints().values().iterator();
|
||||
if (entryPointIter.hasNext()) {
|
||||
TeaVMEntryPoint entryPoint = entryPointIter.next();
|
||||
context.includes().includeClass(entryPoint.getMethod().getClassName());
|
||||
String mainMethod = names.forMethod(entryPoint.getMethod());
|
||||
context.writer().print(mainMethod + "(");
|
||||
|
|
|
@ -67,6 +67,7 @@ public class IncrementalCBuilder {
|
|||
private String targetPath;
|
||||
private String externalTool;
|
||||
private String externalToolWorkingDir;
|
||||
private String mainFunctionName;
|
||||
|
||||
private IncrementalDirectoryBuildTarget buildTarget;
|
||||
private FileSystemWatcher watcher;
|
||||
|
@ -126,6 +127,10 @@ public class IncrementalCBuilder {
|
|||
this.externalToolWorkingDir = externalToolWorkingDir;
|
||||
}
|
||||
|
||||
public void setMainFunctionName(String mainFunctionName) {
|
||||
this.mainFunctionName = mainFunctionName;
|
||||
}
|
||||
|
||||
public void addProgressHandler(ProgressHandler handler) {
|
||||
synchronized (progressHandlers) {
|
||||
progressHandlers.add(handler);
|
||||
|
@ -329,7 +334,7 @@ public class IncrementalCBuilder {
|
|||
vm.installPlugins();
|
||||
|
||||
vm.setLastKnownClasses(lastReachedClasses);
|
||||
vm.entryPoint(mainClass);
|
||||
vm.entryPoint(mainClass, mainFunctionName != null ? mainFunctionName : "main");
|
||||
|
||||
log.info("Starting build");
|
||||
progressListener.last = 0;
|
||||
|
|
|
@ -62,6 +62,12 @@ public class TeaVMCBuilderRunner {
|
|||
.hasArg()
|
||||
.withDescription("Minimum heap size in bytes")
|
||||
.create());
|
||||
options.addOption(OptionBuilder
|
||||
.withLongOpt("entry-point")
|
||||
.withArgName("name")
|
||||
.hasArg()
|
||||
.withDescription("Name of entry point function (main by default)")
|
||||
.create('e'));
|
||||
options.addOption(OptionBuilder
|
||||
.withLongOpt("external-tool")
|
||||
.withArgName("path")
|
||||
|
@ -108,6 +114,9 @@ public class TeaVMCBuilderRunner {
|
|||
|
||||
builder.setLog(new ConsoleTeaVMToolLog(commandLine.hasOption('v')));
|
||||
builder.setLineNumbersGenerated(commandLine.hasOption('g'));
|
||||
if (commandLine.hasOption('e')) {
|
||||
builder.setMainFunctionName(commandLine.getOptionValue('e'));
|
||||
}
|
||||
|
||||
String[] args = commandLine.getArgs();
|
||||
if (args.length != 1) {
|
||||
|
|
|
@ -103,6 +103,7 @@ public class TeaVMTool {
|
|||
private Set<File> generatedFiles = new HashSet<>();
|
||||
private int minHeapSize = 32 * (1 << 20);
|
||||
private ReferenceCache referenceCache;
|
||||
private String mainFunctionName;
|
||||
|
||||
public File getTargetDirectory() {
|
||||
return targetDirectory;
|
||||
|
@ -248,6 +249,10 @@ public class TeaVMTool {
|
|||
this.wasmVersion = wasmVersion;
|
||||
}
|
||||
|
||||
public void setMainFunctionName(String mainFunctionName) {
|
||||
this.mainFunctionName = mainFunctionName;
|
||||
}
|
||||
|
||||
public void setProgressListener(TeaVMProgressListener progressListener) {
|
||||
this.progressListener = progressListener;
|
||||
}
|
||||
|
@ -389,7 +394,7 @@ public class TeaVMTool {
|
|||
vm.add(transformer);
|
||||
}
|
||||
if (mainClass != null) {
|
||||
vm.entryPoint(mainClass, entryPointName);
|
||||
vm.entryPoint(mainClass, entryPointName != null ? entryPointName : "main");
|
||||
}
|
||||
for (String className : classesToPreserve) {
|
||||
vm.preserveType(className);
|
||||
|
|
Loading…
Reference in New Issue
Block a user