mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-26 00:23:14 +01:00
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
This commit is contained in:
14
ir/ir.h
Normal file
14
ir/ir.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// this head contains stuff used by all the IR
|
||||
|
||||
#ifndef LLVMDC_IR_IR_H
|
||||
#define LLVMDC_IR_IR_H
|
||||
|
||||
#include "ir/irforw.h"
|
||||
#include "root.h"
|
||||
|
||||
struct IrBase : Object
|
||||
{
|
||||
virtual ~IrBase() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
45
ir/irforw.h
Normal file
45
ir/irforw.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef LLVMDC_IR_IRFORW_H
|
||||
#define LLVMDC_IR_IRFORW_H
|
||||
|
||||
// dmd forward declarations
|
||||
struct Module;
|
||||
struct Dsymbol;
|
||||
struct Declaration;
|
||||
struct VarDeclaration;
|
||||
struct FuncDeclaration;
|
||||
struct AggregateDeclaration;
|
||||
struct StructDeclaration;
|
||||
struct ClassDeclaration;
|
||||
struct InterfaceDeclaration;
|
||||
struct Expression;
|
||||
struct BaseClass;
|
||||
struct Array;
|
||||
struct Argument;
|
||||
|
||||
struct Type;
|
||||
struct TypeStruct;
|
||||
struct TypeClass;
|
||||
struct TypeEnum;
|
||||
struct TypeArray;
|
||||
struct TypeFunction;
|
||||
|
||||
// llvm forward declarations
|
||||
namespace llvm
|
||||
{
|
||||
class Value;
|
||||
class GlobalValue;
|
||||
class GlobalVariable;
|
||||
class Function;
|
||||
class Constant;
|
||||
class ConstantStruct;
|
||||
class ConstantArray;
|
||||
class TargetData;
|
||||
class Type;
|
||||
class StructType;
|
||||
class ArrayType;
|
||||
class PointerType;
|
||||
class BasicBlock;
|
||||
class Instruction;
|
||||
}
|
||||
|
||||
#endif
|
||||
44
ir/irfunction.cpp
Normal file
44
ir/irfunction.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "gen/tollvm.h"
|
||||
#include "ir/irfunction.h"
|
||||
|
||||
IrFinally::IrFinally()
|
||||
{
|
||||
bb = 0;
|
||||
retbb = 0;
|
||||
}
|
||||
|
||||
IrFinally::IrFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb)
|
||||
{
|
||||
bb = b;
|
||||
retbb = rb;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrFunction::IrFunction(FuncDeclaration* fd)
|
||||
{
|
||||
decl = fd;
|
||||
|
||||
Type* t = DtoDType(fd->type);
|
||||
assert(t->ty == Tfunction);
|
||||
type = (TypeFunction*)t;
|
||||
func = NULL;
|
||||
allocapoint = NULL;
|
||||
finallyretval = NULL;
|
||||
|
||||
queued = false;
|
||||
defined = false;
|
||||
|
||||
retArg = NULL;
|
||||
thisVar = NULL;
|
||||
nestedVar = NULL;
|
||||
_arguments = NULL;
|
||||
_argptr = NULL;
|
||||
dwarfSubProg = NULL;
|
||||
}
|
||||
|
||||
IrFunction::~IrFunction()
|
||||
{
|
||||
}
|
||||
44
ir/irfunction.h
Normal file
44
ir/irfunction.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef LLVMDC_IR_IRFUNCTION_H
|
||||
#define LLVMDC_IR_IRFUNCTION_H
|
||||
|
||||
#include "ir/ir.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
// represents a finally block
|
||||
struct IrFinally
|
||||
{
|
||||
llvm::BasicBlock* bb;
|
||||
llvm::BasicBlock* retbb;
|
||||
|
||||
IrFinally();
|
||||
IrFinally(llvm::BasicBlock* b, llvm::BasicBlock* rb);
|
||||
};
|
||||
|
||||
// represents a function
|
||||
struct IrFunction : IrBase
|
||||
{
|
||||
llvm::Function* func;
|
||||
llvm::Instruction* allocapoint;
|
||||
FuncDeclaration* decl;
|
||||
TypeFunction* type;
|
||||
|
||||
// finally blocks
|
||||
typedef std::vector<IrFinally> FinallyVec;
|
||||
FinallyVec finallys;
|
||||
llvm::Value* finallyretval;
|
||||
|
||||
bool queued;
|
||||
bool defined;
|
||||
llvm::Value* retArg;
|
||||
llvm::Value* thisVar;
|
||||
llvm::Value* nestedVar;
|
||||
llvm::Value* _arguments;
|
||||
llvm::Value* _argptr;
|
||||
llvm::Constant* dwarfSubProg;
|
||||
|
||||
IrFunction(FuncDeclaration* fd);
|
||||
virtual ~IrFunction();
|
||||
};
|
||||
|
||||
#endif
|
||||
10
ir/irmodule.cpp
Normal file
10
ir/irmodule.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "ir/irmodule.h"
|
||||
|
||||
IrModule::IrModule(Module* module)
|
||||
{
|
||||
M = module;
|
||||
}
|
||||
|
||||
IrModule::~IrModule()
|
||||
{
|
||||
}
|
||||
16
ir/irmodule.h
Normal file
16
ir/irmodule.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef LLVMDC_IR_IRMODULE_H
|
||||
#define LLVMDC_IR_IRMODULE_H
|
||||
|
||||
#include "ir/ir.h"
|
||||
|
||||
struct Module;
|
||||
|
||||
struct IrModule : IrBase
|
||||
{
|
||||
IrModule(Module* module);
|
||||
virtual ~IrModule();
|
||||
|
||||
Module* M;
|
||||
};
|
||||
|
||||
#endif
|
||||
38
ir/irstruct.cpp
Normal file
38
ir/irstruct.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "gen/llvm.h"
|
||||
#include "mtype.h"
|
||||
#include "aggregate.h"
|
||||
#include "ir/irstruct.h"
|
||||
|
||||
IrInterface::IrInterface(BaseClass* b, const llvm::StructType* vt)
|
||||
{
|
||||
base = b;
|
||||
decl = b->base;
|
||||
vtblTy = vt;
|
||||
vtblInit = NULL;
|
||||
vtbl = NULL;
|
||||
infoTy = NULL;
|
||||
infoInit = NULL;
|
||||
info = NULL;
|
||||
}
|
||||
|
||||
IrInterface::~IrInterface()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrStruct::IrStruct(Type* t)
|
||||
: recty((t->llvmType != NULL) ? *t->llvmType : llvm::OpaqueType::get())
|
||||
{
|
||||
type = t;
|
||||
defined = false;
|
||||
constinited = false;
|
||||
interfaceInfosTy = NULL;
|
||||
interfaceInfos = NULL;
|
||||
}
|
||||
|
||||
IrStruct::~IrStruct()
|
||||
{
|
||||
}
|
||||
65
ir/irstruct.h
Normal file
65
ir/irstruct.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef LLVMDC_IR_IRSTRUCT_H
|
||||
#define LLVMDC_IR_IRSTRUCT_H
|
||||
|
||||
#include "ir/ir.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
struct IrInterface : IrBase
|
||||
{
|
||||
BaseClass* base;
|
||||
ClassDeclaration* decl;
|
||||
|
||||
const llvm::StructType* vtblTy;
|
||||
llvm::ConstantStruct* vtblInit;
|
||||
llvm::GlobalVariable* vtbl;
|
||||
|
||||
const llvm::StructType* infoTy;
|
||||
llvm::ConstantStruct* infoInit;
|
||||
llvm::Constant* info;
|
||||
|
||||
IrInterface(BaseClass* b, const llvm::StructType* vt);
|
||||
~IrInterface();
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// represents a struct or class
|
||||
struct IrStruct : IrBase
|
||||
{
|
||||
struct Offset
|
||||
{
|
||||
VarDeclaration* var;
|
||||
const llvm::Type* type;
|
||||
llvm::Constant* init;
|
||||
|
||||
Offset(VarDeclaration* v, const llvm::Type* ty)
|
||||
: var(v), type(ty), init(NULL) {}
|
||||
};
|
||||
|
||||
typedef std::multimap<unsigned, Offset> OffsetMap;
|
||||
typedef std::vector<VarDeclaration*> VarDeclVector;
|
||||
typedef std::map<ClassDeclaration*, IrInterface*> InterfaceMap;
|
||||
typedef InterfaceMap::iterator InterfaceIter;
|
||||
|
||||
public:
|
||||
IrStruct(Type*);
|
||||
virtual ~IrStruct();
|
||||
|
||||
Type* type;
|
||||
llvm::PATypeHolder recty;
|
||||
OffsetMap offsets;
|
||||
VarDeclVector defaultFields;
|
||||
|
||||
InterfaceMap interfaces;
|
||||
const llvm::ArrayType* interfaceInfosTy;
|
||||
llvm::GlobalVariable* interfaceInfos;
|
||||
|
||||
bool defined;
|
||||
bool constinited;
|
||||
};
|
||||
|
||||
#endif
|
||||
63
ir/irvar.cpp
Normal file
63
ir/irvar.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "declaration.h"
|
||||
#include "ir/irvar.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrVar* VarDeclaration::getIrVar()
|
||||
{
|
||||
assert(irGlobal || irLocal || irField);
|
||||
return irGlobal ? (IrVar*)irGlobal : irLocal ? (IrVar*)irLocal : (IrVar*)irField;
|
||||
}
|
||||
|
||||
llvm::Value*& VarDeclaration::getIrValue()
|
||||
{
|
||||
return getIrVar()->value;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrVar::IrVar(VarDeclaration* var)
|
||||
{
|
||||
V = var;
|
||||
value = NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrGlobal::IrGlobal(VarDeclaration* v): IrVar(v),
|
||||
type(llvm::OpaqueType::get())
|
||||
{
|
||||
constInit = NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrLocal::IrLocal(VarDeclaration* v) : IrVar(v)
|
||||
{
|
||||
nestedIndex = -1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IrField::IrField(VarDeclaration* v) : IrVar(v)
|
||||
{
|
||||
index = -1;
|
||||
indexOffset = 0;
|
||||
constInit = NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
42
ir/irvar.h
Normal file
42
ir/irvar.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef LLVMDC_IR_IRVAR_H
|
||||
#define LLVMDC_IR_IRVAR_H
|
||||
|
||||
#include "ir/ir.h"
|
||||
#include "llvm/Type.h"
|
||||
|
||||
struct IrVar : IrBase
|
||||
{
|
||||
IrVar(VarDeclaration* var);
|
||||
|
||||
VarDeclaration* V;
|
||||
llvm::Value* value;
|
||||
};
|
||||
|
||||
// represents a global variable
|
||||
struct IrGlobal : IrVar
|
||||
{
|
||||
IrGlobal(VarDeclaration* v);
|
||||
|
||||
llvm::PATypeHolder type;
|
||||
llvm::Constant* constInit;
|
||||
};
|
||||
|
||||
// represents a local variable variable
|
||||
struct IrLocal : IrVar
|
||||
{
|
||||
IrLocal(VarDeclaration* v);
|
||||
|
||||
int nestedIndex;
|
||||
};
|
||||
|
||||
// represents an aggregate field variable
|
||||
struct IrField : IrVar
|
||||
{
|
||||
IrField(VarDeclaration* v);
|
||||
|
||||
int index;
|
||||
size_t indexOffset;
|
||||
llvm::Constant* constInit;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user