Changed use of toObjFile to a new codegen method.

More versioning of DMD specific codegen code.
This commit is contained in:
Tomas Lindquist Olsen
2009-03-27 17:54:27 +01:00
parent c42c90ea80
commit daef67acc3
23 changed files with 446 additions and 351 deletions
+16 -2
View File
@@ -140,11 +140,17 @@ struct StructDeclaration : AggregateDeclaration
PROT getAccess(Dsymbol *smember); // determine access to smember
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
void toDt(dt_t **pdt);
void toDebug(); // to symbolic debug info
#endif
StructDeclaration *isStructDeclaration() { return this; }
#if IN_LLVM
void codegen(Ir*);
#endif
};
struct UnionDeclaration : StructDeclaration
@@ -250,9 +256,9 @@ struct ClassDeclaration : AggregateDeclaration
void addLocalClass(ClassDeclarations *);
#if IN_DMD
// Back end
void toObjFile(int multiobj); // compile to .obj file
#if IN_DMD
void toDebug();
unsigned baseVtblOffset(BaseClass *bc);
Symbol *toSymbol();
@@ -264,6 +270,10 @@ struct ClassDeclaration : AggregateDeclaration
#endif
ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
#if IN_LLVM
virtual void codegen(Ir*);
#endif
};
struct InterfaceDeclaration : ClassDeclaration
@@ -283,12 +293,16 @@ struct InterfaceDeclaration : ClassDeclaration
#endif
virtual int isCOMinterface();
void toObjFile(int multiobj); // compile to .obj file
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
Symbol *toSymbol();
#endif
InterfaceDeclaration *isInterfaceDeclaration() { return this; }
#if IN_LLVM
void codegen(Ir*);
#endif
};
#endif /* DMD_AGGREGATE_H */
+4 -1
View File
@@ -171,6 +171,8 @@ void AttribDeclaration::emitComment(Scope *sc)
}
}
#if IN_DMD
void AttribDeclaration::toObjFile(int multiobj)
{
Array *d = include(NULL, NULL);
@@ -184,7 +186,6 @@ void AttribDeclaration::toObjFile(int multiobj)
}
}
#if IN_DMD
int AttribDeclaration::cvMember(unsigned char *p)
{
int nwritten = 0;
@@ -1142,6 +1143,7 @@ const char *PragmaDeclaration::kind()
return "pragma";
}
#if IN_DMD
void PragmaDeclaration::toObjFile(int multiobj)
{
if (ident == Id::lib)
@@ -1160,6 +1162,7 @@ void PragmaDeclaration::toObjFile(int multiobj)
}
AttribDeclaration::toObjFile(multiobj);
}
#endif
void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
+16 -2
View File
@@ -50,8 +50,14 @@ struct AttribDeclaration : Dsymbol
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
AttribDeclaration *isAttribDeclaration() { return this; }
#if IN_DMD
virtual void toObjFile(int multiobj); // compile to .obj file
int cvMember(unsigned char *p);
#endif
#if IN_LLVM
virtual void codegen(Ir*);
#endif
};
struct StorageClassDeclaration: AttribDeclaration
@@ -108,8 +114,9 @@ struct AnonDeclaration : AttribDeclaration
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
const char *kind();
// LDC
void toObjFile(int multiobj); // compile to .obj file
#if IN_LLVM
void codegen(Ir*);
#endif
};
struct PragmaDeclaration : AttribDeclaration
@@ -122,7 +129,14 @@ struct PragmaDeclaration : AttribDeclaration
int oneMember(Dsymbol **ps);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
const char *kind();
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
#endif
#if IN_LLVM
void codegen(Ir*);
#endif
};
struct ConditionalDeclaration : AttribDeclaration
+24 -24
View File
@@ -138,8 +138,10 @@ struct Declaration : Dsymbol
Declaration *isDeclaration() { return this; }
// llvm
virtual void toObjFile(int unused = 0); // compile to .obj file
#if IN_LLVM
/// Codegen traversal
virtual void codegen(Ir* ir);
#endif
};
/**************************************************************/
@@ -159,8 +161,10 @@ struct TupleDeclaration : Declaration
TupleDeclaration *isTupleDeclaration() { return this; }
// LDC we need this
void toObjFile(int multiobj); // compile to .obj file
#if IN_LLVM
/// Codegen traversal
void codegen(Ir* ir);
#endif
};
/**************************************************************/
@@ -190,8 +194,8 @@ struct TypedefDeclaration : Declaration
void toDocBuffer(OutBuffer *buf);
void toObjFile(int multiobj); // compile to .obj file
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
void toDebug();
int cvMember(unsigned char *p);
#endif
@@ -202,6 +206,11 @@ struct TypedefDeclaration : Declaration
Symbol *sinit;
Symbol *toInitializer();
#endif
#if IN_LLVM
/// Codegen traversal
void codegen(Ir* ir);
#endif
};
/**************************************************************/
@@ -268,8 +277,8 @@ struct VarDeclaration : Declaration
void checkNestedReference(Scope *sc, Loc loc);
Dsymbol *toAlias();
void toObjFile(int multiobj); // compile to .obj file
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
Symbol *toSymbol();
int cvMember(unsigned char *p);
#endif
@@ -278,6 +287,9 @@ struct VarDeclaration : Declaration
VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; }
#if IN_LLVM
/// Codegen traversal
void codegen(Ir* ir);
// LDC
AnonDeclaration* anonDecl;
unsigned offset2;
@@ -345,8 +357,8 @@ struct TypeInfoDeclaration : VarDeclaration
void emitComment(Scope *sc);
void toObjFile(int multiobj); // compile to .obj file
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
Symbol *toSymbol();
virtual void toDt(dt_t **pdt);
#endif
@@ -354,7 +366,8 @@ struct TypeInfoDeclaration : VarDeclaration
virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return this; }
#if IN_LLVM
// LDC
/// Codegen traversal
void codegen(Ir* ir);
virtual void llvmDeclare();
virtual void llvmDefine();
#endif
@@ -369,7 +382,6 @@ struct TypeInfoStructDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -384,7 +396,6 @@ struct TypeInfoClassDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -399,7 +410,6 @@ struct TypeInfoInterfaceDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -414,7 +424,6 @@ struct TypeInfoTypedefDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -429,7 +438,6 @@ struct TypeInfoPointerDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -444,7 +452,6 @@ struct TypeInfoArrayDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -459,7 +466,6 @@ struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -474,7 +480,6 @@ struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -489,7 +494,6 @@ struct TypeInfoEnumDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -504,7 +508,6 @@ struct TypeInfoFunctionDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -519,7 +522,6 @@ struct TypeInfoDelegateDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -534,7 +536,6 @@ struct TypeInfoTupleDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -550,7 +551,6 @@ struct TypeInfoConstDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -565,7 +565,6 @@ struct TypeInfoInvariantDeclaration : TypeInfoDeclaration
#endif
#if IN_LLVM
// LDC
void llvmDeclare();
void llvmDefine();
#endif
@@ -716,9 +715,7 @@ struct FuncDeclaration : Declaration
#if IN_DMD
Symbol *toSymbol();
Symbol *toThunkSymbol(int offset); // thunk version
#endif
void toObjFile(int multiobj); // compile to .obj file
#if IN_DMD
int cvMember(unsigned char *p);
#endif
@@ -727,6 +724,9 @@ struct FuncDeclaration : Declaration
#if IN_LLVM
// LDC stuff
/// Codegen traversal
void codegen(Ir* ir);
// vars declared in this function that nested funcs reference
// is this is not empty, nestedFrameRef is set and these VarDecls
// probably have nestedref set too, see VarDeclaration::checkNestedReference
+2
View File
@@ -48,6 +48,7 @@ Dsymbol::Dsymbol()
#if IN_LLVM
this->llvmInternal = LLVMnone;
this->irsym = NULL;
#endif
}
@@ -66,6 +67,7 @@ Dsymbol::Dsymbol(Identifier *ident)
#if IN_LLVM
this->llvmInternal = LLVMnone;
this->irsym = NULL;
#endif
}
+6 -2
View File
@@ -84,6 +84,8 @@ struct TYPE;
// llvm
#if IN_LLVM
struct Ir;
struct IrSymbol;
namespace llvm
{
class Value;
@@ -180,9 +182,7 @@ struct Dsymbol : Object
// Backend
virtual Symbol *toSymbol(); // to backend symbol
#endif
virtual void toObjFile(int multiobj); // compile to .obj file
#if IN_DMD
virtual int cvMember(unsigned char *p); // emit cv debug info for member
Symbol *toImport(); // to backend import symbol
@@ -232,10 +232,14 @@ struct Dsymbol : Object
virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; }
#if IN_LLVM
/// Codegen traversal
virtual void codegen(Ir* ir);
// llvm stuff
int llvmInternal;
IrDsymbol ir;
IrSymbol* irsym;
#endif
};
+5 -1
View File
@@ -61,14 +61,18 @@ struct EnumDeclaration : ScopeDsymbol
EnumDeclaration *isEnumDeclaration() { return this; }
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
void toDebug();
int cvMember(unsigned char *p);
#if IN_DMD
Symbol *sinit;
Symbol *toInitializer();
#endif
#if IN_LLVM
void codegen(Ir*);
#endif
};
+5 -2
View File
@@ -28,6 +28,7 @@ struct Library;
// Back end
#if IN_LLVM
struct Ir;
struct DValue;
typedef DValue elem;
namespace llvm { class Module; }
@@ -175,16 +176,18 @@ struct Module : Package
#endif
void genmoduleinfo();
#if IN_LLVM
// LDC
llvm::Module* genLLVMModule(int multiobj);
llvm::Module* genLLVMModule(Ir* sir);
void buildTargetFiles();
File* buildFilePath(const char* forcename, const char* path, const char* ext);
Module *isModule() { return this; }
bool llvmForceLogging;
// array ops emitted in this module already
StringTable arrayfuncs;
#endif
};
+17 -2
View File
@@ -15,7 +15,11 @@
#include <alloca.h>
#endif
#ifdef __DMC__
#include <math.h>
#else
#include <cmath>
#endif
#include <stdio.h>
#include <assert.h>
@@ -65,7 +69,11 @@ static double zero = 0;
#include "aggregate.h"
#include "hdrgen.h"
#include "gen/tollvm.h"
#if IN_LLVM
//#include "gen/tollvm.h"
Ir* Type::sir = NULL;
unsigned GetTypeAlignment(Ir* ir, Type* t);
#endif
FuncDeclaration *hasThis(Scope *sc);
@@ -164,7 +172,11 @@ char Type::needThisPrefix()
return 'M'; // name mangling prefix for functions needing 'this'
}
#if IN_LLVM
void Type::init(Ir* _sir)
#else
void Type::init()
#endif
{ int i;
int j;
@@ -238,6 +250,9 @@ void Type::init()
tvoidptr = tvoid->pointerTo();
// LDC
sir = _sir;
// set size_t / ptrdiff_t types and pointer size
if (global.params.is64bit)
{
@@ -1017,7 +1032,7 @@ unsigned TypeBasic::alignsize()
{
if (ty == Tvoid)
return 1;
return getABITypeAlign(DtoType(this));
return GetTypeAlignment(sir, this);
}
+6
View File
@@ -26,6 +26,7 @@
#include "../ir/irtype.h"
#include "../ir/irfuncty.h"
namespace llvm { class Type; }
struct Ir;
#endif
struct Scope;
@@ -207,7 +208,11 @@ struct Type : Object
int covariant(Type *t);
char *toChars();
static char needThisPrefix();
#if IN_LLVM
static void init(Ir*);
#else
static void init();
#endif
d_uns64 size();
virtual d_uns64 size(Loc loc);
virtual unsigned alignsize();
@@ -275,6 +280,7 @@ struct Type : Object
#if IN_LLVM
// LDC
IrType ir;
static Ir* sir;
#endif
};
+16 -3
View File
@@ -337,10 +337,12 @@ Dsymbol *TemplateDeclaration::syntaxCopy(Dsymbol *)
#endif
d = Dsymbol::arraySyntaxCopy(members);
td = new TemplateDeclaration(loc, ident, p, d);
#if IN_LLVM
// LDC
td->intrinsicName = intrinsicName;
#endif
return td;
}
@@ -2950,10 +2952,12 @@ TemplateInstance::TemplateInstance(Loc loc, Identifier *ident)
this->isnested = NULL;
this->errors = 0;
#if IN_LLVM
// LDC
this->emittedInModule = NULL;
this->tinst = NULL;
this->tmodule = NULL;
#endif
}
/*****************
@@ -2982,9 +2986,11 @@ TemplateInstance::TemplateInstance(Loc loc, TemplateDeclaration *td, Objects *ti
this->isnested = NULL;
this->errors = 0;
#if IN_LLVM
// LDC
this->tinst = NULL;
this->tmodule = NULL;
#endif
assert((size_t)tempdecl->scope > 0x10000);
}
@@ -3270,6 +3276,7 @@ void TemplateInstance::semantic(Scope *sc)
//printf("setting aliasdecl\n");
aliasdecl = new AliasDeclaration(loc, s->ident, s);
#if IN_LLVM
// LDC propagate internal information
if (tempdecl->llvmInternal) {
s->llvmInternal = tempdecl->llvmInternal;
@@ -3277,6 +3284,7 @@ void TemplateInstance::semantic(Scope *sc)
fd->intrinsicName = tempdecl->intrinsicName;
}
}
#endif
}
}
}
@@ -3957,6 +3965,8 @@ void TemplateInstance::semantic3(Scope *sc)
}
}
#if IN_DMD
void TemplateInstance::toObjFile(int multiobj)
{
#if LOG
@@ -3979,6 +3989,8 @@ void TemplateInstance::toObjFile(int multiobj)
}
}
#endif
void TemplateInstance::inlineScan()
{
#if LOG
@@ -4559,9 +4571,10 @@ void TemplateMixin::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
}
#if IN_DMD
void TemplateMixin::toObjFile(int multiobj)
{
//printf("TemplateMixin::toObjFile('%s')\n", toChars());
TemplateInstance::toObjFile(multiobj);
}
#endif
+15 -1
View File
@@ -91,9 +91,11 @@ struct TemplateDeclaration : ScopeDsymbol
TemplateTupleParameter *isVariadic();
int isOverloadable();
#if IN_LLVM
// LDC
std::string intrinsicName;
#endif
};
struct TemplateParameter
@@ -310,7 +312,9 @@ struct TemplateInstance : ScopeDsymbol
char *toChars();
char *mangle();
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
#endif
// Internal
static void semanticTiargs(Loc loc, Scope *sc, Objects *tiargs);
@@ -324,11 +328,15 @@ struct TemplateInstance : ScopeDsymbol
TemplateInstance *isTemplateInstance() { return this; }
AliasDeclaration *isAliasDeclaration();
#if IN_LLVM
// LDC
TemplateInstance *tinst; // enclosing template instance
Module* tmodule; // module from outermost enclosing template instantiation
Module* emittedInModule; // which module this template instance has been emitted in
void printInstantiationTrace();
void codegen(Ir*);
#endif
};
struct TemplateMixin : TemplateInstance
@@ -351,9 +359,15 @@ struct TemplateMixin : TemplateInstance
char *mangle();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
#if IN_DMD
void toObjFile(int multiobj); // compile to .obj file
#endif
TemplateMixin *isTemplateMixin() { return this; }
#if IN_LLVM
void codegen(Ir*);
#endif
};
Expression *isExpression(Object *o);