From: Devang Patel Date: Wed, 31 Oct 2007 20:01:01 +0000 (+0000) Subject: Take 2. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a4718e813e5e99d478567a482217c7eef8572c5;p=clang Take 2. Make target info available to clang code generator. This is far from complete but this helps clang codegen module make progress. At the moment target triplet and target description strings are hard coded in clang::TargetInfo git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43572 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp index 70cefea364..a2023e441f 100644 --- a/CodeGen/CodeGenModule.cpp +++ b/CodeGen/CodeGenModule.cpp @@ -24,9 +24,10 @@ using namespace clang; using namespace CodeGen; -CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M) - : Context(C), TheModule(M), - Types(C, M), MemCpyFn(0), CFConstantStringClassRef(0) {} +CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M, + const llvm::TargetData &TD) + : Context(C), TheModule(M), TheTargetData(TD), + Types(C, M, TD), MemCpyFn(0), CFConstantStringClassRef(0) {} llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) { // See if it is already in the map. diff --git a/CodeGen/CodeGenModule.h b/CodeGen/CodeGenModule.h index 4ca4f8c550..a044c0d02e 100644 --- a/CodeGen/CodeGenModule.h +++ b/CodeGen/CodeGenModule.h @@ -23,6 +23,7 @@ namespace llvm { class Constant; class Function; class GlobalVariable; + class TargetData; } namespace clang { @@ -39,6 +40,7 @@ namespace CodeGen { class CodeGenModule { ASTContext &Context; llvm::Module &TheModule; + const llvm::TargetData &TheTargetData; CodeGenTypes Types; llvm::Function *MemCpyFn; @@ -49,7 +51,7 @@ class CodeGenModule { std::vector BuiltinFunctions; public: - CodeGenModule(ASTContext &C, llvm::Module &M); + CodeGenModule(ASTContext &C, llvm::Module &M, const llvm::TargetData &TD); ASTContext &getContext() const { return Context; } llvm::Module &getModule() const { return TheModule; } diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp index 017b65c152..b65d596db7 100644 --- a/CodeGen/CodeGenTypes.cpp +++ b/CodeGen/CodeGenTypes.cpp @@ -60,8 +60,9 @@ namespace { }; } -CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M) - : Context(Ctx), Target(Ctx.Target), TheModule(M) { +CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M, + const llvm::TargetData &TD) + : Context(Ctx), Target(Ctx.Target), TheModule(M), TheTargetData(TD) { } CodeGenTypes::~CodeGenTypes() { diff --git a/CodeGen/CodeGenTypes.h b/CodeGen/CodeGenTypes.h index 95aea85c8e..fe012f70f3 100644 --- a/CodeGen/CodeGenTypes.h +++ b/CodeGen/CodeGenTypes.h @@ -21,6 +21,7 @@ namespace llvm { class Module; class Type; class PATypeHolder; + class TargetData; } namespace clang { @@ -61,6 +62,7 @@ class CodeGenTypes { ASTContext &Context; TargetInfo &Target; llvm::Module& TheModule; + const llvm::TargetData& TheTargetData; llvm::DenseMap TagDeclTypes; @@ -91,7 +93,7 @@ class CodeGenTypes { /// interface to convert type T into a llvm::Type. const llvm::Type *ConvertNewType(QualType T); public: - CodeGenTypes(ASTContext &Ctx, llvm::Module &M); + CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::TargetData &TD); ~CodeGenTypes(); TargetInfo &getTarget() const { return Target; } diff --git a/CodeGen/ModuleBuilder.cpp b/CodeGen/ModuleBuilder.cpp index 4a5a470563..a7586b64c2 100644 --- a/CodeGen/ModuleBuilder.cpp +++ b/CodeGen/ModuleBuilder.cpp @@ -18,8 +18,9 @@ using namespace clang; /// Init - Create an ModuleBuilder with the specified ASTContext. clang::CodeGen::BuilderTy * -clang::CodeGen::Init(ASTContext &Context, llvm::Module &M) { - return new CodeGenModule(Context, M); +clang::CodeGen::Init(ASTContext &Context, llvm::Module &M, + const llvm::TargetData &TD) { + return new CodeGenModule(Context, M, TD); } void clang::CodeGen::Terminate(BuilderTy *B) { diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 37d637bf10..04c238287a 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -379,14 +379,18 @@ ASTConsumer *clang::CreateUnitValsChecker(Diagnostic &Diags) { // LLVM Emitter #include "clang/Basic/Diagnostic.h" +#include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/ModuleBuilder.h" #include "llvm/Module.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetMachine.h" #include namespace { class LLVMEmitter : public ASTConsumer { Diagnostic &Diags; llvm::Module *M; + const llvm::TargetData *TD; ASTContext *Ctx; CodeGen::BuilderTy *Builder; public: @@ -394,7 +398,9 @@ namespace { virtual void Initialize(ASTContext &Context, unsigned MainFileID) { Ctx = &Context; M = new llvm::Module("foo"); - Builder = CodeGen::Init(Context, *M); + M->setTargetTriple(Ctx->Target.getTargetTriple()); + TD = new llvm::TargetData(Ctx->Target.getTargetDescription()); + Builder = CodeGen::Init(Context, *M, *TD); } virtual void HandleTopLevelDecl(Decl *D) { diff --git a/Driver/Makefile b/Driver/Makefile index 6d2cfe0a75..7262cdc74a 100644 --- a/Driver/Makefile +++ b/Driver/Makefile @@ -6,6 +6,8 @@ TOOLNAME = clang USEDLIBS = clangCodeGen.a clangAnalysis.a clangRewrite.a clangSEMA.a \ clangAST.a clangParse.a clangLex.a clangBasic.a \ LLVMCore.a LLVMSupport.a LLVMSystem.a \ - LLVMBitWriter.a LLVMBitReader.a + LLVMBitWriter.a LLVMBitReader.a LLVMTarget.a + + include $(LEVEL)/Makefile.common diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index 334f87851d..0637af864b 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -218,6 +218,17 @@ public: getLongLongInfo(Size, Align, Loc); return static_cast(Size); } + + const char *getTargetTriple() { + // FIXME ! + return "i686-apple-darwin9"; + } + const char *getTargetDescription() { + // FIXME ! + // Hard code darwin-x86 for now. + return "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:\ +32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"; + } private: void ComputeWCharInfo(SourceLocation Loc); }; diff --git a/include/clang/CodeGen/ModuleBuilder.h b/include/clang/CodeGen/ModuleBuilder.h index 0b1ae476ed..96b0f59b8e 100644 --- a/include/clang/CodeGen/ModuleBuilder.h +++ b/include/clang/CodeGen/ModuleBuilder.h @@ -16,6 +16,7 @@ namespace llvm { class Module; + class TargetData; } namespace clang { @@ -29,7 +30,8 @@ namespace CodeGen { typedef void BuilderTy; /// 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. ///