using namespace CodeGen;
-CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M)
- : Context(C), TheModule(M), Types(C, M), CFConstantStringClassRef(0) {}
+CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M,
+ const llvm::TargetData &TD)
+ : Context(C), TheModule(M), TheTargetData(TD),
+ Types(C, M, TD), CFConstantStringClassRef(0) {}
llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) {
// See if it is already in the map.
class Constant;
class Function;
class GlobalVariable;
+ class TargetData;
}
namespace clang {
class CodeGenModule {
ASTContext &Context;
llvm::Module &TheModule;
+ const llvm::TargetData &TheTargetData;
CodeGenTypes Types;
llvm::Function *MemCpyFn;
std::vector<llvm::Function *> 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; }
};
}
-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() {
class Module;
class Type;
class PATypeHolder;
+ class TargetData;
}
namespace clang {
ASTContext &Context;
TargetInfo &Target;
llvm::Module& TheModule;
+ const llvm::TargetData& TheTargetData;
llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes;
/// 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; }
/// 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) {
// 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 "llvm/Target/TargetMachineRegistry.h"
#include <iostream>
namespace {
class LLVMEmitter : public ASTConsumer {
Diagnostic &Diags;
llvm::Module *M;
+ const llvm::TargetData *TD;
ASTContext *Ctx;
CodeGen::BuilderTy *Builder;
public:
virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
Ctx = &Context;
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) {
TOOLNAME = clang
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 \
- 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
getLongLongInfo(Size, Align, Loc);
return static_cast<unsigned>(Size);
}
+
+ const char *getTargetTriple() {
+ // FIXME !
+ return "i686-apple-darwin9";
+ }
private:
void ComputeWCharInfo(SourceLocation Loc);
};
namespace llvm {
class Module;
+ class TargetData;
}
namespace clang {
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.
///