1.1 --- a/sourcepawn/jit/sp_vm_basecontext.cpp Thu Aug 08 09:40:23 2013 -0700
1.2 +++ b/sourcepawn/jit/sp_vm_basecontext.cpp Thu Aug 08 09:41:24 2013 -0700
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * vim: set ts=4 :
1.6 + * vim: set ts=4 sw=4 tw=99 noet:
1.7 * =============================================================================
1.8 * SourcePawn
1.9 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
1.10 @@ -46,7 +46,6 @@
1.11 BaseContext::BaseContext(BaseRuntime *pRuntime)
1.12 {
1.13 m_pRuntime = pRuntime;
1.14 - m_pPlugin = m_pRuntime->m_pPlugin;
1.15
1.16 m_InExec = false;
1.17 m_CustomMsg = false;
1.18 @@ -75,8 +74,8 @@
1.19 m_pNullString = NULL;
1.20 }
1.21
1.22 - m_ctx.hp = m_pPlugin->data_size;
1.23 - m_ctx.sp = m_pPlugin->mem_size - sizeof(cell_t);
1.24 + m_ctx.hp = m_pRuntime->plugin()->data_size;
1.25 + m_ctx.sp = m_pRuntime->plugin()->mem_size - sizeof(cell_t);
1.26 m_ctx.frm = m_ctx.sp;
1.27 m_ctx.n_err = SP_ERROR_NONE;
1.28 m_ctx.n_idx = SP_ERROR_NONE;
1.29 @@ -204,7 +203,7 @@
1.30 return SP_ERROR_HEAPLOW;
1.31 }
1.32
1.33 - addr = (cell_t *)(m_pPlugin->memory + m_ctx.hp);
1.34 + addr = (cell_t *)(m_pRuntime->plugin()->memory + m_ctx.hp);
1.35 /* store size of allocation in cells */
1.36 *addr = (cell_t)cells;
1.37 addr++;
1.38 @@ -229,12 +228,12 @@
1.39
1.40 /* check the bounds of this address */
1.41 local_addr -= sizeof(cell_t);
1.42 - if (local_addr < (cell_t)m_pPlugin->data_size || local_addr >= m_ctx.sp)
1.43 + if (local_addr < (cell_t)m_pRuntime->plugin()->data_size || local_addr >= m_ctx.sp)
1.44 {
1.45 return SP_ERROR_INVALID_ADDRESS;
1.46 }
1.47
1.48 - addr = (cell_t *)(m_pPlugin->memory + local_addr);
1.49 + addr = (cell_t *)(m_pRuntime->plugin()->memory + local_addr);
1.50 cellcount = (*addr) * sizeof(cell_t);
1.51 /* check if this memory count looks valid */
1.52 if ((signed)(m_ctx.hp - cellcount - sizeof(cell_t)) != local_addr)
1.53 @@ -250,7 +249,7 @@
1.54
1.55 int BaseContext::HeapRelease(cell_t local_addr)
1.56 {
1.57 - if (local_addr < (cell_t)m_pPlugin->data_size)
1.58 + if (local_addr < (cell_t)m_pRuntime->plugin()->data_size)
1.59 {
1.60 return SP_ERROR_INVALID_ADDRESS;
1.61 }
1.62 @@ -334,14 +333,14 @@
1.63 int BaseContext::LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr)
1.64 {
1.65 if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp))
1.66 - || (local_addr < 0) || ((ucell_t)local_addr >= m_pPlugin->mem_size))
1.67 + || (local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
1.68 {
1.69 return SP_ERROR_INVALID_ADDRESS;
1.70 }
1.71
1.72 if (phys_addr)
1.73 {
1.74 - *phys_addr = (cell_t *)(m_pPlugin->memory + local_addr);
1.75 + *phys_addr = (cell_t *)(m_pRuntime->plugin()->memory + local_addr);
1.76 }
1.77
1.78 return SP_ERROR_NONE;
1.79 @@ -365,11 +364,11 @@
1.80 int BaseContext::LocalToString(cell_t local_addr, char **addr)
1.81 {
1.82 if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp))
1.83 - || (local_addr < 0) || ((ucell_t)local_addr >= m_pPlugin->mem_size))
1.84 + || (local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
1.85 {
1.86 return SP_ERROR_INVALID_ADDRESS;
1.87 }
1.88 - *addr = (char *)(m_pPlugin->memory + local_addr);
1.89 + *addr = (char *)(m_pRuntime->plugin()->memory + local_addr);
1.90
1.91 return SP_ERROR_NONE;
1.92 }
1.93 @@ -385,7 +384,7 @@
1.94 size_t len;
1.95
1.96 if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp))
1.97 - || (local_addr < 0) || ((ucell_t)local_addr >= m_pPlugin->mem_size))
1.98 + || (local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
1.99 {
1.100 return SP_ERROR_INVALID_ADDRESS;
1.101 }
1.102 @@ -396,7 +395,7 @@
1.103 }
1.104
1.105 len = strlen(source);
1.106 - dest = (char *)(m_pPlugin->memory + local_addr);
1.107 + dest = (char *)(m_pRuntime->plugin()->memory + local_addr);
1.108
1.109 if (len >= bytes)
1.110 {
1.111 @@ -455,7 +454,7 @@
1.112
1.113 if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp))
1.114 || (local_addr < 0)
1.115 - || ((ucell_t)local_addr >= m_pPlugin->mem_size))
1.116 + || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
1.117 {
1.118 return SP_ERROR_INVALID_ADDRESS;
1.119 }
1.120 @@ -466,7 +465,7 @@
1.121 }
1.122
1.123 len = strlen(source);
1.124 - dest = (char *)(m_pPlugin->memory + local_addr);
1.125 + dest = (char *)(m_pRuntime->plugin()->memory + local_addr);
1.126
1.127 if ((size_t)len >= maxbytes)
1.128 {
1.129 @@ -586,21 +585,18 @@
1.130
1.131 /* We got this far. It's time to start profiling. */
1.132
1.133 - if ((m_pPlugin->prof_flags & SP_PROF_CALLBACKS) == SP_PROF_CALLBACKS)
1.134 + if ((m_pRuntime->plugin()->prof_flags & SP_PROF_CALLBACKS) == SP_PROF_CALLBACKS)
1.135 {
1.136 - serial = m_pPlugin->profiler->OnCallbackBegin(this, pubfunc);
1.137 + serial = m_pRuntime->plugin()->profiler->OnCallbackBegin(this, pubfunc);
1.138 }
1.139
1.140 /* See if we have to compile the callee. */
1.141 if ((fn = m_pRuntime->m_PubJitFuncs[public_id]) == NULL)
1.142 {
1.143 - uint32_t func_idx;
1.144 -
1.145 /* We might not have to - check pcode offset. */
1.146 - if ((func_idx = FuncLookup((CompData *)m_pRuntime->m_pCo, pubfunc->code_offs)) != 0)
1.147 + fn = m_pRuntime->GetJittedFunctionByOffset(pubfunc->code_offs);
1.148 + if (fn)
1.149 {
1.150 - fn = m_pRuntime->GetJittedFunction(func_idx);
1.151 - assert(fn != NULL);
1.152 m_pRuntime->m_PubJitFuncs[public_id] = fn;
1.153 }
1.154 else
1.155 @@ -629,7 +625,7 @@
1.156 /* Push parameters */
1.157
1.158 m_ctx.sp -= sizeof(cell_t) * (num_params + 1);
1.159 - sp = (cell_t *)(m_pPlugin->memory + m_ctx.sp);
1.160 + sp = (cell_t *)(m_pRuntime->plugin()->memory + m_ctx.sp);
1.161
1.162 sp[0] = num_params;
1.163 for (unsigned int i = 0; i < num_params; i++)
1.164 @@ -687,9 +683,9 @@
1.165 m_ctx.hp = save_hp;
1.166 m_ctx.rp = save_rp;
1.167
1.168 - if ((m_pPlugin->prof_flags & SP_PROF_CALLBACKS) == SP_PROF_CALLBACKS)
1.169 + if ((m_pRuntime->plugin()->prof_flags & SP_PROF_CALLBACKS) == SP_PROF_CALLBACKS)
1.170 {
1.171 - m_pPlugin->profiler->OnCallbackEnd(serial);
1.172 + m_pRuntime->plugin()->profiler->OnCallbackEnd(serial);
1.173 }
1.174
1.175 m_ctx.err_cip = save_cip;
1.176 @@ -746,7 +742,6 @@
1.177 {
1.178 uint32_t max, iter;
1.179 sp_fdbg_symbol_t *sym;
1.180 - sp_fdbg_arraydim_t *arr;
1.181 uint8_t *cursor = (uint8_t *)(m_pPlugin->debug.symbols);
1.182
1.183 max = m_pPlugin->debug.syms_num;
1.184 @@ -765,7 +760,6 @@
1.185 if (sym->dimcount > 0)
1.186 {
1.187 cursor += sizeof(sp_fdbg_symbol_t);
1.188 - arr = (sp_fdbg_arraydim_t *)cursor;
1.189 cursor += sizeof(sp_fdbg_arraydim_t) * sym->dimcount;
1.190 continue;
1.191 }
1.192 @@ -779,7 +773,6 @@
1.193 {
1.194 uint32_t max, iter;
1.195 sp_u_fdbg_symbol_t *sym;
1.196 - sp_u_fdbg_arraydim_t *arr;
1.197 uint8_t *cursor = (uint8_t *)(m_pPlugin->debug.symbols);
1.198
1.199 max = m_pPlugin->debug.syms_num;
1.200 @@ -798,7 +791,6 @@
1.201 if (sym->dimcount > 0)
1.202 {
1.203 cursor += sizeof(sp_u_fdbg_symbol_t);
1.204 - arr = (sp_u_fdbg_arraydim_t *)cursor;
1.205 cursor += sizeof(sp_u_fdbg_arraydim_t) * sym->dimcount;
1.206 continue;
1.207 }
1.208 @@ -848,7 +840,7 @@
1.209
1.210 cell_t *BaseContext::GetLocalParams()
1.211 {
1.212 - return (cell_t *)(m_pPlugin->memory + m_ctx.frm + (2 * sizeof(cell_t)));
1.213 + return (cell_t *)(m_pRuntime->plugin()->memory + m_ctx.frm + (2 * sizeof(cell_t)));
1.214 }
1.215
1.216 void BaseContext::SetKey(int k, void *value)