@@ -292,7 +292,8 @@ M3Result AllocateSlots (IM3Compilation o, u16 * o_slot, u8 i_type)
292
292
293
293
M3Result AllocateConstantSlots (IM3Compilation o , u16 * o_slot , u8 i_type )
294
294
{
295
- return AllocateSlotsWithinRange (o , o_slot , i_type , o -> slotFirstConstIndex , o -> slotFirstDynamicIndex );
295
+ u16 maxTableIndex = o -> slotFirstConstIndex + d_m3MaxConstantTableSize ;
296
+ return AllocateSlotsWithinRange (o , o_slot , i_type , o -> slotFirstConstIndex , M3_MIN (o -> slotFirstDynamicIndex , maxTableIndex ));
296
297
}
297
298
298
299
@@ -1116,10 +1117,10 @@ _ (Read_u8 (& opcode, & o->wasm, o->wasmEnd)); m3log (compile, d_i
1116
1117
1117
1118
//printf("Extended opcode: 0x%x\n", i_opcode);
1118
1119
1119
- const M3OpInfo * opinfo = GetOpInfo (i_opcode );
1120
- _throwif (m3Err_unknownOpcode , not opinfo );
1120
+ IM3OpInfo opInfo = GetOpInfo (i_opcode );
1121
+ _throwif (m3Err_unknownOpcode , not opInfo );
1121
1122
1122
- M3Compiler compiler = opinfo -> compiler ;
1123
+ M3Compiler compiler = opInfo -> compiler ;
1123
1124
_throwif (m3Err_noCompiler , not compiler );
1124
1125
1125
1126
_ ((* compiler ) (o , i_opcode ));
@@ -2011,74 +2012,75 @@ M3Result Compile_Operator (IM3Compilation o, m3opcode_t i_opcode)
2011
2012
{
2012
2013
M3Result result ;
2013
2014
2014
- const M3OpInfo * op = GetOpInfo (i_opcode );
2015
+ IM3OpInfo opInfo = GetOpInfo (i_opcode );
2016
+ _throwif (m3Err_unknownOpcode , not opInfo );
2015
2017
2016
- IM3Operation operation ;
2018
+ IM3Operation op ;
2017
2019
2018
2020
// This preserve is for for FP compare operations.
2019
2021
// either need additional slot destination operations or the
2020
2022
// easy fix, move _r0 out of the way.
2021
2023
// moving out the way might be the optimal solution most often?
2022
2024
// otherwise, the _r0 reg can get buried down in the stack
2023
2025
// and be idle & wasted for a moment.
2024
- if (IsFpType (GetStackTopType (o )) and IsIntType (op -> type ))
2026
+ if (IsFpType (GetStackTopType (o )) and IsIntType (opInfo -> type ))
2025
2027
{
2026
- _ (PreserveRegisterIfOccupied (o , op -> type ));
2028
+ _ (PreserveRegisterIfOccupied (o , opInfo -> type ));
2027
2029
}
2028
2030
2029
- if (op -> stackOffset == 0 )
2031
+ if (opInfo -> stackOffset == 0 )
2030
2032
{
2031
2033
if (IsStackTopInRegister (o ))
2032
2034
{
2033
- operation = op -> operations [0 ]; // _s
2035
+ op = opInfo -> operations [0 ]; // _s
2034
2036
}
2035
2037
else
2036
2038
{
2037
- _ (PreserveRegisterIfOccupied (o , op -> type ));
2038
- operation = op -> operations [1 ]; // _r
2039
+ _ (PreserveRegisterIfOccupied (o , opInfo -> type ));
2040
+ op = opInfo -> operations [1 ]; // _r
2039
2041
}
2040
2042
}
2041
2043
else
2042
2044
{
2043
2045
if (IsStackTopInRegister (o ))
2044
2046
{
2045
- operation = op -> operations [0 ]; // _rs
2047
+ op = opInfo -> operations [0 ]; // _rs
2046
2048
2047
2049
if (IsStackTopMinus1InRegister (o ))
2048
2050
{ d_m3Assert (i_opcode == 0x38 or i_opcode == 0x39 );
2049
- operation = op -> operations [3 ]; // _rr for fp.store
2051
+ op = opInfo -> operations [3 ]; // _rr for fp.store
2050
2052
}
2051
2053
}
2052
2054
else if (IsStackTopMinus1InRegister (o ))
2053
2055
{
2054
- operation = op -> operations [1 ]; // _sr
2056
+ op = opInfo -> operations [1 ]; // _sr
2055
2057
2056
- if (not operation ) // must be commutative, then
2057
- operation = op -> operations [0 ];
2058
+ if (not op ) // must be commutative, then
2059
+ op = opInfo -> operations [0 ];
2058
2060
}
2059
2061
else
2060
2062
{
2061
- _ (PreserveRegisterIfOccupied (o , op -> type )); // _ss
2062
- operation = op -> operations [2 ];
2063
+ _ (PreserveRegisterIfOccupied (o , opInfo -> type )); // _ss
2064
+ op = opInfo -> operations [2 ];
2063
2065
}
2064
2066
}
2065
2067
2066
- if (operation )
2068
+ if (op )
2067
2069
{
2068
- _ (EmitOp (o , operation ));
2070
+ _ (EmitOp (o , op ));
2069
2071
2070
2072
_ (EmitSlotNumOfStackTopAndPop (o ));
2071
2073
2072
- if (op -> stackOffset < 0 )
2074
+ if (opInfo -> stackOffset < 0 )
2073
2075
_ (EmitSlotNumOfStackTopAndPop (o ));
2074
2076
2075
- if (op -> type != c_m3Type_none )
2076
- _ (PushRegister (o , op -> type ));
2077
+ if (opInfo -> type != c_m3Type_none )
2078
+ _ (PushRegister (o , opInfo -> type ));
2077
2079
}
2078
2080
else
2079
2081
{
2080
2082
# ifdef DEBUG
2081
- result = ErrorCompile ("no operation found for opcode" , o , "'%s'" , op -> name );
2083
+ result = ErrorCompile ("no operation found for opcode" , o , "'%s'" , opInfo -> name );
2082
2084
# else
2083
2085
result = ErrorCompile ("no operation found for opcode" , o , "%x" , i_opcode );
2084
2086
# endif
@@ -2093,7 +2095,9 @@ M3Result Compile_Convert (IM3Compilation o, m3opcode_t i_opcode)
2093
2095
{
2094
2096
M3Result result = m3Err_none ;
2095
2097
2096
- const M3OpInfo * opInfo = GetOpInfo (i_opcode );
2098
+ _try {
2099
+ IM3OpInfo opInfo = GetOpInfo (i_opcode );
2100
+ _throwif (m3Err_unknownOpcode , not opInfo );
2097
2101
2098
2102
bool destInSlot = IsRegisterTypeAllocated (o , opInfo -> type );
2099
2103
bool sourceInSlot = IsStackTopInSlot (o );
@@ -2108,6 +2112,7 @@ _ (PushAllocatedSlotAndEmit (o, opInfo->type))
2108
2112
else
2109
2113
_ (PushRegister (o , opInfo -> type ))
2110
2114
2115
+ }
2111
2116
_catch : return result ;
2112
2117
}
2113
2118
@@ -2122,9 +2127,10 @@ _try {
2122
2127
_ (ReadLEB_u32 (& alignHint , & o -> wasm , o -> wasmEnd ));
2123
2128
_ (ReadLEB_u32 (& memoryOffset , & o -> wasm , o -> wasmEnd ));
2124
2129
m3log (compile , d_indent " (offset = %d)" , get_indention_string (o ), memoryOffset );
2125
- const M3OpInfo * op = GetOpInfo (i_opcode );
2130
+ IM3OpInfo opInfo = GetOpInfo (i_opcode );
2131
+ _throwif (m3Err_unknownOpcode , not opInfo );
2126
2132
2127
- if (IsFpType (op -> type ))
2133
+ if (IsFpType (opInfo -> type ))
2128
2134
_ (PreserveRegisterIfOccupied (o , c_m3Type_f64 ));
2129
2135
2130
2136
_ (Compile_Operator (o , i_opcode ));
@@ -2439,7 +2445,8 @@ const M3OpInfo c_operationsFC [] =
2439
2445
# endif
2440
2446
};
2441
2447
2442
- const M3OpInfo * GetOpInfo (m3opcode_t opcode )
2448
+
2449
+ IM3OpInfo GetOpInfo (m3opcode_t opcode )
2443
2450
{
2444
2451
switch (opcode >> 8 ) {
2445
2452
case 0x00 :
@@ -2480,7 +2487,7 @@ _ (Read_opcode (& opcode, & o->wasm, o->wasmEnd)); log_opco
2480
2487
}
2481
2488
}
2482
2489
2483
- IM3OpInfo opinfo = GetOpInfo (opcode );
2490
+ IM3OpInfo opinfo = GetOpInfo (opcode );
2484
2491
2485
2492
if (opinfo == NULL )
2486
2493
_throw (ErrorCompile (m3Err_unknownOpcode , o , "opcode '%x' not available" , opcode ));
@@ -2648,6 +2655,7 @@ M3Result CompileLocals (IM3Compilation o)
2648
2655
{
2649
2656
M3Result result ;
2650
2657
2658
+ u32 numLocals = 0 ;
2651
2659
u32 numLocalBlocks ;
2652
2660
_ (ReadLEB_u32 (& numLocalBlocks , & o -> wasm , o -> wasmEnd ));
2653
2661
@@ -2660,11 +2668,14 @@ _ (ReadLEB_u32 (& numLocalBlocks, & o->wasm, o->wasmEnd));
2660
2668
_ (ReadLEB_u32 (& varCount , & o -> wasm , o -> wasmEnd ));
2661
2669
_ (ReadLEB_i7 (& waType , & o -> wasm , o -> wasmEnd ));
2662
2670
_ (NormalizeType (& localType , waType ));
2663
- m3log (compile , "pushing locals. count: %d; type: %s" , varCount , c_waTypes [localType ]);
2671
+ numLocals += varCount ; m3log (compile , "pushing locals. count: %d; type: %s" , varCount , c_waTypes [localType ]);
2664
2672
while (varCount -- )
2665
2673
_ (PushAllocatedSlot (o , localType ));
2666
2674
}
2667
2675
2676
+ if (o -> function )
2677
+ o -> function -> numLocals = numLocals ;
2678
+
2668
2679
_catch : return result ;
2669
2680
}
2670
2681
0 commit comments