2014-04-21 02:14:48 +00:00
|
|
|
/* Copyright (c) 2008-2014, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2013-02-12 04:31:19 +00:00
|
|
|
#ifndef AVIAN_CODEGEN_COMPILER_H
|
|
|
|
#define AVIAN_CODEGEN_COMPILER_H
|
2007-11-20 16:21:17 +00:00
|
|
|
|
2014-02-07 21:24:56 +00:00
|
|
|
#include <avian/system/system.h>
|
2013-02-27 20:25:50 +00:00
|
|
|
#include "avian/zone.h"
|
2008-02-11 17:21:41 +00:00
|
|
|
#include "assembler.h"
|
2014-05-01 01:07:10 +00:00
|
|
|
#include "ir.h"
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2013-02-11 15:07:46 +00:00
|
|
|
namespace avian {
|
|
|
|
namespace codegen {
|
2007-11-20 16:21:17 +00:00
|
|
|
|
2009-04-27 01:53:42 +00:00
|
|
|
class TraceHandler {
|
|
|
|
public:
|
|
|
|
virtual void handleTrace(Promise* address, unsigned argumentIndex) = 0;
|
|
|
|
};
|
|
|
|
|
2007-11-20 16:21:17 +00:00
|
|
|
class Compiler {
|
|
|
|
public:
|
2008-05-31 22:14:27 +00:00
|
|
|
class Client {
|
|
|
|
public:
|
2013-02-11 15:07:46 +00:00
|
|
|
virtual intptr_t getThunk(lir::UnaryOperation op, unsigned size) = 0;
|
|
|
|
virtual intptr_t getThunk(lir::BinaryOperation op, unsigned size,
|
2009-09-20 21:43:32 +00:00
|
|
|
unsigned resultSize) = 0;
|
2013-02-11 15:07:46 +00:00
|
|
|
virtual intptr_t getThunk(lir::TernaryOperation op, unsigned size,
|
2010-12-20 00:47:21 +00:00
|
|
|
unsigned resultSize, bool* threadParameter) = 0;
|
2008-05-31 22:14:27 +00:00
|
|
|
};
|
2014-05-01 03:54:52 +00:00
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
static const unsigned Aligned = 1 << 0;
|
|
|
|
static const unsigned NoReturn = 1 << 1;
|
2009-04-22 01:39:25 +00:00
|
|
|
static const unsigned TailJump = 1 << 2;
|
2009-10-18 00:18:03 +00:00
|
|
|
static const unsigned LongJumpOrCall = 1 << 3;
|
2007-12-30 22:24:48 +00:00
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
class Operand { };
|
2008-09-13 21:09:26 +00:00
|
|
|
class State { };
|
2008-11-14 00:59:21 +00:00
|
|
|
class Subroutine { };
|
2007-12-30 22:24:48 +00:00
|
|
|
|
2008-09-13 21:09:26 +00:00
|
|
|
virtual State* saveState() = 0;
|
|
|
|
virtual void restoreState(State* state) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2008-11-14 00:59:21 +00:00
|
|
|
virtual Subroutine* startSubroutine() = 0;
|
2010-01-05 00:17:16 +00:00
|
|
|
virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address)
|
|
|
|
= 0;
|
2009-07-20 14:26:01 +00:00
|
|
|
virtual void linkSubroutine(Subroutine* subroutine) = 0;
|
2008-11-14 00:59:21 +00:00
|
|
|
|
2008-05-19 04:31:52 +00:00
|
|
|
virtual void init(unsigned logicalCodeSize, unsigned parameterFootprint,
|
2008-09-28 19:00:52 +00:00
|
|
|
unsigned localFootprint, unsigned alignedFrameSize) = 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
|
|
|
|
2014-05-01 03:54:52 +00:00
|
|
|
virtual Operand* constant(int64_t value, ir::Type type) = 0;
|
|
|
|
virtual Operand* promiseConstant(Promise* value, ir::Type type) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual Operand* address(Promise* address) = 0;
|
2007-12-30 22:24:48 +00:00
|
|
|
virtual Operand* memory(Operand* base,
|
2014-05-01 03:54:52 +00:00
|
|
|
ir::Type type,
|
2007-12-30 22:24:48 +00:00
|
|
|
int displacement = 0,
|
2014-05-01 05:46:26 +00:00
|
|
|
Operand* index = 0) = 0;
|
2007-12-16 00:24:15 +00:00
|
|
|
|
2014-05-01 04:27:19 +00:00
|
|
|
virtual Operand* threadRegister() = 0;
|
2009-04-05 21:42:10 +00:00
|
|
|
|
2014-05-01 02:11:54 +00:00
|
|
|
virtual void push(ir::Type type, Operand* value) = 0;
|
2014-05-01 02:20:19 +00:00
|
|
|
virtual void save(ir::Type type, Operand* value) = 0;
|
2014-05-01 02:28:33 +00:00
|
|
|
virtual Operand* pop(ir::Type type) = 0;
|
2008-07-05 20:21:13 +00:00
|
|
|
virtual void pushed() = 0;
|
2009-01-30 01:36:19 +00:00
|
|
|
virtual void popped(unsigned footprint) = 0;
|
2009-05-15 02:08:01 +00:00
|
|
|
virtual unsigned topOfStack() = 0;
|
2008-11-02 22:25:51 +00:00
|
|
|
virtual Operand* peek(unsigned footprint, unsigned index) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
|
|
|
virtual Operand* call(Operand* address,
|
|
|
|
unsigned flags,
|
|
|
|
TraceHandler* traceHandler,
|
2014-05-01 03:54:52 +00:00
|
|
|
ir::Type resultType,
|
2008-02-11 17:21:41 +00:00
|
|
|
unsigned argumentCount,
|
|
|
|
...) = 0;
|
2008-02-12 02:06:12 +00:00
|
|
|
|
2008-07-05 20:21:13 +00:00
|
|
|
virtual Operand* stackCall(Operand* address,
|
|
|
|
unsigned flags,
|
|
|
|
TraceHandler* traceHandler,
|
2014-05-01 03:54:52 +00:00
|
|
|
ir::Type resultType,
|
2008-07-05 20:21:13 +00:00
|
|
|
unsigned argumentFootprint) = 0;
|
|
|
|
|
2014-05-01 02:01:14 +00:00
|
|
|
virtual void return_(ir::Type type, Operand* value) = 0;
|
|
|
|
virtual void return_() = 0;
|
2008-02-12 02:06:12 +00:00
|
|
|
|
2014-05-01 03:35:08 +00:00
|
|
|
virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0;
|
2008-09-25 00:48:32 +00:00
|
|
|
virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0;
|
2008-11-02 22:25:51 +00:00
|
|
|
virtual void storeLocal(unsigned footprint, Operand* src,
|
|
|
|
unsigned index) = 0;
|
|
|
|
virtual Operand* loadLocal(unsigned footprint, unsigned index) = 0;
|
2008-11-25 17:34:48 +00:00
|
|
|
virtual void saveLocals() = 0;
|
2008-05-19 04:31:52 +00:00
|
|
|
|
2008-05-31 22:14:27 +00:00
|
|
|
virtual void checkBounds(Operand* object, unsigned lengthOffset,
|
|
|
|
Operand* index, intptr_t handler) = 0;
|
|
|
|
|
2014-05-01 04:33:54 +00:00
|
|
|
virtual void store(ir::Type srcType,
|
|
|
|
Operand* src,
|
|
|
|
ir::Type dstType,
|
2009-02-28 23:17:24 +00:00
|
|
|
Operand* dst) = 0;
|
2009-03-06 17:56:11 +00:00
|
|
|
virtual Operand* load(unsigned srcSize, unsigned srcSelectSize, Operand* src,
|
|
|
|
unsigned dstSize) = 0;
|
|
|
|
virtual Operand* loadz(unsigned size, unsigned srcSelectSize, Operand* src,
|
|
|
|
unsigned dstSize) = 0;
|
2009-10-07 00:50:32 +00:00
|
|
|
|
2014-05-01 04:11:49 +00:00
|
|
|
virtual void condJump(lir::TernaryOperation op,
|
|
|
|
unsigned size,
|
|
|
|
Operand* a,
|
|
|
|
Operand* b,
|
|
|
|
Operand* address) = 0;
|
2009-10-07 00:50:32 +00:00
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual void jmp(Operand* address) = 0;
|
2009-04-26 02:54:36 +00:00
|
|
|
virtual void exit(Operand* address) = 0;
|
2013-12-18 22:11:30 +00:00
|
|
|
|
2014-05-01 04:11:49 +00:00
|
|
|
virtual Operand* binaryOp(lir::TernaryOperation op,
|
|
|
|
ir::Type type,
|
|
|
|
Operand* a,
|
|
|
|
Operand* b) = 0;
|
|
|
|
virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a)
|
|
|
|
= 0;
|
|
|
|
virtual void nullaryOp(lir::Operation op) = 0;
|
2013-12-18 22:11:30 +00:00
|
|
|
|
2014-05-01 04:02:57 +00:00
|
|
|
virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0;
|
|
|
|
virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0;
|
|
|
|
virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2011-02-28 06:03:13 +00:00
|
|
|
virtual void compile(uintptr_t stackOverflowHandler,
|
|
|
|
unsigned stackLimitOffset) = 0;
|
|
|
|
virtual unsigned resolve(uint8_t* dst) = 0;
|
2007-12-11 23:52:28 +00:00
|
|
|
virtual unsigned poolSize() = 0;
|
2011-02-28 06:03:13 +00:00
|
|
|
virtual void write() = 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*
|
2013-02-11 15:07:46 +00:00
|
|
|
makeCompiler(vm::System* system, Assembler* assembler, vm::Zone* zone,
|
2008-05-31 22:14:27 +00:00
|
|
|
Compiler::Client* client);
|
2007-11-21 22:15:33 +00:00
|
|
|
|
2013-02-11 15:07:46 +00:00
|
|
|
} // namespace codegen
|
|
|
|
} // namespace avian
|
2007-11-20 16:21:17 +00:00
|
|
|
|
2013-02-12 04:31:19 +00:00
|
|
|
#endif // AVIAN_CODEGEN_COMPILER_H
|