break Architecture out of Assembler

This commit is contained in:
Joshua Warner 2013-02-23 23:03:01 -07:00
parent 56625b89d8
commit 4c8b593539
15 changed files with 172 additions and 125 deletions

View File

@ -0,0 +1,137 @@
/* Copyright (c) 2008-2012, 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. */
#ifndef AVIAN_CODEGEN_ARCHITECTURE_H
#define AVIAN_CODEGEN_ARCHITECTURE_H
namespace vm {
class Allocator;
class Zone;
}
namespace avian {
namespace codegen {
class Assembler;
class RegisterFile;
class OperandMask {
public:
uint8_t typeMask;
uint64_t registerMask;
OperandMask(uint8_t typeMask, uint64_t registerMask):
typeMask(typeMask),
registerMask(registerMask)
{ }
OperandMask():
typeMask(~0),
registerMask(~static_cast<uint64_t>(0))
{ }
};
class Architecture {
public:
virtual unsigned floatRegisterSize() = 0;
virtual const RegisterFile* registerFile() = 0;
virtual int scratch() = 0;
virtual int stack() = 0;
virtual int thread() = 0;
virtual int returnLow() = 0;
virtual int returnHigh() = 0;
virtual int virtualCallTarget() = 0;
virtual int virtualCallIndex() = 0;
virtual bool bigEndian() = 0;
virtual uintptr_t maximumImmediateJump() = 0;
virtual bool alwaysCondensed(lir::BinaryOperation op) = 0;
virtual bool alwaysCondensed(lir::TernaryOperation op) = 0;
virtual bool reserved(int register_) = 0;
virtual unsigned frameFootprint(unsigned footprint) = 0;
virtual unsigned argumentFootprint(unsigned footprint) = 0;
virtual bool argumentAlignment() = 0;
virtual bool argumentRegisterAlignment() = 0;
virtual unsigned argumentRegisterCount() = 0;
virtual int argumentRegister(unsigned index) = 0;
virtual bool hasLinkRegister() = 0;
virtual unsigned stackAlignmentInWords() = 0;
virtual bool matchCall(void* returnAddress, void* target) = 0;
virtual void updateCall(lir::UnaryOperation op, void* returnAddress,
void* newTarget) = 0;
virtual void setConstant(void* dst, uint64_t constant) = 0;
virtual unsigned alignFrameSize(unsigned sizeInWords) = 0;
virtual void nextFrame(void* start, unsigned size, unsigned footprint,
void* link, bool mostRecent,
unsigned targetParameterFootprint, void** ip,
void** stack) = 0;
virtual void* frameIp(void* stack) = 0;
virtual unsigned frameHeaderSize() = 0;
virtual unsigned frameReturnAddressSize() = 0;
virtual unsigned frameFooterSize() = 0;
virtual int returnAddressOffset() = 0;
virtual int framePointerOffset() = 0;
virtual void plan
(lir::UnaryOperation op,
unsigned aSize, OperandMask& aMask,
bool* thunk) = 0;
virtual void planSource
(lir::BinaryOperation op,
unsigned aSize, OperandMask& aMask,
unsigned bSize, bool* thunk) = 0;
virtual void planDestination
(lir::BinaryOperation op,
unsigned aSize, const OperandMask& aMask,
unsigned bSize, OperandMask& bMask) = 0;
virtual void planMove
(unsigned size, OperandMask& src,
OperandMask& tmp,
const OperandMask& dst) = 0;
virtual void planSource
(lir::TernaryOperation op,
unsigned aSize, OperandMask& aMask,
unsigned bSize, OperandMask& bMask,
unsigned cSize, bool* thunk) = 0;
virtual void planDestination
(lir::TernaryOperation op,
unsigned aSize, const OperandMask& aMask,
unsigned bSize, const OperandMask& bMask,
unsigned cSize, OperandMask& cMask) = 0;
virtual Assembler* makeAssembler(vm::Allocator*, vm::Zone*) = 0;
virtual void acquire() = 0;
virtual void release() = 0;
};
} // namespace codegen
} // namespace avian
#endif // AVIAN_CODEGEN_ARCHITECTURE_H

View File

@ -20,7 +20,7 @@
namespace avian {
namespace codegen {
class RegisterFile;
class Architecture;
class OperandInfo {
public:
@ -35,22 +35,6 @@ public:
{ }
};
class OperandMask {
public:
uint8_t typeMask;
uint64_t registerMask;
OperandMask(uint8_t typeMask, uint64_t registerMask):
typeMask(typeMask),
registerMask(registerMask)
{ }
OperandMask():
typeMask(~0),
registerMask(~static_cast<uint64_t>(0))
{ }
};
#ifdef AVIAN_TAILS
const bool TailCalls = true;
#else
@ -80,98 +64,6 @@ class Assembler {
virtual unsigned resolve(unsigned start, Block* next) = 0;
};
class Architecture {
public:
virtual unsigned floatRegisterSize() = 0;
virtual const RegisterFile* registerFile() = 0;
virtual int scratch() = 0;
virtual int stack() = 0;
virtual int thread() = 0;
virtual int returnLow() = 0;
virtual int returnHigh() = 0;
virtual int virtualCallTarget() = 0;
virtual int virtualCallIndex() = 0;
virtual bool bigEndian() = 0;
virtual uintptr_t maximumImmediateJump() = 0;
virtual bool alwaysCondensed(lir::BinaryOperation op) = 0;
virtual bool alwaysCondensed(lir::TernaryOperation op) = 0;
virtual bool reserved(int register_) = 0;
virtual unsigned frameFootprint(unsigned footprint) = 0;
virtual unsigned argumentFootprint(unsigned footprint) = 0;
virtual bool argumentAlignment() = 0;
virtual bool argumentRegisterAlignment() = 0;
virtual unsigned argumentRegisterCount() = 0;
virtual int argumentRegister(unsigned index) = 0;
virtual bool hasLinkRegister() = 0;
virtual unsigned stackAlignmentInWords() = 0;
virtual bool matchCall(void* returnAddress, void* target) = 0;
virtual void updateCall(lir::UnaryOperation op, void* returnAddress,
void* newTarget) = 0;
virtual void setConstant(void* dst, uint64_t constant) = 0;
virtual unsigned alignFrameSize(unsigned sizeInWords) = 0;
virtual void nextFrame(void* start, unsigned size, unsigned footprint,
void* link, bool mostRecent,
unsigned targetParameterFootprint, void** ip,
void** stack) = 0;
virtual void* frameIp(void* stack) = 0;
virtual unsigned frameHeaderSize() = 0;
virtual unsigned frameReturnAddressSize() = 0;
virtual unsigned frameFooterSize() = 0;
virtual int returnAddressOffset() = 0;
virtual int framePointerOffset() = 0;
virtual void plan
(lir::UnaryOperation op,
unsigned aSize, OperandMask& aMask,
bool* thunk) = 0;
virtual void planSource
(lir::BinaryOperation op,
unsigned aSize, OperandMask& aMask,
unsigned bSize, bool* thunk) = 0;
virtual void planDestination
(lir::BinaryOperation op,
unsigned aSize, const OperandMask& aMask,
unsigned bSize, OperandMask& bMask) = 0;
virtual void planMove
(unsigned size, OperandMask& src,
OperandMask& tmp,
const OperandMask& dst) = 0;
virtual void planSource
(lir::TernaryOperation op,
unsigned aSize, OperandMask& aMask,
unsigned bSize, OperandMask& bMask,
unsigned cSize, bool* thunk) = 0;
virtual void planDestination
(lir::TernaryOperation op,
unsigned aSize, const OperandMask& aMask,
unsigned bSize, const OperandMask& bMask,
unsigned cSize, OperandMask& cMask) = 0;
virtual Assembler* makeAssembler(vm::Allocator*, vm::Zone*) = 0;
virtual void acquire() = 0;
virtual void release() = 0;
};
virtual void setClient(Client* client) = 0;
virtual Architecture* arch() = 0;

View File

@ -11,16 +11,20 @@
#ifndef AVIAN_CODEGEN_TARGETS_H
#define AVIAN_CODEGEN_TARGETS_H
#include <avian/vm/codegen/assembler.h>
namespace vm {
class System;
}
namespace avian {
namespace codegen {
Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures);
class Architecture;
Assembler::Architecture* makeArchitectureX86(vm::System* system, bool useNativeFeatures);
Assembler::Architecture* makeArchitectureArm(vm::System* system, bool useNativeFeatures);
Assembler::Architecture* makeArchitecturePowerpc(vm::System* system, bool useNativeFeatures);
Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures);
Architecture* makeArchitectureX86(vm::System* system, bool useNativeFeatures);
Architecture* makeArchitectureArm(vm::System* system, bool useNativeFeatures);
Architecture* makeArchitecturePowerpc(vm::System* system, bool useNativeFeatures);
} // namespace codegen
} // namespace avian

View File

@ -14,6 +14,7 @@
#include <avian/vm/codegen/compiler.h>
#include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/architecture.h>
#include <avian/vm/codegen/promise.h>
#include "codegen/compiler/regalloc.h"

View File

@ -11,6 +11,8 @@
#include "codegen/compiler/context.h"
#include "codegen/compiler/resource.h"
#include <avian/vm/codegen/architecture.h>
namespace avian {
namespace codegen {
namespace compiler {

View File

@ -75,7 +75,7 @@ class Context {
vm::System* system;
Assembler* assembler;
Assembler::Architecture* arch;
Architecture* arch;
vm::Zone* zone;
Compiler::Client* client;
Stack* stack;

View File

@ -13,6 +13,8 @@
#include "codegen/compiler/context.h"
#include "codegen/compiler/frame.h"
#include <avian/vm/codegen/architecture.h>
namespace avian {
namespace codegen {
namespace compiler {

View File

@ -11,6 +11,8 @@
#ifndef AVIAN_CODEGEN_COMPILER_SITE_H
#define AVIAN_CODEGEN_COMPILER_SITE_H
#include <avian/vm/codegen/architecture.h>
#include "codegen/compiler/value.h"
#include "codegen/compiler/context.h"

View File

@ -11,6 +11,7 @@
#include <avian/util/runtime-array.h>
#include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/architecture.h>
#include <avian/vm/codegen/registers.h>
#include "context.h"
@ -136,7 +137,7 @@ nextFrame(ArchitectureContext* con, uint32_t* start, unsigned size UNUSED,
*stack = static_cast<void**>(*stack) + offset;
}
class MyArchitecture: public Assembler::Architecture {
class MyArchitecture: public Architecture {
public:
MyArchitecture(System* system): con(system), referenceCount(0) {
populateTables(&con);
@ -950,7 +951,7 @@ Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) {
} // namespace arm
Assembler::Architecture*
Architecture*
makeArchitectureArm(System* system, bool)
{
return new (allocate(system, sizeof(arm::MyArchitecture))) arm::MyArchitecture(system);

View File

@ -9,6 +9,7 @@
details. */
#include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/architecture.h>
#include <avian/vm/codegen/registers.h>
#include "alloc-vector.h"
@ -235,7 +236,7 @@ nextFrame(ArchitectureContext* c UNUSED, int32_t* start, unsigned size,
*stack = static_cast<void**>(*stack) + offset;
}
class MyArchitecture: public Assembler::Architecture {
class MyArchitecture: public Architecture {
public:
MyArchitecture(System* system): c(system), referenceCount(0) {
populateTables(&c);
@ -996,7 +997,7 @@ Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) {
} // namespace powerpc
Assembler::Architecture*
Architecture*
makeArchitecturePowerpc(System* system, bool)
{
return new (allocate(system, sizeof(powerpc::MyArchitecture))) powerpc::MyArchitecture(system);

View File

@ -24,6 +24,7 @@
#include <avian/util/math.h>
#include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/architecture.h>
#include <avian/vm/codegen/registers.h>
#include <avian/vm/codegen/lir.h>
#include <avian/vm/codegen/promise.h>
@ -147,7 +148,7 @@ nextFrame(ArchitectureContext* c UNUSED, uint8_t* start, unsigned size UNUSED,
*stack = static_cast<void**>(*stack) + offset;
}
class MyArchitecture: public Assembler::Architecture {
class MyArchitecture: public Architecture {
public:
MyArchitecture(System* system, bool useNativeFeatures):
c(system, useNativeFeatures),
@ -1148,7 +1149,7 @@ Assembler* MyArchitecture::makeAssembler(Allocator* allocator, Zone* zone) {
} // namespace x86
Assembler::Architecture* makeArchitectureX86(System* system, bool useNativeFeatures)
Architecture* makeArchitectureX86(System* system, bool useNativeFeatures)
{
return new (allocate(system, sizeof(x86::MyArchitecture)))
x86::MyArchitecture(system, useNativeFeatures);

View File

@ -8,6 +8,8 @@
There is NO WARRANTY for this software. See license.txt for
details. */
#include "common.h"
#include <avian/vm/codegen/targets.h>
#include "environment.h"
@ -15,7 +17,7 @@
namespace avian {
namespace codegen {
Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures UNUSED) {
Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures UNUSED) {
#ifndef AVIAN_TARGET_ARCH
#error "Must specify native target!"
#endif

View File

@ -16,6 +16,7 @@
#include "arch.h"
#include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/architecture.h>
#include <avian/vm/codegen/compiler.h>
#include <avian/vm/codegen/targets.h>
@ -294,7 +295,7 @@ class MyThread: public Thread {
void** thunkTable;
CallTrace* trace;
Reference* reference;
avian::codegen::Assembler::Architecture* arch;
avian::codegen::Architecture* arch;
Context* transition;
TraceContext* traceContext;
uintptr_t stackLimit;

View File

@ -31,7 +31,7 @@ class BasicEnv {
public:
System* s;
Heap* heap;
Assembler::Architecture* arch;
Architecture* arch;
BasicEnv():
s(makeSystem(0)),

View File

@ -16,6 +16,7 @@
#include "target.h"
#include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/architecture.h>
#include <avian/vm/codegen/targets.h>
#include <avian/vm/codegen/lir.h>
@ -29,7 +30,7 @@ class BasicEnv {
public:
System* s;
Heap* heap;
Assembler::Architecture* arch;
Architecture* arch;
BasicEnv():
s(makeSystem(0)),