Move frm from sp_context_t to PluginContext.

This commit is contained in:
David Anderson 2015-02-24 21:01:05 -08:00
parent d2005bd42a
commit 4c9321f02a
5 changed files with 41 additions and 31 deletions

View File

@ -135,13 +135,15 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
// Save the original frm. BaseContext won't, and if we error, we won't hit // Save the original frm. BaseContext won't, and if we error, we won't hit
// the stack unwinding code. // the stack unwinding code.
cell_t orig_frm = ctx->frm; cell_t orig_frm = cx->frm();
cell_t pri = 0; cell_t pri = 0;
cell_t alt = 0; cell_t alt = 0;
cell_t *cip = code + (aCodeStart / 4); cell_t *cip = code + (aCodeStart / 4);
cell_t *stk = reinterpret_cast<cell_t *>(plugin->memory + ctx->sp); cell_t *stk = reinterpret_cast<cell_t *>(plugin->memory + ctx->sp);
cell_t &frm = *cx->addressOfFrm();
for (;;) { for (;;) {
if (cip >= codeend) { if (cip >= codeend) {
err = SP_ERROR_INVALID_INSTRUCTION; err = SP_ERROR_INVALID_INSTRUCTION;
@ -175,7 +177,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
break; break;
case OP_ZERO_S: case OP_ZERO_S:
Write(plugin, ctx->frm + *cip++, 0); Write(plugin, frm + *cip++, 0);
break; break;
case OP_PUSH_PRI: case OP_PUSH_PRI:
@ -215,7 +217,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
int i = 1; int i = 1;
do { do {
cell_t addr = ctx->frm + *cip++; cell_t addr = frm + *cip++;
*--stk = addr; *--stk = addr;
} while (i++ < n); } while (i++ < n);
break; break;
@ -233,7 +235,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
int i = 1; int i = 1;
do { do {
cell_t value = Read(plugin, ctx->frm + *cip++); cell_t value = Read(plugin, frm + *cip++);
*--stk = value; *--stk = value;
} while (i++ < n); } while (i++ < n);
break; break;
@ -278,9 +280,9 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
case OP_PROC: case OP_PROC:
{ {
*--stk = ctx->frm; *--stk = frm;
*--stk = 0; *--stk = 0;
ctx->frm = uintptr_t(stk) - uintptr_t(plugin->memory); frm = uintptr_t(stk) - uintptr_t(plugin->memory);
break; break;
} }
@ -399,8 +401,8 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
case OP_INC_S: case OP_INC_S:
{ {
cell_t offset = *cip++; cell_t offset = *cip++;
cell_t value = Read(plugin, ctx->frm + offset); cell_t value = Read(plugin, frm + offset);
Write(plugin, ctx->frm + offset, value + 1); Write(plugin, frm + offset, value + 1);
break; break;
} }
@ -429,8 +431,8 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
case OP_DEC_S: case OP_DEC_S:
{ {
cell_t offset = *cip++; cell_t offset = *cip++;
cell_t value = Read(plugin, ctx->frm + offset); cell_t value = Read(plugin, frm + offset);
Write(plugin, ctx->frm + offset, value - 1); Write(plugin, frm + offset, value - 1);
break; break;
} }
@ -450,27 +452,27 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
break; break;
case OP_LOAD_S_PRI: case OP_LOAD_S_PRI:
pri = Read(plugin, ctx->frm + *cip++); pri = Read(plugin, frm + *cip++);
break; break;
case OP_LOAD_S_ALT: case OP_LOAD_S_ALT:
alt = Read(plugin, ctx->frm + *cip++); alt = Read(plugin, frm + *cip++);
break; break;
case OP_LOAD_S_BOTH: case OP_LOAD_S_BOTH:
pri = Read(plugin, ctx->frm + *cip++); pri = Read(plugin, frm + *cip++);
alt = Read(plugin, ctx->frm + *cip++); alt = Read(plugin, frm + *cip++);
break; break;
case OP_LREF_S_PRI: case OP_LREF_S_PRI:
{ {
pri = Read(plugin, ctx->frm + *cip++); pri = Read(plugin, frm + *cip++);
pri = Read(plugin, pri); pri = Read(plugin, pri);
break; break;
} }
case OP_LREF_S_ALT: case OP_LREF_S_ALT:
{ {
alt = Read(plugin, ctx->frm + *cip++); alt = Read(plugin, frm + *cip++);
alt = Read(plugin, alt); alt = Read(plugin, alt);
break; break;
} }
@ -483,10 +485,10 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
break; break;
case OP_ADDR_PRI: case OP_ADDR_PRI:
pri = ctx->frm + *cip++; pri = frm + *cip++;
break; break;
case OP_ADDR_ALT: case OP_ADDR_ALT:
alt = ctx->frm + *cip++; alt = frm + *cip++;
break; break;
case OP_STOR_PRI: case OP_STOR_PRI:
@ -497,10 +499,10 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
break; break;
case OP_STOR_S_PRI: case OP_STOR_S_PRI:
Write(plugin, ctx->frm + *cip++, pri); Write(plugin, frm + *cip++, pri);
break; break;
case OP_STOR_S_ALT: case OP_STOR_S_ALT:
Write(plugin, ctx->frm +*cip++, alt); Write(plugin, frm +*cip++, alt);
break; break;
case OP_IDXADDR: case OP_IDXADDR:
@ -510,7 +512,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
case OP_SREF_S_PRI: case OP_SREF_S_PRI:
{ {
cell_t offset = *cip++; cell_t offset = *cip++;
cell_t addr = Read(plugin, ctx->frm + offset); cell_t addr = Read(plugin, frm + offset);
Write(plugin, addr, pri); Write(plugin, addr, pri);
break; break;
} }
@ -518,7 +520,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
case OP_SREF_S_ALT: case OP_SREF_S_ALT:
{ {
cell_t offset = *cip++; cell_t offset = *cip++;
cell_t addr = Read(plugin, ctx->frm + offset); cell_t addr = Read(plugin, frm + offset);
Write(plugin, addr, alt); Write(plugin, addr, alt);
break; break;
} }
@ -573,7 +575,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
{ {
cell_t offset = *cip++; cell_t offset = *cip++;
cell_t value = *cip++; cell_t value = *cip++;
Write(plugin, ctx->frm + offset, value); Write(plugin, frm + offset, value);
break; break;
} }
@ -645,7 +647,7 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
case OP_RETN: case OP_RETN:
{ {
stk++; stk++;
ctx->frm = *stk++; frm = *stk++;
stk += *stk + 1; stk += *stk + 1;
*rval = pri; *rval = pri;
err = SP_ERROR_NONE; err = SP_ERROR_NONE;
@ -889,12 +891,12 @@ Interpret(PluginRuntime *rt, uint32_t aCodeStart, cell_t *rval)
} }
done: done:
assert(orig_frm == ctx->frm); assert(orig_frm == frm);
ctx->sp = uintptr_t(stk) - uintptr_t(plugin->memory); ctx->sp = uintptr_t(stk) - uintptr_t(plugin->memory);
return err; return err;
error: error:
ctx->frm = orig_frm; frm = orig_frm;
goto done; goto done;
} }

View File

@ -74,7 +74,6 @@ typedef struct sp_context_s
{ {
cell_t hp; /**< Heap pointer */ cell_t hp; /**< Heap pointer */
cell_t sp; /**< Stack pointer */ cell_t sp; /**< Stack pointer */
cell_t frm; /**< Frame pointer */
cell_t rval; /**< Return value from InvokeFunction() */ cell_t rval; /**< Return value from InvokeFunction() */
sp_plugin_t *plugin; sp_plugin_t *plugin;
PluginContext *basecx; PluginContext *basecx;

View File

@ -53,7 +53,7 @@ PluginContext::PluginContext(PluginRuntime *pRuntime)
m_ctx.hp = m_pRuntime->plugin()->data_size; m_ctx.hp = m_pRuntime->plugin()->data_size;
m_ctx.sp = m_pRuntime->plugin()->mem_size - sizeof(cell_t); m_ctx.sp = m_pRuntime->plugin()->mem_size - sizeof(cell_t);
m_ctx.frm = m_ctx.sp; frm_ = m_ctx.sp;
rp_ = 0; rp_ = 0;
last_native_ = -1; last_native_ = -1;
native_error_ = SP_ERROR_NONE; native_error_ = SP_ERROR_NONE;
@ -784,7 +784,7 @@ PluginContext::GetLastNativeError()
cell_t * cell_t *
PluginContext::GetLocalParams() PluginContext::GetLocalParams()
{ {
return (cell_t *)(m_pRuntime->plugin()->memory + m_ctx.frm + (2 * sizeof(cell_t))); return (cell_t *)(m_pRuntime->plugin()->memory + frm_ + (2 * sizeof(cell_t)));
} }
void void

View File

@ -107,9 +107,16 @@ class PluginContext : public IPluginContext
int32_t *addressOfCip() { int32_t *addressOfCip() {
return &cip_; return &cip_;
} }
cell_t *addressOfFrm() {
return &frm_;
}
int32_t cip() const { int32_t cip() const {
return cip_; return cip_;
} }
cell_t frm() const {
return frm_;
}
// Return stack logic. // Return stack logic.
bool pushReturnCip(cell_t cip) { bool pushReturnCip(cell_t cip) {
@ -167,6 +174,9 @@ class PluginContext : public IPluginContext
// Most recent CIP. // Most recent CIP.
int32_t cip_; int32_t cip_;
// Frame pointer.
cell_t frm_;
}; };
#endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_ #endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_

View File

@ -98,8 +98,7 @@ class Compiler
return ExternalAddress(&ctx->hp); return ExternalAddress(&ctx->hp);
} }
ExternalAddress frmAddr() { ExternalAddress frmAddr() {
sp_context_t *ctx = rt_->GetBaseContext()->GetCtx(); return ExternalAddress(context_->addressOfFrm());
return ExternalAddress(&ctx->frm);
} }
private: private: