зеркало из https://github.com/microsoft/clang-1.git
Make target info available to clang code generator.
This is far from complete but this helps clang codegen module make progress. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43536 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
8be9d0a9cd
Коммит
f767e218ee
|
@ -24,8 +24,10 @@ using namespace clang;
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
|
|
||||||
CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M)
|
CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M,
|
||||||
: Context(C), TheModule(M), Types(C, M), CFConstantStringClassRef(0) {}
|
const llvm::TargetData &TD)
|
||||||
|
: Context(C), TheModule(M), TheTargetData(TD),
|
||||||
|
Types(C, M, TD), CFConstantStringClassRef(0) {}
|
||||||
|
|
||||||
llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) {
|
llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) {
|
||||||
// See if it is already in the map.
|
// See if it is already in the map.
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace llvm {
|
||||||
class Constant;
|
class Constant;
|
||||||
class Function;
|
class Function;
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
|
class TargetData;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
@ -39,6 +40,7 @@ namespace CodeGen {
|
||||||
class CodeGenModule {
|
class CodeGenModule {
|
||||||
ASTContext &Context;
|
ASTContext &Context;
|
||||||
llvm::Module &TheModule;
|
llvm::Module &TheModule;
|
||||||
|
const llvm::TargetData &TheTargetData;
|
||||||
CodeGenTypes Types;
|
CodeGenTypes Types;
|
||||||
|
|
||||||
llvm::Function *MemCpyFn;
|
llvm::Function *MemCpyFn;
|
||||||
|
@ -49,7 +51,7 @@ class CodeGenModule {
|
||||||
|
|
||||||
std::vector<llvm::Function *> BuiltinFunctions;
|
std::vector<llvm::Function *> BuiltinFunctions;
|
||||||
public:
|
public:
|
||||||
CodeGenModule(ASTContext &C, llvm::Module &M);
|
CodeGenModule(ASTContext &C, llvm::Module &M, const llvm::TargetData &TD);
|
||||||
|
|
||||||
ASTContext &getContext() const { return Context; }
|
ASTContext &getContext() const { return Context; }
|
||||||
llvm::Module &getModule() const { return TheModule; }
|
llvm::Module &getModule() const { return TheModule; }
|
||||||
|
|
|
@ -60,8 +60,9 @@ namespace {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M)
|
CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M,
|
||||||
: Context(Ctx), Target(Ctx.Target), TheModule(M) {
|
const llvm::TargetData &TD)
|
||||||
|
: Context(Ctx), Target(Ctx.Target), TheModule(M), TheTargetData(TD) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeGenTypes::~CodeGenTypes() {
|
CodeGenTypes::~CodeGenTypes() {
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace llvm {
|
||||||
class Module;
|
class Module;
|
||||||
class Type;
|
class Type;
|
||||||
class PATypeHolder;
|
class PATypeHolder;
|
||||||
|
class TargetData;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
@ -61,6 +62,7 @@ class CodeGenTypes {
|
||||||
ASTContext &Context;
|
ASTContext &Context;
|
||||||
TargetInfo &Target;
|
TargetInfo &Target;
|
||||||
llvm::Module& TheModule;
|
llvm::Module& TheModule;
|
||||||
|
const llvm::TargetData& TheTargetData;
|
||||||
|
|
||||||
llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes;
|
llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes;
|
||||||
|
|
||||||
|
@ -91,7 +93,7 @@ class CodeGenTypes {
|
||||||
/// interface to convert type T into a llvm::Type.
|
/// interface to convert type T into a llvm::Type.
|
||||||
const llvm::Type *ConvertNewType(QualType T);
|
const llvm::Type *ConvertNewType(QualType T);
|
||||||
public:
|
public:
|
||||||
CodeGenTypes(ASTContext &Ctx, llvm::Module &M);
|
CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::TargetData &TD);
|
||||||
~CodeGenTypes();
|
~CodeGenTypes();
|
||||||
|
|
||||||
TargetInfo &getTarget() const { return Target; }
|
TargetInfo &getTarget() const { return Target; }
|
||||||
|
|
|
@ -18,8 +18,9 @@ using namespace clang;
|
||||||
|
|
||||||
/// Init - Create an ModuleBuilder with the specified ASTContext.
|
/// Init - Create an ModuleBuilder with the specified ASTContext.
|
||||||
clang::CodeGen::BuilderTy *
|
clang::CodeGen::BuilderTy *
|
||||||
clang::CodeGen::Init(ASTContext &Context, llvm::Module &M) {
|
clang::CodeGen::Init(ASTContext &Context, llvm::Module &M,
|
||||||
return new CodeGenModule(Context, M);
|
const llvm::TargetData &TD) {
|
||||||
|
return new CodeGenModule(Context, M, TD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clang::CodeGen::Terminate(BuilderTy *B) {
|
void clang::CodeGen::Terminate(BuilderTy *B) {
|
||||||
|
|
|
@ -379,14 +379,19 @@ ASTConsumer *clang::CreateUnitValsChecker(Diagnostic &Diags) {
|
||||||
// LLVM Emitter
|
// LLVM Emitter
|
||||||
|
|
||||||
#include "clang/Basic/Diagnostic.h"
|
#include "clang/Basic/Diagnostic.h"
|
||||||
|
#include "clang/Basic/TargetInfo.h"
|
||||||
#include "clang/CodeGen/ModuleBuilder.h"
|
#include "clang/CodeGen/ModuleBuilder.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
#include "llvm/Target/TargetMachineRegistry.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class LLVMEmitter : public ASTConsumer {
|
class LLVMEmitter : public ASTConsumer {
|
||||||
Diagnostic &Diags;
|
Diagnostic &Diags;
|
||||||
llvm::Module *M;
|
llvm::Module *M;
|
||||||
|
const llvm::TargetData *TD;
|
||||||
ASTContext *Ctx;
|
ASTContext *Ctx;
|
||||||
CodeGen::BuilderTy *Builder;
|
CodeGen::BuilderTy *Builder;
|
||||||
public:
|
public:
|
||||||
|
@ -394,7 +399,16 @@ namespace {
|
||||||
virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
|
virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
|
||||||
Ctx = &Context;
|
Ctx = &Context;
|
||||||
M = new llvm::Module("foo");
|
M = new llvm::Module("foo");
|
||||||
Builder = CodeGen::Init(Context, *M);
|
M->setTargetTriple(Ctx->Target.getTargetTriple());
|
||||||
|
std::string Err;
|
||||||
|
const llvm::TargetMachineRegistry::entry *TME =
|
||||||
|
llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*M, Err);
|
||||||
|
assert(TME && "Unable to determine target machine");
|
||||||
|
// FIXME : Set appropriate subtarget features.
|
||||||
|
std::string FeatureStr;
|
||||||
|
llvm::TargetMachine *TheMachine = TME->CtorFn(*M, FeatureStr);
|
||||||
|
TD = TheMachine->getTargetData();
|
||||||
|
Builder = CodeGen::Init(Context, *M, *TD);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void HandleTopLevelDecl(Decl *D) {
|
virtual void HandleTopLevelDecl(Decl *D) {
|
||||||
|
|
|
@ -4,8 +4,12 @@ CXXFLAGS = -fno-rtti
|
||||||
|
|
||||||
TOOLNAME = clang
|
TOOLNAME = clang
|
||||||
USEDLIBS = clangCodeGen.a clangAnalysis.a clangRewrite.a clangSEMA.a \
|
USEDLIBS = clangCodeGen.a clangAnalysis.a clangRewrite.a clangSEMA.a \
|
||||||
clangAST.a clangParse.a clangLex.a clangBasic.a \
|
clangAST.a clangParse.a clangLex.a clangBasic.a LLVMX86 \
|
||||||
LLVMCore.a LLVMSupport.a LLVMSystem.a \
|
LLVMCore.a LLVMSupport.a LLVMSystem.a \
|
||||||
LLVMBitWriter.a LLVMBitReader.a
|
LLVMBitWriter.a LLVMBitReader.a LLVMTarget.a LLVMCodeGen.a \
|
||||||
|
LLVMSelectionDAG.a LLVMScalarOpts.a LLVMTransformUtils.a \
|
||||||
|
LLVMCore.a LLVMAnalysis.a
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include $(LEVEL)/Makefile.common
|
include $(LEVEL)/Makefile.common
|
||||||
|
|
|
@ -218,6 +218,11 @@ public:
|
||||||
getLongLongInfo(Size, Align, Loc);
|
getLongLongInfo(Size, Align, Loc);
|
||||||
return static_cast<unsigned>(Size);
|
return static_cast<unsigned>(Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *getTargetTriple() {
|
||||||
|
// FIXME !
|
||||||
|
return "i686-apple-darwin9";
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void ComputeWCharInfo(SourceLocation Loc);
|
void ComputeWCharInfo(SourceLocation Loc);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Module;
|
class Module;
|
||||||
|
class TargetData;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
@ -29,7 +30,8 @@ namespace CodeGen {
|
||||||
typedef void BuilderTy;
|
typedef void BuilderTy;
|
||||||
|
|
||||||
/// Init - Create an ModuleBuilder with the specified ASTContext.
|
/// Init - Create an ModuleBuilder with the specified ASTContext.
|
||||||
BuilderTy *Init(ASTContext &Context, llvm::Module &M);
|
BuilderTy *Init(ASTContext &Context, llvm::Module &M,
|
||||||
|
const llvm::TargetData &TD);
|
||||||
|
|
||||||
/// CodeGenFunction - Convert the AST node for a FunctionDecl into LLVM.
|
/// CodeGenFunction - Convert the AST node for a FunctionDecl into LLVM.
|
||||||
///
|
///
|
||||||
|
|
Загрузка…
Ссылка в новой задаче