2015-02-24 01:40:36 +01:00
|
|
|
// vim: set sts=2 ts=8 sw=2 tw=99 et:
|
|
|
|
//
|
|
|
|
// Copyright (C) 2006-2015 AlliedModders LLC
|
|
|
|
//
|
|
|
|
// This file is part of SourcePawn. SourcePawn is free software: you can
|
|
|
|
// redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
// License as published by the Free Software Foundation, either version 3 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along with
|
|
|
|
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
|
|
|
//
|
2008-07-11 10:18:43 +02:00
|
|
|
#ifndef _INCLUDE_SOURCEPAWN_JIT_RUNTIME_H_
|
|
|
|
#define _INCLUDE_SOURCEPAWN_JIT_RUNTIME_H_
|
|
|
|
|
|
|
|
#include <sp_vm_api.h>
|
2013-08-23 02:10:59 +02:00
|
|
|
#include <am-vector.h>
|
2013-08-24 07:29:44 +02:00
|
|
|
#include <am-inlinelist.h>
|
2008-07-11 10:18:43 +02:00
|
|
|
#include "jit_shared.h"
|
2015-02-24 01:04:57 +01:00
|
|
|
#include "compiled-function.h"
|
2015-02-24 01:14:59 +01:00
|
|
|
#include "scripted-invoker.h"
|
2008-07-11 10:18:43 +02:00
|
|
|
|
|
|
|
class BaseContext;
|
|
|
|
|
|
|
|
class DebugInfo : public IPluginDebugInfo
|
|
|
|
{
|
|
|
|
public:
|
2013-08-08 18:41:24 +02:00
|
|
|
DebugInfo(sp_plugin_t *plugin);
|
2008-07-11 10:18:43 +02:00
|
|
|
public:
|
2013-08-08 18:41:24 +02:00
|
|
|
int LookupFile(ucell_t addr, const char **filename);
|
|
|
|
int LookupFunction(ucell_t addr, const char **name);
|
|
|
|
int LookupLine(ucell_t addr, uint32_t *line);
|
2008-07-11 10:18:43 +02:00
|
|
|
private:
|
2013-08-08 18:41:24 +02:00
|
|
|
sp_plugin_t *m_pPlugin;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct floattbl_t
|
|
|
|
{
|
|
|
|
floattbl_t() {
|
|
|
|
found = false;
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
bool found;
|
|
|
|
unsigned int index;
|
2008-07-11 10:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Jit wants fast access to this so we expose things as public */
|
2015-02-24 01:40:36 +01:00
|
|
|
class PluginRuntime
|
2013-08-15 08:54:25 +02:00
|
|
|
: public SourcePawn::IPluginRuntime,
|
2015-02-24 01:40:36 +01:00
|
|
|
public ke::InlineListNode<PluginRuntime>
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
2013-08-08 18:41:24 +02:00
|
|
|
public:
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime();
|
|
|
|
~PluginRuntime();
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual int CreateBlank(uint32_t heastk);
|
|
|
|
virtual int CreateFromMemory(sp_file_hdr_t *hdr, uint8_t *base);
|
|
|
|
virtual bool IsDebugging();
|
|
|
|
virtual IPluginDebugInfo *GetDebugInfo();
|
|
|
|
virtual int FindNativeByName(const char *name, uint32_t *index);
|
|
|
|
virtual int GetNativeByIndex(uint32_t index, sp_native_t **native);
|
2014-05-11 23:36:32 +02:00
|
|
|
virtual sp_native_t *GetNativeByIndex(uint32_t index);
|
2013-08-08 18:41:24 +02:00
|
|
|
virtual uint32_t GetNativesNum();
|
|
|
|
virtual int FindPublicByName(const char *name, uint32_t *index);
|
|
|
|
virtual int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
|
|
|
|
virtual uint32_t GetPublicsNum();
|
|
|
|
virtual int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
|
|
|
|
virtual int FindPubvarByName(const char *name, uint32_t *index);
|
|
|
|
virtual int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
|
|
|
|
virtual uint32_t GetPubVarsNum();
|
|
|
|
virtual IPluginFunction *GetFunctionByName(const char *public_name);
|
|
|
|
virtual IPluginFunction *GetFunctionById(funcid_t func_id);
|
|
|
|
virtual IPluginContext *GetDefaultContext();
|
|
|
|
virtual int ApplyCompilationOptions(ICompilation *co);
|
|
|
|
virtual void SetPauseState(bool paused);
|
|
|
|
virtual bool IsPaused();
|
|
|
|
virtual size_t GetMemUsage();
|
|
|
|
virtual unsigned char *GetCodeHash();
|
|
|
|
virtual unsigned char *GetDataHash();
|
2015-02-24 01:27:57 +01:00
|
|
|
CompiledFunction *GetJittedFunctionByOffset(cell_t pcode_offset);
|
|
|
|
void AddJittedFunction(CompiledFunction *fn);
|
2013-08-08 18:41:24 +02:00
|
|
|
void SetName(const char *name);
|
|
|
|
unsigned GetNativeReplacement(size_t index);
|
2015-02-24 00:47:47 +01:00
|
|
|
ScriptedInvoker *GetPublicFunction(size_t index);
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
BaseContext *GetBaseContext();
|
|
|
|
const sp_plugin_t *plugin() const {
|
|
|
|
return &m_plugin;
|
|
|
|
}
|
|
|
|
|
2013-08-15 08:54:25 +02:00
|
|
|
size_t NumJitFunctions() const {
|
|
|
|
return m_JitFunctions.length();
|
|
|
|
}
|
2015-02-24 01:27:57 +01:00
|
|
|
CompiledFunction *GetJitFunction(size_t i) const {
|
2013-08-15 08:54:25 +02:00
|
|
|
return m_JitFunctions[i];
|
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
private:
|
|
|
|
void SetupFloatNativeRemapping();
|
|
|
|
|
|
|
|
private:
|
|
|
|
sp_plugin_t m_plugin;
|
|
|
|
uint8_t *alt_pcode_;
|
|
|
|
unsigned int m_NumFuncs;
|
|
|
|
unsigned int m_MaxFuncs;
|
|
|
|
floattbl_t *float_table_;
|
2015-02-24 01:27:57 +01:00
|
|
|
CompiledFunction **function_map_;
|
2013-08-08 18:41:24 +02:00
|
|
|
size_t function_map_size_;
|
2015-02-24 01:27:57 +01:00
|
|
|
ke::Vector<CompiledFunction *> m_JitFunctions;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
DebugInfo m_Debug;
|
|
|
|
BaseContext *m_pCtx;
|
2015-02-24 00:47:47 +01:00
|
|
|
ScriptedInvoker **m_PubFuncs;
|
2015-02-24 01:27:57 +01:00
|
|
|
CompiledFunction **m_PubJitFuncs;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
unsigned int m_CompSerial;
|
|
|
|
|
|
|
|
unsigned char m_CodeHash[16];
|
|
|
|
unsigned char m_DataHash[16];
|
2008-07-11 10:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_INCLUDE_SOURCEPAWN_JIT_RUNTIME_H_
|
2013-08-15 08:54:25 +02:00
|
|
|
|