Index: include/clang/Basic/TargetInfo.h =================================================================== --- include/clang/Basic/TargetInfo.h (revision 50341) +++ include/clang/Basic/TargetInfo.h (working copy) @@ -59,8 +59,8 @@ /// getPointerWidth - Return the width of pointers on this target, for the /// specified address space. FIXME: implement correctly. - uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; } - uint64_t getPointerAlign(unsigned AddrSpace) const { return 32; } + virtual uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; } + virtual uint64_t getPointerAlign(unsigned AddrSpace) const { return 32; } /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this /// target, in bits. @@ -81,8 +81,8 @@ /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for /// this target, in bits. - unsigned getIntWidth() const { return 32; } // FIXME - unsigned getIntAlign() const { return 32; } // FIXME + virtual unsigned getIntWidth() const { return 32; } // FIXME + virtual unsigned getIntAlign() const { return 32; } // FIXME /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' /// for this target, in bits. Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp (revision 50341) +++ lib/Basic/Targets.cpp (working copy) @@ -863,6 +863,28 @@ } // end anonymous namespace. +namespace { +class PIC16TargetInfo : public TargetInfo{ +public: + PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) {} + virtual uint64_t getPointerWidth(unsigned AddrSpace) const { return 16; } + virtual uint64_t getPointerAlign(unsigned AddrSpace) const { return 8; } + virtual unsigned getIntWidth() const { return 16; } + virtual unsigned getIntAlign() const { return 8; } + virtual void getTargetDefines(std::vector &Defines) const { + Define(Defines, "__pic16"); + } + virtual void getTargetBuiltins(const Builtin::Info *&Records, + unsigned &NumRecords) const {} + virtual const char *getVAListDeclaration() const { return "";} + virtual const char *getClobbers() const {return "";} + virtual const char *getTargetPrefix() const {return "";} + virtual void getGCCRegNames(const char * const *&Names, unsigned &NumNames) const {} + virtual bool validateAsmConstraint(char c, TargetInfo::ConstraintInfo &info) const {return true;} + virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, unsigned &NumAliases) const {} +}; +} + //===----------------------------------------------------------------------===// // Driver code //===----------------------------------------------------------------------===// @@ -890,6 +912,9 @@ if (T.find("x86_64-") == 0) return new DarwinX86_64TargetInfo(T); + if (T.find("pic16-") == 0) + return new PIC16TargetInfo(T); + if (IsX86(T)) return new DarwinI386TargetInfo(T); Index: lib/CodeGen/CGDecl.cpp =================================================================== --- lib/CodeGen/CGDecl.cpp (revision 50341) +++ lib/CodeGen/CGDecl.cpp (working copy) @@ -15,6 +15,7 @@ #include "CodeGenModule.h" #include "clang/AST/AST.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/TargetInfo.h" #include "llvm/GlobalVariable.h" #include "llvm/Type.h" using namespace clang; @@ -113,10 +114,35 @@ llvm::Value *DeclPtr; if (Ty->isConstantSizeType()) { - // A normal fixed sized variable becomes an alloca in the entry block. - const llvm::Type *LTy = ConvertType(Ty); - // TODO: Alignment - DeclPtr = CreateTempAlloca(LTy, D.getName()); + if (strncmp (this->Target.getTargetTriple(), "pic16-", 6) == 0) { + const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty); + llvm::Constant *Init = 0; + if (D.getInit() == 0) { + Init = llvm::Constant::getNullValue(LTy); + } else { + Init = CGM.EmitConstantExpr(D.getInit(), this); + } + + assert(Init && "Unable to create initialiser for static decl"); + + std::string ContextName; + if (const FunctionDecl * FD = dyn_cast(CurFuncDecl)) + ContextName = FD->getName(); + else + assert(0 && "Unknown context for block var decl"); // FIXME Handle objc. + + DeclPtr = + new llvm::GlobalVariable(LTy, false, llvm::GlobalValue::InternalLinkage, + Init, ContextName + "_ovr_" + D.getName(), + &CGM.getModule(), 0, Ty.getAddressSpace()); + + } + else { + // A normal fixed sized variable becomes an alloca in the entry block. + const llvm::Type *LTy = ConvertType(Ty); + // TODO: Alignment + DeclPtr = CreateTempAlloca(LTy, D.getName()); + } } else { // TODO: Create a dynamic alloca. assert(0 && "FIXME: Local VLAs not implemented yet"); @@ -148,20 +174,37 @@ // Variable sized values always are passed by-reference. DeclPtr = Arg; } else { - // A fixed sized first class variable becomes an alloca in the entry block. - const llvm::Type *LTy = ConvertType(Ty); - if (LTy->isFirstClassType()) { - // TODO: Alignment - DeclPtr = new llvm::AllocaInst(LTy, 0, std::string(D.getName())+".addr", - AllocaInsertPt); + if (strncmp(this->Target.getTargetTriple(), "pic16-", 6) == 0){ + const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty); - // Store the initial value into the alloca. - Builder.CreateStore(Arg, DeclPtr); + llvm::Constant *Init = llvm::Constant::getNullValue(LTy); + + std::string ContextName; + if (const FunctionDecl * FD = dyn_cast(CurFuncDecl)) + ContextName = FD->getName(); + else + assert(0 && "Unknown context for block var decl"); // FIXME Handle objc. + + DeclPtr = + new llvm::GlobalVariable(LTy, false, llvm::GlobalValue::InternalLinkage, + Init, ContextName + "_arg_" + D.getName(), + &CGM.getModule(), 0, Ty.getAddressSpace()); } else { - // Otherwise, if this is an aggregate, just use the input pointer. - DeclPtr = Arg; + // A fixed sized first class variable becomes an alloca in the entry block. + const llvm::Type *LTy = ConvertType(Ty); + if (LTy->isFirstClassType()) { + // TODO: Alignment + DeclPtr = new llvm::AllocaInst(LTy, 0, std::string(D.getName())+".addr", + AllocaInsertPt); + + // Store the initial value into the alloca. + Builder.CreateStore(Arg, DeclPtr); + } else { + // Otherwise, if this is an aggregate, just use the input pointer. + DeclPtr = Arg; + } + Arg->setName(D.getName()); } - Arg->setName(D.getName()); } llvm::Value *&DMEntry = LocalDeclMap[&D];