sourcepawn/jit/BaseRuntime.h
author David Anderson <dvander@alliedmods.net>
Fri Jul 11 08:18:43 2008 +0000 (2008-07-11)
changeset 2193 db7c6362f3f2
child 2226 d10b38524be3
permissions -rw-r--r--
landed massive refactoring of the JIT. contexts are actually contexts now, and a higher level structure wraps sp_plugin_t info. on that note, both sp_plugin_t and sp_context_t are entirely opaque, and not even core has access to them. amazingly, i managed to keep binary compatibility here although a large number of functions are deprecated (and core should eventually stop calling them).

NOTE: the JIT is now embeddable out-of-box and usable by other projects which is pretty cool. I will commit a shell app demonstrating this soon
     1 #ifndef _INCLUDE_SOURCEPAWN_JIT_RUNTIME_H_
     2 #define _INCLUDE_SOURCEPAWN_JIT_RUNTIME_H_
     3 
     4 #include <sp_vm_api.h>
     5 #include "jit_shared.h"
     6 #include "sp_vm_function.h"
     7 
     8 class BaseContext;
     9 
    10 class DebugInfo : public IPluginDebugInfo
    11 {
    12 public:
    13 	DebugInfo(sp_plugin_t *plugin);
    14 public:
    15 	int LookupFile(ucell_t addr, const char **filename);
    16 	int LookupFunction(ucell_t addr, const char **name);
    17 	int LookupLine(ucell_t addr, uint32_t *line);
    18 private:
    19 	sp_plugin_t *m_pPlugin;
    20 };
    21 
    22 /* Jit wants fast access to this so we expose things as public */
    23 class BaseRuntime : public SourcePawn::IPluginRuntime
    24 {
    25 public:
    26 	BaseRuntime(sp_plugin_t *pl);
    27 	~BaseRuntime();
    28 public:
    29 	virtual bool IsDebugging();
    30 	virtual IPluginDebugInfo *GetDebugInfo();
    31 	virtual int FindNativeByName(const char *name, uint32_t *index);
    32 	virtual int GetNativeByIndex(uint32_t index, sp_native_t **native);
    33 	virtual uint32_t GetNativesNum();
    34 	virtual int FindPublicByName(const char *name, uint32_t *index);
    35 	virtual int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
    36 	virtual uint32_t GetPublicsNum();
    37 	virtual int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
    38 	virtual int FindPubvarByName(const char *name, uint32_t *index);
    39 	virtual int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
    40 	virtual uint32_t GetPubVarsNum();
    41 	virtual IPluginFunction *GetFunctionByName(const char *public_name);
    42 	virtual IPluginFunction *GetFunctionById(funcid_t func_id);
    43 	virtual IPluginContext *GetDefaultContext();
    44 	virtual int ApplyCompilationOptions(ICompilation *co);
    45 	virtual void SetPauseState(bool paused);
    46 	virtual bool IsPaused();
    47 	virtual size_t GetMemUsage();
    48 public:
    49 	BaseContext *GetBaseContext();
    50 private:
    51 	void ClearCompile();
    52 	void RefreshFunctionCache();
    53 public:
    54 	DebugInfo m_Debug;
    55 	sp_plugin_t *m_pPlugin;
    56 	BaseContext *m_pCtx;
    57 	CFunction **m_PubFuncs;
    58 };
    59 
    60 #endif //_INCLUDE_SOURCEPAWN_JIT_RUNTIME_H_