| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
#include "stdafx.h" |
|---|
| 24 |
#include "criscript.h" |
|---|
| 25 |
#include "cilVm.h" |
|---|
| 26 |
namespace cri { |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
void CCilVm::storeLocalVariable( const int32_t iIndex ) |
|---|
| 39 |
{ |
|---|
| 40 |
VM_CALLSTACK* stack = getCurrentCallStack( VM_CALLSTACK_CALLSTACK ); |
|---|
| 41 |
assert( stack->iLocalVariableStartIndex + iIndex <= (int32_t)m_iLocalVariableListIndex ); |
|---|
| 42 |
|
|---|
| 43 |
OPERAND_FLAG flag = m_LocalVariableList[ stack->iLocalVariableStartIndex + iIndex ].getFlag(); |
|---|
| 44 |
if( flag & OPERAND_FLAG_READONLY ) |
|---|
| 45 |
{ |
|---|
| 46 |
|
|---|
| 47 |
popEvalStack(); |
|---|
| 48 |
return; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
if( flag & OPERAND_FLAG_STRICT ) |
|---|
| 52 |
{ |
|---|
| 53 |
|
|---|
| 54 |
storeAsRestrictedType( m_LocalVariableList[ stack->iLocalVariableStartIndex + iIndex ] ); |
|---|
| 55 |
popEvalStack(); |
|---|
| 56 |
return; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
getEvalStackFirstEntry().moveTo( m_LocalVariableList[ stack->iLocalVariableStartIndex + iIndex ] ); |
|---|
| 60 |
popEvalStackFast(); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
void CCilVm::loadLocalVariable( const int32_t iIndex ) |
|---|
| 67 |
{ |
|---|
| 68 |
VM_CALLSTACK* stack = getCurrentCallStack( VM_CALLSTACK_CALLSTACK ); |
|---|
| 69 |
assert( stack->iLocalVariableStartIndex + iIndex <= (int32_t)m_iLocalVariableListIndex ); |
|---|
| 70 |
|
|---|
| 71 |
pushEvalStack( m_LocalVariableList[ stack->iLocalVariableStartIndex + iIndex ] ); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
CVariable& CCilVm::getLocalVariable( const int32_t iIndex ) |
|---|
| 79 |
{ |
|---|
| 80 |
assert( iIndex < MAX_LOCAL_VARIABLE ); |
|---|
| 81 |
|
|---|
| 82 |
VM_CALLSTACK* stack = getCurrentCallStack( VM_CALLSTACK_CALLSTACK ); |
|---|
| 83 |
assert( stack->iLocalVariableStartIndex + iIndex <= (int32_t)m_iLocalVariableListIndex ); |
|---|
| 84 |
return m_LocalVariableList[ stack->iLocalVariableStartIndex + iIndex ]; |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
bool CCilVm::setLocalVariable( const int32_t iIndex, const CVariable& value ) |
|---|
| 91 |
{ |
|---|
| 92 |
assert( iIndex < MAX_LOCAL_VARIABLE ); |
|---|
| 93 |
|
|---|
| 94 |
VM_CALLSTACK* stack = getCurrentCallStack( VM_CALLSTACK_CALLSTACK ); |
|---|
| 95 |
assert( stack->iLocalVariableStartIndex + iIndex <= (int32_t)m_iLocalVariableListIndex ); |
|---|
| 96 |
m_LocalVariableList[ stack->iLocalVariableStartIndex + iIndex ] = value; |
|---|
| 97 |
return true; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
void CCilVm::reserveLocalVariables( const RID ridLocalsToReserve ) |
|---|
| 105 |
{ |
|---|
| 106 |
assert( TypeFromToken( ridLocalsToReserve ) == MDT_PARAMDEF ); |
|---|
| 107 |
vector< OPERAND_TYPE_FLAG >* pParamList; |
|---|
| 108 |
int32_t iIndex; |
|---|
| 109 |
if( isBuiltinRid( ridLocalsToReserve ) ) |
|---|
| 110 |
{ |
|---|
| 111 |
|
|---|
| 112 |
iIndex = IndexFromBuiltinRid( ridLocalsToReserve ); |
|---|
| 113 |
pParamList = &m_MetaData.getBuiltinParamListTable()[ iIndex ]; |
|---|
| 114 |
|
|---|
| 115 |
} |
|---|
| 116 |
else |
|---|
| 117 |
{ |
|---|
| 118 |
iIndex = RidFromToken( ridLocalsToReserve ); |
|---|
| 119 |
pParamList = &m_MetaData.getParamListTable()[ iIndex ]; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
uint32_t iSize = (uint32_t)pParamList->size(); |
|---|
| 124 |
assert( m_iLocalVariableListIndex + iSize < MAX_LOCAL_VARIABLE ); |
|---|
| 125 |
|
|---|
| 126 |
CVariable variable; |
|---|
| 127 |
for( uint32_t i = 0; i < iSize; i++ ) |
|---|
| 128 |
{ |
|---|
| 129 |
RID ridConstraint = (*pParamList)[ i ].ridConstraintType; |
|---|
| 130 |
if( ridConstraint ) |
|---|
| 131 |
{ |
|---|
| 132 |
|
|---|
| 133 |
VMOBJECTREF obj = createObject( MDT_TYPEDEF | ridConstraint ); |
|---|
| 134 |
variable.setObjectRefWithFlags( obj, |
|---|
| 135 |
(*pParamList)[ i ].flag, |
|---|
| 136 |
MDT_TYPEDEF | ridConstraint ); |
|---|
| 137 |
} |
|---|
| 138 |
else |
|---|
| 139 |
{ |
|---|
| 140 |
variable.iOperandType = (*pParamList)[ i ].type; |
|---|
| 141 |
variable.iOperandFlag = (*pParamList)[ i ].flag; |
|---|
| 142 |
variable.ridConstraintType = 0; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
m_LocalVariableList[ m_iLocalVariableListIndex ] = variable; |
|---|
| 146 |
updateLocalVariableListIndex(); |
|---|
| 147 |
} |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
void CCilVm::disposeLocalVariables( const uint32_t iLocalsToDispose ) |
|---|
| 155 |
{ |
|---|
| 156 |
assert( iLocalsToDispose <= m_iLocalVariableListIndex ); |
|---|
| 157 |
|
|---|
| 158 |
#ifdef VM_TRACK_ERASEWHENPOP |
|---|
| 159 |
for( uint32_t i = 0; i < iLocalsToDispose; ++i ) |
|---|
| 160 |
m_LocalVariableList[ --m_iLocalVariableListIndex ].erase(); |
|---|
| 161 |
#else |
|---|
| 162 |
m_iLocalVariableListIndex -= iLocalsToDispose; |
|---|
| 163 |
#endif |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
} |
|---|