Improve _try

This commit is contained in:
Vova
2021-11-08 22:23:27 +02:00
parent a35f31a406
commit 452a71e22a
7 changed files with 22 additions and 55 deletions
+8 -11
View File
@@ -26,8 +26,6 @@ u8 ConvertTypeCharToTypeId (char i_code)
M3Result SignatureToFuncType (IM3FuncType * o_functionType, ccstr_t i_signature)
{
M3Result result = m3Err_none;
IM3FuncType funcType = NULL;
_try {
@@ -129,15 +127,16 @@ M3Result FindAndLinkFunction (IM3Module io_module,
voidptr_t i_function,
voidptr_t i_userdata)
{
M3Result result = m3Err_functionLookupFailed;
_try {
_throwif(m3Err_moduleNotLinked, !io_module->runtime);
_throwif(m3Err_moduleNotLinked, !(io_module->runtime));
const bool wildcardModule = (strcmp (i_moduleName, "*") == 0);
bool wildcardModule = (strcmp (i_moduleName, "*") == 0);
result = m3Err_functionLookupFailed;
for (u32 i = 0; i < io_module->numFunctions; ++i)
{
IM3Function f = & io_module->functions [i];
const IM3Function f = & io_module->functions [i];
if (f->import.moduleUtf8 and f->import.fieldUtf8)
{
@@ -145,15 +144,13 @@ M3Result FindAndLinkFunction (IM3Module io_module,
(wildcardModule or strcmp (f->import.moduleUtf8, i_moduleName) == 0))
{
if (i_signature) {
result = ValidateSignature (f, i_signature);
if (M3_UNLIKELY(result)) return result;
_ (ValidateSignature (f, i_signature));
}
result = CompileRawFunction (io_module, f, i_function, i_userdata);
if (M3_UNLIKELY(result)) return result;
_ (CompileRawFunction (io_module, f, i_function, i_userdata));
}
}
}
_catch:
} _catch:
return result;
}
+1 -23
View File
@@ -1204,8 +1204,6 @@ _ (PushConst (o, value.u, c_m3Type_f64));
static
M3Result Compile_ExtendedOpcode (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result = m3Err_none;
_try {
u8 opcode;
_ (Read_u8 (& opcode, & o->wasm, o->wasmEnd)); m3log (compile, d_indent " (FC: %" PRIi32 ")", get_indention_string (o), opcode);
@@ -1322,8 +1320,6 @@ _ (Pop (o));
static
M3Result Compile_GetLocal (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result;
_try {
u32 localIndex;
@@ -1534,8 +1530,6 @@ _ (SetStackPolymorphic (o));
static
M3Result Compile_BranchTable (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result;
_try {
u32 targetCount;
_ (ReadLEB_u32 (& targetCount, & o->wasm, o->wasmEnd));
@@ -1617,8 +1611,6 @@ _ (SetStackPolymorphic (o));
static
M3Result CompileCallArgsAndReturn (IM3Compilation o, u16 * o_stackOffset, IM3FuncType i_type, bool i_isIndirect)
{
M3Result result = m3Err_none;
_try {
u16 topSlot = GetMaxUsedSlotPlusOne (o);
@@ -1665,8 +1657,6 @@ _ (Push (o, type, topSlot));
static
M3Result Compile_Call (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result;
_try {
u32 functionIndex;
_ (ReadLEB_u32 (& functionIndex, & o->wasm, o->wasmEnd));
@@ -1712,8 +1702,6 @@ _ (EmitOp (o, op));
static
M3Result Compile_CallIndirect (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result;
_try {
u32 typeIndex;
_ (ReadLEB_u32 (& typeIndex, & o->wasm, o->wasmEnd));
@@ -1912,8 +1900,6 @@ _ (CompileBlock (o, blockType, i_opcode));
static
M3Result CompileElseBlock (IM3Compilation o, pc_t * o_startPC, IM3FuncType i_blockType)
{
M3Result result;
_try {
IM3CodePage elsePage;
@@ -1940,8 +1926,6 @@ _ (EmitOp (o, op_Branch));
static
M3Result Compile_If (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result;
/* [ op_If ]
[ <else-pc> ] ----> [ ..else.. ]
[ ..if.. ] [ ..block.. ]
@@ -2191,8 +2175,6 @@ _ (PushRegister (o, opInfo->type));
static
M3Result Compile_Convert (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result = m3Err_none;
_try {
IM3OpInfo opInfo = GetOpInfo (i_opcode);
_throwif (m3Err_unknownOpcode, not opInfo);
@@ -2217,8 +2199,6 @@ _ (PushRegister (o, opInfo->type))
static
M3Result Compile_Load_Store (IM3Compilation o, m3opcode_t i_opcode)
{
M3Result result;
_try {
u32 alignHint, memoryOffset;
@@ -2675,7 +2655,7 @@ _ (PushAllocatedSlot (o, type));
M3Result CompileBlock (IM3Compilation o, IM3FuncType i_blockType, m3opcode_t i_blockOpcode)
{
M3Result result = m3Err_none; d_m3Assert (not IsRegisterAllocated (o, 0));
d_m3Assert (not IsRegisterAllocated (o, 0));
d_m3Assert (not IsRegisterAllocated (o, 1));
M3CompilationScope outerScope = o->block;
M3CompilationScope * block = & o->block;
@@ -2851,8 +2831,6 @@ M3Result ReserveConstants (IM3Compilation o)
M3Result CompileFunction (IM3Function io_function)
{
M3Result result = m3Err_none;
if (!io_function->wasm) return "function body is missing";
IM3FuncType funcType = io_function->funcType; m3log (compile, "compiling: [%d] %s %s; wasm-size: %d",
+1 -1
View File
@@ -192,7 +192,7 @@ static inline bool IsIntRegisterSlotAlias (u16 i_slot) { return (i_slot
//-----------------------------------------------------------------------------------------------------------------------------------
u16 GetMaxUsedSlotPlusOne (IM3Compilation o);
u16 GetMaxUsedSlotPlusOne (IM3Compilation o);
M3Result CompileBlock (IM3Compilation io, IM3FuncType i_blockType, m3opcode_t i_blockOpcode);
-2
View File
@@ -16,8 +16,6 @@
IM3Environment m3_NewEnvironment ()
{
M3Result result = m3Err_none;
IM3Environment env = m3_AllocStruct (M3Environment);
if (env)
+4 -5
View File
@@ -23,11 +23,10 @@ void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message);
# endif
#define _try
#define _(TRY) { result = TRY; if (result) { EXCEPTION_PRINT (result); goto _catch; } }
#define _throw(ERROR) { result = ERROR; EXCEPTION_PRINT (result); goto _catch; }
#define _throwif(ERROR, COND) if (M3_UNLIKELY(COND)) \
{ result = ERROR; EXCEPTION_PRINT (result); goto _catch; }
#define _try M3Result result;
#define _(TRY) { result = TRY; if (M3_UNLIKELY(result)) { EXCEPTION_PRINT (result); goto _catch; } }
#define _throw(ERROR) { result = ERROR; EXCEPTION_PRINT (result); goto _catch; }
#define _throwif(ERROR, COND) if (M3_UNLIKELY(COND)) { _throw(ERROR); }
#define _throwifnull(PTR) _throwif (m3Err_mallocFailed, !(PTR))
+6 -6
View File
@@ -48,11 +48,11 @@ void m3_FreeModule (IM3Module i_module)
M3Result Module_AddGlobal (IM3Module io_module, IM3Global * o_global, u8 i_type, bool i_mutable, bool i_isImported)
{
M3Result result = m3Err_none;
_try {
result = m3Err_none;
u32 index = io_module->numGlobals++;
io_module->globals = m3_ReallocArray (M3Global, io_module->globals, io_module->numGlobals, index);
_throwifnull(io_module->globals);
_throwifnull (io_module->globals);
M3Global * global = & io_module->globals [index];
global->type = i_type;
@@ -68,19 +68,19 @@ _try {
M3Result Module_PreallocFunctions (IM3Module io_module, u32 i_totalFunctions)
{
M3Result result = m3Err_none;
_try {
result = m3Err_none;
if (i_totalFunctions > io_module->allFunctions) {
io_module->functions = m3_ReallocArray (M3Function, io_module->functions, i_totalFunctions, io_module->allFunctions);
io_module->allFunctions = i_totalFunctions;
_throwifnull (io_module->functions);
}
_catch: return result;
} _catch:
return result;
}
M3Result Module_AddFunction (IM3Module io_module, u32 i_typeIndex, IM3ImportInfo i_importInfo)
{
M3Result result = m3Err_none;
_try {
u32 index = io_module->numFunctions++;
+2 -7
View File
@@ -38,7 +38,6 @@ _ (ReadLEB_u32 (& o_memory->maxPages, io_bytes, i_end));
M3Result ParseSection_Type (IM3Module io_module, bytes_t i_bytes, cbytes_t i_end)
{
M3Result result = m3Err_none;
IM3FuncType ftype = NULL;
_try {
@@ -309,9 +308,7 @@ M3Result ParseSection_Element (IM3Module io_module, bytes_t i_bytes, cbytes_t
M3Result result = m3Err_none;
u32 numSegments;
result = ReadLEB_u32 (& numSegments, & i_bytes, i_end); m3log (parse, "** Element [%d]", numSegments);
_throwif ("error parsing Element section", result);
_ (ReadLEB_u32 (& numSegments, & i_bytes, i_end)); m3log (parse, "** Element [%d]", numSegments);
_throwif ("too many element segments", numSegments > d_m3MaxSaneElementSegments);
@@ -592,9 +589,7 @@ M3Result ParseModuleSection (M3Module * o_module, u8 i_sectionType, bytes_t i_
M3Result m3_ParseModule (IM3Environment i_environment, IM3Module * o_module, cbytes_t i_bytes, u32 i_numBytes)
{
M3Result result; m3log (parse, "load module: %d bytes", i_numBytes);
IM3Module module;
IM3Module module; m3log (parse, "load module: %d bytes", i_numBytes);
_try {
module = m3_AllocStruct (M3Module);
_throwifnull (module);