Reuse the same app source

extensions
Volodymyr Shymanskyy 5 years ago
parent e8dce0924b
commit 4394f84931

@ -1,12 +1,13 @@
M3_SRC_DIR := ../../../source
SOURCES := main.c \
SOURCES := ../../app/main.c \
$(shell find $(M3_SRC_DIR) -type f -name '*.c')
override CFLAGS += -std=c99 -O3 -flto -Wfatal-errors -fstrict-aliasing -I$(M3_SRC_DIR)
all: wasm3
override CFLAGS += -std=c99 -O3 -flto -Wfatal-errors -fstrict-aliasing -I$(M3_SRC_DIR)
wasm3: $(SOURCES)
$(CC) $(CFLAGS) $(SOURCES) -o wasm3 -lm

@ -1,78 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "m3.h"
#include "m3_core.h"
#define FATAL(msg, ...) { printf("Fatal: " msg "\n", ##__VA_ARGS__); return 1; }
int main (int i_argc, const char * i_argv [])
{
M3Result result = c_m3Err_none;
if (i_argc < 3) FATAL("not enough arguments");
u8* wasm = NULL;
u32 fsize = 0;
//printf("Loading WebAssembly...\n");
FILE* f = fopen (i_argv[1], "rb");
if (f)
{
fseek (f, 0, SEEK_END);
fsize = ftell(f);
fseek (f, 0, SEEK_SET);
if (fsize > 1000000) FATAL("file is too big");
wasm = (u8*) malloc(fsize);
fread (wasm, 1, fsize, f);
fclose (f);
}
IM3Module module;
result = m3_ParseModule (& module, wasm, fsize);
if (result) FATAL("m3_ParseModule: %s", result);
IM3Runtime env = m3_NewRuntime (4096);
if (!env) FATAL("m3_NewRuntime");
result = m3_LoadModule (env, module);
if (result) FATAL("m3_LoadModule: %s", result);
IM3Function func;
result = m3_FindFunction (& func, env, "__post_instantiate");
if (not result)
{
result = m3_Call (func);
if (result) FATAL("__post_instantiate failed: %s", result);
}
const char* fname = i_argv[2];
result = m3_FindFunction (& func, env, fname);
if (result) FATAL("m3_FindFunction: %s", result);
//printf("Running...\n");
if (!strcmp(fname, "_main") || !strcmp(fname, "main")) {
i_argc -= 2;
i_argv += 2;
result = m3_CallMain (func, i_argc, i_argv);
} else {
i_argc -= 3;
i_argv += 3;
result = m3_CallWithArgs (func, i_argc, i_argv);
}
free (wasm);
if (result) FATAL("m3_Call: %s", result);
printf ("\n");
return 0;
}

@ -7,10 +7,11 @@ PKG_RELEASE:=1
PKG_MAINTAINER:=Volodymyr Shymanskyy
PKG_LICENSE:=MIT
PKG_SOURCE_URL:=file:///home/vshymanskyy/_Projects/_experiments/Wasm/vsh-m3
#PKG_SOURCE_PROTO:=git
#PKG_SOURCE_URL:=git://github.com/vshymanskyy/m3.git
#PKG_SOURCE_VERSION:=master
#PKG_SOURCE_URL:=file:///path/to/local/m3/
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=git://github.com/vshymanskyy/m3.git
PKG_SOURCE_VERSION:=master
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz

Loading…
Cancel
Save