extensions
Volodymyr Shymanskyy 3 years ago
parent aa0379bb40
commit 4924e414e9

@ -23,11 +23,17 @@ default_envs =
maix
#titiva TODO: undefined reference to `_exit'
[env]
framework = arduino
monitor_speed = 115200
src_filter =
+<*>
-<m3/extensions/*>
[env:mkr1000]
platform = atmelsam
board = mkr1000USB
framework = arduino
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -37,8 +43,6 @@ src_build_flags =
[env:due]
platform = atmelsam
board = due
framework = arduino
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -47,8 +51,6 @@ src_build_flags =
[env:mega1284]
platform = atmelavr
board = wildfirev3
framework = arduino
monitor_speed = 115200
src_build_flags =
-Dd_m3CodePageAlignSize=512
@ -58,8 +60,6 @@ src_build_flags =
[env:tinyBLE]
platform = nordicnrf51
board = seeedTinyBLE
framework = arduino
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -68,8 +68,6 @@ src_build_flags =
[env:blenano]
platform = nordicnrf51
board = redBearLabBLENano
framework = arduino
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -78,8 +76,6 @@ src_build_flags =
[env:blenano2]
platform = nordicnrf52
board = redbear_blenano2
framework = arduino
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -88,9 +84,7 @@ src_build_flags =
[env:teensy31]
platform = teensy
board = teensy31
framework = arduino
upload_protocol = teensy-cli
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -98,12 +92,10 @@ src_build_flags =
[env:bluepill-mapple]
platform = ststm32
framework = arduino
board = bluepill_f103c8_128k
board_build.core = maple
upload_protocol = stlink
#upload_protocol = dfu
monitor_speed = 115200
src_build_flags =
-Dd_m3FixedHeap=8192
@ -113,9 +105,7 @@ src_build_flags =
[env:bluepill]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink
monitor_speed = 115200
src_build_flags =
-Dd_m3FixedHeap=8192
@ -125,8 +115,6 @@ src_build_flags =
[env:az3166]
platform = ststm32
board = mxchip_az3166
framework = arduino
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -135,8 +123,6 @@ src_build_flags =
[env:maix]
platform = kendryte210
board = sipeed-maix-one-dock
framework = arduino
monitor_speed = 115200
src_build_flags =
-O3 -Wfatal-errors
@ -145,8 +131,6 @@ src_build_flags =
[env:titiva]
platform = titiva
board = lptm4c1294ncpdt
framework = arduino
monitor_speed = 115200
src_build_flags =
-DLED_BUILTIN=13

@ -5,6 +5,10 @@ framework = stm32cube
upload_protocol = stlink
lib_deps = jeeh
src_filter =
+<*>
-<m3/extensions/*>
src_build_flags =
-Dd_m3FixedHeap=8192
-Os -Wfatal-errors

@ -17,6 +17,10 @@ upload_speed = 460800
board_build.f_cpu = 160000000L
src_filter =
+<*>
-<m3/extensions/*>
src_build_flags =
-Dd_m3FixedHeap=8192
-O3 -Wfatal-errors

@ -11,14 +11,17 @@
[platformio]
default_envs = hifive1-revb
[env:hifive1]
[env]
platform = sifive
framework = freedom-e-sdk
board = hifive1
monitor_speed = 115200
board_build.f_cpu = 320000000L
src_filter =
+<*>
-<m3/extensions/*>
src_build_flags =
-Dd_m3FixedHeap=8192
-Os -Wfatal-errors
@ -26,19 +29,8 @@ src_build_flags =
build_flags = -lm
[env:hifive1]
board = hifive1
[env:hifive1-revb]
platform = sifive
framework = freedom-e-sdk
board = hifive1-revb
monitor_speed = 115200
board_build.f_cpu = 320000000L
src_build_flags =
-Dd_m3FixedHeap=8192
-Os -Wfatal-errors
-flto
build_flags = -lm

@ -158,6 +158,12 @@ M3CodePageHeader;
#define d_m3Reg0SlotAlias 30000
#define d_m3Fp0SlotAlias 30001
#define d_m3MaxSaneTypesCount 100000
#define d_m3MaxSaneFunctionsCount 100000
#define d_m3MaxSaneImportsCount 10000
#define d_m3MaxSaneExportsCount 10000
#define d_m3MaxSaneGlobalsCount 100000
#define d_m3MaxSaneDataSegments 100000
#define d_m3MaxSaneUtf8Length 2000
#define d_m3MaxSaneFunctionArgRetCount 1000 // still insane, but whatever

@ -50,9 +50,6 @@ typedef struct M3DataSegment
}
M3DataSegment;
void FreeImportInfo (M3ImportInfo * i_info);
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3Global
@ -128,6 +125,8 @@ M3Result Module_AddGlobal (IM3Module io_module, IM
M3Result Module_AddFunction (IM3Module io_module, u32 i_typeIndex, IM3ImportInfo i_importInfo /* can be null */);
IM3Function Module_GetFunction (IM3Module i_module, u32 i_functionIndex);
void FreeImportInfo (M3ImportInfo * i_info);
//---------------------------------------------------------------------------------------------------------------------------------
typedef struct M3Environment

@ -6,7 +6,7 @@
//
#include "m3_function.h"
#include "m3_env.h"
M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes)
@ -34,17 +34,17 @@ u16 GetFuncTypeNumReturns (const IM3FuncType i_funcType)
u8 GetFuncTypeReturnType (const IM3FuncType i_funcType, u16 i_index)
{
u8 type = c_m3Type_unknown;
u8 type = c_m3Type_unknown;
if (i_funcType)
{
if (i_index < i_funcType->numRets)
{
type = i_funcType->types [i_index];
}
}
if (i_funcType)
{
if (i_index < i_funcType->numRets)
{
type = i_funcType->types [i_index];
}
}
return type;
return type;
}
@ -196,7 +196,7 @@ u16 GetFunctionNumReturns (IM3Function i_function)
u8 GetFunctionReturnType (const IM3Function i_function, u16 i_index)
{
return i_function ? GetFuncTypeReturnType (i_function->funcType, i_index) : c_m3Type_unknown;
return i_function ? GetFuncTypeReturnType (i_function->funcType, i_index) : c_m3Type_unknown;
}

@ -30,7 +30,7 @@ typedef M3FuncType * IM3FuncType;
M3Result AllocFuncType (IM3FuncType * o_functionType, u32 i_numTypes);
bool AreFuncTypesEqual (const IM3FuncType i_typeA, const IM3FuncType i_typeB);
u16 GetFuncTypeNumReturns (const IM3FuncType i_funcType);
u8 GetFuncTypeReturnType (const IM3FuncType i_funcType, u16 i_index);
u8 GetFuncTypeReturnType (const IM3FuncType i_funcType, u16 i_index);
//---------------------------------------------------------------------------------------------------------------------------------
@ -71,10 +71,10 @@ typedef struct M3Function
u16 numLocals; // not including args
u16 numLocalBytes;
bool ownsWasmCode;
bool ownsWasmCode;
u16 numConstantBytes;
void * constants;
u16 numConstantBytes;
void * constants;
}
M3Function;

@ -26,7 +26,7 @@ void m3_PrintM3Info ()
// printf (" sizeof M3CodePage : %zu bytes (%d slots) \n", sizeof (M3CodePage), c_m3CodePageNumSlots);
printf (" sizeof M3MemPage : %u bytes \n", d_m3MemPageSize);
printf (" sizeof M3Compilation : %zu bytes \n", sizeof (M3Compilation));
printf (" sizeof M3Function : %zu bytes \n", sizeof (M3Function));
printf (" sizeof M3Function : %zu bytes \n", sizeof (M3Function));
printf ("----------------------------------------------------------------\n\n");
}

@ -46,6 +46,8 @@ _try {
u32 numTypes;
_ (ReadLEB_u32 (& numTypes, & i_bytes, i_end)); m3log (parse, "** Type [%d]", numTypes);
_throwif("too many types", numTypes > d_m3MaxSaneTypesCount);
if (numTypes)
{
// table of IM3FuncType (that point to the actual M3FuncType struct in the Environment)
@ -123,6 +125,8 @@ M3Result ParseSection_Function (IM3Module io_module, bytes_t i_bytes, cbytes_t
u32 numFunctions;
_ (ReadLEB_u32 (& numFunctions, & i_bytes, i_end)); m3log (parse, "** Function [%d]", numFunctions);
_throwif("too many functions", numFunctions > d_m3MaxSaneFunctionsCount);
for (u32 i = 0; i < numFunctions; ++i)
{
u32 funcTypeIndex;
@ -144,6 +148,8 @@ M3Result ParseSection_Import (IM3Module io_module, bytes_t i_bytes, cbytes_t i
u32 numImports;
_ (ReadLEB_u32 (& numImports, & i_bytes, i_end)); m3log (parse, "** Import [%d]", numImports);
_throwif("too many imports", numImports > d_m3MaxSaneImportsCount);
for (u32 i = 0; i < numImports; ++i)
{
u8 importKind;
@ -215,6 +221,8 @@ M3Result ParseSection_Export (IM3Module io_module, bytes_t i_bytes, cbytes_t
u32 numExports;
_ (ReadLEB_u32 (& numExports, & i_bytes, i_end)); m3log (parse, "** Export [%d]", numExports);
_throwif("too many exports", numExports > d_m3MaxSaneExportsCount);
for (u32 i = 0; i < numExports; ++i)
{
const char * utf8;
@ -377,6 +385,8 @@ M3Result ParseSection_Data (M3Module * io_module, bytes_t i_bytes, cbytes_t i_
u32 numDataSegments;
_ (ReadLEB_u32 (& numDataSegments, & i_bytes, i_end)); m3log (parse, "** Data [%d]", numDataSegments);
_throwif("too many data segments", numDataSegments > d_m3MaxSaneDataSegments);
io_module->dataSegments = m3_AllocArray (M3DataSegment, numDataSegments);
_throwifnull(io_module->dataSegments);
io_module->numDataSegments = numDataSegments;
@ -429,6 +439,8 @@ M3Result ParseSection_Global (M3Module * io_module, bytes_t i_bytes, cbytes_t
u32 numGlobals;
_ (ReadLEB_u32 (& numGlobals, & i_bytes, i_end)); m3log (parse, "** Global [%d]", numGlobals);
_throwif("too many globals", numGlobals > d_m3MaxSaneGlobalsCount);
for (u32 i = 0; i < numGlobals; ++i)
{
i8 waType;
@ -478,6 +490,8 @@ _ (ReadLEB_u32 (& payloadLength, & i_bytes, i_end));
u32 numNames;
_ (ReadLEB_u32 (& numNames, & i_bytes, i_end));
_throwif("too many names", numNames > d_m3MaxSaneFunctionsCount);
for (u32 i = 0; i < numNames; ++i)
{
u32 index;

@ -226,9 +226,9 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
// Calling m3_RunStart is optional
M3Result m3_RunStart (IM3Module i_module);
// Arguments and return values are passed in and out through the stack pointer _sp.
// Placeholder return value slots are first and arguments after. So, the first argument is at _sp [numReturns]
// Return values should be written into _sp [0] to _sp [num_returns - 1]
// Arguments and return values are passed in and out through the stack pointer _sp.
// Placeholder return value slots are first and arguments after. So, the first argument is at _sp [numReturns]
// Return values should be written into _sp [0] to _sp [num_returns - 1]
typedef const void * (* M3RawCall) (IM3Runtime runtime, IM3ImportContext _ctx, uint64_t * _sp, void * _mem);
M3Result m3_LinkRawFunction (IM3Module io_module,

Loading…
Cancel
Save