extensions
Steven Massey 5 years ago
parent d4f6006cbf
commit 859766d87c

@ -333,8 +333,9 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
GCC_OPTIMIZATION_LEVEL = s;
GCC_OPTIMIZATION_LEVEL = fast;
GCC_VERSION = "";
OTHER_CFLAGS = "-fomit-frame-pointer";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;

@ -128,6 +128,22 @@ i32 m3_fopen (IM3Module i_module, ccstr_t i_path, ccstr_t i_mode)
}
// HACK: just getting some code running. stderr pointer needs to be statically placed at init
i32 m3_getStderr (IM3Module i_module)
{
i32 std = AllocateHeap (& i_module->memory, sizeof (FILE *));
i32 offset = AllocateHeap (& i_module->memory, sizeof (i32));
i32 * ptr = (i32 *) (i_module->memory.wasmPages + offset);
* ptr = std;
void ** file = (void **) (i_module->memory.wasmPages + std);
*file = stderr;
return offset;
}
// TODO: system calls should be able to return traps. make return first arg.
i32 m3_fread (void * io_ptr, i32 i_size, i32 i_count, FILE * i_file)
@ -138,6 +154,14 @@ i32 m3_fread (void * io_ptr, i32 i_size, i32 i_count, FILE * i_file)
}
i32 m3_fwrite (void * i_ptr, i32 i_size, i32 i_count, FILE * i_file)
{
FILE * file = * (void **) i_file;
return (i32) fwrite (i_ptr, i_size, i_count, file);
}
M3Result EmbedHost (IM3Runtime i_runtime)
{
M3Result result = c_m3Err_none;
@ -189,4 +213,21 @@ void m3Export (const void * i_data, i32 i_size)
fclose (f);
}
M3Result m3_LinkCStd (IM3Module io_module)
{
M3Result result = c_m3Err_none;
m3_LinkFunction (io_module, "_printf", "v(**)", (void *) m3_printf);
m3_LinkFunction (io_module, "_fopen", "i(M**)", (void *) m3_fopen);
m3_LinkFunction (io_module, "_fread", "i(*ii*)", (void *) m3_fread);
m3_LinkFunction (io_module, "_fwrite", "i(*ii*)", (void *) m3_fwrite);
m3_LinkFunction (io_module, "_exit", "v(i)", (void *) exit);
m3_LinkFunction (io_module, "g$_stderr", "i(M)", (void *) m3_getStderr);
catch: return result;
}

@ -9,7 +9,6 @@
#ifndef m3_host_h
#define m3_host_h
//#include <inttypes.h>
#include "m3_core.h"
# if __cplusplus
@ -37,6 +36,10 @@ extern "C" {
i32 m3_fopen (IM3Module i_module, ccstr_t i_path, ccstr_t i_mode);
M3Result m3_LinkCStd (IM3Module io_module);
# if __cplusplus
}
# endif

@ -60,7 +60,6 @@ int main (int argc, const char * argv [])
if (not result)
{
m3_LinkFunction (module, "_printf", "v(**)", (void *) m3_printf);
m3_LinkFunction (module, "_m3TestOut", "v(iFi)", (void *) m3TestOut);
m3_LinkFunction (module, "_m3StdOut", "v(*)", (void *) m3Output);
m3_LinkFunction (module, "_m3Export", "v(*i)", (void *) m3Export);
@ -73,8 +72,9 @@ int main (int argc, const char * argv [])
m3_LinkFunction (module, "_free", "v(Mi)", (void *) m3_free);
m3_LinkFunction (module, "_memset", "*(*ii)", (void *) m3_memset);
m3_LinkFunction (module, "_memcpy", "*(**i)", (void *) m3_memcpy);
m3_LinkFunction (module, "_fopen", "i(M**)", (void *) m3_fopen);
m3_LinkFunction (module, "_fread", "i(*ii*)", (void *) m3_fread);
m3_LinkCStd (module);
m3_PrintRuntimeInfo (env);

Loading…
Cancel
Save