extensions
Volodymyr Shymanskyy 5 years ago
parent 4f032632ae
commit 646eeaa53e

@ -23,9 +23,12 @@ M3State;
// TODO: This binding code only work'n for System V AMD64 ABI calling convention (macOS & Linux)
// Needs work for MS cdecl
#define d_m3BindingArgList i64 _i0, i64 _i1, i64 _i2, i64 _i3, i64 _i4, i64 _i5, f64 _f0, f64 _f1, f64 _f2, f64 _f3, f64 _f4
#define d_m3BindingArgs _i0, _i1, _i2, _i3, _i4, _i5, _f0, _f1, _f2, _f3, _f4
#define d_m3BindingDefaultArgs 0,0,0,0,0,0, 0.,0.,0.,0.,0.
#define d_m3BindingArgList i64 _i0, i64 _i1, i64 _i2, i64 _i3, i64 _i4, i64 _i5, \
f64 _f0, f64 _f1, f64 _f2, f64 _f3, f64 _f4
#define d_m3BindingArgs _i0, _i1, _i2, _i3, _i4, _i5, \
_f0, _f1, _f2, _f3, _f4
#define d_m3BindingDefaultArgs 0,0,0,0,0,0, \
0.,0.,0.,0.,0.
typedef m3ret_t (* M3ArgPusher) (d_m3BindingArgList, M3State * i_state);
typedef f64 (* M3ArgPusherFpReturn) (d_m3BindingArgList, M3State * i_state);
@ -400,7 +403,8 @@ M3Result m3_LinkCFunction (IM3Module io_module,
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
M3Result LinkRawFunction (IM3Module io_module, IM3Function io_function, ccstr_t /* unused: */ signature, const void * i_function)
// TODO: validate signature as well?
M3Result LinkRawFunction (IM3Module io_module, IM3Function io_function, ccstr_t signature, const void * i_function)
{
M3Result result = c_m3Err_none; d_m3Assert (io_module->runtime);

@ -2099,7 +2099,9 @@ _ (Compile_ReserveConstants (o));
o->block.initStackIndex = o->stackIndex;
pc_t pc2 = GetPagePC (o->page);
d_m3AssertFatal (pc2 == pc);
if (pc2 != pc) {
m3Abort("pc2 != pc");
}
_ (EmitOp (o, op_Entry));
EmitPointer (o, io_function);

@ -164,6 +164,7 @@ M3Result Compile_BlockStatements (IM3Compilation io);
M3Result Compile_Function (IM3Function io_function);
bool PeekNextOpcode (IM3Compilation o, u8 i_opcode);
u16 GetMaxExecSlot (IM3Compilation o);
//M3Result Optimize_ConstOp (IM3Compilation o, u64 i_word, u8 i_waType);

@ -142,6 +142,26 @@
* Apply settings
*/
# if defined (M3_COMPILER_MSVC)
# define vectorcall
# elif defined(WIN32)
# define vectorcall __vectorcall
# elif defined (ESP8266)
# include <c_types.h>
# define vectorcall //ICACHE_FLASH_ATTR
# elif defined (ESP32)
# include "esp_system.h"
# define vectorcall IRAM_ATTR
# elif defined (FOMU)
# define vectorcall __attribute__((section(".ramtext")))
# elif defined(HIFIVE1)
# include <metal/itim.h>
# define vectorcall
# else
# define vectorcall
# endif
# if defined(PARTICLE)
# define d_m3LogOutput false
# define d_m3MaxFunctionStackHeight 256

@ -9,16 +9,13 @@
#include "m3_core.h"
void m3NotImplemented() {
puts("Error: Not implemented");
void m3Abort(const char* message) {
fprintf(stderr, "Error: %s\n", message);
abort();
}
void m3AbortIfNot(bool condition) {
if (!condition) {
puts("Error: Fatal");
abort();
}
void m3NotImplemented() {
m3Abort("Not implemented");
}
M3_WEAK

@ -108,10 +108,8 @@ const void * const cvptr_t;
# ifdef DEBUG
# define d_m3Assert(ASS) assert (ASS)
# define d_m3AssertFatal(ASS) assert (ASS)
# else
# define d_m3Assert(ASS)
# define d_m3AssertFatal(ASS) m3AbortIfNot (ASS)
# endif
typedef void /*const*/ * code_t;
@ -173,11 +171,13 @@ static const char * const c_waCompactTypes [] = { "0", "i", "I", "f", "F", "v"
# define _m3Error(RESULT, RT, MOD, FUN, FILE, LINE, FORMAT, ...) (RESULT)
#endif
#define ErrorRuntime(RESULT, RUNTIME, FORMAT, ...) _m3Error (RESULT, RUNTIME, NULL, NULL, __FILE__, __LINE__, FORMAT, ##__VA_ARGS__)
#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 ErrorRuntime(RESULT, RUNTIME, FORMAT, ...) _m3Error (RESULT, RUNTIME, NULL, NULL, __FILE__, __LINE__, FORMAT, ##__VA_ARGS__)
#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__)
#if d_m3VerboseErrorMessages
M3Result m3Error (M3Result i_result, IM3Runtime i_runtime, IM3Module i_module, IM3Function i_function, const char * const i_file, u32 i_lineNum, const char * const i_errorMessage, ...);
#endif
#if d_m3LogNativeStack
void m3StackCheckInit ();
@ -189,8 +189,8 @@ size_t m3StackGetMax ();
#define m3StackGetMax() 0
#endif
void m3Abort (const char* message);
void m3NotImplemented (void);
void m3AbortIfNot (bool condition);
void m3Yield (void);

@ -266,7 +266,7 @@ M3Result InitMemory (IM3Runtime io_runtime, IM3Module i_module)
result = ResizeMemory (io_runtime, i_module->memoryInfo.initPages);
}
_catch: return result;
return result;
}
@ -319,7 +319,7 @@ M3Result ResizeMemory (IM3Runtime io_runtime, u32 i_numPages)
}
else result = c_m3Err_wasmMemoryOverflow;
_catch: return result;
return result;
}
@ -376,9 +376,7 @@ M3Result InitDataSegments (M3Memory * io_memory, IM3Module io_module)
bytes_t start = segment->initExpr;
_ (EvaluateExpression (io_module, & segmentOffset, c_m3Type_i32, & start, segment->initExpr + segment->initExprSize));
u32 minMemorySize = segment->size + segmentOffset + 1; m3log (runtime, "loading data segment: %d; size: %d; offset: %d", i, segment->size, segmentOffset);
//_ (Module_EnsureMemorySize (io_module, io_memory, minMemorySize));
m3log (runtime, "loading data segment: %d; size: %d; offset: %d", i, segment->size, segmentOffset);
if (io_memory->wasmPages)
{
@ -454,7 +452,7 @@ M3Result InitStartFunc (IM3Module io_module)
M3Result result = c_m3Err_none;
if (io_module->startFunction >= 0) {
if (io_module->startFunction >= io_module->numFunctions) {
if ((u32)io_module->startFunction >= io_module->numFunctions) {
return "start function index out of bounds";
}
IM3Function function = &io_module->functions [io_module->startFunction];

@ -248,7 +248,7 @@ void ReleaseCodePage (IM3Runtime io_runtime,
//size_t m3_GetMemorySize (void * i_memory);
M3Result m3Error (M3Result i_result, IM3Runtime i_runtime, IM3Module i_module, IM3Function i_function, const char * const i_file, u32 i_lineNum, const char * const i_errorMessage, ...);
M3Result m3Error (M3Result i_result, IM3Runtime i_runtime, IM3Module i_module, IM3Function i_function, const char * const i_file, u32 i_lineNum, const char * const i_errorMessage, ...);
#endif /* m3_env_h */

@ -421,8 +421,7 @@ void ProfileHit (cstr_t i_operationName)
{
if (slot->opName != i_operationName)
{
printf ("**** profiler slot collision; increase mask width: c_m3ProfilerSlotMask\n");
abort ();
m3Abort ("profiler slot collision; increase c_m3ProfilerSlotMask");
}
}

@ -11,40 +11,11 @@
#include "m3_core.h"
// default Windows x64 calling convention doesn't have enough registers for M3. It only supports
// 4 args passed through registers but its enhanced __vectorcall calling convention does.
# if defined (M3_COMPILER_MSVC)
# define vectorcall
# elif defined(WIN32)
# define vectorcall __vectorcall
# elif defined (ESP8266)
# include <c_types.h>
# define vectorcall //ICACHE_FLASH_ATTR
# elif defined (ESP32)
# include "esp_system.h"
# define vectorcall IRAM_ATTR
# elif defined (FOMU)
# define vectorcall __attribute__((section(".ramtext")))
# elif defined(HIFIVE1)
# include <metal/itim.h>
# define vectorcall
# define hotcall METAL_PLACE_IN_ITIM
# else
# define vectorcall
# endif
//---------------------------------------------------------------------------------------------------------------
# define d_m3OpSig pc_t _pc, u64 * _sp, u8 * _mem, m3reg_t _r0, f64 _fp0
# define d_m3OpArgs _sp, _mem, _r0, _fp0
# define d_m3OpAllArgs _pc, _sp, _mem, _r0, _fp0
# define d_m3OpDefaultArgs 666, NAN
typedef m3ret_t (vectorcall * IM3Operation) (d_m3OpSig);
#endif /* m3_exec_defs_h */

@ -146,10 +146,12 @@ i32 AllocatePrivateHeap (M3Memory * io_memory, i32 i_size)
size_t size = (u8 *) io_memory->mallocated->end - io_memory->wasmPages;
d_m3AssertFatal (ptrOffset < size);
if (ptrOffset >= size) {
m3Abort("ptrOffset >= size");
}
return (i32) ptrOffset;*/
return 0;
}

Loading…
Cancel
Save