mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-10-15 18:17:00 +02:00
[svn r5] Initial commit. Most things are very rough.
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "llvm/Instructions.h"
|
||||
|
||||
#include "elem.h"
|
||||
|
||||
#include "irstate.h"
|
||||
#include "logger.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
elem::elem()
|
||||
{
|
||||
mem = 0;
|
||||
val = 0;
|
||||
arg = 0;
|
||||
|
||||
type = NONE;
|
||||
inplace = false;
|
||||
field = false;
|
||||
|
||||
vardecl = 0;
|
||||
funcdecl = 0;
|
||||
}
|
||||
|
||||
llvm::Value* elem::getValue()
|
||||
{
|
||||
assert(val || mem);
|
||||
switch(type)
|
||||
{
|
||||
case NONE:
|
||||
assert(0 && "type == NONE");
|
||||
break;
|
||||
|
||||
case VAR:
|
||||
case REF: {
|
||||
if (val) {
|
||||
return val;
|
||||
}
|
||||
else {
|
||||
if (!llvm::isa<llvm::PointerType>(mem->getType()))
|
||||
{
|
||||
Logger::cout() << "unexpected type: " << *mem->getType() << '\n';
|
||||
assert(0);
|
||||
}
|
||||
const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(mem->getType());
|
||||
if (!pt->getElementType()->isFirstClassType()) {
|
||||
return mem;
|
||||
}
|
||||
else {
|
||||
return new llvm::LoadInst(mem, "tmp", gIR->scopebb());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case VAL:
|
||||
case NUL:
|
||||
case FUNC:
|
||||
case CONST:
|
||||
case SLICE:
|
||||
return val ? val : mem;
|
||||
}
|
||||
assert(0 && "type == invalid value");
|
||||
return 0;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#ifndef LLVMDC_GEN_ELEM_H
|
||||
#define LLVMDC_GEN_ELEM_H
|
||||
|
||||
#include "llvm/Value.h"
|
||||
|
||||
#include "root.h"
|
||||
#include "declaration.h"
|
||||
#include "aggregate.h"
|
||||
|
||||
// represents a value. be it a constant literal, a variable etc.
|
||||
// maintains all the information for doing load/store appropriately
|
||||
struct elem : Object
|
||||
{
|
||||
enum {
|
||||
NONE,
|
||||
VAR,
|
||||
VAL,
|
||||
FUNC,
|
||||
CONST,
|
||||
NUL,
|
||||
REF,
|
||||
SLICE
|
||||
};
|
||||
|
||||
public:
|
||||
elem();
|
||||
|
||||
llvm::Value* mem;
|
||||
llvm::Value* val;
|
||||
llvm::Value* arg;
|
||||
int type;
|
||||
bool inplace;
|
||||
bool field;
|
||||
|
||||
VarDeclaration* vardecl;
|
||||
FuncDeclaration* funcdecl;
|
||||
|
||||
llvm::Value* getValue();
|
||||
//llvm::Value* getMemory();
|
||||
|
||||
bool isNull() {return !(mem || val);}
|
||||
};
|
||||
|
||||
#endif // LLVMDC_GEN_ELEM_H
|
||||
@@ -0,0 +1,8 @@
|
||||
enum
|
||||
{
|
||||
LLVMnone,
|
||||
LLVMnull,
|
||||
LLVMmangle,
|
||||
LLVMintrinsic,
|
||||
LLVMbind,
|
||||
};
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/* DMDFE backend stubs
|
||||
* This file contains the implementations of the backend routines.
|
||||
* For dmdfe these do nothing but print a message saying the module
|
||||
* has been parsed. Substitute your own behaviors for these routimes.
|
||||
*/
|
||||
|
||||
#include "irstate.h"
|
||||
|
||||
#include "mtype.h"
|
||||
|
||||
IRState* gIR = 0;
|
||||
llvm::TargetData* gTargetData = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
IRScope::IRScope()
|
||||
{
|
||||
begin = end = 0;
|
||||
returned = false;
|
||||
}
|
||||
|
||||
IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e)
|
||||
{
|
||||
begin = b;
|
||||
end = e;
|
||||
returned = false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
IRState::IRState()
|
||||
{
|
||||
dmodule = 0;
|
||||
module = 0;
|
||||
inLvalue = false;
|
||||
emitMain = false;
|
||||
mainFunc = 0;
|
||||
}
|
||||
|
||||
llvm::Function* IRState::topfunc()
|
||||
{
|
||||
assert(!funcs.empty() && "Function stack is empty!");
|
||||
return funcs.top();
|
||||
}
|
||||
|
||||
TypeFunction* IRState::topfunctype()
|
||||
{
|
||||
assert(!functypes.empty() && "TypeFunction stack is empty!");
|
||||
return functypes.top();
|
||||
}
|
||||
|
||||
llvm::Instruction* IRState::topallocapoint()
|
||||
{
|
||||
assert(!functypes.empty() && "AllocaPoint stack is empty!");
|
||||
return functypes.top()->llvmAllocaPoint;
|
||||
}
|
||||
|
||||
IRStruct& IRState::topstruct()
|
||||
{
|
||||
assert(!structs.empty() && "Struct vector is empty!");
|
||||
return structs.back();
|
||||
}
|
||||
|
||||
llvm::Value* IRState::toplval()
|
||||
{
|
||||
assert(!lvals.empty() && "Lval vector is empty!");
|
||||
return lvals.back();
|
||||
}
|
||||
|
||||
IRScope& IRState::scope()
|
||||
{
|
||||
assert(!scopes.empty());
|
||||
return scopes.back();
|
||||
}
|
||||
|
||||
llvm::BasicBlock* IRState::scopebb()
|
||||
{
|
||||
return scopebegin();
|
||||
}
|
||||
llvm::BasicBlock* IRState::scopebegin()
|
||||
{
|
||||
IRScope& s = scope();
|
||||
assert(s.begin);
|
||||
return s.begin;
|
||||
}
|
||||
llvm::BasicBlock* IRState::scopeend()
|
||||
{
|
||||
IRScope& s = scope();
|
||||
assert(s.end);
|
||||
return s.end;
|
||||
}
|
||||
bool IRState::scopereturned()
|
||||
{
|
||||
return scope().returned;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IRStruct::IRStruct()
|
||||
: recty(llvm::OpaqueType::get())
|
||||
{
|
||||
type = 0;
|
||||
}
|
||||
|
||||
IRStruct::IRStruct(TypeStruct* t)
|
||||
: recty(llvm::OpaqueType::get())
|
||||
{
|
||||
type = t;
|
||||
}
|
||||
|
||||
IRStruct::~IRStruct()
|
||||
{
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
#ifndef LLVMDC_GEN_IRSTATE_H
|
||||
#define LLVMDC_GEN_IRSTATE_H
|
||||
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/BasicBlock.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
|
||||
#include "root.h"
|
||||
|
||||
// global ir state for current module
|
||||
struct IRState;
|
||||
extern IRState* gIR;
|
||||
extern llvm::TargetData* gTargetData;
|
||||
|
||||
struct TypeFunction;
|
||||
struct TypeStruct;
|
||||
struct ClassDeclaration;
|
||||
struct FuncDeclaration;
|
||||
struct Module;
|
||||
struct TypeStruct;
|
||||
|
||||
// represents a scope
|
||||
struct IRScope
|
||||
{
|
||||
llvm::BasicBlock* begin;
|
||||
llvm::BasicBlock* end;
|
||||
bool returned;
|
||||
|
||||
IRScope();
|
||||
IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e);
|
||||
};
|
||||
|
||||
// represents a struct
|
||||
struct IRStruct : Object
|
||||
{
|
||||
typedef std::vector<const llvm::Type*> TypeVector;
|
||||
typedef std::vector<llvm::Constant*> ConstantVector;
|
||||
typedef std::vector<llvm::PATypeHolder> PATypeHolderVector;
|
||||
|
||||
public:
|
||||
IRStruct();
|
||||
IRStruct(TypeStruct*);
|
||||
virtual ~IRStruct();
|
||||
|
||||
TypeStruct* type;
|
||||
TypeVector fields;
|
||||
ConstantVector inits;
|
||||
llvm::PATypeHolder recty;
|
||||
};
|
||||
|
||||
// represents a clas
|
||||
struct IRClass : Object
|
||||
{
|
||||
// TODO
|
||||
};
|
||||
|
||||
// represents the module
|
||||
struct IRState : Object
|
||||
{
|
||||
IRState();
|
||||
|
||||
// module
|
||||
Module* dmodule;
|
||||
llvm::Module* module;
|
||||
|
||||
// functions
|
||||
std::stack<llvm::Function*> funcs;
|
||||
llvm::Function* topfunc();
|
||||
std::stack<TypeFunction*> functypes;
|
||||
TypeFunction* topfunctype();
|
||||
llvm::Instruction* topallocapoint();
|
||||
|
||||
// structs
|
||||
typedef std::vector<IRStruct> StructVector;
|
||||
StructVector structs;
|
||||
IRStruct& topstruct();
|
||||
|
||||
// classes TODO move into IRClass
|
||||
typedef std::vector<ClassDeclaration*> ClassDeclVec;
|
||||
ClassDeclVec classes;
|
||||
typedef std::vector<FuncDeclaration*> FuncDeclVec;
|
||||
typedef std::vector<FuncDeclVec> ClassMethodVec;
|
||||
ClassMethodVec classmethods;
|
||||
typedef std::vector<bool> BoolVec;
|
||||
BoolVec queueClassMethods;
|
||||
|
||||
// D main function
|
||||
bool emitMain;
|
||||
llvm::Function* mainFunc;
|
||||
|
||||
// L-values
|
||||
bool inLvalue;
|
||||
typedef std::vector<llvm::Value*> LvalVec;
|
||||
LvalVec lvals;
|
||||
llvm::Value* toplval();
|
||||
|
||||
// basic block scopes
|
||||
std::vector<IRScope> scopes;
|
||||
IRScope& scope();
|
||||
llvm::BasicBlock* scopebegin();
|
||||
llvm::BasicBlock* scopeend();
|
||||
llvm::BasicBlock* scopebb();
|
||||
bool scopereturned();
|
||||
|
||||
// loop blocks
|
||||
typedef std::vector<IRScope> BBVec;
|
||||
BBVec loopbbs;
|
||||
|
||||
// this holds the array being indexed or sliced so $ will work
|
||||
// might be a better way but it works. problem is I only get a
|
||||
// VarDeclaration for __dollar, but I can't see how to get the
|
||||
// array pointer from this :(
|
||||
LvalVec arrays;
|
||||
};
|
||||
|
||||
#endif // LLVMDC_GEN_IRSTATE_H
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef LLVMD_NO_LOGGER
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
static std::string indent_str;
|
||||
void indent()
|
||||
{
|
||||
indent_str += " ";
|
||||
}
|
||||
void undent()
|
||||
{
|
||||
assert(!indent_str.empty());
|
||||
indent_str.resize(indent_str.size()-2);
|
||||
}
|
||||
std::ostream& cout()
|
||||
{
|
||||
return std::cout << indent_str;
|
||||
}
|
||||
void println(const char* fmt,...)
|
||||
{
|
||||
printf(indent_str.c_str());
|
||||
va_list va;
|
||||
va_start(va,fmt);
|
||||
vprintf(fmt,va);
|
||||
va_end(va);
|
||||
printf("\n");
|
||||
}
|
||||
void print(const char* fmt,...)
|
||||
{
|
||||
printf(indent_str.c_str());
|
||||
va_list va;
|
||||
va_start(va,fmt);
|
||||
vprintf(fmt,va);
|
||||
va_end(va);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
#ifndef _llvmd_gen_logger_h_
|
||||
#define _llvmd_gen_logger_h_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
#ifndef LLVMD_NO_LOGGER
|
||||
void indent();
|
||||
void undent();
|
||||
std::ostream& cout();
|
||||
void println(const char* fmt,...);
|
||||
void print(const char* fmt,...);
|
||||
#else
|
||||
inline void indent() {}
|
||||
inline void undent() {}
|
||||
inline std::ostream& cout() { return std::cout; }
|
||||
inline void println(const char* fmt, ...) {}
|
||||
inline void print(const char* fmt, ...) {}
|
||||
#endif
|
||||
|
||||
struct LoggerScope
|
||||
{
|
||||
LoggerScope()
|
||||
{
|
||||
#ifndef LLVMD_NO_LOGGER
|
||||
//std::cout << "-->indented\n";
|
||||
Logger::indent();
|
||||
#endif
|
||||
|
||||
}
|
||||
~LoggerScope()
|
||||
{
|
||||
#ifndef LLVMD_NO_LOGGER
|
||||
//std::cout << "<--undented\n";
|
||||
Logger::undent();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#ifndef LLVMD_NO_LOGGER
|
||||
#define LOG_SCOPE Logger::LoggerScope _logscope;
|
||||
#else
|
||||
#define LOG_SCOPE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
#include "runtime.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include "root.h"
|
||||
#include "mars.h"
|
||||
|
||||
static llvm::Module* M = NULL;
|
||||
static bool runtime_failed = false;
|
||||
|
||||
bool LLVM_D_InitRuntime()
|
||||
{
|
||||
Logger::println("*** Loading D runtime ***");
|
||||
LOG_SCOPE;
|
||||
|
||||
std::string filename(global.params.runtimeImppath);
|
||||
filename.append("/llvmdcore.bc");
|
||||
llvm::MemoryBuffer* buffer = llvm::MemoryBuffer::getFile(filename.c_str(), filename.length());
|
||||
if (!buffer) {
|
||||
Logger::println("Failed to load runtime library from disk");
|
||||
runtime_failed = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string errstr;
|
||||
bool retval = false;
|
||||
M = llvm::ParseBitcodeFile(buffer, &errstr);
|
||||
if (M) {
|
||||
retval = true;
|
||||
}
|
||||
else {
|
||||
Logger::println("Failed to load runtime: %s", errstr.c_str());
|
||||
runtime_failed = true;
|
||||
}
|
||||
|
||||
delete buffer;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void LLVM_D_FreeRuntime()
|
||||
{
|
||||
if (M) {
|
||||
Logger::println("*** Freeing D runtime ***");
|
||||
delete M;
|
||||
}
|
||||
}
|
||||
|
||||
llvm::Function* LLVM_D_GetRuntimeFunction(llvm::Module* target, const char* name)
|
||||
{
|
||||
// TODO maybe check the target module first, to allow overriding the runtime on a pre module basis?
|
||||
// could be done and seems like it could be neat too :)
|
||||
|
||||
if (global.params.noruntime) {
|
||||
error("No implicit runtime calls allowed with -noruntime option enabled");
|
||||
fatal();
|
||||
}
|
||||
|
||||
if (!M) {
|
||||
assert(!runtime_failed);
|
||||
LLVM_D_InitRuntime();
|
||||
}
|
||||
|
||||
llvm::Function* fn = M->getFunction(name);
|
||||
if (!fn)
|
||||
return NULL;
|
||||
|
||||
const llvm::FunctionType* fnty = fn->getFunctionType();
|
||||
return llvm::cast<llvm::Function>(target->getOrInsertFunction(name, fnty));
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// D runtime support helpers
|
||||
|
||||
bool LLVM_D_InitRuntime();
|
||||
void LLVM_D_FreeRuntime();
|
||||
|
||||
llvm::Function* LLVM_D_GetRuntimeFunction(llvm::Module* target, const char* name);
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
|
||||
// Copyright (c) 1999-2005 by Digital Mars
|
||||
// All Rights Reserved
|
||||
// written by Walter Bright
|
||||
// www.digitalmars.com
|
||||
// License for redistribution is by either the Artistic License
|
||||
// in artistic.txt, or the GNU General Public License in gnu.txt.
|
||||
// See the included readme.txt for details.
|
||||
|
||||
// stubbed out for dmdfe. Original is in dmd/tocsym.c
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "mars.h"
|
||||
#include "module.h"
|
||||
#include "mtype.h"
|
||||
#include "declaration.h"
|
||||
#include "statement.h"
|
||||
#include "enum.h"
|
||||
#include "aggregate.h"
|
||||
#include "init.h"
|
||||
#include "attrib.h"
|
||||
#include "lexer.h"
|
||||
#include "symbol.h"
|
||||
|
||||
/********************************* SymbolDeclaration ****************************/
|
||||
|
||||
SymbolDeclaration::SymbolDeclaration(Loc loc, Symbol *s, StructDeclaration *dsym)
|
||||
: Declaration(new Identifier("", TOKidentifier))
|
||||
{
|
||||
}
|
||||
|
||||
Symbol *SymbolDeclaration::toSymbol()
|
||||
{
|
||||
return sym;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
* Helper
|
||||
*/
|
||||
|
||||
Symbol *Dsymbol::toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *Dsymbol::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************
|
||||
* Generate import symbol from symbol.
|
||||
*/
|
||||
|
||||
Symbol *Dsymbol::toImport()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *Dsymbol::toImport(Symbol *sym)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *VarDeclaration::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *ClassInfoDeclaration::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *ModuleInfoDeclaration::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *TypeInfoDeclaration::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *FuncDeclaration::toSymbol()
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *FuncDeclaration::toThunkSymbol(int offset)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*/
|
||||
|
||||
Symbol *FuncAliasDeclaration::toSymbol()
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/****************************************
|
||||
* Create a static symbol we can hang DT initializers onto.
|
||||
*/
|
||||
|
||||
Symbol *static_sym()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
* Create the "ClassInfo" symbol
|
||||
*/
|
||||
|
||||
Symbol *ClassDeclaration::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
* Create the "InterfaceInfo" symbol
|
||||
*/
|
||||
|
||||
Symbol *InterfaceDeclaration::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
* Create the "ModuleInfo" symbol
|
||||
*/
|
||||
|
||||
Symbol *Module::toSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************
|
||||
* This is accessible via the ClassData, but since it is frequently
|
||||
* needed directly (like for rtti comparisons), make it directly accessible.
|
||||
*/
|
||||
|
||||
Symbol *ClassDeclaration::toVtblSymbol()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************************
|
||||
* Create the static initializer for the struct/class.
|
||||
*/
|
||||
|
||||
Symbol *AggregateDeclaration::toInitializer()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/******************************************
|
||||
*/
|
||||
|
||||
Symbol *Module::toModuleAssert()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************
|
||||
*/
|
||||
|
||||
Symbol *Module::toModuleArray()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/********************************************
|
||||
* Determine the right symbol to look up
|
||||
* an associative array element.
|
||||
* Input:
|
||||
* flags 0 don't add value signature
|
||||
* 1 add value signature
|
||||
*/
|
||||
|
||||
Symbol *TypeAArray::aaGetSymbol(char *func, int flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
|
||||
// Copyright (c) 1999-2005 by Digital Mars
|
||||
// All Rights Reserved
|
||||
// written by Walter Bright
|
||||
// www.digitalmars.com
|
||||
// License for redistribution is by either the Artistic License
|
||||
// in artistic.txt, or the GNU General Public License in gnu.txt.
|
||||
// See the included readme.txt for details.
|
||||
|
||||
// stubbed out for dmdfe. Original is in dmd/todt.c
|
||||
|
||||
#include "lexer.h"
|
||||
#include "mtype.h"
|
||||
#include "expression.h"
|
||||
#include "init.h"
|
||||
#include "enum.h"
|
||||
#include "aggregate.h"
|
||||
#include "declaration.h"
|
||||
|
||||
struct dt_t {};
|
||||
|
||||
dt_t *Initializer::toDt()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
dt_t *StructInitializer::toDt()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
dt_t *ArrayInitializer::toDt()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
dt_t *ArrayInitializer::toDtBit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
dt_t *ExpInitializer::toDt()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t *VoidInitializer::toDt()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
dt_t **Expression::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **IntegerExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **RealExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **ComplexExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **NullExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **StringExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **SymOffExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **VarExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **ArrayLiteralExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
dt_t **StructLiteralExp::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ClassDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
|
||||
void ClassDeclaration::toDt2(dt_t **pdt, ClassDeclaration *cd)
|
||||
{
|
||||
}
|
||||
|
||||
void StructDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TypeInfoPointerDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoArrayDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoFunctionDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoDelegateDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
dt_t **Type::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **TypeSArray::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **TypeStruct::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
dt_t **TypeTypedef::toDt(dt_t **pdt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2910
File diff suppressed because it is too large
Load Diff
+1089
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
// D -> LLVM helpers
|
||||
|
||||
struct StructInitializer;
|
||||
|
||||
const llvm::Type* LLVM_DtoType(Type* t);
|
||||
|
||||
llvm::Type* LLVM_DtoStructType(Type* t);
|
||||
llvm::Value* LLVM_DtoStructZeroInit(TypeStruct* t, llvm::Value* v);
|
||||
llvm::Value* LLVM_DtoStructCopy(TypeStruct* t, llvm::Value* dst, llvm::Value* src);
|
||||
llvm::Constant* LLVM_DtoStructInitializer(StructInitializer* si);
|
||||
|
||||
llvm::FunctionType* LLVM_DtoFunctionType(Type* t, const llvm::Type* thisparam = 0);
|
||||
llvm::FunctionType* LLVM_DtoFunctionType(FuncDeclaration* fdecl);
|
||||
|
||||
llvm::StructType* LLVM_DtoDelegateType(Type* t);
|
||||
llvm::Value* LLVM_DtoNullDelegate(llvm::Value* v);
|
||||
llvm::Value* LLVM_DtoDelegateCopy(llvm::Value* dst, llvm::Value* src);
|
||||
|
||||
llvm::StructType* LLVM_DtoArrayType(Type* t);
|
||||
llvm::ArrayType* LLVM_DtoStaticArrayType(Type* t);
|
||||
llvm::Value* LLVM_DtoNullArray(llvm::Value* v);
|
||||
llvm::Value* LLVM_DtoArrayAssign(llvm::Value* l, llvm::Value* r);
|
||||
void LLVM_DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr);
|
||||
llvm::Constant* LLVM_DtoArrayInitializer(ArrayInitializer* si);
|
||||
void LLVM_DtoArrayCopy(elem* dst, elem* src);
|
||||
|
||||
void LLVM_DtoArrayInit(llvm::Value* l, llvm::Value* r);
|
||||
|
||||
llvm::GlobalValue::LinkageTypes LLVM_DtoLinkage(PROT prot, uint stc);
|
||||
unsigned LLVM_DtoCallingConv(LINK l);
|
||||
|
||||
llvm::Value* LLVM_DtoPointedType(llvm::Value* ptr, llvm::Value* val);
|
||||
llvm::Value* LLVM_DtoBoolean(llvm::Value* val);
|
||||
|
||||
const llvm::Type* LLVM_DtoSize_t();
|
||||
|
||||
void LLVM_DtoMain();
|
||||
|
||||
void LLVM_DtoCallClassDtors(TypeClass* tc, llvm::Value* instance);
|
||||
void LLVM_DtoInitClass(TypeClass* tc, llvm::Value* dst);
|
||||
|
||||
llvm::Constant* LLVM_DtoInitializer(Type* type, Initializer* init);
|
||||
|
||||
#include "enums.h"
|
||||
+816
@@ -0,0 +1,816 @@
|
||||
|
||||
// Copyright (c) 1999-2004 by Digital Mars
|
||||
// All Rights Reserved
|
||||
// written by Walter Bright
|
||||
// www.digitalmars.com
|
||||
// License for redistribution is by either the Artistic License
|
||||
// in artistic.txt, or the GNU General Public License in gnu.txt.
|
||||
// See the included readme.txt for details.
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "llvm/Type.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/Analysis/Verifier.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetMachineRegistry.h"
|
||||
|
||||
#include "mars.h"
|
||||
#include "module.h"
|
||||
#include "mtype.h"
|
||||
#include "declaration.h"
|
||||
#include "statement.h"
|
||||
#include "enum.h"
|
||||
#include "aggregate.h"
|
||||
#include "init.h"
|
||||
#include "attrib.h"
|
||||
#include "id.h"
|
||||
#include "import.h"
|
||||
#include "template.h"
|
||||
#include "irstate.h"
|
||||
#include "elem.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include "tollvm.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
Module::genobjfile()
|
||||
{
|
||||
Logger::cout() << "Generating module: " << (md ? md->toChars() : toChars()) << '\n';
|
||||
LOG_SCOPE;
|
||||
|
||||
deleteObjFile();
|
||||
|
||||
IRState ir;
|
||||
gIR = &ir;
|
||||
|
||||
ir.dmodule = this;
|
||||
|
||||
std::string mname(toChars());
|
||||
if (md != 0)
|
||||
mname = md->toChars();
|
||||
ir.module = new llvm::Module(mname);
|
||||
|
||||
std::string target_triple(global.params.tt_arch);
|
||||
target_triple.append(global.params.tt_os);
|
||||
ir.module->setTargetTriple(target_triple);
|
||||
ir.module->setDataLayout(global.params.data_layout);
|
||||
|
||||
gTargetData = new llvm::TargetData(ir.module);
|
||||
|
||||
for (int k=0; k < members->dim; k++) {
|
||||
Dsymbol* dsym = (Dsymbol*)(members->data[k]);
|
||||
assert(dsym);
|
||||
dsym->toObjFile();
|
||||
}
|
||||
|
||||
delete gTargetData;
|
||||
gTargetData = 0;
|
||||
|
||||
std::string verifyErr;
|
||||
if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
|
||||
{
|
||||
error("%s", verifyErr.c_str());
|
||||
fatal();
|
||||
}
|
||||
|
||||
if (ir.emitMain) {
|
||||
LLVM_DtoMain();
|
||||
}
|
||||
|
||||
// run passes
|
||||
// TODO
|
||||
|
||||
/*if (global.params.llvmLL) {
|
||||
//assert(0);
|
||||
std::ofstream os(llfile->name->toChars());
|
||||
//llvm::WriteAssemblyToFile(ir.module, os);
|
||||
ir.module->print(os);
|
||||
}*/
|
||||
|
||||
//if (global.params.llvmBC) {
|
||||
Logger::println("Writing LLVM bitcode\n");
|
||||
std::ofstream os(bcfile->name->toChars(), std::ios::binary);
|
||||
llvm::WriteBitcodeToFile(ir.module, os);
|
||||
//}
|
||||
|
||||
delete ir.module;
|
||||
gIR = NULL;
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
// Put out instance of ModuleInfo for this Module
|
||||
|
||||
void Module::genmoduleinfo()
|
||||
{
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void Dsymbol::toObjFile()
|
||||
{
|
||||
warning("Ignoring Dsymbol::toObjFile for %s", toChars());
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void Declaration::toObjFile()
|
||||
{
|
||||
warning("Ignoring Declaration::toObjFile for %s", toChars());
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
unsigned AggregateDeclaration::offsetToIndex(unsigned os)
|
||||
{
|
||||
for (unsigned i=0; i<fields.dim; ++i) {
|
||||
VarDeclaration* vd = (VarDeclaration*)fields.data[i];
|
||||
if (os == vd->offset)
|
||||
return i;
|
||||
}
|
||||
assert(0 && "Offset not found in any aggregate field");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx)
|
||||
{
|
||||
// start at the bottom of the inheritance chain
|
||||
if (cd->baseClass != 0) {
|
||||
unsigned o = LLVM_ClassOffsetToIndex(cd->baseClass, os, idx);
|
||||
if (o != (unsigned)-1)
|
||||
return o;
|
||||
}
|
||||
|
||||
// check this class
|
||||
unsigned i;
|
||||
for (i=0; i<cd->fields.dim; ++i) {
|
||||
VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i];
|
||||
if (os == vd->offset)
|
||||
return i+idx;
|
||||
}
|
||||
idx += i;
|
||||
|
||||
return (unsigned)-1;
|
||||
}
|
||||
|
||||
unsigned ClassDeclaration::offsetToIndex(unsigned os)
|
||||
{
|
||||
unsigned idx = 0;
|
||||
unsigned r = LLVM_ClassOffsetToIndex(this, os, idx);
|
||||
assert(r != (unsigned)-1 && "Offset not found in any aggregate field");
|
||||
return r+1; // vtable is 0
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void InterfaceDeclaration::toObjFile()
|
||||
{
|
||||
warning("Ignoring InterfaceDeclaration::toObjFile for %s", toChars());
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void StructDeclaration::toObjFile()
|
||||
{
|
||||
TypeStruct* ts = (TypeStruct*)type;
|
||||
if (llvmType != 0)
|
||||
return;
|
||||
|
||||
static int sdi = 0;
|
||||
Logger::print("StructDeclaration::toObjFile(%d): %s\n", sdi++, toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
gIR->structs.push_back(IRStruct(ts));
|
||||
|
||||
std::vector<FuncDeclaration*> mfs;
|
||||
|
||||
for (int k=0; k < members->dim; k++) {
|
||||
Dsymbol* dsym = (Dsymbol*)(members->data[k]);
|
||||
|
||||
// need late generation of member functions
|
||||
// they need the llvm::StructType to exist to take the 'this' parameter
|
||||
if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
|
||||
mfs.push_back(fd);
|
||||
}
|
||||
else {
|
||||
dsym->toObjFile();
|
||||
}
|
||||
}
|
||||
|
||||
llvm::StructType* structtype = llvm::StructType::get(gIR->topstruct().fields);
|
||||
|
||||
// refine abstract types for stuff like: struct S{S* next;}
|
||||
if (gIR->topstruct().recty != 0)
|
||||
{
|
||||
llvm::PATypeHolder& pa = gIR->topstruct().recty;
|
||||
llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype);
|
||||
structtype = llvm::cast<llvm::StructType>(pa.get());
|
||||
}
|
||||
|
||||
ts->llvmType = structtype;
|
||||
llvmType = structtype;
|
||||
|
||||
if (parent->isModule()) {
|
||||
gIR->module->addTypeName(mangle(),ts->llvmType);
|
||||
}
|
||||
|
||||
// generate static data
|
||||
llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage;
|
||||
llvm::Constant* _init = 0;
|
||||
|
||||
// always generate the constant initalizer
|
||||
if (!zeroInit) {
|
||||
Logger::println("Not zero initialized");
|
||||
//assert(tk == gIR->topstruct().size());
|
||||
#ifndef LLVMD_NO_LOGGER
|
||||
Logger::cout() << *structtype << '\n';
|
||||
for (size_t k=0; k<gIR->topstruct().inits.size(); ++k) {
|
||||
Logger::cout() << "Type:" << '\n';
|
||||
Logger::cout() << *gIR->topstruct().inits[k]->getType() << '\n';
|
||||
Logger::cout() << "Value:" << '\n';
|
||||
Logger::cout() << *gIR->topstruct().inits[k] << '\n';
|
||||
}
|
||||
Logger::cout() << "Initializer printed" << '\n';
|
||||
#endif
|
||||
llvmInitZ = llvm::ConstantStruct::get(structtype,gIR->topstruct().inits);
|
||||
}
|
||||
else {
|
||||
Logger::println("Zero initialized");
|
||||
llvmInitZ = llvm::ConstantAggregateZero::get(structtype);
|
||||
}
|
||||
|
||||
// only provide the constant initializer for the defining module
|
||||
if (getModule() == gIR->dmodule)
|
||||
{
|
||||
_init = llvmInitZ;
|
||||
}
|
||||
|
||||
std::string initname(mangle());
|
||||
initname.append("__initZ");
|
||||
llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, _init, initname, gIR->module);
|
||||
ts->llvmInit = initvar;
|
||||
|
||||
// generate member functions
|
||||
size_t n = mfs.size();
|
||||
for (size_t i=0; i<n; ++i) {
|
||||
mfs[i]->toObjFile();
|
||||
}
|
||||
|
||||
llvmDModule = gIR->dmodule;
|
||||
|
||||
gIR->structs.pop_back();
|
||||
|
||||
// generate typeinfo
|
||||
type->getTypeInfo(NULL); // generate TypeInfo
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
static void LLVM_AddBaseClassData(BaseClasses* bcs)
|
||||
{
|
||||
// add base class data members first
|
||||
for (int j=0; j<bcs->dim; j++)
|
||||
{
|
||||
BaseClass* bc = (BaseClass*)(bcs->data[j]);
|
||||
assert(bc);
|
||||
LLVM_AddBaseClassData(&bc->base->baseclasses);
|
||||
for (int k=0; k < bc->base->members->dim; k++) {
|
||||
Dsymbol* dsym = (Dsymbol*)(bc->base->members->data[k]);
|
||||
if (dsym->isVarDeclaration())
|
||||
{
|
||||
dsym->toObjFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClassDeclaration::toObjFile()
|
||||
{
|
||||
TypeClass* ts = (TypeClass*)type;
|
||||
if (ts->llvmType != 0 || llvmInProgress)
|
||||
return;
|
||||
|
||||
llvmInProgress = true;
|
||||
|
||||
static int fdi = 0;
|
||||
Logger::print("ClassDeclaration::toObjFile(%d): %s\n", fdi++, toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
gIR->structs.push_back(IRStruct());
|
||||
gIR->classes.push_back(this);
|
||||
gIR->classmethods.push_back(IRState::FuncDeclVec());
|
||||
gIR->queueClassMethods.push_back(true);
|
||||
|
||||
// add vtable
|
||||
const llvm::Type* vtabty = llvm::PointerType::get(llvm::Type::Int8Ty);
|
||||
gIR->topstruct().fields.push_back(vtabty);
|
||||
gIR->topstruct().inits.push_back(0);
|
||||
|
||||
// base classes first
|
||||
LLVM_AddBaseClassData(&baseclasses);
|
||||
|
||||
// then add own members
|
||||
for (int k=0; k < members->dim; k++) {
|
||||
Dsymbol* dsym = (Dsymbol*)(members->data[k]);
|
||||
dsym->toObjFile();
|
||||
}
|
||||
|
||||
llvm::StructType* structtype = llvm::StructType::get(gIR->topstruct().fields);
|
||||
ts->llvmType = structtype;
|
||||
llvmType = structtype;
|
||||
|
||||
bool emit_vtable = false;
|
||||
bool define_vtable = false;
|
||||
if (parent->isModule()) {
|
||||
gIR->module->addTypeName(mangle(),ts->llvmType);
|
||||
emit_vtable = true;
|
||||
define_vtable = (getModule() == gIR->dmodule);
|
||||
}
|
||||
else {
|
||||
assert(0 && "class parent is not a module");
|
||||
}
|
||||
|
||||
// generate member functions
|
||||
gIR->queueClassMethods.back() = false;
|
||||
IRState::FuncDeclVec& mfs = gIR->classmethods.back();
|
||||
size_t n = mfs.size();
|
||||
for (size_t i=0; i<n; ++i) {
|
||||
mfs[i]->toObjFile();
|
||||
}
|
||||
|
||||
// create vtable initializer
|
||||
if (emit_vtable)
|
||||
{
|
||||
llvm::GlobalVariable* vtblVar = 0;
|
||||
std::vector<llvm::Constant*> inits;
|
||||
inits.reserve(vtbl.dim);
|
||||
for (int k=0; k < vtbl.dim; k++)
|
||||
{
|
||||
Dsymbol* dsym = (Dsymbol*)vtbl.data[k];
|
||||
assert(dsym);
|
||||
//Logger::cout() << "vtblsym: " << dsym->toChars() << '\n';
|
||||
|
||||
if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
|
||||
fd->toObjFile();
|
||||
Logger::cout() << "casting to constant" << *fd->llvmValue << '\n';
|
||||
llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue);
|
||||
c = llvm::ConstantExpr::getBitCast(c, llvm::PointerType::get(llvm::Type::Int8Ty));
|
||||
inits.push_back(c);
|
||||
}
|
||||
else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
|
||||
llvm::Constant* c = llvm::Constant::getNullValue(llvm::PointerType::get(llvm::Type::Int8Ty));
|
||||
inits.push_back(c);
|
||||
}
|
||||
else
|
||||
assert(0);
|
||||
}
|
||||
if (!inits.empty())
|
||||
{
|
||||
llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage;
|
||||
std::string varname(mangle());
|
||||
varname.append("__vtblZ");
|
||||
const llvm::ArrayType* vtbl_ty = llvm::ArrayType::get(llvm::PointerType::get(llvm::Type::Int8Ty), inits.size());
|
||||
vtblVar = new llvm::GlobalVariable(vtbl_ty, true, _linkage, 0, varname, gIR->module);
|
||||
if (define_vtable) {
|
||||
//Logger::cout() << "vtbl:::" << '\n' << *vtbl_st << '\n';// << " == | == " << _init << '\n';
|
||||
llvm::Constant* _init = llvm::ConstantArray::get(vtbl_ty, inits);
|
||||
vtblVar->setInitializer(_init);
|
||||
}
|
||||
llvmVtbl = vtblVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// generate initializer
|
||||
llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage;
|
||||
llvm::Constant* _init = 0;
|
||||
|
||||
// first field is always the vtable
|
||||
assert(vtblVar != 0);
|
||||
llvm::Constant* vtbl_init_var = llvm::ConstantExpr::getBitCast(vtblVar, llvm::PointerType::get(llvm::Type::Int8Ty));
|
||||
gIR->topstruct().inits[0] = vtbl_init_var;
|
||||
|
||||
//assert(tk == gIR->topstruct().size());
|
||||
#ifndef LLVMD_NO_LOGGER
|
||||
Logger::cout() << *structtype << '\n';
|
||||
for (size_t k=0; k<gIR->topstruct().inits.size(); ++k)
|
||||
Logger::cout() << *gIR->topstruct().inits[k] << '\n';
|
||||
#endif
|
||||
_init = llvm::ConstantStruct::get(structtype,gIR->topstruct().inits);
|
||||
assert(_init);
|
||||
std::string initname(mangle());
|
||||
initname.append("__initZ");
|
||||
Logger::cout() << *_init << '\n';
|
||||
llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, 0, initname, gIR->module);
|
||||
ts->llvmInit = initvar;
|
||||
if (define_vtable) {
|
||||
initvar->setInitializer(_init);
|
||||
}
|
||||
}
|
||||
|
||||
gIR->queueClassMethods.pop_back();
|
||||
gIR->classmethods.pop_back();
|
||||
gIR->classes.pop_back();
|
||||
gIR->structs.pop_back();
|
||||
|
||||
llvmInProgress = false;
|
||||
}
|
||||
|
||||
/******************************************
|
||||
* Get offset of base class's vtbl[] initializer from start of csym.
|
||||
* Returns ~0 if not this csym.
|
||||
*/
|
||||
|
||||
unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc)
|
||||
{
|
||||
return ~0;
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void VarDeclaration::toObjFile()
|
||||
{
|
||||
static int vdi = 0;
|
||||
Logger::print("VarDeclaration::toObjFile(%d): %s | %s\n", vdi++, toChars(), type->toChars());
|
||||
LOG_SCOPE;
|
||||
llvm::Module* M = gIR->module;
|
||||
|
||||
// handle bind pragma
|
||||
if (llvmInternal == LLVMbind) {
|
||||
Logger::println("var is bound: %s", llvmInternal1);
|
||||
llvmValue = M->getGlobalVariable(llvmInternal1);
|
||||
assert(llvmValue);
|
||||
return;
|
||||
}
|
||||
|
||||
// global variable or magic
|
||||
if (!parent || parent->isModule())
|
||||
{
|
||||
bool _isconst = isConst();
|
||||
if (!_isconst)
|
||||
_isconst = (storage_class & STCconst) ? true : false; // doesn't seem to work ):
|
||||
llvm::GlobalValue::LinkageTypes _linkage = LLVM_DtoLinkage(protection, storage_class);
|
||||
const llvm::Type* _type = LLVM_DtoType(type);
|
||||
|
||||
llvm::Constant* _init = 0;
|
||||
bool _signed = !type->isunsigned();
|
||||
|
||||
_init = LLVM_DtoInitializer(type, init);
|
||||
|
||||
assert(_type);
|
||||
assert(_init);
|
||||
//Logger::cout() << "initializer: " << *_init << '\n';
|
||||
if (_type != _init->getType()) {
|
||||
Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n";
|
||||
// zero initalizer
|
||||
if (_init->isNullValue())
|
||||
_init = llvm::Constant::getNullValue(_type);
|
||||
// pointer to global constant (struct.init)
|
||||
else if (llvm::isa<llvm::GlobalVariable>(_init))
|
||||
{
|
||||
assert(_init->getType()->getContainedType(0) == _type);
|
||||
llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init);
|
||||
assert(type->ty == Tstruct);
|
||||
TypeStruct* ts = (TypeStruct*)type;
|
||||
assert(ts->sym->llvmInitZ);
|
||||
_init = ts->sym->llvmInitZ;
|
||||
}
|
||||
// array single value init
|
||||
else if (llvm::isa<llvm::ArrayType>(_type))
|
||||
{
|
||||
const llvm::ArrayType* at = llvm::cast<llvm::ArrayType>(_type);
|
||||
assert(_type->getContainedType(0) == _init->getType());
|
||||
std::vector<llvm::Constant*> initvals;
|
||||
initvals.resize(at->getNumElements(), _init);
|
||||
_init = llvm::ConstantArray::get(at, initvals);
|
||||
}
|
||||
else
|
||||
assert(0);
|
||||
}
|
||||
|
||||
Logger::println("Creating global variable");
|
||||
std::string _name(mangle());
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,_init,_name,M);
|
||||
llvmValue = gvar;
|
||||
|
||||
//if (storage_class & STCprivate)
|
||||
// gvar->setVisibility(llvm::GlobalValue::ProtectedVisibility);
|
||||
}
|
||||
|
||||
// inside aggregate declaration. declare a field.
|
||||
else
|
||||
{
|
||||
Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset);
|
||||
|
||||
const llvm::Type* _type = LLVM_DtoType(type);
|
||||
gIR->topstruct().fields.push_back(_type);
|
||||
|
||||
llvm::Constant* _init = LLVM_DtoInitializer(type, init);
|
||||
if (_type != _init->getType())
|
||||
{
|
||||
if (llvm::isa<llvm::ArrayType>(_type))
|
||||
{
|
||||
const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(_type);
|
||||
uint64_t n = arrty->getNumElements();
|
||||
std::vector<llvm::Constant*> vals(n,_init);
|
||||
_init = llvm::ConstantArray::get(arrty, vals);
|
||||
}
|
||||
else
|
||||
assert(0);
|
||||
}
|
||||
gIR->topstruct().inits.push_back(_init);
|
||||
}
|
||||
|
||||
Logger::println("VarDeclaration::toObjFile is done");
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void TypedefDeclaration::toObjFile()
|
||||
{
|
||||
static int tdi = 0;
|
||||
Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void EnumDeclaration::toObjFile()
|
||||
{
|
||||
warning("Ignoring EnumDeclaration::toObjFile for %s", toChars());
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
void FuncDeclaration::toObjFile()
|
||||
{
|
||||
if (llvmValue != 0 && llvmDModule == gIR->dmodule) {
|
||||
return;
|
||||
}
|
||||
|
||||
// has already been pulled in by a reference to (
|
||||
if (!gIR->queueClassMethods.empty() && gIR->queueClassMethods.back()) {
|
||||
Logger::println("queueing %s", toChars());
|
||||
assert(!gIR->classmethods.empty());
|
||||
gIR->classmethods.back().push_back(this);
|
||||
return; // will be generated later when the this parameter has a type
|
||||
}
|
||||
|
||||
static int fdi = 0;
|
||||
Logger::print("FuncDeclaration::toObjFile(%d,%s): %s\n", fdi++, needThis()?"this":"static",toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
if (llvmInternal == LLVMintrinsic && fbody) {
|
||||
error("intrinsics cannot have function bodies");
|
||||
fatal();
|
||||
}
|
||||
|
||||
TypeFunction* f = (TypeFunction*)type;
|
||||
assert(f != 0);
|
||||
|
||||
// return value type
|
||||
const llvm::Type* rettype;
|
||||
const llvm::Type* actualRettype;
|
||||
Type* rt = f->next;
|
||||
bool retinptr = false;
|
||||
bool usesthis = false;
|
||||
|
||||
if (isMain()) {
|
||||
rettype = llvm::Type::Int32Ty;
|
||||
actualRettype = rettype;
|
||||
gIR->emitMain = true;
|
||||
}
|
||||
else if (rt) {
|
||||
if (rt->ty == Tstruct || rt->ty == Tdelegate || rt->ty == Tarray) {
|
||||
rettype = llvm::PointerType::get(LLVM_DtoType(rt));
|
||||
actualRettype = llvm::Type::VoidTy;
|
||||
f->llvmRetInPtr = retinptr = true;
|
||||
}
|
||||
else {
|
||||
rettype = LLVM_DtoType(rt);
|
||||
actualRettype = rettype;
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// parameter types
|
||||
std::vector<const llvm::Type*> paramvec;
|
||||
|
||||
if (retinptr) {
|
||||
Logger::print("returning through pointer parameter\n");
|
||||
paramvec.push_back(rettype);
|
||||
}
|
||||
|
||||
if (needThis()) {
|
||||
if (AggregateDeclaration* ad = isMember()) {
|
||||
Logger::print("isMember = this is: %s\n", ad->type->toChars());
|
||||
const llvm::Type* thisty = LLVM_DtoType(ad->type);
|
||||
if (llvm::isa<llvm::StructType>(thisty))
|
||||
thisty = llvm::PointerType::get(thisty);
|
||||
paramvec.push_back(thisty);
|
||||
usesthis = true;
|
||||
}
|
||||
else
|
||||
assert(0);
|
||||
}
|
||||
|
||||
size_t n = Argument::dim(f->parameters);
|
||||
for (int i=0; i < n; ++i) {
|
||||
Argument* arg = Argument::getNth(f->parameters, i);
|
||||
// ensure scalar
|
||||
Type* argT = arg->type;
|
||||
assert(argT);
|
||||
|
||||
if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
|
||||
//assert(arg->vardecl);
|
||||
//arg->vardecl->refparam = true;
|
||||
}
|
||||
else
|
||||
arg->llvmCopy = true;
|
||||
|
||||
const llvm::Type* at = LLVM_DtoType(argT);
|
||||
if (llvm::isa<llvm::StructType>(at)) {
|
||||
Logger::println("struct param");
|
||||
paramvec.push_back(llvm::PointerType::get(at));
|
||||
}
|
||||
else if (llvm::isa<llvm::ArrayType>(at)) {
|
||||
Logger::println("sarray param");
|
||||
assert(argT->ty == Tsarray);
|
||||
//paramvec.push_back(llvm::PointerType::get(at->getContainedType(0)));
|
||||
paramvec.push_back(llvm::PointerType::get(at));
|
||||
}
|
||||
else {
|
||||
if (!arg->llvmCopy) {
|
||||
Logger::println("ref param");
|
||||
at = llvm::PointerType::get(at);
|
||||
}
|
||||
else {
|
||||
Logger::println("in param");
|
||||
}
|
||||
paramvec.push_back(at);
|
||||
}
|
||||
}
|
||||
|
||||
// construct function
|
||||
bool isvararg = f->varargs;
|
||||
llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg);
|
||||
|
||||
// mangled name
|
||||
char* mangled_name = (llvmInternal == LLVMintrinsic) ? llvmInternal1 : mangle();
|
||||
llvm::Function* func = gIR->module->getFunction(mangled_name);
|
||||
|
||||
// make the function
|
||||
/*if (func != 0) {
|
||||
llvmValue = func;
|
||||
f->llvmType = functype;
|
||||
return; // already pulled in from a forward declaration
|
||||
}
|
||||
else */
|
||||
if (func == 0) {
|
||||
func = new llvm::Function(functype,LLVM_DtoLinkage(protection, storage_class),mangled_name,gIR->module);
|
||||
}
|
||||
|
||||
if (llvmInternal != LLVMintrinsic)
|
||||
func->setCallingConv(LLVM_DtoCallingConv(f->linkage));
|
||||
|
||||
llvmValue = func;
|
||||
f->llvmType = functype;
|
||||
|
||||
if (isMain()) {
|
||||
gIR->mainFunc = func;
|
||||
}
|
||||
|
||||
// name parameters
|
||||
llvm::Function::arg_iterator iarg = func->arg_begin();
|
||||
int k = 0;
|
||||
int nunnamed = 0;
|
||||
if (retinptr) {
|
||||
iarg->setName("retval");
|
||||
f->llvmRetArg = iarg;
|
||||
++iarg;
|
||||
}
|
||||
if (usesthis) {
|
||||
iarg->setName("this");
|
||||
++iarg;
|
||||
}
|
||||
for (; iarg != func->arg_end(); ++iarg)
|
||||
{
|
||||
Argument* arg = Argument::getNth(f->parameters, k++);
|
||||
//arg->llvmValue = iarg;
|
||||
//printf("identifier: '%s' %p\n", arg->ident->toChars(), arg->ident);
|
||||
if (arg->ident != 0) {
|
||||
if (arg->vardecl) {
|
||||
arg->vardecl->llvmValue = iarg;
|
||||
}
|
||||
iarg->setName(arg->ident->toChars());
|
||||
}
|
||||
else {
|
||||
++nunnamed;
|
||||
}
|
||||
}
|
||||
|
||||
// only members of the current module maybe be defined
|
||||
if (getModule() == gIR->dmodule)
|
||||
{
|
||||
bool allow_fbody = true;
|
||||
// handle static constructor / destructor
|
||||
if (isStaticCtorDeclaration() || isStaticDtorDeclaration()) {
|
||||
const llvm::ArrayType* sctor_type = llvm::ArrayType::get(llvm::PointerType::get(functype),1);
|
||||
//Logger::cout() << "static ctor type: " << *sctor_type << '\n';
|
||||
|
||||
llvm::Constant* sctor_func = llvm::cast<llvm::Constant>(llvmValue);
|
||||
//Logger::cout() << "static ctor func: " << *sctor_func << '\n';
|
||||
|
||||
llvm::Constant* sctor_init = 0;
|
||||
if (llvmInternal == LLVMnull)
|
||||
{
|
||||
llvm::Constant* sctor_init_null = llvm::Constant::getNullValue(sctor_func->getType());
|
||||
sctor_init = llvm::ConstantArray::get(sctor_type,&sctor_init_null,1);
|
||||
allow_fbody = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sctor_init = llvm::ConstantArray::get(sctor_type,&sctor_func,1);
|
||||
}
|
||||
|
||||
//Logger::cout() << "static ctor init: " << *sctor_init << '\n';
|
||||
|
||||
|
||||
// output the llvm.global_ctors array
|
||||
const char* varname = isStaticCtorDeclaration() ? "_d_module_ctor_array" : "_d_module_dtor_array";
|
||||
llvm::GlobalVariable* sctor_arr = new llvm::GlobalVariable(sctor_type, false, llvm::GlobalValue::AppendingLinkage, sctor_init, varname, gIR->module);
|
||||
}
|
||||
|
||||
// function definition
|
||||
if (allow_fbody && fbody != 0)
|
||||
{
|
||||
assert(nunnamed == 0);
|
||||
gIR->funcs.push(func);
|
||||
gIR->functypes.push(f);
|
||||
|
||||
IRScope irs;
|
||||
irs.begin = new llvm::BasicBlock("entry",func);
|
||||
irs.end = new llvm::BasicBlock("endentry",func);
|
||||
|
||||
//assert(gIR->scopes.empty());
|
||||
gIR->scopes.push_back(irs);
|
||||
|
||||
// create alloca point
|
||||
f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb());
|
||||
|
||||
// output function body
|
||||
fbody->toIR(gIR);
|
||||
|
||||
// llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
|
||||
// in automatically, so we do it here.
|
||||
if (!isMain() && (gIR->scopebb()->empty() || !llvm::isa<llvm::TerminatorInst>(gIR->scopebb()->back()))) {
|
||||
// pass the previous block into this block
|
||||
//new llvm::BranchInst(irs.end, irs.begin);
|
||||
new llvm::ReturnInst(gIR->scopebb());
|
||||
}
|
||||
|
||||
// erase alloca point
|
||||
f->llvmAllocaPoint->eraseFromParent();
|
||||
f->llvmAllocaPoint = 0;
|
||||
|
||||
gIR->scopes.pop_back();
|
||||
//assert(gIR->scopes.empty());
|
||||
|
||||
gIR->functypes.pop();
|
||||
gIR->funcs.pop();
|
||||
|
||||
// get rid of the endentry block, it's never used
|
||||
func->getBasicBlockList().pop_back();
|
||||
|
||||
// if the last block is empty now, it must be unreachable or it's a bug somewhere else
|
||||
llvm::BasicBlock* lastbb = &func->getBasicBlockList().back();
|
||||
if (lastbb->empty()) {
|
||||
new llvm::UnreachableInst(lastbb);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::println("only declaration");
|
||||
}
|
||||
|
||||
llvmDModule = gIR->dmodule;
|
||||
|
||||
Logger::println("FuncDeclaration done\n");
|
||||
}
|
||||
+403
@@ -0,0 +1,403 @@
|
||||
|
||||
|
||||
// Copyright (c) 1999-2004 by Digital Mars
|
||||
// All Rights Reserved
|
||||
// written by Walter Bright
|
||||
// www.digitalmars.com
|
||||
// License for redistribution is by either the Artistic License
|
||||
// in artistic.txt, or the GNU General Public License in gnu.txt.
|
||||
// See the included readme.txt for details.
|
||||
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
|
||||
#include "mars.h"
|
||||
#include "module.h"
|
||||
#include "mtype.h"
|
||||
#include "scope.h"
|
||||
#include "init.h"
|
||||
#include "expression.h"
|
||||
#include "attrib.h"
|
||||
#include "declaration.h"
|
||||
#include "template.h"
|
||||
#include "id.h"
|
||||
#include "enum.h"
|
||||
#include "import.h"
|
||||
#include "aggregate.h"
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
/*******************************************
|
||||
|
||||
* Get a canonicalized form of the TypeInfo for use with the internal
|
||||
|
||||
* runtime library routines. Canonicalized in that static arrays are
|
||||
|
||||
* represented as dynamic arrays, enums are represented by their
|
||||
|
||||
* underlying type, etc. This reduces the number of TypeInfo's needed,
|
||||
|
||||
* so we can use the custom internal ones more.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Expression *Type::getInternalTypeInfo(Scope *sc)
|
||||
|
||||
{ TypeInfoDeclaration *tid;
|
||||
|
||||
Expression *e;
|
||||
|
||||
Type *t;
|
||||
|
||||
static TypeInfoDeclaration *internalTI[TMAX];
|
||||
|
||||
|
||||
|
||||
//printf("Type::getInternalTypeInfo() %s\n", toChars());
|
||||
|
||||
t = toBasetype();
|
||||
|
||||
switch (t->ty)
|
||||
|
||||
{
|
||||
|
||||
case Tsarray:
|
||||
|
||||
t = t->next->arrayOf(); // convert to corresponding dynamic array type
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case Tclass:
|
||||
|
||||
if (((TypeClass *)t)->sym->isInterfaceDeclaration())
|
||||
|
||||
break;
|
||||
|
||||
goto Linternal;
|
||||
|
||||
|
||||
|
||||
case Tarray:
|
||||
|
||||
if (t->next->ty != Tclass)
|
||||
|
||||
break;
|
||||
|
||||
goto Linternal;
|
||||
|
||||
|
||||
|
||||
case Tfunction:
|
||||
|
||||
case Tdelegate:
|
||||
|
||||
case Tpointer:
|
||||
|
||||
Linternal:
|
||||
|
||||
tid = internalTI[t->ty];
|
||||
|
||||
if (!tid)
|
||||
|
||||
{ tid = new TypeInfoDeclaration(t, 1);
|
||||
|
||||
internalTI[t->ty] = tid;
|
||||
|
||||
}
|
||||
|
||||
e = new VarExp(0, tid);
|
||||
|
||||
e = e->addressOf(sc);
|
||||
|
||||
e->type = tid->type; // do this so we don't get redundant dereference
|
||||
|
||||
return e;
|
||||
|
||||
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
//printf("\tcalling getTypeInfo() %s\n", t->toChars());
|
||||
|
||||
return t->getTypeInfo(sc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/****************************************************
|
||||
|
||||
* Get the exact TypeInfo.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Expression *Type::getTypeInfo(Scope *sc)
|
||||
|
||||
{
|
||||
|
||||
Expression *e;
|
||||
|
||||
Type *t;
|
||||
|
||||
|
||||
|
||||
//printf("Type::getTypeInfo() %p, %s\n", this, toChars());
|
||||
|
||||
t = merge(); // do this since not all Type's are merge'd
|
||||
|
||||
if (!t->vtinfo)
|
||||
|
||||
{ t->vtinfo = t->getTypeInfoDeclaration();
|
||||
|
||||
assert(t->vtinfo);
|
||||
|
||||
|
||||
|
||||
/* If this has a custom implementation in std/typeinfo, then
|
||||
|
||||
* do not generate a COMDAT for it.
|
||||
|
||||
*/
|
||||
|
||||
if (!t->builtinTypeInfo())
|
||||
|
||||
{ // Generate COMDAT
|
||||
|
||||
if (sc) // if in semantic() pass
|
||||
|
||||
{ // Find module that will go all the way to an object file
|
||||
|
||||
Module *m = sc->module->importedFrom;
|
||||
|
||||
m->members->push(t->vtinfo);
|
||||
|
||||
}
|
||||
|
||||
else // if in obj generation pass
|
||||
|
||||
{
|
||||
|
||||
t->vtinfo->toObjFile();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
e = new VarExp(0, t->vtinfo);
|
||||
|
||||
//e = e->addressOf(sc);
|
||||
e->type = t->vtinfo->type; // do this so we don't get redundant dereference
|
||||
|
||||
return e;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *Type::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
//printf("Type::getTypeInfoDeclaration() %s\n", toChars());
|
||||
|
||||
return new TypeInfoDeclaration(this, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeTypedef::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoTypedefDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoPointerDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeDArray::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoArrayDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeSArray::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoStaticArrayDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeAArray::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoAssociativeArrayDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeStruct::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoStructDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeClass::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
if (sym->isInterfaceDeclaration())
|
||||
|
||||
return new TypeInfoInterfaceDeclaration(this);
|
||||
|
||||
else
|
||||
|
||||
return new TypeInfoClassDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeEnum::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoEnumDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeFunction::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoFunctionDeclaration(this);
|
||||
|
||||
}
|
||||
enum RET TypeFunction::retStyle()
|
||||
|
||||
{
|
||||
|
||||
return RETstack;
|
||||
|
||||
}
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeDelegate::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoDelegateDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
TypeInfoDeclaration *TypeTuple::getTypeInfoDeclaration()
|
||||
|
||||
{
|
||||
|
||||
return new TypeInfoTupleDeclaration(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TypeInfoDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
|
||||
void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
|
||||
void TypeInfoStructDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
|
||||
void TypeInfoClassDeclaration::toDt(dt_t **pdt)
|
||||
{
|
||||
}
|
||||
|
||||
void TypeInfoDeclaration::toObjFile()
|
||||
{
|
||||
Logger::println("TypeInfoDeclaration::toObjFile()");
|
||||
LOG_SCOPE;
|
||||
Logger::println("type = '%s'", tinfo->toChars());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
/* These decide if there's an instance for them already in std.typeinfo,
|
||||
* because then the compiler doesn't need to build one.
|
||||
*/
|
||||
|
||||
int Type::builtinTypeInfo()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TypeBasic::builtinTypeInfo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TypeDArray::builtinTypeInfo()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
/***************************************
|
||||
* Create a static array of TypeInfo references
|
||||
* corresponding to an array of Expression's.
|
||||
* Used to supply hidden _arguments[] value for variadic D functions.
|
||||
*/
|
||||
|
||||
Expression *createTypeInfoArray(Scope *sc, Expression *args[], int dim)
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user