1 // Header for compiler.c
2 // $Id: compiler.h,v 1.11 2004/02/02 00:13:46 iain Exp $
7 // -------------------------------------------------------------
12 #define LABEL(foo) label_ ## foo,
18 #ifdef USE_DIRECT_THREADING
19 typedef void* Opcode; // Generated opcode: pointer to a label in exec().
24 typedef git_uint32* Block; // Generated code block: array of labels.
26 // -------------------------------------------------------------
29 extern int gPeephole; // Peephole optimisation of generated code?
30 extern int gDebug; // Insert debug statements into generated code?
31 extern int gCacheRAM; // Keep RAM-based code in the JIT cache?
33 // -------------------------------------------------------------
36 extern const char* gLabelNames[];
38 extern void initCompiler (size_t cacheSize);
39 extern void shutdownCompiler ();
41 extern void emitData (git_uint32);
42 extern void emitFinalCode (Label);
43 extern void emitConstBranch (Label op, git_uint32 address);
45 extern void abortCompilation ();
47 extern git_uint32 undoEmit();
48 extern void nextInstructionIsReferenced ();
50 extern Block peekAtEmittedStuff (int numOpcodes);
52 // -------------------------------------------------------------
53 // Accessing compiled code
55 extern void pruneCodeCache (git_uint32 start, git_uint32 size);
56 extern void resetCodeCache ();
57 extern void compressCodeCache ();
59 extern Block compile (git_uint32 pc);
61 typedef struct HashNode HashNode;
65 git_uint32 address; // Glulx address for this entry.
66 git_sint16 codeOffset; // Offset in 4-byte words from this hash node to the compiled code.
67 git_sint16 headerOffset; // Offset in 4-byte words from this hash node to the block header.
69 int pad; // This pad assures that PatchNode and HashNode are the same size.
70 HashNode * next; // Next node in the same hash table slot.
74 typedef struct BlockHeader
76 git_uint16 numHashNodes; // Number of lookup-able addresses in this block.
77 git_uint16 compiledSize; // Total size of this block, in 4-byte words.
78 git_uint32 glulxSize; // Size of the glulx code this block represents, in bytes.
79 git_uint32 runCounter; // Total number of opcodes executed in this block.
80 } // (used to determine which blocks stay in the cache)
83 // This is the header for the block currently being executed --
84 // that is, the one containing the return value of the last call
86 extern BlockHeader * gBlockHeader;
88 // Hash table for code lookup -- inlined for speed
90 extern HashNode ** gHashTable; // Hash table of glulx address -> code.
91 extern git_uint32 gHashSize; // Number of slots in the hash table.
93 GIT_INLINE Block getCode (git_uint32 pc)
95 HashNode * n = gHashTable [pc & (gHashSize-1)];
100 gBlockHeader = (BlockHeader*) ((git_uint32*)n + n->headerOffset);
101 return (git_uint32*)n + n->codeOffset;
108 #endif // GIT_COMPILER_H