2007-11-20 16:21:17 +00:00
|
|
|
#ifndef COMPILER_H
|
|
|
|
#define COMPILER_H
|
|
|
|
|
2007-11-21 22:15:33 +00:00
|
|
|
#include "system.h"
|
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
namespace vm {
|
|
|
|
|
|
|
|
class Operand { };
|
|
|
|
|
2007-12-11 00:48:09 +00:00
|
|
|
class Compiler;
|
|
|
|
|
2007-11-26 23:15:53 +00:00
|
|
|
class Promise {
|
|
|
|
public:
|
|
|
|
virtual ~Promise() { }
|
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
virtual intptr_t value(Compiler*) = 0;
|
2007-11-26 23:15:53 +00:00
|
|
|
};
|
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
class Compiler {
|
|
|
|
public:
|
|
|
|
virtual ~Compiler() { }
|
|
|
|
|
2007-11-26 23:15:53 +00:00
|
|
|
virtual Promise* poolOffset() = 0;
|
|
|
|
virtual Promise* codeOffset() = 0;
|
2007-12-11 00:48:09 +00:00
|
|
|
virtual Promise* logicalIpToOffset(unsigned) = 0;
|
2007-11-26 23:15:53 +00:00
|
|
|
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual Operand* poolAppend(Operand*) = 0;
|
|
|
|
|
|
|
|
virtual Operand* constant(intptr_t) = 0;
|
|
|
|
|
2007-11-25 23:00:55 +00:00
|
|
|
virtual Operand* stack() = 0;
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual Operand* base() = 0;
|
|
|
|
virtual Operand* thread() = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual Operand* indirectTarget() = 0;
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual Operand* temporary() = 0;
|
2007-12-11 00:48:09 +00:00
|
|
|
virtual Operand* stack(unsigned) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual void release(Operand*) = 0;
|
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual Operand* label() = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual void mark(Operand*) = 0;
|
|
|
|
|
|
|
|
virtual Operand* indirectCall
|
|
|
|
(Operand* address, unsigned argumentCount, ...) = 0;
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual void indirectCallNoReturn
|
2007-11-21 22:15:33 +00:00
|
|
|
(Operand* address, unsigned argumentCount, ...) = 0;
|
|
|
|
virtual Operand* directCall
|
|
|
|
(Operand* address, unsigned argumentCount, ...) = 0;
|
2007-11-26 23:15:53 +00:00
|
|
|
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual void return_(Operand*) = 0;
|
|
|
|
virtual void ret() = 0;
|
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
virtual void push(unsigned count) = 0;
|
2007-12-11 00:48:09 +00:00
|
|
|
virtual void push(Operand*) = 0;
|
|
|
|
virtual void push2(Operand*) = 0;
|
2007-12-12 22:19:13 +00:00
|
|
|
virtual void pop(unsigned count) = 0;
|
2007-12-11 00:48:09 +00:00
|
|
|
virtual Operand* pop() = 0;
|
|
|
|
virtual Operand* pop2() = 0;
|
|
|
|
virtual void pop(Operand*) = 0;
|
|
|
|
virtual void pop2(Operand*) = 0;
|
|
|
|
virtual Operand* call(Operand*) = 0;
|
|
|
|
virtual Operand* alignedCall(Operand*) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual void mov(Operand* src, Operand* dst) = 0;
|
|
|
|
virtual void cmp(Operand* subtrahend, Operand* minuend) = 0;
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual void jl(Operand*) = 0;
|
|
|
|
virtual void jg(Operand*) = 0;
|
|
|
|
virtual void jle(Operand*) = 0;
|
|
|
|
virtual void jge(Operand*) = 0;
|
|
|
|
virtual void je(Operand*) = 0;
|
|
|
|
virtual void jne(Operand*) = 0;
|
|
|
|
virtual void jmp(Operand*) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual void add(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void sub(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void mul(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void div(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void rem(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void shl(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void shr(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void ushr(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void and_(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void or_(Operand* v, Operand* dst) = 0;
|
|
|
|
virtual void xor_(Operand* v, Operand* dst) = 0;
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual void neg(Operand*) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2007-12-09 20:03:21 +00:00
|
|
|
virtual Operand* memory(Operand* base, int displacement = 0,
|
|
|
|
Operand* index = 0, unsigned scale = 1) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual Operand* select1(Operand*) = 0;
|
|
|
|
virtual Operand* select2(Operand*) = 0;
|
|
|
|
virtual Operand* select2z(Operand*) = 0;
|
|
|
|
virtual Operand* select4(Operand*) = 0;
|
|
|
|
virtual Operand* select8(Operand*) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
|
|
|
|
virtual void prologue() = 0;
|
2007-12-12 18:59:45 +00:00
|
|
|
virtual void reserve(unsigned size) = 0;
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual void epilogue() = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual void startLogicalIp(unsigned) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual Operand* logicalIp(unsigned) = 0;
|
|
|
|
|
2007-12-11 23:52:28 +00:00
|
|
|
virtual unsigned codeSize() = 0;
|
|
|
|
virtual unsigned poolSize() = 0;
|
2007-12-11 21:26:59 +00:00
|
|
|
virtual void writeTo(uint8_t*) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2007-12-11 00:48:09 +00:00
|
|
|
virtual void updateCall(void* returnAddress, void* newTarget) = 0;
|
2007-11-26 23:15:53 +00:00
|
|
|
|
2007-11-21 22:15:33 +00:00
|
|
|
virtual void dispose() = 0;
|
2007-11-20 16:21:17 +00:00
|
|
|
};
|
|
|
|
|
2007-11-21 22:15:33 +00:00
|
|
|
Compiler*
|
|
|
|
makeCompiler(System* system, void* indirectCaller);
|
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
} // namespace vm
|
|
|
|
|
|
|
|
#endif//COMPILER_H
|