MCPcopy Create free account
hub / github.com/anjo76/angelscript / WriteByteCode

Method WriteByteCode

sdk/angelscript/source/as_restore.cpp:5153–5612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5151}
5152
5153void asCWriter::WriteByteCode(asCScriptFunction *func)
5154{
5155 asDWORD *bc = func->scriptData->byteCode.AddressOf();
5156 size_t length = func->scriptData->byteCode.GetLength();
5157
5158 // The length cannot be stored, because it is platform dependent,
5159 // instead we store the number of instructions
5160 asUINT count = bytecodeNbrByPos[bytecodeNbrByPos.GetLength()-1] + 1;
5161 WriteEncodedInt64(count);
5162
5163 asDWORD *startBC = bc;
5164 while( length )
5165 {
5166 asDWORD tmpBC[4]; // The biggest instructions take up 4 DWORDs
5167 asDWORD c = *(asBYTE*)bc;
5168
5169 // Copy the instruction to a temp buffer so we can work on it before saving
5170 memcpy(tmpBC, bc, asBCTypeSize[asBCInfo[c].type]*sizeof(asDWORD));
5171
5172 if( c == asBC_ALLOC ) // PTR_DW_ARG
5173 {
5174 // Translate the object type
5175 asCObjectType *ot = *(asCObjectType**)(tmpBC+1);
5176 *(asPWORD*)(tmpBC+1) = FindTypeInfoIdx(ot);
5177
5178 // Translate the constructor func id, unless it is 0
5179 if( *(int*)&tmpBC[1+AS_PTR_SIZE] != 0 )
5180 {
5181 // Increment 1 to the translated function id, as 0 will be reserved for no function
5182 *(int*)&tmpBC[1+AS_PTR_SIZE] = 1+FindFunctionIndex(engine->scriptFunctions[*(int*)&tmpBC[1+AS_PTR_SIZE]]);
5183 }
5184 }
5185 else if( c == asBC_REFCPY || // PTR_ARG
5186 c == asBC_RefCpyV || // wW_PTR_ARG
5187 c == asBC_OBJTYPE ) // PTR_ARG
5188 {
5189 // Translate object type pointers into indices
5190 *(asPWORD*)(tmpBC+1) = FindTypeInfoIdx(*(asCObjectType**)(tmpBC+1));
5191 }
5192 else if( c == asBC_JitEntry ) // PTR_ARG
5193 {
5194 // We don't store the JIT argument
5195 *(asPWORD*)(tmpBC+1) = 0;
5196 }
5197 else if( c == asBC_TYPEID || // DW_ARG
5198 c == asBC_Cast ) // DW_ARG
5199 {
5200 // Translate type ids into indices
5201 *(int*)(tmpBC+1) = FindTypeIdIdx(*(int*)(tmpBC+1));
5202 }
5203 else if( c == asBC_ADDSi || // W_DW_ARG
5204 c == asBC_LoadThisR ) // W_DW_ARG
5205 {
5206 // Translate property offsets into indices
5207 *(((short*)tmpBC)+1) = (short)FindObjectPropIndex(*(((short*)tmpBC)+1), *(int*)(tmpBC+1), bc);
5208
5209 // Translate type ids into indices
5210 *(int*)(tmpBC+1) = FindTypeIdIdx(*(int*)(tmpBC+1));

Callers

nothing calls this directly

Calls 11

CastToObjectTypeFunction · 0.85
AdjustOffsetMethod · 0.80
MoveToMethod · 0.80
GetTypeInfoOfLocalVarMethod · 0.80
PushLastMethod · 0.80
PopLastMethod · 0.80
SetRepeatCountMethod · 0.80
SetNextTypeMethod · 0.80
AddressOfMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected