extensions
Steven Massey 5 years ago
parent af00f6f099
commit 215e13d331

@ -20,13 +20,15 @@ int main ()
uLongf length = 900000;
void * dest = malloc (length);
FILE * f = fopen ("/Users/smassey/98-0.txt", "r+b");
FILE * f = fopen ("/Users/smassey/Sync/Local/98-0.txt", "r+b");
size_t s = 0;
if (f)
{
size_t d = fread (data, 1, srcLength, f);
m3Out_i32 (d);
// ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
// const Bytef *source, uLong sourceLen,
// int level));

@ -59,13 +59,10 @@
B56FD4C12282A49C006B249B /* m3_module.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = m3_module.c; path = ../../source/m3_module.c; sourceTree = "<group>"; };
B59469F822654B8F008572B8 /* m3 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = m3; sourceTree = BUILT_PRODUCTS_DIR; };
B5946A0322654C05008572B8 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../../source/main.cpp; sourceTree = "<group>"; };
B5BE67F42280DCCC00D5CA2A /* test.trap.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = test.trap.c; path = ../../test/test.trap.c; sourceTree = "<group>"; };
B5C4BE4522790CE400CEB4AB /* mandelbrot.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mandelbrot.c; path = ../../benchmark/mandelbrot.c; sourceTree = "<group>"; };
B5C4BE4722790FE200CEB4AB /* perf.dsp.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = perf.dsp.c; path = ../../benchmark/perf.dsp.c; sourceTree = "<group>"; };
B5D5F5FA2277B12100FEA827 /* output.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = output.c; path = ../../test/output.c; sourceTree = "<group>"; };
B5EE06AA2266EF3800DCF003 /* m3_core.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = m3_core.c; path = ../../source/m3_core.c; sourceTree = "<group>"; };
B5EE06AC2266EF7100DCF003 /* m3_core.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = m3_core.h; path = ../../source/m3_core.h; sourceTree = "<group>"; };
B5EFD6DD228E49FE001965C7 /* test.host.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = test.host.c; path = ../../test/test.host.c; sourceTree = "<group>"; };
B5F778892275781B001A4F1E /* m3_optimize.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = m3_optimize.c; path = ../../source/m3_optimize.c; sourceTree = "<group>"; };
B5F7788C227579A9001A4F1E /* m3_info.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = m3_info.c; path = ../../source/m3_info.c; sourceTree = "<group>"; };
B5FD6505227A53110077AAA3 /* m3_exec_defs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = m3_exec_defs.h; path = ../../source/m3_exec_defs.h; sourceTree = "<group>"; };
@ -136,11 +133,8 @@
isa = PBXGroup;
children = (
B51327812277EB6000447182 /* perf.crc.c */,
B5D5F5FA2277B12100FEA827 /* output.c */,
B5C4BE4522790CE400CEB4AB /* mandelbrot.c */,
B5C4BE4722790FE200CEB4AB /* perf.dsp.c */,
B5BE67F42280DCCC00D5CA2A /* test.trap.c */,
B5EFD6DD228E49FE001965C7 /* test.host.c */,
B51D6D5622C69EF2008BA3E0 /* test.zlib.c */,
);
name = tests;
@ -329,6 +323,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
GCC_VERSION = "";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@ -338,8 +333,8 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEAD_CODE_STRIPPING = YES;
GCC_OPTIMIZATION_LEVEL = fast;
OTHER_CFLAGS = "-fomit-frame-pointer";
GCC_OPTIMIZATION_LEVEL = s;
GCC_VERSION = "";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;

@ -992,7 +992,7 @@ _ (EmitOp (o, op));
EmitPointer (o, operand);
EmitOffset (o, execTop);
}
else result = ErrorCompile (c_m3Err_functionImportMissing, o, "missing symbol: '%s'", GetFunctionName (function));
else result = ErrorCompile (c_m3Err_functionImportMissing, o, "missing function: '%s'", GetFunctionName (function));
}
else result = c_m3Err_functionLookupFailed;
@ -1360,7 +1360,7 @@ const M3OpInfo c_operations [] =
{ "i32.div_s", -1, i_32, d_binOpList (i32, Divide) }, // 0x6d
{ "i32.div_u", -1, i_32, d_binOpList (u32, Divide) }, // 0x6e
{ "i32.rem_s", -1, i_32, d_binOpList (i32, Remainder) }, // 0x6f
{ "i32.rem_u", -1, i_32, NULL, NULL, NULL }, // 0x70
{ "i32.rem_u", -1, i_32, d_binOpList (u32, Remainder) }, // 0x70
{ "i32.and", -1, i_32, d_commutativeBinOpList (u64, And) }, // 0x71
{ "i32.or", -1, i_32, d_commutativeBinOpList (u64, Or) }, // 0x72
{ "i32.xor", -1, i_32, d_commutativeBinOpList (u64, Xor) }, // 0x73

@ -47,14 +47,14 @@
// m3log (...) --------------------------------------------------------------------
# define d_m3LogParse 0
# define d_m3LogCompile 0
# define d_m3LogParse 1
# define d_m3LogCompile 1
# define d_m3LogStack 0
# define d_m3LogEmit 0
# define d_m3LogCodePages 0
# define d_m3LogModule 0
# define d_m3LogRuntime 0
# define d_m3LogExec 0
# define d_m3LogRuntime 1
# define d_m3LogExec 1

@ -59,6 +59,15 @@ const void * const cvptr_t;
# endif
typedef struct M3MemoryHeader
{
IM3Module module;
void * end;
}
M3MemoryHeader;
static const char * m3LogTruncFilename (const char * i_file)
{
const char * file = i_file + strlen (i_file);
@ -197,6 +206,7 @@ static const char * const c_waTypes [] = { "nil", "i32", "i64", "f32", "f64"
#define ErrorModule(RESULT, MOD, FORMAT, ...) _m3Error (RESULT, MOD->runtime, MOD, NULL, __FILE__, __LINE__, FORMAT, ##__VA_ARGS__)
#define ErrorCompile(RESULT, COMP, FORMAT, ...) _m3Error (RESULT, COMP->runtime, COMP->module, NULL, __FILE__, __LINE__, FORMAT, ##__VA_ARGS__)
//#define ErrorExec(RESULT, MODULE, FORMAT, ...) _m3Error (RESULT, COMP->runtime, COMP->module, NULL, __FILE__, __LINE__, FORMAT, ##__VA_ARGS__)
#define min(A,B) (A < B) ? A : B
#define max(A,B) (A > B) ? A : B

@ -70,13 +70,6 @@ ccstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp);
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3MemoryHeader
{
IM3Module module;
void * end;
}
M3MemoryHeader;
typedef struct M3Memory
{
M3MemoryHeader * mallocated;

@ -10,6 +10,15 @@
#include "m3_compile.h"
void ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset)
{
M3MemoryHeader * info = (M3MemoryHeader *) (i_mem - sizeof (M3MemoryHeader));
u8 * mem8 = i_mem + i_offset;
ErrorModule (c_m3Err_trapOutOfBoundsMemoryAccess, info->module, "memory bounds: [%p %p); accessed: %p; offset: %u overflow: %lld bytes", i_mem, info->end, mem8, i_offset, mem8 - (u8 *) info->end);
}
void ReportError2 (IM3Function i_function, M3Result i_result)
{
i_function->module->runtime->runtimeError = i_result;
@ -289,3 +298,25 @@ d_m3OpDef (i32_Remainder)
}
else return c_m3Err_trapRemainderByZero;
}
//inline
m3ret_t Remainder_u32 (i64 * o_result, u32 i_op1, u32 i_op2)
{
if (i_op2 != 0)
{
// // max negative divided by -1 overflows max positive
// if (op0 == 0x80000000 and _r0 == -1)
// _r0 = 0;
// else
// _r0 = op0 % _r0;
u32 result = i_op1 % i_op2;
* o_result = result;
return c_m3Err_none;
}
else return c_m3Err_trapRemainderByZero;
}

@ -214,6 +214,8 @@ d_m3Op_f (f32, Multiply, *) d_m3Op_f (f64, Multiply, *)
#define d_m3CommutativeFuncOp(REG, TYPE, NAME, FUNC) d_m3RetSig op_##TYPE##_##NAME##_sr (d_m3OpSig) \
{ \
TYPE * stack = (TYPE *) (_sp + immediate (i32)); \
@ -244,24 +246,25 @@ d_m3CommutativeFuncOp(REG, TYPE, NAME, FUNC)
#define d_m3FuncOp_i(TYPE, NAME, FUNC) d_m3FuncOp_ (_r0, TYPE, NAME, FUNC)
inline m3ret_t Remainder_u32 (i64 * o_result, u32 i_op1, u32 i_op2)
{
if (i_op2 != 0)
{
// // max negative divided by -1 overflows max positive
// if (op0 == 0x80000000 and _r0 == -1)
// _r0 = 0;
// else
// _r0 = op0 % _r0;
u32 result = i_op1 % i_op2;
* o_result = result;
return 0;
}
else return c_m3Err_trapRemainderByZero;
}
//inline
m3ret_t Remainder_u32 (i64 * o_result, u32 i_op1, u32 i_op2);
//{
// if (i_op2 != 0)
// {
// // // max negative divided by -1 overflows max positive
// // if (op0 == 0x80000000 and _r0 == -1)
// // _r0 = 0;
// // else
// // _r0 = op0 % _r0;
//
// u32 result = i_op1 % i_op2;
//
// * o_result = result;
//
// return c_m3Err_none;
// }
// else return c_m3Err_trapRemainderByZero;
//}
d_m3FuncOp_i (u32, Remainder, Remainder_u32);
@ -776,15 +779,17 @@ d_m3Op (f64_Store)
//#define d_outOfBounds return c_m3Err_trapOutOfBoundsMemoryAccess
#define d_outOfBounds { printf ("%p %p\n", mem8, end); return c_m3Err_trapOutOfBoundsMemoryAccess; }
void ReportOutOfBoundsMemoryError (pc_t i_pc, u8 * i_mem, u32 i_offset);
#define d_outOfBounds { printf ("%d %p\n", operand, end); ReportOutOfBoundsMemoryError (_pc, _mem, operand); return c_m3Err_trapOutOfBoundsMemoryAccess; }
#define d_m3Store_i(SRC_TYPE, SIZE_TYPE) \
d_m3Op (SRC_TYPE##_Store_##SIZE_TYPE##_sr) \
{ \
u32 operand = * (u32 *) (_sp + immediate (i32)); \
u32 operand = * (u32 *) (_sp + immediate (i32)); \
\
u32 offset = immediate (u32); \
u32 offset = immediate (u32); \
operand += offset; \
\
u8 * end = * ((u8 **) _mem - 1); \

@ -8,9 +8,10 @@
#include "m3_host.h"
#include "m3_core.h"
#include <stdio.h>
#include "m3_env.h"
#include <stdio.h>
#include <assert.h>
void m3_printf (cstr_t i_format, const void * i_varArgs)
{
@ -71,6 +72,10 @@ i32 AllocateHeap (M3Memory * io_memory, i32 i_size)
i_size = (i_size + 7) & ~7;
size_t ptrOffset = io_memory->heapOffset + (io_memory->heapAllocated += i_size);
size_t size = (u8 *) io_memory->mallocated->end - io_memory->wasmPages;
assert (ptrOffset < size);
return (i32) ptrOffset;
}
@ -97,6 +102,12 @@ void * m3_memset (void * i_ptr, i32 i_value, i32 i_size)
}
void * m3_memcpy (void * o_dst, void * i_src, i32 i_size)
{
return memcpy (o_dst, i_src, i_size);
}
i32 m3_fopen (IM3Module i_module, ccstr_t i_path, ccstr_t i_mode)
{
i32 offset = 0;

@ -30,6 +30,7 @@ extern "C" {
i32 m3_malloc (IM3Module i_module, i32 i_size);
void m3_free (IM3Module i_module, i32 i_data);
void * m3_memset (void * i_ptr, i32 i_value, i32 i_size);
void * m3_memcpy (void * o_dst, void * i_src, i32 i_size);
i32 m3_fread (void * ptr, i32 size, i32 count, FILE * stream);

@ -117,7 +117,7 @@ M3Result Module_EnsureMemorySize (IM3Module i_module, M3Memory * io_memory, m3
// Just get'n some tests/benchmarks going for now:
i32 pages = 2;
size_t extra = c_m3MemPageSize * pages + 900000 * 2 + sizeof (M3MemoryHeader);
size_t extra = c_m3MemPageSize * pages + 900000 * 4 + sizeof (M3MemoryHeader);
m3word_t alignedSize = i_memorySize + extra;

@ -72,6 +72,7 @@ int main (int argc, const char * argv [])
m3_LinkFunction (module, "_malloc", "i(Mi)", (void *) m3_malloc);
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);

Loading…
Cancel
Save