2008-02-19 18:06:52 +00:00
|
|
|
/* Copyright (c) 2008, Avian Contributors
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
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-12-31 22:40:56 +00:00
|
|
|
#include "zone.h"
|
2008-02-11 17:21:41 +00:00
|
|
|
#include "assembler.h"
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
namespace vm {
|
|
|
|
|
|
|
|
class Compiler {
|
|
|
|
public:
|
2008-02-11 17:21:41 +00:00
|
|
|
static const unsigned Aligned = 1 << 0;
|
|
|
|
static const unsigned NoReturn = 1 << 1;
|
2008-05-06 21:13:02 +00:00
|
|
|
static const unsigned Indirect = 1 << 2;
|
2007-12-30 22:24:48 +00:00
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
class Operand { };
|
2007-12-30 22:24:48 +00:00
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual ~Compiler() { }
|
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual void pushState() = 0;
|
|
|
|
virtual void popState() = 0;
|
2008-04-28 15:53:48 +00:00
|
|
|
virtual void saveStack() = 0;
|
|
|
|
virtual void resetStack() = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2008-05-19 04:31:52 +00:00
|
|
|
virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint,
|
|
|
|
unsigned localFootprint) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
|
|
|
virtual void visitLogicalIp(unsigned logicalIp) = 0;
|
|
|
|
virtual void startLogicalIp(unsigned logicalIp) = 0;
|
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
virtual Promise* machineIp(unsigned logicalIp) = 0;
|
2007-11-26 23:15:53 +00:00
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual Promise* poolAppend(intptr_t value) = 0;
|
|
|
|
virtual Promise* poolAppendPromise(Promise* value) = 0;
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2008-02-12 02:06:12 +00:00
|
|
|
virtual Operand* constant(int64_t value) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual Operand* promiseConstant(Promise* value) = 0;
|
|
|
|
virtual Operand* address(Promise* address) = 0;
|
2007-12-30 22:24:48 +00:00
|
|
|
virtual Operand* memory(Operand* base,
|
|
|
|
int displacement = 0,
|
|
|
|
Operand* index = 0,
|
2008-04-09 19:08:13 +00:00
|
|
|
unsigned scale = 1) = 0;
|
2007-12-16 00:24:15 +00:00
|
|
|
|
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
|
|
|
|
2008-03-13 20:50:56 +00:00
|
|
|
virtual bool isConstant(Operand* value) = 0;
|
|
|
|
virtual int64_t constantValue(Operand* value) = 0;
|
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
virtual Operand* label() = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual void mark(Operand* label) = 0;
|
|
|
|
|
2008-04-26 20:56:03 +00:00
|
|
|
virtual void push(unsigned size) = 0;
|
2008-02-12 02:06:12 +00:00
|
|
|
virtual void push(unsigned size, Operand* value) = 0;
|
|
|
|
virtual Operand* pop(unsigned size) = 0;
|
|
|
|
virtual void pushed(unsigned count) = 0;
|
|
|
|
virtual void popped(unsigned count) = 0;
|
2008-02-17 20:57:40 +00:00
|
|
|
virtual Operand* peek(unsigned size, unsigned index) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
|
|
|
virtual Operand* call(Operand* address,
|
|
|
|
unsigned flags,
|
|
|
|
TraceHandler* traceHandler,
|
|
|
|
unsigned resultSize,
|
|
|
|
unsigned argumentCount,
|
|
|
|
...) = 0;
|
2008-02-12 02:06:12 +00:00
|
|
|
|
|
|
|
virtual void return_(unsigned size, Operand* value) = 0;
|
|
|
|
|
2008-05-19 04:31:52 +00:00
|
|
|
virtual void storeLocal(unsigned size, Operand* src, unsigned index) = 0;
|
|
|
|
virtual Operand* loadLocal(unsigned size, unsigned index) = 0;
|
|
|
|
|
2008-02-12 02:06:12 +00:00
|
|
|
virtual void store(unsigned size, Operand* src, Operand* dst) = 0;
|
|
|
|
virtual Operand* load(unsigned size, Operand* src) = 0;
|
|
|
|
virtual Operand* loadz(unsigned size, Operand* src) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual Operand* load4To8(Operand* src) = 0;
|
2008-02-12 02:06:12 +00:00
|
|
|
virtual void cmp(unsigned size, Operand* a, Operand* b) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual void jl(Operand* address) = 0;
|
|
|
|
virtual void jg(Operand* address) = 0;
|
|
|
|
virtual void jle(Operand* address) = 0;
|
|
|
|
virtual void jge(Operand* address) = 0;
|
|
|
|
virtual void je(Operand* address) = 0;
|
|
|
|
virtual void jne(Operand* address) = 0;
|
|
|
|
virtual void jmp(Operand* address) = 0;
|
2008-02-12 02:06:12 +00:00
|
|
|
virtual Operand* add(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* sub(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* mul(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* div(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* rem(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* shl(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* shr(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* ushr(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* and_(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* or_(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* xor_(unsigned size, Operand* a, Operand* b) = 0;
|
|
|
|
virtual Operand* neg(unsigned size, Operand* a) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
|
|
|
virtual unsigned compile() = 0;
|
2007-12-11 23:52:28 +00:00
|
|
|
virtual unsigned poolSize() = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual void writeTo(uint8_t* dst) = 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*
|
2008-05-06 21:13:02 +00:00
|
|
|
makeCompiler(System* system, Assembler* assembler, Zone* zone,
|
|
|
|
void* indirection);
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
} // namespace vm
|
|
|
|
|
|
|
|
#endif//COMPILER_H
|