Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1 | //===--- PCHWriter.h - Precompiled Headers Writer ---------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the PCHWriter class, which writes a precompiled header. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Frontend/PCHWriter.h" |
Douglas Gregor | e778504 | 2009-04-20 15:53:59 +0000 | [diff] [blame] | 15 | #include "../Sema/Sema.h" // FIXME: move header into include/clang/Sema |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 16 | #include "../Sema/IdentifierResolver.h" // FIXME: move header |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclContextInternals.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 21 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 22 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 23 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 24 | #include "clang/Lex/PreprocessingRecord.h" |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 26 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 27 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 28 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 29 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 30 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 31 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 32 | #include "clang/Basic/Version.h" |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/APFloat.h" |
| 34 | #include "llvm/ADT/APInt.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 36 | #include "llvm/Bitcode/BitstreamWriter.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 37 | #include "llvm/Support/MemoryBuffer.h" |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 38 | #include "llvm/System/Path.h" |
Chris Lattner | 3c304bd | 2009-04-11 18:40:46 +0000 | [diff] [blame] | 39 | #include <cstdio> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | using namespace clang; |
| 41 | |
| 42 | //===----------------------------------------------------------------------===// |
| 43 | // Type serialization |
| 44 | //===----------------------------------------------------------------------===// |
Chris Lattner | 12b1c76 | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 45 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 46 | namespace { |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 47 | class PCHTypeWriter { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | PCHWriter &Writer; |
| 49 | PCHWriter::RecordData &Record; |
| 50 | |
| 51 | public: |
| 52 | /// \brief Type code that corresponds to the record generated. |
| 53 | pch::TypeCode Code; |
| 54 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | PCHTypeWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 56 | : Writer(Writer), Record(Record), Code(pch::TYPE_EXT_QUAL) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 57 | |
| 58 | void VisitArrayType(const ArrayType *T); |
| 59 | void VisitFunctionType(const FunctionType *T); |
| 60 | void VisitTagType(const TagType *T); |
| 61 | |
| 62 | #define TYPE(Class, Base) void Visit##Class##Type(const Class##Type *T); |
| 63 | #define ABSTRACT_TYPE(Class, Base) |
| 64 | #define DEPENDENT_TYPE(Class, Base) |
| 65 | #include "clang/AST/TypeNodes.def" |
| 66 | }; |
| 67 | } |
| 68 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 69 | void PCHTypeWriter::VisitBuiltinType(const BuiltinType *T) { |
| 70 | assert(false && "Built-in types are never serialized"); |
| 71 | } |
| 72 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 73 | void PCHTypeWriter::VisitComplexType(const ComplexType *T) { |
| 74 | Writer.AddTypeRef(T->getElementType(), Record); |
| 75 | Code = pch::TYPE_COMPLEX; |
| 76 | } |
| 77 | |
| 78 | void PCHTypeWriter::VisitPointerType(const PointerType *T) { |
| 79 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 80 | Code = pch::TYPE_POINTER; |
| 81 | } |
| 82 | |
| 83 | void PCHTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 85 | Code = pch::TYPE_BLOCK_POINTER; |
| 86 | } |
| 87 | |
| 88 | void PCHTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) { |
| 89 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 90 | Code = pch::TYPE_LVALUE_REFERENCE; |
| 91 | } |
| 92 | |
| 93 | void PCHTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) { |
| 94 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 95 | Code = pch::TYPE_RVALUE_REFERENCE; |
| 96 | } |
| 97 | |
| 98 | void PCHTypeWriter::VisitMemberPointerType(const MemberPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | Writer.AddTypeRef(T->getPointeeType(), Record); |
| 100 | Writer.AddTypeRef(QualType(T->getClass(), 0), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 101 | Code = pch::TYPE_MEMBER_POINTER; |
| 102 | } |
| 103 | |
| 104 | void PCHTypeWriter::VisitArrayType(const ArrayType *T) { |
| 105 | Writer.AddTypeRef(T->getElementType(), Record); |
| 106 | Record.push_back(T->getSizeModifier()); // FIXME: stable values |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 107 | Record.push_back(T->getIndexTypeCVRQualifiers()); // FIXME: stable values |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void PCHTypeWriter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 111 | VisitArrayType(T); |
| 112 | Writer.AddAPInt(T->getSize(), Record); |
| 113 | Code = pch::TYPE_CONSTANT_ARRAY; |
| 114 | } |
| 115 | |
| 116 | void PCHTypeWriter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
| 117 | VisitArrayType(T); |
| 118 | Code = pch::TYPE_INCOMPLETE_ARRAY; |
| 119 | } |
| 120 | |
| 121 | void PCHTypeWriter::VisitVariableArrayType(const VariableArrayType *T) { |
| 122 | VisitArrayType(T); |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 123 | Writer.AddSourceLocation(T->getLBracketLoc(), Record); |
| 124 | Writer.AddSourceLocation(T->getRBracketLoc(), Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 125 | Writer.AddStmt(T->getSizeExpr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 126 | Code = pch::TYPE_VARIABLE_ARRAY; |
| 127 | } |
| 128 | |
| 129 | void PCHTypeWriter::VisitVectorType(const VectorType *T) { |
| 130 | Writer.AddTypeRef(T->getElementType(), Record); |
| 131 | Record.push_back(T->getNumElements()); |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 132 | Record.push_back(T->isAltiVec()); |
| 133 | Record.push_back(T->isPixel()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 134 | Code = pch::TYPE_VECTOR; |
| 135 | } |
| 136 | |
| 137 | void PCHTypeWriter::VisitExtVectorType(const ExtVectorType *T) { |
| 138 | VisitVectorType(T); |
| 139 | Code = pch::TYPE_EXT_VECTOR; |
| 140 | } |
| 141 | |
| 142 | void PCHTypeWriter::VisitFunctionType(const FunctionType *T) { |
| 143 | Writer.AddTypeRef(T->getResultType(), Record); |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 144 | FunctionType::ExtInfo C = T->getExtInfo(); |
| 145 | Record.push_back(C.getNoReturn()); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame^] | 146 | Record.push_back(C.getRegParm()); |
Douglas Gregor | ab8bbf4 | 2010-01-18 17:14:39 +0000 | [diff] [blame] | 147 | // FIXME: need to stabilize encoding of calling convention... |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 148 | Record.push_back(C.getCC()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void PCHTypeWriter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
| 152 | VisitFunctionType(T); |
| 153 | Code = pch::TYPE_FUNCTION_NO_PROTO; |
| 154 | } |
| 155 | |
| 156 | void PCHTypeWriter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 157 | VisitFunctionType(T); |
| 158 | Record.push_back(T->getNumArgs()); |
| 159 | for (unsigned I = 0, N = T->getNumArgs(); I != N; ++I) |
| 160 | Writer.AddTypeRef(T->getArgType(I), Record); |
| 161 | Record.push_back(T->isVariadic()); |
| 162 | Record.push_back(T->getTypeQuals()); |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 163 | Record.push_back(T->hasExceptionSpec()); |
| 164 | Record.push_back(T->hasAnyExceptionSpec()); |
| 165 | Record.push_back(T->getNumExceptions()); |
| 166 | for (unsigned I = 0, N = T->getNumExceptions(); I != N; ++I) |
| 167 | Writer.AddTypeRef(T->getExceptionType(I), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 168 | Code = pch::TYPE_FUNCTION_PROTO; |
| 169 | } |
| 170 | |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 171 | #if 0 |
| 172 | // For when we want it.... |
| 173 | void PCHTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { |
| 174 | Writer.AddDeclRef(T->getDecl(), Record); |
| 175 | Code = pch::TYPE_UNRESOLVED_USING; |
| 176 | } |
| 177 | #endif |
| 178 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 179 | void PCHTypeWriter::VisitTypedefType(const TypedefType *T) { |
| 180 | Writer.AddDeclRef(T->getDecl(), Record); |
| 181 | Code = pch::TYPE_TYPEDEF; |
| 182 | } |
| 183 | |
| 184 | void PCHTypeWriter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 185 | Writer.AddStmt(T->getUnderlyingExpr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 186 | Code = pch::TYPE_TYPEOF_EXPR; |
| 187 | } |
| 188 | |
| 189 | void PCHTypeWriter::VisitTypeOfType(const TypeOfType *T) { |
| 190 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 191 | Code = pch::TYPE_TYPEOF; |
| 192 | } |
| 193 | |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 194 | void PCHTypeWriter::VisitDecltypeType(const DecltypeType *T) { |
| 195 | Writer.AddStmt(T->getUnderlyingExpr()); |
| 196 | Code = pch::TYPE_DECLTYPE; |
| 197 | } |
| 198 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 199 | void PCHTypeWriter::VisitTagType(const TagType *T) { |
| 200 | Writer.AddDeclRef(T->getDecl(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 201 | assert(!T->isBeingDefined() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 202 | "Cannot serialize in the middle of a type definition"); |
| 203 | } |
| 204 | |
| 205 | void PCHTypeWriter::VisitRecordType(const RecordType *T) { |
| 206 | VisitTagType(T); |
| 207 | Code = pch::TYPE_RECORD; |
| 208 | } |
| 209 | |
| 210 | void PCHTypeWriter::VisitEnumType(const EnumType *T) { |
| 211 | VisitTagType(T); |
| 212 | Code = pch::TYPE_ENUM; |
| 213 | } |
| 214 | |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 215 | void PCHTypeWriter::VisitElaboratedType(const ElaboratedType *T) { |
| 216 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 217 | Record.push_back(T->getTagKind()); |
| 218 | Code = pch::TYPE_ELABORATED; |
| 219 | } |
| 220 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 221 | void |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 222 | PCHTypeWriter::VisitSubstTemplateTypeParmType( |
| 223 | const SubstTemplateTypeParmType *T) { |
| 224 | Writer.AddTypeRef(QualType(T->getReplacedParameter(), 0), Record); |
| 225 | Writer.AddTypeRef(T->getReplacementType(), Record); |
| 226 | Code = pch::TYPE_SUBST_TEMPLATE_TYPE_PARM; |
| 227 | } |
| 228 | |
| 229 | void |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 230 | PCHTypeWriter::VisitTemplateSpecializationType( |
| 231 | const TemplateSpecializationType *T) { |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 232 | // FIXME: Serialize this type (C++ only) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 233 | assert(false && "Cannot serialize template specialization types"); |
| 234 | } |
| 235 | |
| 236 | void PCHTypeWriter::VisitQualifiedNameType(const QualifiedNameType *T) { |
Douglas Gregor | 6a2bfb2 | 2009-04-15 18:43:11 +0000 | [diff] [blame] | 237 | // FIXME: Serialize this type (C++ only) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 238 | assert(false && "Cannot serialize qualified name types"); |
| 239 | } |
| 240 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 241 | void PCHTypeWriter::VisitInjectedClassNameType(const InjectedClassNameType *T) { |
| 242 | Writer.AddDeclRef(T->getDecl(), Record); |
| 243 | Writer.AddTypeRef(T->getUnderlyingType(), Record); |
| 244 | Code = pch::TYPE_INJECTED_CLASS_NAME; |
| 245 | } |
| 246 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 247 | void PCHTypeWriter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 248 | Writer.AddDeclRef(T->getDecl(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 249 | Record.push_back(T->getNumProtocols()); |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 250 | for (ObjCInterfaceType::qual_iterator I = T->qual_begin(), |
| 251 | E = T->qual_end(); I != E; ++I) |
| 252 | Writer.AddDeclRef(*I, Record); |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 253 | Code = pch::TYPE_OBJC_INTERFACE; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 256 | void |
| 257 | PCHTypeWriter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 258 | Writer.AddTypeRef(T->getPointeeType(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 259 | Record.push_back(T->getNumProtocols()); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 260 | for (ObjCInterfaceType::qual_iterator I = T->qual_begin(), |
Steve Naroff | 446ee4e | 2009-05-27 16:21:00 +0000 | [diff] [blame] | 261 | E = T->qual_end(); I != E; ++I) |
| 262 | Writer.AddDeclRef(*I, Record); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 263 | Code = pch::TYPE_OBJC_OBJECT_POINTER; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 264 | } |
| 265 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 266 | namespace { |
| 267 | |
| 268 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { |
| 269 | PCHWriter &Writer; |
| 270 | PCHWriter::RecordData &Record; |
| 271 | |
| 272 | public: |
| 273 | TypeLocWriter(PCHWriter &Writer, PCHWriter::RecordData &Record) |
| 274 | : Writer(Writer), Record(Record) { } |
| 275 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 276 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 277 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 278 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 279 | #include "clang/AST/TypeLocNodes.def" |
| 280 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 281 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); |
| 282 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | } |
| 286 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 287 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 288 | // nothing to do |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 289 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 290 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 291 | Writer.AddSourceLocation(TL.getBuiltinLoc(), Record); |
| 292 | if (TL.needsExtraLocalData()) { |
| 293 | Record.push_back(TL.getWrittenTypeSpec()); |
| 294 | Record.push_back(TL.getWrittenSignSpec()); |
| 295 | Record.push_back(TL.getWrittenWidthSpec()); |
| 296 | Record.push_back(TL.hasModeAttr()); |
| 297 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 298 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 299 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 300 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 301 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 302 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 303 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 304 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 305 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 306 | Writer.AddSourceLocation(TL.getCaretLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 307 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 308 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 309 | Writer.AddSourceLocation(TL.getAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 310 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 311 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 312 | Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 313 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 314 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 315 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 316 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 317 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 318 | Writer.AddSourceLocation(TL.getLBracketLoc(), Record); |
| 319 | Writer.AddSourceLocation(TL.getRBracketLoc(), Record); |
| 320 | Record.push_back(TL.getSizeExpr() ? 1 : 0); |
| 321 | if (TL.getSizeExpr()) |
| 322 | Writer.AddStmt(TL.getSizeExpr()); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 323 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 324 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 325 | VisitArrayTypeLoc(TL); |
| 326 | } |
| 327 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 328 | VisitArrayTypeLoc(TL); |
| 329 | } |
| 330 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 331 | VisitArrayTypeLoc(TL); |
| 332 | } |
| 333 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( |
| 334 | DependentSizedArrayTypeLoc TL) { |
| 335 | VisitArrayTypeLoc(TL); |
| 336 | } |
| 337 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( |
| 338 | DependentSizedExtVectorTypeLoc TL) { |
| 339 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 340 | } |
| 341 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 342 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 343 | } |
| 344 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 345 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 346 | } |
| 347 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
| 348 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 349 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 350 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 351 | Writer.AddDeclRef(TL.getArg(i), Record); |
| 352 | } |
| 353 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 354 | VisitFunctionTypeLoc(TL); |
| 355 | } |
| 356 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 357 | VisitFunctionTypeLoc(TL); |
| 358 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 359 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 360 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 361 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 362 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 363 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 364 | } |
| 365 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 366 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 367 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 368 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 369 | } |
| 370 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 371 | Writer.AddSourceLocation(TL.getTypeofLoc(), Record); |
| 372 | Writer.AddSourceLocation(TL.getLParenLoc(), Record); |
| 373 | Writer.AddSourceLocation(TL.getRParenLoc(), Record); |
| 374 | Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 375 | } |
| 376 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 377 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 378 | } |
| 379 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 380 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 381 | } |
| 382 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 383 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 384 | } |
| 385 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
| 386 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 387 | } |
| 388 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 389 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 390 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 391 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( |
| 392 | SubstTemplateTypeParmTypeLoc TL) { |
| 393 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 394 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 395 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( |
| 396 | TemplateSpecializationTypeLoc TL) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 397 | Writer.AddSourceLocation(TL.getTemplateNameLoc(), Record); |
| 398 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 399 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 400 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 401 | Writer.AddTemplateArgumentLoc(TL.getArgLoc(i), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 402 | } |
| 403 | void TypeLocWriter::VisitQualifiedNameTypeLoc(QualifiedNameTypeLoc TL) { |
| 404 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 405 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 406 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 407 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 408 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 409 | void TypeLocWriter::VisitTypenameTypeLoc(TypenameTypeLoc TL) { |
| 410 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
| 411 | } |
| 412 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 413 | Writer.AddSourceLocation(TL.getNameLoc(), Record); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 414 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 415 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 416 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 417 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 418 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 419 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 420 | Writer.AddSourceLocation(TL.getStarLoc(), Record); |
| 421 | Writer.AddSourceLocation(TL.getLAngleLoc(), Record); |
| 422 | Writer.AddSourceLocation(TL.getRAngleLoc(), Record); |
| 423 | Record.push_back(TL.hasBaseTypeAsWritten()); |
| 424 | Record.push_back(TL.hasProtocolsAsWritten()); |
| 425 | if (TL.hasProtocolsAsWritten()) |
| 426 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 427 | Writer.AddSourceLocation(TL.getProtocolLoc(i), Record); |
| 428 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 429 | |
Chris Lattner | 4dcf151a | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 430 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 431 | // PCHWriter Implementation |
| 432 | //===----------------------------------------------------------------------===// |
| 433 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 434 | static void EmitBlockID(unsigned ID, const char *Name, |
| 435 | llvm::BitstreamWriter &Stream, |
| 436 | PCHWriter::RecordData &Record) { |
| 437 | Record.clear(); |
| 438 | Record.push_back(ID); |
| 439 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); |
| 440 | |
| 441 | // Emit the block name if present. |
| 442 | if (Name == 0 || Name[0] == 0) return; |
| 443 | Record.clear(); |
| 444 | while (*Name) |
| 445 | Record.push_back(*Name++); |
| 446 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); |
| 447 | } |
| 448 | |
| 449 | static void EmitRecordID(unsigned ID, const char *Name, |
| 450 | llvm::BitstreamWriter &Stream, |
| 451 | PCHWriter::RecordData &Record) { |
| 452 | Record.clear(); |
| 453 | Record.push_back(ID); |
| 454 | while (*Name) |
| 455 | Record.push_back(*Name++); |
| 456 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, |
| 460 | PCHWriter::RecordData &Record) { |
| 461 | #define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record) |
| 462 | RECORD(STMT_STOP); |
| 463 | RECORD(STMT_NULL_PTR); |
| 464 | RECORD(STMT_NULL); |
| 465 | RECORD(STMT_COMPOUND); |
| 466 | RECORD(STMT_CASE); |
| 467 | RECORD(STMT_DEFAULT); |
| 468 | RECORD(STMT_LABEL); |
| 469 | RECORD(STMT_IF); |
| 470 | RECORD(STMT_SWITCH); |
| 471 | RECORD(STMT_WHILE); |
| 472 | RECORD(STMT_DO); |
| 473 | RECORD(STMT_FOR); |
| 474 | RECORD(STMT_GOTO); |
| 475 | RECORD(STMT_INDIRECT_GOTO); |
| 476 | RECORD(STMT_CONTINUE); |
| 477 | RECORD(STMT_BREAK); |
| 478 | RECORD(STMT_RETURN); |
| 479 | RECORD(STMT_DECL); |
| 480 | RECORD(STMT_ASM); |
| 481 | RECORD(EXPR_PREDEFINED); |
| 482 | RECORD(EXPR_DECL_REF); |
| 483 | RECORD(EXPR_INTEGER_LITERAL); |
| 484 | RECORD(EXPR_FLOATING_LITERAL); |
| 485 | RECORD(EXPR_IMAGINARY_LITERAL); |
| 486 | RECORD(EXPR_STRING_LITERAL); |
| 487 | RECORD(EXPR_CHARACTER_LITERAL); |
| 488 | RECORD(EXPR_PAREN); |
| 489 | RECORD(EXPR_UNARY_OPERATOR); |
| 490 | RECORD(EXPR_SIZEOF_ALIGN_OF); |
| 491 | RECORD(EXPR_ARRAY_SUBSCRIPT); |
| 492 | RECORD(EXPR_CALL); |
| 493 | RECORD(EXPR_MEMBER); |
| 494 | RECORD(EXPR_BINARY_OPERATOR); |
| 495 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); |
| 496 | RECORD(EXPR_CONDITIONAL_OPERATOR); |
| 497 | RECORD(EXPR_IMPLICIT_CAST); |
| 498 | RECORD(EXPR_CSTYLE_CAST); |
| 499 | RECORD(EXPR_COMPOUND_LITERAL); |
| 500 | RECORD(EXPR_EXT_VECTOR_ELEMENT); |
| 501 | RECORD(EXPR_INIT_LIST); |
| 502 | RECORD(EXPR_DESIGNATED_INIT); |
| 503 | RECORD(EXPR_IMPLICIT_VALUE_INIT); |
| 504 | RECORD(EXPR_VA_ARG); |
| 505 | RECORD(EXPR_ADDR_LABEL); |
| 506 | RECORD(EXPR_STMT); |
| 507 | RECORD(EXPR_TYPES_COMPATIBLE); |
| 508 | RECORD(EXPR_CHOOSE); |
| 509 | RECORD(EXPR_GNU_NULL); |
| 510 | RECORD(EXPR_SHUFFLE_VECTOR); |
| 511 | RECORD(EXPR_BLOCK); |
| 512 | RECORD(EXPR_BLOCK_DECL_REF); |
| 513 | RECORD(EXPR_OBJC_STRING_LITERAL); |
| 514 | RECORD(EXPR_OBJC_ENCODE); |
| 515 | RECORD(EXPR_OBJC_SELECTOR_EXPR); |
| 516 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); |
| 517 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); |
| 518 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); |
| 519 | RECORD(EXPR_OBJC_KVC_REF_EXPR); |
| 520 | RECORD(EXPR_OBJC_MESSAGE_EXPR); |
| 521 | RECORD(EXPR_OBJC_SUPER_EXPR); |
| 522 | RECORD(STMT_OBJC_FOR_COLLECTION); |
| 523 | RECORD(STMT_OBJC_CATCH); |
| 524 | RECORD(STMT_OBJC_FINALLY); |
| 525 | RECORD(STMT_OBJC_AT_TRY); |
| 526 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); |
| 527 | RECORD(STMT_OBJC_AT_THROW); |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 528 | RECORD(EXPR_CXX_OPERATOR_CALL); |
| 529 | RECORD(EXPR_CXX_CONSTRUCT); |
| 530 | RECORD(EXPR_CXX_STATIC_CAST); |
| 531 | RECORD(EXPR_CXX_DYNAMIC_CAST); |
| 532 | RECORD(EXPR_CXX_REINTERPRET_CAST); |
| 533 | RECORD(EXPR_CXX_CONST_CAST); |
| 534 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); |
| 535 | RECORD(EXPR_CXX_BOOL_LITERAL); |
| 536 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 537 | #undef RECORD |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 538 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 540 | void PCHWriter::WriteBlockInfoBlock() { |
| 541 | RecordData Record; |
| 542 | Stream.EnterSubblock(llvm::bitc::BLOCKINFO_BLOCK_ID, 3); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 544 | #define BLOCK(X) EmitBlockID(pch::X ## _ID, #X, Stream, Record) |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 545 | #define RECORD(X) EmitRecordID(pch::X, #X, Stream, Record) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 547 | // PCH Top-Level Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 548 | BLOCK(PCH_BLOCK); |
Zhongxing Xu | 51e774d | 2009-06-03 09:23:28 +0000 | [diff] [blame] | 549 | RECORD(ORIGINAL_FILE_NAME); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 550 | RECORD(TYPE_OFFSET); |
| 551 | RECORD(DECL_OFFSET); |
| 552 | RECORD(LANGUAGE_OPTIONS); |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 553 | RECORD(METADATA); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 554 | RECORD(IDENTIFIER_OFFSET); |
| 555 | RECORD(IDENTIFIER_TABLE); |
| 556 | RECORD(EXTERNAL_DEFINITIONS); |
| 557 | RECORD(SPECIAL_TYPES); |
| 558 | RECORD(STATISTICS); |
| 559 | RECORD(TENTATIVE_DEFINITIONS); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 560 | RECORD(UNUSED_STATIC_FUNCS); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 561 | RECORD(LOCALLY_SCOPED_EXTERNAL_DECLS); |
| 562 | RECORD(SELECTOR_OFFSETS); |
| 563 | RECORD(METHOD_POOL); |
| 564 | RECORD(PP_COUNTER_VALUE); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 565 | RECORD(SOURCE_LOCATION_OFFSETS); |
| 566 | RECORD(SOURCE_LOCATION_PRELOADS); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 567 | RECORD(STAT_CACHE); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 568 | RECORD(EXT_VECTOR_DECLS); |
Ted Kremenek | 5b4ec63 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 569 | RECORD(VERSION_CONTROL_BRANCH_REVISION); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 570 | RECORD(UNUSED_STATIC_FUNCS); |
| 571 | RECORD(MACRO_DEFINITION_OFFSETS); |
| 572 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 573 | // SourceManager Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 574 | BLOCK(SOURCE_MANAGER_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 575 | RECORD(SM_SLOC_FILE_ENTRY); |
| 576 | RECORD(SM_SLOC_BUFFER_ENTRY); |
| 577 | RECORD(SM_SLOC_BUFFER_BLOB); |
| 578 | RECORD(SM_SLOC_INSTANTIATION_ENTRY); |
| 579 | RECORD(SM_LINE_TABLE); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 580 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 581 | // Preprocessor Block. |
Chris Lattner | 2f4efd1 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 582 | BLOCK(PREPROCESSOR_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 583 | RECORD(PP_MACRO_OBJECT_LIKE); |
| 584 | RECORD(PP_MACRO_FUNCTION_LIKE); |
| 585 | RECORD(PP_TOKEN); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 586 | RECORD(PP_MACRO_INSTANTIATION); |
| 587 | RECORD(PP_MACRO_DEFINITION); |
| 588 | |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 589 | // Decls and Types block. |
| 590 | BLOCK(DECLTYPES_BLOCK); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 591 | RECORD(TYPE_EXT_QUAL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 592 | RECORD(TYPE_COMPLEX); |
| 593 | RECORD(TYPE_POINTER); |
| 594 | RECORD(TYPE_BLOCK_POINTER); |
| 595 | RECORD(TYPE_LVALUE_REFERENCE); |
| 596 | RECORD(TYPE_RVALUE_REFERENCE); |
| 597 | RECORD(TYPE_MEMBER_POINTER); |
| 598 | RECORD(TYPE_CONSTANT_ARRAY); |
| 599 | RECORD(TYPE_INCOMPLETE_ARRAY); |
| 600 | RECORD(TYPE_VARIABLE_ARRAY); |
| 601 | RECORD(TYPE_VECTOR); |
| 602 | RECORD(TYPE_EXT_VECTOR); |
| 603 | RECORD(TYPE_FUNCTION_PROTO); |
| 604 | RECORD(TYPE_FUNCTION_NO_PROTO); |
| 605 | RECORD(TYPE_TYPEDEF); |
| 606 | RECORD(TYPE_TYPEOF_EXPR); |
| 607 | RECORD(TYPE_TYPEOF); |
| 608 | RECORD(TYPE_RECORD); |
| 609 | RECORD(TYPE_ENUM); |
| 610 | RECORD(TYPE_OBJC_INTERFACE); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 611 | RECORD(TYPE_OBJC_OBJECT_POINTER); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 612 | RECORD(DECL_ATTR); |
| 613 | RECORD(DECL_TRANSLATION_UNIT); |
| 614 | RECORD(DECL_TYPEDEF); |
| 615 | RECORD(DECL_ENUM); |
| 616 | RECORD(DECL_RECORD); |
| 617 | RECORD(DECL_ENUM_CONSTANT); |
| 618 | RECORD(DECL_FUNCTION); |
| 619 | RECORD(DECL_OBJC_METHOD); |
| 620 | RECORD(DECL_OBJC_INTERFACE); |
| 621 | RECORD(DECL_OBJC_PROTOCOL); |
| 622 | RECORD(DECL_OBJC_IVAR); |
| 623 | RECORD(DECL_OBJC_AT_DEFS_FIELD); |
| 624 | RECORD(DECL_OBJC_CLASS); |
| 625 | RECORD(DECL_OBJC_FORWARD_PROTOCOL); |
| 626 | RECORD(DECL_OBJC_CATEGORY); |
| 627 | RECORD(DECL_OBJC_CATEGORY_IMPL); |
| 628 | RECORD(DECL_OBJC_IMPLEMENTATION); |
| 629 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); |
| 630 | RECORD(DECL_OBJC_PROPERTY); |
| 631 | RECORD(DECL_OBJC_PROPERTY_IMPL); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 632 | RECORD(DECL_FIELD); |
| 633 | RECORD(DECL_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 634 | RECORD(DECL_IMPLICIT_PARAM); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 635 | RECORD(DECL_PARM_VAR); |
Chris Lattner | 0ff8cda | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 636 | RECORD(DECL_FILE_SCOPE_ASM); |
| 637 | RECORD(DECL_BLOCK); |
| 638 | RECORD(DECL_CONTEXT_LEXICAL); |
| 639 | RECORD(DECL_CONTEXT_VISIBLE); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 640 | // Statements and Exprs can occur in the Decls and Types block. |
Chris Lattner | 0558df2 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 641 | AddStmtsExprs(Stream, Record); |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 642 | #undef RECORD |
| 643 | #undef BLOCK |
| 644 | Stream.ExitBlock(); |
| 645 | } |
| 646 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 647 | /// \brief Adjusts the given filename to only write out the portion of the |
| 648 | /// filename that is not part of the system root directory. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | /// |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 650 | /// \param Filename the file name to adjust. |
| 651 | /// |
| 652 | /// \param isysroot When non-NULL, the PCH file is a relocatable PCH file and |
| 653 | /// the returned filename will be adjusted by this system root. |
| 654 | /// |
| 655 | /// \returns either the original filename (if it needs no adjustment) or the |
| 656 | /// adjusted filename (which points into the @p Filename parameter). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | static const char * |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 658 | adjustFilenameForRelocatablePCH(const char *Filename, const char *isysroot) { |
| 659 | assert(Filename && "No file name to adjust?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 660 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 661 | if (!isysroot) |
| 662 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 664 | // Verify that the filename and the system root have the same prefix. |
| 665 | unsigned Pos = 0; |
| 666 | for (; Filename[Pos] && isysroot[Pos]; ++Pos) |
| 667 | if (Filename[Pos] != isysroot[Pos]) |
| 668 | return Filename; // Prefixes don't match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 670 | // We hit the end of the filename before we hit the end of the system root. |
| 671 | if (!Filename[Pos]) |
| 672 | return Filename; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 673 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 674 | // If the file name has a '/' at the current position, skip over the '/'. |
| 675 | // We distinguish sysroot-based includes from absolute includes by the |
| 676 | // absence of '/' at the beginning of sysroot-based includes. |
| 677 | if (Filename[Pos] == '/') |
| 678 | ++Pos; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 680 | return Filename + Pos; |
| 681 | } |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 682 | |
Douglas Gregor | ab41e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 683 | /// \brief Write the PCH metadata (e.g., i686-apple-darwin9). |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 684 | void PCHWriter::WriteMetadata(ASTContext &Context, const char *isysroot) { |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 685 | using namespace llvm; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 687 | // Metadata |
| 688 | const TargetInfo &Target = Context.Target; |
| 689 | BitCodeAbbrev *MetaAbbrev = new BitCodeAbbrev(); |
| 690 | MetaAbbrev->Add(BitCodeAbbrevOp(pch::METADATA)); |
| 691 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH major |
| 692 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH minor |
| 693 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major |
| 694 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor |
| 695 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable |
| 696 | MetaAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Target triple |
| 697 | unsigned MetaAbbrevCode = Stream.EmitAbbrev(MetaAbbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 698 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 699 | RecordData Record; |
| 700 | Record.push_back(pch::METADATA); |
| 701 | Record.push_back(pch::VERSION_MAJOR); |
| 702 | Record.push_back(pch::VERSION_MINOR); |
| 703 | Record.push_back(CLANG_VERSION_MAJOR); |
| 704 | Record.push_back(CLANG_VERSION_MINOR); |
| 705 | Record.push_back(isysroot != 0); |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 706 | const std::string &TripleStr = Target.getTriple().getTriple(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 707 | Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, TripleStr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 709 | // Original file name |
| 710 | SourceManager &SM = Context.getSourceManager(); |
| 711 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { |
| 712 | BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev(); |
| 713 | FileAbbrev->Add(BitCodeAbbrevOp(pch::ORIGINAL_FILE_NAME)); |
| 714 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
| 715 | unsigned FileAbbrevCode = Stream.EmitAbbrev(FileAbbrev); |
| 716 | |
| 717 | llvm::sys::Path MainFilePath(MainFile->getName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 719 | MainFilePath.makeAbsolute(); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 720 | |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 721 | const char *MainFileNameStr = MainFilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | MainFileNameStr = adjustFilenameForRelocatablePCH(MainFileNameStr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 723 | isysroot); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 724 | RecordData Record; |
| 725 | Record.push_back(pch::ORIGINAL_FILE_NAME); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 726 | Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 727 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 728 | |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 729 | // Repository branch/version information. |
| 730 | BitCodeAbbrev *RepoAbbrev = new BitCodeAbbrev(); |
| 731 | RepoAbbrev->Add(BitCodeAbbrevOp(pch::VERSION_CONTROL_BRANCH_REVISION)); |
| 732 | RepoAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag |
| 733 | unsigned RepoAbbrevCode = Stream.EmitAbbrev(RepoAbbrev); |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 734 | Record.clear(); |
Ted Kremenek | 5b4ec63 | 2010-01-22 20:59:36 +0000 | [diff] [blame] | 735 | Record.push_back(pch::VERSION_CONTROL_BRANCH_REVISION); |
Ted Kremenek | f7a96a3 | 2010-01-22 22:12:47 +0000 | [diff] [blame] | 736 | Stream.EmitRecordWithBlob(RepoAbbrevCode, Record, |
| 737 | getClangFullRepositoryVersion()); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /// \brief Write the LangOptions structure. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 741 | void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) { |
| 742 | RecordData Record; |
| 743 | Record.push_back(LangOpts.Trigraphs); |
| 744 | Record.push_back(LangOpts.BCPLComment); // BCPL-style '//' comments. |
| 745 | Record.push_back(LangOpts.DollarIdents); // '$' allowed in identifiers. |
| 746 | Record.push_back(LangOpts.AsmPreprocessor); // Preprocessor in asm mode. |
| 747 | Record.push_back(LangOpts.GNUMode); // True in gnu99 mode false in c99 mode (etc) |
| 748 | Record.push_back(LangOpts.ImplicitInt); // C89 implicit 'int'. |
| 749 | Record.push_back(LangOpts.Digraphs); // C94, C99 and C++ |
| 750 | Record.push_back(LangOpts.HexFloats); // C99 Hexadecimal float constants. |
| 751 | Record.push_back(LangOpts.C99); // C99 Support |
| 752 | Record.push_back(LangOpts.Microsoft); // Microsoft extensions. |
| 753 | Record.push_back(LangOpts.CPlusPlus); // C++ Support |
| 754 | Record.push_back(LangOpts.CPlusPlus0x); // C++0x Support |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 755 | Record.push_back(LangOpts.CXXOperatorNames); // Treat C++ operator names as keywords. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 757 | Record.push_back(LangOpts.ObjC1); // Objective-C 1 support enabled. |
| 758 | Record.push_back(LangOpts.ObjC2); // Objective-C 2 support enabled. |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 759 | Record.push_back(LangOpts.ObjCNonFragileABI); // Objective-C |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 760 | // modern abi enabled. |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 761 | Record.push_back(LangOpts.ObjCNonFragileABI2); // Objective-C enhanced |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 762 | // modern abi enabled. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 763 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 764 | Record.push_back(LangOpts.PascalStrings); // Allow Pascal strings |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 765 | Record.push_back(LangOpts.WritableStrings); // Allow writable strings |
| 766 | Record.push_back(LangOpts.LaxVectorConversions); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 767 | Record.push_back(LangOpts.AltiVec); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 768 | Record.push_back(LangOpts.Exceptions); // Support exception handling. |
Daniel Dunbar | 7348288 | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 769 | Record.push_back(LangOpts.SjLjExceptions); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 770 | |
| 771 | Record.push_back(LangOpts.NeXTRuntime); // Use NeXT runtime. |
| 772 | Record.push_back(LangOpts.Freestanding); // Freestanding implementation |
| 773 | Record.push_back(LangOpts.NoBuiltin); // Do not use builtin functions (-fno-builtin) |
| 774 | |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 775 | // Whether static initializers are protected by locks. |
| 776 | Record.push_back(LangOpts.ThreadsafeStatics); |
Douglas Gregor | 972d954 | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 777 | Record.push_back(LangOpts.POSIXThreads); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 778 | Record.push_back(LangOpts.Blocks); // block extension to C |
| 779 | Record.push_back(LangOpts.EmitAllDecls); // Emit all declarations, even if |
| 780 | // they are unused. |
| 781 | Record.push_back(LangOpts.MathErrno); // Math functions must respect errno |
| 782 | // (modulo the platform support). |
| 783 | |
| 784 | Record.push_back(LangOpts.OverflowChecking); // Extension to call a handler function when |
| 785 | // signed integer arithmetic overflows. |
| 786 | |
| 787 | Record.push_back(LangOpts.HeinousExtensions); // Extensions that we really don't like and |
| 788 | // may be ripped out at any time. |
| 789 | |
| 790 | Record.push_back(LangOpts.Optimize); // Whether __OPTIMIZE__ should be defined. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 791 | Record.push_back(LangOpts.OptimizeSize); // Whether __OPTIMIZE_SIZE__ should be |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 792 | // defined. |
| 793 | Record.push_back(LangOpts.Static); // Should __STATIC__ be defined (as |
| 794 | // opposed to __DYNAMIC__). |
| 795 | Record.push_back(LangOpts.PICLevel); // The value for __PIC__, if non-zero. |
| 796 | |
| 797 | Record.push_back(LangOpts.GNUInline); // Should GNU inline semantics be |
| 798 | // used (instead of C99 semantics). |
| 799 | Record.push_back(LangOpts.NoInline); // Should __NO_INLINE__ be defined. |
Anders Carlsson | a33d9b4 | 2009-05-13 19:49:53 +0000 | [diff] [blame] | 800 | Record.push_back(LangOpts.AccessControl); // Whether C++ access control should |
| 801 | // be enabled. |
Eli Friedman | 15b9176 | 2009-06-05 07:05:05 +0000 | [diff] [blame] | 802 | Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or |
| 803 | // unsigned type |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 804 | Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 805 | Record.push_back(LangOpts.getGCMode()); |
| 806 | Record.push_back(LangOpts.getVisibilityMode()); |
Daniel Dunbar | ab8e281 | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 807 | Record.push_back(LangOpts.getStackProtectorMode()); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 808 | Record.push_back(LangOpts.InstantiationDepth); |
Nate Begeman | b9e7e63 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 809 | Record.push_back(LangOpts.OpenCL); |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 810 | Record.push_back(LangOpts.CatchUndefined); |
Anders Carlsson | 92f5822 | 2009-08-22 22:30:33 +0000 | [diff] [blame] | 811 | Record.push_back(LangOpts.ElideConstructors); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 812 | Stream.EmitRecord(pch::LANGUAGE_OPTIONS, Record); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 815 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 816 | // stat cache Serialization |
| 817 | //===----------------------------------------------------------------------===// |
| 818 | |
| 819 | namespace { |
| 820 | // Trait used for the on-disk hash table of stat cache results. |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 821 | class PCHStatCacheTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 822 | public: |
| 823 | typedef const char * key_type; |
| 824 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 826 | typedef std::pair<int, struct stat> data_type; |
| 827 | typedef const data_type& data_type_ref; |
| 828 | |
| 829 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 830 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 831 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | |
| 833 | std::pair<unsigned,unsigned> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 834 | EmitKeyDataLength(llvm::raw_ostream& Out, const char *path, |
| 835 | data_type_ref Data) { |
| 836 | unsigned StrLen = strlen(path); |
| 837 | clang::io::Emit16(Out, StrLen); |
| 838 | unsigned DataLen = 1; // result value |
| 839 | if (Data.first == 0) |
| 840 | DataLen += 4 + 4 + 2 + 8 + 8; |
| 841 | clang::io::Emit8(Out, DataLen); |
| 842 | return std::make_pair(StrLen + 1, DataLen); |
| 843 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 844 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 845 | void EmitKey(llvm::raw_ostream& Out, const char *path, unsigned KeyLen) { |
| 846 | Out.write(path, KeyLen); |
| 847 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 848 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 849 | void EmitData(llvm::raw_ostream& Out, key_type_ref, |
| 850 | data_type_ref Data, unsigned DataLen) { |
| 851 | using namespace clang::io; |
| 852 | uint64_t Start = Out.tell(); (void)Start; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 854 | // Result of stat() |
| 855 | Emit8(Out, Data.first? 1 : 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 857 | if (Data.first == 0) { |
| 858 | Emit32(Out, (uint32_t) Data.second.st_ino); |
| 859 | Emit32(Out, (uint32_t) Data.second.st_dev); |
| 860 | Emit16(Out, (uint16_t) Data.second.st_mode); |
| 861 | Emit64(Out, (uint64_t) Data.second.st_mtime); |
| 862 | Emit64(Out, (uint64_t) Data.second.st_size); |
| 863 | } |
| 864 | |
| 865 | assert(Out.tell() - Start == DataLen && "Wrong data length"); |
| 866 | } |
| 867 | }; |
| 868 | } // end anonymous namespace |
| 869 | |
| 870 | /// \brief Write the stat() system call cache to the PCH file. |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 871 | void PCHWriter::WriteStatCache(MemorizeStatCalls &StatCalls, |
| 872 | const char *isysroot) { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 873 | // Build the on-disk hash table containing information about every |
| 874 | // stat() call. |
| 875 | OnDiskChainedHashTableGenerator<PCHStatCacheTrait> Generator; |
| 876 | unsigned NumStatEntries = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | for (MemorizeStatCalls::iterator Stat = StatCalls.begin(), |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 878 | StatEnd = StatCalls.end(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 879 | Stat != StatEnd; ++Stat, ++NumStatEntries) { |
| 880 | const char *Filename = Stat->first(); |
| 881 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
| 882 | Generator.insert(Filename, Stat->second); |
| 883 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 885 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 886 | llvm::SmallString<4096> StatCacheData; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 887 | uint32_t BucketOffset; |
| 888 | { |
| 889 | llvm::raw_svector_ostream Out(StatCacheData); |
| 890 | // Make sure that no bucket is at offset 0 |
| 891 | clang::io::Emit32(Out, 0); |
| 892 | BucketOffset = Generator.Emit(Out); |
| 893 | } |
| 894 | |
| 895 | // Create a blob abbreviation |
| 896 | using namespace llvm; |
| 897 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 898 | Abbrev->Add(BitCodeAbbrevOp(pch::STAT_CACHE)); |
| 899 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 900 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
| 901 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 902 | unsigned StatCacheAbbrev = Stream.EmitAbbrev(Abbrev); |
| 903 | |
| 904 | // Write the stat cache |
| 905 | RecordData Record; |
| 906 | Record.push_back(pch::STAT_CACHE); |
| 907 | Record.push_back(BucketOffset); |
| 908 | Record.push_back(NumStatEntries); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 909 | Stream.EmitRecordWithBlob(StatCacheAbbrev, Record, StatCacheData.str()); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 913 | // Source Manager Serialization |
| 914 | //===----------------------------------------------------------------------===// |
| 915 | |
| 916 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 917 | /// file. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 918 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 919 | using namespace llvm; |
| 920 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 921 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_FILE_ENTRY)); |
| 922 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 923 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 924 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 925 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 926 | // FileEntry fields. |
| 927 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size |
| 928 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 929 | // HeaderFileInfo fields. |
| 930 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isImport |
| 931 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // DirInfo |
| 932 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumIncludes |
| 933 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // ControllingMacro |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 934 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 935 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 939 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 940 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 941 | using namespace llvm; |
| 942 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 943 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_ENTRY)); |
| 944 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 945 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location |
| 946 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic |
| 947 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives |
| 948 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 949 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | /// \brief Create an abbreviation for the SLocEntry that refers to a |
| 953 | /// buffer's blob. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 954 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 955 | using namespace llvm; |
| 956 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 957 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_BUFFER_BLOB)); |
| 958 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 959 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /// \brief Create an abbreviation for the SLocEntry that refers to an |
| 963 | /// buffer. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 964 | static unsigned CreateSLocInstantiationAbbrev(llvm::BitstreamWriter &Stream) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 965 | using namespace llvm; |
| 966 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 967 | Abbrev->Add(BitCodeAbbrevOp(pch::SM_SLOC_INSTANTIATION_ENTRY)); |
| 968 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset |
| 969 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location |
| 970 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location |
| 971 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location |
Douglas Gregor | f60e991 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 972 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 973 | return Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | /// \brief Writes the block containing the serialized form of the |
| 977 | /// source manager. |
| 978 | /// |
| 979 | /// TODO: We should probably use an on-disk hash table (stored in a |
| 980 | /// blob), indexed based on the file name, so that we only create |
| 981 | /// entries for files that we actually need. In the common case (no |
| 982 | /// errors), we probably won't have to create file entries for any of |
| 983 | /// the files in the AST. |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 984 | void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 985 | const Preprocessor &PP, |
| 986 | const char *isysroot) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 987 | RecordData Record; |
| 988 | |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 989 | // Enter the source manager block. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 990 | Stream.EnterSubblock(pch::SOURCE_MANAGER_BLOCK_ID, 3); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 991 | |
| 992 | // Abbreviations for the various kinds of source-location entries. |
Chris Lattner | 828e18c | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 993 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); |
| 994 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); |
| 995 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream); |
| 996 | unsigned SLocInstantiationAbbrv = CreateSLocInstantiationAbbrev(Stream); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 997 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 998 | // Write the line table. |
| 999 | if (SourceMgr.hasLineTable()) { |
| 1000 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1001 | |
| 1002 | // Emit the file names |
| 1003 | Record.push_back(LineTable.getNumFilenames()); |
| 1004 | for (unsigned I = 0, N = LineTable.getNumFilenames(); I != N; ++I) { |
| 1005 | // Emit the file name |
| 1006 | const char *Filename = LineTable.getFilename(I); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1007 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1008 | unsigned FilenameLen = Filename? strlen(Filename) : 0; |
| 1009 | Record.push_back(FilenameLen); |
| 1010 | if (FilenameLen) |
| 1011 | Record.insert(Record.end(), Filename, Filename + FilenameLen); |
| 1012 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1013 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1014 | // Emit the line entries |
| 1015 | for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); |
| 1016 | L != LEnd; ++L) { |
| 1017 | // Emit the file ID |
| 1018 | Record.push_back(L->first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1019 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1020 | // Emit the line entries |
| 1021 | Record.push_back(L->second.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1022 | for (std::vector<LineEntry>::iterator LE = L->second.begin(), |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1023 | LEEnd = L->second.end(); |
| 1024 | LE != LEEnd; ++LE) { |
| 1025 | Record.push_back(LE->FileOffset); |
| 1026 | Record.push_back(LE->LineNo); |
| 1027 | Record.push_back(LE->FilenameID); |
| 1028 | Record.push_back((unsigned)LE->FileKind); |
| 1029 | Record.push_back(LE->IncludeOffset); |
| 1030 | } |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1031 | } |
Zhongxing Xu | 3d8216a | 2009-05-22 08:38:27 +0000 | [diff] [blame] | 1032 | Stream.EmitRecord(pch::SM_LINE_TABLE, Record); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1035 | // Write out the source location entry table. We skip the first |
| 1036 | // entry, which is always the same dummy entry. |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1037 | std::vector<uint32_t> SLocEntryOffsets; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1038 | RecordData PreloadSLocs; |
| 1039 | SLocEntryOffsets.reserve(SourceMgr.sloc_entry_size() - 1); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1040 | for (unsigned I = 1, N = SourceMgr.sloc_entry_size(); I != N; ++I) { |
| 1041 | // Get this source location entry. |
| 1042 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getSLocEntry(I); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1043 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1044 | // Record the offset of this source-location entry. |
| 1045 | SLocEntryOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1046 | |
| 1047 | // Figure out which record code to use. |
| 1048 | unsigned Code; |
| 1049 | if (SLoc->isFile()) { |
| 1050 | if (SLoc->getFile().getContentCache()->Entry) |
| 1051 | Code = pch::SM_SLOC_FILE_ENTRY; |
| 1052 | else |
| 1053 | Code = pch::SM_SLOC_BUFFER_ENTRY; |
| 1054 | } else |
| 1055 | Code = pch::SM_SLOC_INSTANTIATION_ENTRY; |
| 1056 | Record.clear(); |
| 1057 | Record.push_back(Code); |
| 1058 | |
| 1059 | Record.push_back(SLoc->getOffset()); |
| 1060 | if (SLoc->isFile()) { |
| 1061 | const SrcMgr::FileInfo &File = SLoc->getFile(); |
| 1062 | Record.push_back(File.getIncludeLoc().getRawEncoding()); |
| 1063 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding |
| 1064 | Record.push_back(File.hasLineDirectives()); |
| 1065 | |
| 1066 | const SrcMgr::ContentCache *Content = File.getContentCache(); |
| 1067 | if (Content->Entry) { |
| 1068 | // The source location entry is a file. The blob associated |
| 1069 | // with this entry is the file name. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1071 | // Emit size/modification time for this file. |
| 1072 | Record.push_back(Content->Entry->getSize()); |
| 1073 | Record.push_back(Content->Entry->getModificationTime()); |
| 1074 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1075 | // Emit header-search information associated with this file. |
| 1076 | HeaderFileInfo HFI; |
| 1077 | HeaderSearch &HS = PP.getHeaderSearchInfo(); |
| 1078 | if (Content->Entry->getUID() < HS.header_file_size()) |
| 1079 | HFI = HS.header_file_begin()[Content->Entry->getUID()]; |
| 1080 | Record.push_back(HFI.isImport); |
| 1081 | Record.push_back(HFI.DirInfo); |
| 1082 | Record.push_back(HFI.NumIncludes); |
| 1083 | AddIdentifierRef(HFI.ControllingMacro, Record); |
| 1084 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1085 | // Turn the file name into an absolute path, if it isn't already. |
| 1086 | const char *Filename = Content->Entry->getName(); |
| 1087 | llvm::sys::Path FilePath(Filename, strlen(Filename)); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1088 | FilePath.makeAbsolute(); |
Kovarththanan Rajaratnam | aba54a9 | 2010-03-14 07:15:57 +0000 | [diff] [blame] | 1089 | Filename = FilePath.c_str(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1091 | Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1092 | Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1093 | |
| 1094 | // FIXME: For now, preload all file source locations, so that |
| 1095 | // we get the appropriate File entries in the reader. This is |
| 1096 | // a temporary measure. |
| 1097 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1098 | } else { |
| 1099 | // The source location entry is a buffer. The blob associated |
| 1100 | // with this entry contains the contents of the buffer. |
| 1101 | |
| 1102 | // We add one to the size so that we capture the trailing NULL |
| 1103 | // that is required by llvm::MemoryBuffer::getMemBuffer (on |
| 1104 | // the reader side). |
Douglas Gregor | 36c35ba | 2010-03-16 00:35:39 +0000 | [diff] [blame] | 1105 | const llvm::MemoryBuffer *Buffer |
| 1106 | = Content->getBuffer(PP.getDiagnostics()); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1107 | const char *Name = Buffer->getBufferIdentifier(); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1108 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, |
| 1109 | llvm::StringRef(Name, strlen(Name) + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1110 | Record.clear(); |
| 1111 | Record.push_back(pch::SM_SLOC_BUFFER_BLOB); |
| 1112 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1113 | llvm::StringRef(Buffer->getBufferStart(), |
| 1114 | Buffer->getBufferSize() + 1)); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1115 | |
| 1116 | if (strcmp(Name, "<built-in>") == 0) |
| 1117 | PreloadSLocs.push_back(SLocEntryOffsets.size()); |
| 1118 | } |
| 1119 | } else { |
| 1120 | // The source location entry is an instantiation. |
| 1121 | const SrcMgr::InstantiationInfo &Inst = SLoc->getInstantiation(); |
| 1122 | Record.push_back(Inst.getSpellingLoc().getRawEncoding()); |
| 1123 | Record.push_back(Inst.getInstantiationLocStart().getRawEncoding()); |
| 1124 | Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding()); |
| 1125 | |
| 1126 | // Compute the token length for this macro expansion. |
| 1127 | unsigned NextOffset = SourceMgr.getNextOffset(); |
Douglas Gregor | bdfe48a | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1128 | if (I + 1 != N) |
| 1129 | NextOffset = SourceMgr.getSLocEntry(I + 1).getOffset(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1130 | Record.push_back(NextOffset - SLoc->getOffset() - 1); |
| 1131 | Stream.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record); |
| 1132 | } |
| 1133 | } |
| 1134 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1135 | Stream.ExitBlock(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1136 | |
| 1137 | if (SLocEntryOffsets.empty()) |
| 1138 | return; |
| 1139 | |
| 1140 | // Write the source-location offsets table into the PCH block. This |
| 1141 | // table is used for lazily loading source-location information. |
| 1142 | using namespace llvm; |
| 1143 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1144 | Abbrev->Add(BitCodeAbbrevOp(pch::SOURCE_LOCATION_OFFSETS)); |
| 1145 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs |
| 1146 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // next offset |
| 1147 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets |
| 1148 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(Abbrev); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1150 | Record.clear(); |
| 1151 | Record.push_back(pch::SOURCE_LOCATION_OFFSETS); |
| 1152 | Record.push_back(SLocEntryOffsets.size()); |
| 1153 | Record.push_back(SourceMgr.getNextOffset()); |
| 1154 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1155 | (const char *)&SLocEntryOffsets.front(), |
Chris Lattner | 090d9b5 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1156 | SLocEntryOffsets.size()*sizeof(SLocEntryOffsets[0])); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1157 | |
| 1158 | // Write the source location entry preloads array, telling the PCH |
| 1159 | // reader which source locations entries it should load eagerly. |
| 1160 | Stream.EmitRecord(pch::SOURCE_LOCATION_PRELOADS, PreloadSLocs); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1163 | //===----------------------------------------------------------------------===// |
| 1164 | // Preprocessor Serialization |
| 1165 | //===----------------------------------------------------------------------===// |
| 1166 | |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1167 | /// \brief Writes the block containing the serialized form of the |
| 1168 | /// preprocessor. |
| 1169 | /// |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1170 | void PCHWriter::WritePreprocessor(const Preprocessor &PP) { |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1171 | RecordData Record; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1172 | |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1173 | // If the preprocessor __COUNTER__ value has been bumped, remember it. |
| 1174 | if (PP.getCounterValue() != 0) { |
| 1175 | Record.push_back(PP.getCounterValue()); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1176 | Stream.EmitRecord(pch::PP_COUNTER_VALUE, Record); |
Chris Lattner | c1f9d82 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 1177 | Record.clear(); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | // Enter the preprocessor block. |
| 1181 | Stream.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1183 | // If the PCH file contains __DATE__ or __TIME__ emit a warning about this. |
| 1184 | // FIXME: use diagnostics subsystem for localization etc. |
| 1185 | if (PP.SawDateOrTime()) |
| 1186 | fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1188 | // Loop over all the macro definitions that are live at the end of the file, |
| 1189 | // emitting each to the PP section. |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1190 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1191 | for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end(); |
| 1192 | I != E; ++I) { |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 1193 | // FIXME: This emits macros in hash table order, we should do it in a stable |
| 1194 | // order so that output is reproducible. |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1195 | MacroInfo *MI = I->second; |
| 1196 | |
| 1197 | // Don't emit builtin macros like __LINE__ to the PCH file unless they have |
| 1198 | // been redefined by the header (in which case they are not isBuiltinMacro). |
| 1199 | if (MI->isBuiltinMacro()) |
| 1200 | continue; |
| 1201 | |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1202 | AddIdentifierRef(I->first, Record); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1203 | MacroOffsets[I->first] = Stream.GetCurrentBitNo(); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1204 | Record.push_back(MI->getDefinitionLoc().getRawEncoding()); |
| 1205 | Record.push_back(MI->isUsed()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1207 | unsigned Code; |
| 1208 | if (MI->isObjectLike()) { |
| 1209 | Code = pch::PP_MACRO_OBJECT_LIKE; |
| 1210 | } else { |
| 1211 | Code = pch::PP_MACRO_FUNCTION_LIKE; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1213 | Record.push_back(MI->isC99Varargs()); |
| 1214 | Record.push_back(MI->isGNUVarargs()); |
| 1215 | Record.push_back(MI->getNumArgs()); |
| 1216 | for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end(); |
| 1217 | I != E; ++I) |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1218 | AddIdentifierRef(*I, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1219 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1220 | |
| 1221 | // If we have a detailed preprocessing record, record the macro definition |
| 1222 | // ID that corresponds to this macro. |
| 1223 | if (PPRec) |
| 1224 | Record.push_back(getMacroDefinitionID(PPRec->findMacroDefinition(MI))); |
| 1225 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1226 | Stream.EmitRecord(Code, Record); |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1227 | Record.clear(); |
| 1228 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1229 | // Emit the tokens array. |
| 1230 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { |
| 1231 | // Note that we know that the preprocessor does not have any annotation |
| 1232 | // tokens in it because they are created by the parser, and thus can't be |
| 1233 | // in a macro definition. |
| 1234 | const Token &Tok = MI->getReplacementToken(TokNo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1236 | Record.push_back(Tok.getLocation().getRawEncoding()); |
| 1237 | Record.push_back(Tok.getLength()); |
| 1238 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1239 | // FIXME: When reading literal tokens, reconstruct the literal pointer if |
| 1240 | // it is needed. |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1241 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1243 | // FIXME: Should translate token kind to a stable encoding. |
| 1244 | Record.push_back(Tok.getKind()); |
| 1245 | // FIXME: Should translate token flags to a stable encoding. |
| 1246 | Record.push_back(Tok.getFlags()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1248 | Stream.EmitRecord(pch::PP_TOKEN, Record); |
Chris Lattner | df961c2 | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 1249 | Record.clear(); |
| 1250 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1251 | ++NumMacros; |
Chris Lattner | 7c5d24e | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 1252 | } |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1253 | |
| 1254 | // If the preprocessor has a preprocessing record, emit it. |
| 1255 | unsigned NumPreprocessingRecords = 0; |
| 1256 | if (PPRec) { |
| 1257 | for (PreprocessingRecord::iterator E = PPRec->begin(), EEnd = PPRec->end(); |
| 1258 | E != EEnd; ++E) { |
| 1259 | Record.clear(); |
| 1260 | |
| 1261 | if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) { |
| 1262 | Record.push_back(NumPreprocessingRecords++); |
| 1263 | AddSourceLocation(MI->getSourceRange().getBegin(), Record); |
| 1264 | AddSourceLocation(MI->getSourceRange().getEnd(), Record); |
| 1265 | AddIdentifierRef(MI->getName(), Record); |
| 1266 | Record.push_back(getMacroDefinitionID(MI->getDefinition())); |
| 1267 | Stream.EmitRecord(pch::PP_MACRO_INSTANTIATION, Record); |
| 1268 | continue; |
| 1269 | } |
| 1270 | |
| 1271 | if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) { |
| 1272 | // Record this macro definition's location. |
| 1273 | pch::IdentID ID = getMacroDefinitionID(MD); |
| 1274 | if (ID != MacroDefinitionOffsets.size()) { |
| 1275 | if (ID > MacroDefinitionOffsets.size()) |
| 1276 | MacroDefinitionOffsets.resize(ID + 1); |
| 1277 | |
| 1278 | MacroDefinitionOffsets[ID] = Stream.GetCurrentBitNo(); |
| 1279 | } else |
| 1280 | MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo()); |
| 1281 | |
| 1282 | Record.push_back(NumPreprocessingRecords++); |
| 1283 | Record.push_back(ID); |
| 1284 | AddSourceLocation(MD->getSourceRange().getBegin(), Record); |
| 1285 | AddSourceLocation(MD->getSourceRange().getEnd(), Record); |
| 1286 | AddIdentifierRef(MD->getName(), Record); |
| 1287 | AddSourceLocation(MD->getLocation(), Record); |
| 1288 | Stream.EmitRecord(pch::PP_MACRO_DEFINITION, Record); |
| 1289 | continue; |
| 1290 | } |
| 1291 | } |
| 1292 | } |
| 1293 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1294 | Stream.ExitBlock(); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1295 | |
| 1296 | // Write the offsets table for the preprocessing record. |
| 1297 | if (NumPreprocessingRecords > 0) { |
| 1298 | // Write the offsets table for identifier IDs. |
| 1299 | using namespace llvm; |
| 1300 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1301 | Abbrev->Add(BitCodeAbbrevOp(pch::MACRO_DEFINITION_OFFSETS)); |
| 1302 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of records |
| 1303 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macro defs |
| 1304 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1305 | unsigned MacroDefOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1306 | |
| 1307 | Record.clear(); |
| 1308 | Record.push_back(pch::MACRO_DEFINITION_OFFSETS); |
| 1309 | Record.push_back(NumPreprocessingRecords); |
| 1310 | Record.push_back(MacroDefinitionOffsets.size()); |
| 1311 | Stream.EmitRecordWithBlob(MacroDefOffsetAbbrev, Record, |
| 1312 | (const char *)&MacroDefinitionOffsets.front(), |
| 1313 | MacroDefinitionOffsets.size() * sizeof(uint32_t)); |
| 1314 | } |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1317 | //===----------------------------------------------------------------------===// |
| 1318 | // Type Serialization |
| 1319 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0b1fb98 | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1321 | /// \brief Write the representation of a type to the PCH stream. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1322 | void PCHWriter::WriteType(QualType T) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1323 | pch::TypeID &ID = TypeIDs[T]; |
Chris Lattner | f04ad69 | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1324 | if (ID == 0) // we haven't seen this type before. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1325 | ID = NextTypeID++; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1327 | // Record the offset for this type. |
| 1328 | if (TypeOffsets.size() == ID - pch::NUM_PREDEF_TYPE_IDS) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1329 | TypeOffsets.push_back(Stream.GetCurrentBitNo()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1330 | else if (TypeOffsets.size() < ID - pch::NUM_PREDEF_TYPE_IDS) { |
| 1331 | TypeOffsets.resize(ID + 1 - pch::NUM_PREDEF_TYPE_IDS); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1332 | TypeOffsets[ID - pch::NUM_PREDEF_TYPE_IDS] = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | RecordData Record; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1336 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1337 | // Emit the type's representation. |
| 1338 | PCHTypeWriter W(*this, Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1339 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1340 | if (T.hasLocalNonFastQualifiers()) { |
| 1341 | Qualifiers Qs = T.getLocalQualifiers(); |
| 1342 | AddTypeRef(T.getLocalUnqualifiedType(), Record); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1343 | Record.push_back(Qs.getAsOpaqueValue()); |
| 1344 | W.Code = pch::TYPE_EXT_QUAL; |
| 1345 | } else { |
| 1346 | switch (T->getTypeClass()) { |
| 1347 | // For all of the concrete, non-dependent types, call the |
| 1348 | // appropriate visitor function. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1349 | #define TYPE(Class, Base) \ |
Mike Stump | b716633 | 2010-01-20 02:03:14 +0000 | [diff] [blame] | 1350 | case Type::Class: W.Visit##Class##Type(cast<Class##Type>(T)); break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1351 | #define ABSTRACT_TYPE(Class, Base) |
| 1352 | #define DEPENDENT_TYPE(Class, Base) |
| 1353 | #include "clang/AST/TypeNodes.def" |
| 1354 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1355 | // For all of the dependent type nodes (which only occur in C++ |
| 1356 | // templates), produce an error. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1357 | #define TYPE(Class, Base) |
| 1358 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 1359 | #include "clang/AST/TypeNodes.def" |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1360 | assert(false && "Cannot serialize dependent type nodes"); |
| 1361 | break; |
| 1362 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | // Emit the serialized record. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1366 | Stream.EmitRecord(W.Code, Record); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 1367 | |
| 1368 | // Flush any expressions that were written as part of this type. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1369 | FlushStmts(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1372 | //===----------------------------------------------------------------------===// |
| 1373 | // Declaration Serialization |
| 1374 | //===----------------------------------------------------------------------===// |
| 1375 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1376 | /// \brief Write the block containing all of the declaration IDs |
| 1377 | /// lexically declared within the given DeclContext. |
| 1378 | /// |
| 1379 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the |
| 1380 | /// bistream, or 0 if no block was written. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1381 | uint64_t PCHWriter::WriteDeclContextLexicalBlock(ASTContext &Context, |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1382 | DeclContext *DC) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1383 | if (DC->decls_empty()) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1384 | return 0; |
| 1385 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1386 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1387 | RecordData Record; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1388 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
| 1389 | D != DEnd; ++D) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1390 | AddDeclRef(*D, Record); |
| 1391 | |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1392 | ++NumLexicalDeclContexts; |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1393 | Stream.EmitRecord(pch::DECL_CONTEXT_LEXICAL, Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1394 | return Offset; |
| 1395 | } |
| 1396 | |
| 1397 | /// \brief Write the block containing all of the declaration IDs |
| 1398 | /// visible from the given DeclContext. |
| 1399 | /// |
| 1400 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the |
| 1401 | /// bistream, or 0 if no block was written. |
| 1402 | uint64_t PCHWriter::WriteDeclContextVisibleBlock(ASTContext &Context, |
| 1403 | DeclContext *DC) { |
| 1404 | if (DC->getPrimaryContext() != DC) |
| 1405 | return 0; |
| 1406 | |
Douglas Gregor | aff22df | 2009-04-21 22:32:33 +0000 | [diff] [blame] | 1407 | // Since there is no name lookup into functions or methods, and we |
| 1408 | // perform name lookup for the translation unit via the |
| 1409 | // IdentifierInfo chains, don't bother to build a |
| 1410 | // visible-declarations table for these entities. |
| 1411 | if (DC->isFunctionOrMethod() || DC->isTranslationUnit()) |
Douglas Gregor | 58f0699 | 2009-04-18 15:49:20 +0000 | [diff] [blame] | 1412 | return 0; |
| 1413 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1414 | // Force the DeclContext to build a its name-lookup table. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1415 | DC->lookup(DeclarationName()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1416 | |
| 1417 | // Serialize the contents of the mapping used for lookup. Note that, |
| 1418 | // although we have two very different code paths, the serialized |
| 1419 | // representation is the same for both cases: a declaration name, |
| 1420 | // followed by a size, followed by references to the visible |
| 1421 | // declarations that have that name. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1422 | uint64_t Offset = Stream.GetCurrentBitNo(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1423 | RecordData Record; |
| 1424 | StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr()); |
Douglas Gregor | 8c70006 | 2009-04-13 21:20:57 +0000 | [diff] [blame] | 1425 | if (!Map) |
| 1426 | return 0; |
| 1427 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1428 | for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end(); |
| 1429 | D != DEnd; ++D) { |
| 1430 | AddDeclarationName(D->first, Record); |
| 1431 | DeclContext::lookup_result Result = D->second.getLookupResult(Context); |
| 1432 | Record.push_back(Result.second - Result.first); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | for (; Result.first != Result.second; ++Result.first) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1434 | AddDeclRef(*Result.first, Record); |
| 1435 | } |
| 1436 | |
| 1437 | if (Record.size() == 0) |
| 1438 | return 0; |
| 1439 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1440 | Stream.EmitRecord(pch::DECL_CONTEXT_VISIBLE, Record); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 1441 | ++NumVisibleDeclContexts; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1442 | return Offset; |
| 1443 | } |
| 1444 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1445 | //===----------------------------------------------------------------------===// |
| 1446 | // Global Method Pool and Selector Serialization |
| 1447 | //===----------------------------------------------------------------------===// |
| 1448 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1449 | namespace { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1450 | // Trait used for the on-disk hash table used in the method pool. |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 1451 | class PCHMethodPoolTrait { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1452 | PCHWriter &Writer; |
| 1453 | |
| 1454 | public: |
| 1455 | typedef Selector key_type; |
| 1456 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1457 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1458 | typedef std::pair<ObjCMethodList, ObjCMethodList> data_type; |
| 1459 | typedef const data_type& data_type_ref; |
| 1460 | |
| 1461 | explicit PCHMethodPoolTrait(PCHWriter &Writer) : Writer(Writer) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1462 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1463 | static unsigned ComputeHash(Selector Sel) { |
| 1464 | unsigned N = Sel.getNumArgs(); |
| 1465 | if (N == 0) |
| 1466 | ++N; |
| 1467 | unsigned R = 5381; |
| 1468 | for (unsigned I = 0; I != N; ++I) |
| 1469 | if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1470 | R = llvm::HashString(II->getName(), R); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1471 | return R; |
| 1472 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1473 | |
| 1474 | std::pair<unsigned,unsigned> |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1475 | EmitKeyDataLength(llvm::raw_ostream& Out, Selector Sel, |
| 1476 | data_type_ref Methods) { |
| 1477 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); |
| 1478 | clang::io::Emit16(Out, KeyLen); |
| 1479 | unsigned DataLen = 2 + 2; // 2 bytes for each of the method counts |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1480 | for (const ObjCMethodList *Method = &Methods.first; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1481 | Method = Method->Next) |
| 1482 | if (Method->Method) |
| 1483 | DataLen += 4; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1484 | for (const ObjCMethodList *Method = &Methods.second; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1485 | Method = Method->Next) |
| 1486 | if (Method->Method) |
| 1487 | DataLen += 4; |
| 1488 | clang::io::Emit16(Out, DataLen); |
| 1489 | return std::make_pair(KeyLen, DataLen); |
| 1490 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1491 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1492 | void EmitKey(llvm::raw_ostream& Out, Selector Sel, unsigned) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1493 | uint64_t Start = Out.tell(); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1494 | assert((Start >> 32) == 0 && "Selector key offset too large"); |
| 1495 | Writer.SetSelectorOffset(Sel, Start); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1496 | unsigned N = Sel.getNumArgs(); |
| 1497 | clang::io::Emit16(Out, N); |
| 1498 | if (N == 0) |
| 1499 | N = 1; |
| 1500 | for (unsigned I = 0; I != N; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1501 | clang::io::Emit32(Out, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1502 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); |
| 1503 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1504 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1505 | void EmitData(llvm::raw_ostream& Out, key_type_ref, |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1506 | data_type_ref Methods, unsigned DataLen) { |
| 1507 | uint64_t Start = Out.tell(); (void)Start; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1508 | unsigned NumInstanceMethods = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1509 | for (const ObjCMethodList *Method = &Methods.first; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1510 | Method = Method->Next) |
| 1511 | if (Method->Method) |
| 1512 | ++NumInstanceMethods; |
| 1513 | |
| 1514 | unsigned NumFactoryMethods = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1515 | for (const ObjCMethodList *Method = &Methods.second; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1516 | Method = Method->Next) |
| 1517 | if (Method->Method) |
| 1518 | ++NumFactoryMethods; |
| 1519 | |
| 1520 | clang::io::Emit16(Out, NumInstanceMethods); |
| 1521 | clang::io::Emit16(Out, NumFactoryMethods); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1522 | for (const ObjCMethodList *Method = &Methods.first; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1523 | Method = Method->Next) |
| 1524 | if (Method->Method) |
| 1525 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | for (const ObjCMethodList *Method = &Methods.second; Method; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1527 | Method = Method->Next) |
| 1528 | if (Method->Method) |
| 1529 | clang::io::Emit32(Out, Writer.getDeclID(Method->Method)); |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1530 | |
| 1531 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1532 | } |
| 1533 | }; |
| 1534 | } // end anonymous namespace |
| 1535 | |
| 1536 | /// \brief Write the method pool into the PCH file. |
| 1537 | /// |
| 1538 | /// The method pool contains both instance and factory methods, stored |
| 1539 | /// in an on-disk hash table indexed by the selector. |
| 1540 | void PCHWriter::WriteMethodPool(Sema &SemaRef) { |
| 1541 | using namespace llvm; |
| 1542 | |
| 1543 | // Create and write out the blob that contains the instance and |
| 1544 | // factor method pools. |
| 1545 | bool Empty = true; |
| 1546 | { |
| 1547 | OnDiskChainedHashTableGenerator<PCHMethodPoolTrait> Generator; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1549 | // Create the on-disk hash table representation. Start by |
| 1550 | // iterating through the instance method pool. |
| 1551 | PCHMethodPoolTrait::key_type Key; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1552 | unsigned NumSelectorsInMethodPool = 0; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1553 | for (llvm::DenseMap<Selector, ObjCMethodList>::iterator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1554 | Instance = SemaRef.InstanceMethodPool.begin(), |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1555 | InstanceEnd = SemaRef.InstanceMethodPool.end(); |
| 1556 | Instance != InstanceEnd; ++Instance) { |
| 1557 | // Check whether there is a factory method with the same |
| 1558 | // selector. |
| 1559 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Factory |
| 1560 | = SemaRef.FactoryMethodPool.find(Instance->first); |
| 1561 | |
| 1562 | if (Factory == SemaRef.FactoryMethodPool.end()) |
| 1563 | Generator.insert(Instance->first, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1564 | std::make_pair(Instance->second, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1565 | ObjCMethodList())); |
| 1566 | else |
| 1567 | Generator.insert(Instance->first, |
| 1568 | std::make_pair(Instance->second, Factory->second)); |
| 1569 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1570 | ++NumSelectorsInMethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1571 | Empty = false; |
| 1572 | } |
| 1573 | |
| 1574 | // Now iterate through the factory method pool, to pick up any |
| 1575 | // selectors that weren't already in the instance method pool. |
| 1576 | for (llvm::DenseMap<Selector, ObjCMethodList>::iterator |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1577 | Factory = SemaRef.FactoryMethodPool.begin(), |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1578 | FactoryEnd = SemaRef.FactoryMethodPool.end(); |
| 1579 | Factory != FactoryEnd; ++Factory) { |
| 1580 | // Check whether there is an instance method with the same |
| 1581 | // selector. If so, there is no work to do here. |
| 1582 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Instance |
| 1583 | = SemaRef.InstanceMethodPool.find(Factory->first); |
| 1584 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1585 | if (Instance == SemaRef.InstanceMethodPool.end()) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1586 | Generator.insert(Factory->first, |
| 1587 | std::make_pair(ObjCMethodList(), Factory->second)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1588 | ++NumSelectorsInMethodPool; |
| 1589 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1590 | |
| 1591 | Empty = false; |
| 1592 | } |
| 1593 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1594 | if (Empty && SelectorOffsets.empty()) |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1595 | return; |
| 1596 | |
| 1597 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 | llvm::SmallString<4096> MethodPool; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1599 | uint32_t BucketOffset; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1600 | SelectorOffsets.resize(SelVector.size()); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1601 | { |
| 1602 | PCHMethodPoolTrait Trait(*this); |
| 1603 | llvm::raw_svector_ostream Out(MethodPool); |
| 1604 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1605 | clang::io::Emit32(Out, 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1606 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1607 | |
| 1608 | // For every selector that we have seen but which was not |
| 1609 | // written into the hash table, write the selector itself and |
| 1610 | // record it's offset. |
| 1611 | for (unsigned I = 0, N = SelVector.size(); I != N; ++I) |
| 1612 | if (SelectorOffsets[I] == 0) |
| 1613 | Trait.EmitKey(Out, SelVector[I], 0); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | // Create a blob abbreviation |
| 1617 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1618 | Abbrev->Add(BitCodeAbbrevOp(pch::METHOD_POOL)); |
| 1619 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1620 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1621 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1622 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1623 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1624 | // Write the method pool |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1625 | RecordData Record; |
| 1626 | Record.push_back(pch::METHOD_POOL); |
| 1627 | Record.push_back(BucketOffset); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1628 | Record.push_back(NumSelectorsInMethodPool); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1629 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool.str()); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1630 | |
| 1631 | // Create a blob abbreviation for the selector table offsets. |
| 1632 | Abbrev = new BitCodeAbbrev(); |
| 1633 | Abbrev->Add(BitCodeAbbrevOp(pch::SELECTOR_OFFSETS)); |
| 1634 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // index |
| 1635 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1636 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1637 | |
| 1638 | // Write the selector offsets table. |
| 1639 | Record.clear(); |
| 1640 | Record.push_back(pch::SELECTOR_OFFSETS); |
| 1641 | Record.push_back(SelectorOffsets.size()); |
| 1642 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, |
| 1643 | (const char *)&SelectorOffsets.front(), |
| 1644 | SelectorOffsets.size() * 4); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1648 | //===----------------------------------------------------------------------===// |
| 1649 | // Identifier Table Serialization |
| 1650 | //===----------------------------------------------------------------------===// |
| 1651 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1652 | namespace { |
Benjamin Kramer | bd21828 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 1653 | class PCHIdentifierTableTrait { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1654 | PCHWriter &Writer; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1655 | Preprocessor &PP; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1656 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1657 | /// \brief Determines whether this is an "interesting" identifier |
| 1658 | /// that needs a full IdentifierInfo structure written into the hash |
| 1659 | /// table. |
| 1660 | static bool isInterestingIdentifier(const IdentifierInfo *II) { |
| 1661 | return II->isPoisoned() || |
| 1662 | II->isExtensionToken() || |
| 1663 | II->hasMacroDefinition() || |
| 1664 | II->getObjCOrBuiltinID() || |
| 1665 | II->getFETokenInfo<void>(); |
| 1666 | } |
| 1667 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1668 | public: |
| 1669 | typedef const IdentifierInfo* key_type; |
| 1670 | typedef key_type key_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1672 | typedef pch::IdentID data_type; |
| 1673 | typedef data_type data_type_ref; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | |
| 1675 | PCHIdentifierTableTrait(PCHWriter &Writer, Preprocessor &PP) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1676 | : Writer(Writer), PP(PP) { } |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1677 | |
| 1678 | static unsigned ComputeHash(const IdentifierInfo* II) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1679 | return llvm::HashString(II->getName()); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1681 | |
| 1682 | std::pair<unsigned,unsigned> |
| 1683 | EmitKeyDataLength(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1684 | pch::IdentID ID) { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 1685 | unsigned KeyLen = II->getLength() + 1; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1686 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 |
| 1687 | if (isInterestingIdentifier(II)) { |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1688 | DataLen += 2; // 2 bytes for builtin ID, flags |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1689 | if (II->hasMacroDefinition() && |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1690 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro()) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1691 | DataLen += 4; |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1692 | for (IdentifierResolver::iterator D = IdentifierResolver::begin(II), |
| 1693 | DEnd = IdentifierResolver::end(); |
| 1694 | D != DEnd; ++D) |
| 1695 | DataLen += sizeof(pch::DeclID); |
| 1696 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1697 | clang::io::Emit16(Out, DataLen); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 1698 | // We emit the key length after the data length so that every |
| 1699 | // string is preceded by a 16-bit length. This matches the PTH |
| 1700 | // format for storing identifiers. |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 1701 | clang::io::Emit16(Out, KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1702 | return std::make_pair(KeyLen, DataLen); |
| 1703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1704 | |
| 1705 | void EmitKey(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1706 | unsigned KeyLen) { |
| 1707 | // Record the location of the key data. This is used when generating |
| 1708 | // the mapping from persistent IDs to strings. |
| 1709 | Writer.SetIdentifierOffset(II, Out.tell()); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 1710 | Out.write(II->getNameStart(), KeyLen); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1711 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1712 | |
| 1713 | void EmitData(llvm::raw_ostream& Out, const IdentifierInfo* II, |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1714 | pch::IdentID ID, unsigned) { |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1715 | if (!isInterestingIdentifier(II)) { |
| 1716 | clang::io::Emit32(Out, ID << 1); |
| 1717 | return; |
| 1718 | } |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1719 | |
Douglas Gregor | a92193e | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 1720 | clang::io::Emit32(Out, (ID << 1) | 0x01); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1721 | uint32_t Bits = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | bool hasMacroDefinition = |
| 1723 | II->hasMacroDefinition() && |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1724 | !PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro(); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1725 | Bits = (uint32_t)II->getObjCOrBuiltinID(); |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 1726 | Bits = (Bits << 1) | unsigned(hasMacroDefinition); |
| 1727 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); |
| 1728 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); |
| 1729 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1730 | clang::io::Emit16(Out, Bits); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1731 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1732 | if (hasMacroDefinition) |
Douglas Gregor | 5998da5 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 1733 | clang::io::Emit32(Out, Writer.getMacroOffset(II)); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1734 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1735 | // Emit the declaration IDs in reverse order, because the |
| 1736 | // IdentifierResolver provides the declarations as they would be |
| 1737 | // visible (e.g., the function "stat" would come before the struct |
| 1738 | // "stat"), but IdentifierResolver::AddDeclToIdentifierChain() |
| 1739 | // adds declarations to the end of the list (so we need to see the |
| 1740 | // struct "status" before the function "status"). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | llvm::SmallVector<Decl *, 16> Decls(IdentifierResolver::begin(II), |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1742 | IdentifierResolver::end()); |
| 1743 | for (llvm::SmallVector<Decl *, 16>::reverse_iterator D = Decls.rbegin(), |
| 1744 | DEnd = Decls.rend(); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1745 | D != DEnd; ++D) |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1746 | clang::io::Emit32(Out, Writer.getDeclID(*D)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1747 | } |
| 1748 | }; |
| 1749 | } // end anonymous namespace |
| 1750 | |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1751 | /// \brief Write the identifier table into the PCH file. |
| 1752 | /// |
| 1753 | /// The identifier table consists of a blob containing string data |
| 1754 | /// (the actual identifiers themselves) and a separate "offsets" index |
| 1755 | /// that maps identifier IDs to locations within the blob. |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1756 | void PCHWriter::WriteIdentifierTable(Preprocessor &PP) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1757 | using namespace llvm; |
| 1758 | |
| 1759 | // Create and write out the blob that contains the identifier |
| 1760 | // strings. |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1761 | { |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1762 | OnDiskChainedHashTableGenerator<PCHIdentifierTableTrait> Generator; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1764 | // Look for any identifiers that were named while processing the |
| 1765 | // headers, but are otherwise not needed. We add these to the hash |
| 1766 | // table to enable checking of the predefines buffer in the case |
| 1767 | // where the user adds new macro definitions when building the PCH |
| 1768 | // file. |
| 1769 | for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(), |
| 1770 | IDEnd = PP.getIdentifierTable().end(); |
| 1771 | ID != IDEnd; ++ID) |
| 1772 | getIdentifierRef(ID->second); |
| 1773 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1774 | // Create the on-disk hash table representation. |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1775 | IdentifierOffsets.resize(IdentifierIDs.size()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1776 | for (llvm::DenseMap<const IdentifierInfo *, pch::IdentID>::iterator |
| 1777 | ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end(); |
| 1778 | ID != IDEnd; ++ID) { |
| 1779 | assert(ID->first && "NULL identifier in identifier table"); |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 1780 | Generator.insert(ID->first, ID->second); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1781 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1782 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1783 | // Create the on-disk hash table in a buffer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 | llvm::SmallString<4096> IdentifierTable; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1785 | uint32_t BucketOffset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1786 | { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1787 | PCHIdentifierTableTrait Trait(*this, PP); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1788 | llvm::raw_svector_ostream Out(IdentifierTable); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1789 | // Make sure that no bucket is at offset 0 |
Douglas Gregor | a67e58c | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 1790 | clang::io::Emit32(Out, 0); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1791 | BucketOffset = Generator.Emit(Out, Trait); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | // Create a blob abbreviation |
| 1795 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1796 | Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_TABLE)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1797 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1798 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1799 | unsigned IDTableAbbrev = Stream.EmitAbbrev(Abbrev); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1800 | |
| 1801 | // Write the identifier table |
| 1802 | RecordData Record; |
| 1803 | Record.push_back(pch::IDENTIFIER_TABLE); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 1804 | Record.push_back(BucketOffset); |
Daniel Dunbar | ec312a1 | 2009-08-24 09:31:37 +0000 | [diff] [blame] | 1805 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable.str()); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | // Write the offsets table for identifier IDs. |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1809 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 1810 | Abbrev->Add(BitCodeAbbrevOp(pch::IDENTIFIER_OFFSET)); |
| 1811 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers |
| 1812 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
| 1813 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 1814 | |
| 1815 | RecordData Record; |
| 1816 | Record.push_back(pch::IDENTIFIER_OFFSET); |
| 1817 | Record.push_back(IdentifierOffsets.size()); |
| 1818 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, |
| 1819 | (const char *)&IdentifierOffsets.front(), |
| 1820 | IdentifierOffsets.size() * sizeof(uint32_t)); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1823 | //===----------------------------------------------------------------------===// |
| 1824 | // General Serialization Routines |
| 1825 | //===----------------------------------------------------------------------===// |
| 1826 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1827 | /// \brief Write a record containing the given attributes. |
| 1828 | void PCHWriter::WriteAttributeRecord(const Attr *Attr) { |
| 1829 | RecordData Record; |
| 1830 | for (; Attr; Attr = Attr->getNext()) { |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1831 | Record.push_back(Attr->getKind()); // FIXME: stable encoding, target attrs |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1832 | Record.push_back(Attr->isInherited()); |
| 1833 | switch (Attr->getKind()) { |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1834 | default: |
| 1835 | assert(0 && "Does not support PCH writing for this attribute yet!"); |
| 1836 | break; |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1837 | case Attr::Alias: |
| 1838 | AddString(cast<AliasAttr>(Attr)->getAliasee(), Record); |
| 1839 | break; |
| 1840 | |
| 1841 | case Attr::Aligned: |
| 1842 | Record.push_back(cast<AlignedAttr>(Attr)->getAlignment()); |
| 1843 | break; |
| 1844 | |
| 1845 | case Attr::AlwaysInline: |
| 1846 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1847 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1848 | case Attr::AnalyzerNoReturn: |
| 1849 | break; |
| 1850 | |
| 1851 | case Attr::Annotate: |
| 1852 | AddString(cast<AnnotateAttr>(Attr)->getAnnotation(), Record); |
| 1853 | break; |
| 1854 | |
| 1855 | case Attr::AsmLabel: |
| 1856 | AddString(cast<AsmLabelAttr>(Attr)->getLabel(), Record); |
| 1857 | break; |
| 1858 | |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1859 | case Attr::BaseCheck: |
| 1860 | break; |
| 1861 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1862 | case Attr::Blocks: |
| 1863 | Record.push_back(cast<BlocksAttr>(Attr)->getType()); // FIXME: stable |
| 1864 | break; |
| 1865 | |
Eli Friedman | 8f4c59e | 2009-11-09 18:38:53 +0000 | [diff] [blame] | 1866 | case Attr::CDecl: |
| 1867 | break; |
| 1868 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1869 | case Attr::Cleanup: |
| 1870 | AddDeclRef(cast<CleanupAttr>(Attr)->getFunctionDecl(), Record); |
| 1871 | break; |
| 1872 | |
| 1873 | case Attr::Const: |
| 1874 | break; |
| 1875 | |
| 1876 | case Attr::Constructor: |
| 1877 | Record.push_back(cast<ConstructorAttr>(Attr)->getPriority()); |
| 1878 | break; |
| 1879 | |
| 1880 | case Attr::DLLExport: |
| 1881 | case Attr::DLLImport: |
| 1882 | case Attr::Deprecated: |
| 1883 | break; |
| 1884 | |
| 1885 | case Attr::Destructor: |
| 1886 | Record.push_back(cast<DestructorAttr>(Attr)->getPriority()); |
| 1887 | break; |
| 1888 | |
| 1889 | case Attr::FastCall: |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1890 | case Attr::Final: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1891 | break; |
| 1892 | |
| 1893 | case Attr::Format: { |
| 1894 | const FormatAttr *Format = cast<FormatAttr>(Attr); |
| 1895 | AddString(Format->getType(), Record); |
| 1896 | Record.push_back(Format->getFormatIdx()); |
| 1897 | Record.push_back(Format->getFirstArg()); |
| 1898 | break; |
| 1899 | } |
| 1900 | |
Fariborz Jahanian | 5b16092 | 2009-05-20 17:41:43 +0000 | [diff] [blame] | 1901 | case Attr::FormatArg: { |
| 1902 | const FormatArgAttr *Format = cast<FormatArgAttr>(Attr); |
| 1903 | Record.push_back(Format->getFormatIdx()); |
| 1904 | break; |
| 1905 | } |
| 1906 | |
Fariborz Jahanian | 5b53005 | 2009-05-13 18:09:35 +0000 | [diff] [blame] | 1907 | case Attr::Sentinel : { |
| 1908 | const SentinelAttr *Sentinel = cast<SentinelAttr>(Attr); |
| 1909 | Record.push_back(Sentinel->getSentinel()); |
| 1910 | Record.push_back(Sentinel->getNullPos()); |
| 1911 | break; |
| 1912 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1913 | |
Chris Lattner | cf2a721 | 2009-04-20 19:12:28 +0000 | [diff] [blame] | 1914 | case Attr::GNUInline: |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1915 | case Attr::Hiding: |
Ted Kremenek | efbddd2 | 2010-02-17 02:37:45 +0000 | [diff] [blame] | 1916 | case Attr::IBActionKind: |
Ted Kremenek | 47e6990 | 2010-02-18 00:05:52 +0000 | [diff] [blame] | 1917 | case Attr::IBOutletKind: |
Ryan Flynn | 76168e2 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 1918 | case Attr::Malloc: |
Mike Stump | 1feade8 | 2009-08-26 22:31:08 +0000 | [diff] [blame] | 1919 | case Attr::NoDebug: |
Ted Kremenek | 47e6990 | 2010-02-18 00:05:52 +0000 | [diff] [blame] | 1920 | case Attr::NoInline: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1921 | case Attr::NoReturn: |
| 1922 | case Attr::NoThrow: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1923 | break; |
| 1924 | |
| 1925 | case Attr::NonNull: { |
| 1926 | const NonNullAttr *NonNull = cast<NonNullAttr>(Attr); |
| 1927 | Record.push_back(NonNull->size()); |
| 1928 | Record.insert(Record.end(), NonNull->begin(), NonNull->end()); |
| 1929 | break; |
| 1930 | } |
| 1931 | |
Ted Kremenek | 31c780d | 2010-02-18 00:05:45 +0000 | [diff] [blame] | 1932 | case Attr::CFReturnsNotRetained: |
| 1933 | case Attr::CFReturnsRetained: |
| 1934 | case Attr::NSReturnsNotRetained: |
| 1935 | case Attr::NSReturnsRetained: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1936 | case Attr::ObjCException: |
| 1937 | case Attr::ObjCNSObject: |
| 1938 | case Attr::Overloadable: |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1939 | case Attr::Override: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1940 | break; |
| 1941 | |
Anders Carlsson | a860e75 | 2009-08-08 18:23:56 +0000 | [diff] [blame] | 1942 | case Attr::PragmaPack: |
| 1943 | Record.push_back(cast<PragmaPackAttr>(Attr)->getAlignment()); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | |
Anders Carlsson | a860e75 | 2009-08-08 18:23:56 +0000 | [diff] [blame] | 1946 | case Attr::Packed: |
| 1947 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1948 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1949 | case Attr::Pure: |
| 1950 | break; |
| 1951 | |
| 1952 | case Attr::Regparm: |
| 1953 | Record.push_back(cast<RegparmAttr>(Attr)->getNumParams()); |
| 1954 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1955 | |
Nate Begeman | 6f3d838 | 2009-06-26 06:32:41 +0000 | [diff] [blame] | 1956 | case Attr::ReqdWorkGroupSize: |
| 1957 | Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getXDim()); |
| 1958 | Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getYDim()); |
| 1959 | Record.push_back(cast<ReqdWorkGroupSizeAttr>(Attr)->getZDim()); |
| 1960 | break; |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1961 | |
| 1962 | case Attr::Section: |
| 1963 | AddString(cast<SectionAttr>(Attr)->getName(), Record); |
| 1964 | break; |
| 1965 | |
| 1966 | case Attr::StdCall: |
| 1967 | case Attr::TransparentUnion: |
| 1968 | case Attr::Unavailable: |
| 1969 | case Attr::Unused: |
| 1970 | case Attr::Used: |
| 1971 | break; |
| 1972 | |
| 1973 | case Attr::Visibility: |
| 1974 | // FIXME: stable encoding |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1975 | Record.push_back(cast<VisibilityAttr>(Attr)->getVisibility()); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1976 | break; |
| 1977 | |
| 1978 | case Attr::WarnUnusedResult: |
| 1979 | case Attr::Weak: |
Rafael Espindola | 11e8ce7 | 2010-02-23 22:00:30 +0000 | [diff] [blame] | 1980 | case Attr::WeakRef: |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1981 | case Attr::WeakImport: |
| 1982 | break; |
| 1983 | } |
| 1984 | } |
| 1985 | |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1986 | Stream.EmitRecord(pch::DECL_ATTR, Record); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | void PCHWriter::AddString(const std::string &Str, RecordData &Record) { |
| 1990 | Record.push_back(Str.size()); |
| 1991 | Record.insert(Record.end(), Str.begin(), Str.end()); |
| 1992 | } |
| 1993 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1994 | /// \brief Note that the identifier II occurs at the given offset |
| 1995 | /// within the identifier table. |
| 1996 | void PCHWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1997 | IdentifierOffsets[IdentifierIDs[II] - 1] = Offset; |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2000 | /// \brief Note that the selector Sel occurs at the given offset |
| 2001 | /// within the method pool/selector table. |
| 2002 | void PCHWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { |
| 2003 | unsigned ID = SelectorIDs[Sel]; |
| 2004 | assert(ID && "Unknown selector"); |
| 2005 | SelectorOffsets[ID - 1] = Offset; |
| 2006 | } |
| 2007 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2008 | PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream) |
| 2009 | : Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS), |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2010 | NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0), |
| 2011 | NumVisibleDeclContexts(0) { } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2012 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2013 | void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls, |
| 2014 | const char *isysroot) { |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2015 | using namespace llvm; |
| 2016 | |
Douglas Gregor | e778504 | 2009-04-20 15:53:59 +0000 | [diff] [blame] | 2017 | ASTContext &Context = SemaRef.Context; |
| 2018 | Preprocessor &PP = SemaRef.PP; |
| 2019 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2020 | // Emit the file header. |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2021 | Stream.Emit((unsigned)'C', 8); |
| 2022 | Stream.Emit((unsigned)'P', 8); |
| 2023 | Stream.Emit((unsigned)'C', 8); |
| 2024 | Stream.Emit((unsigned)'H', 8); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2025 | |
Chris Lattner | b145b1e | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 2026 | WriteBlockInfoBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2027 | |
| 2028 | // The translation unit is the first declaration we'll emit. |
| 2029 | DeclIDs[Context.getTranslationUnitDecl()] = 1; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2030 | DeclTypesToEmit.push(Context.getTranslationUnitDecl()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2031 | |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2032 | // Make sure that we emit IdentifierInfos (and any attached |
| 2033 | // declarations) for builtins. |
| 2034 | { |
| 2035 | IdentifierTable &Table = PP.getIdentifierTable(); |
| 2036 | llvm::SmallVector<const char *, 32> BuiltinNames; |
| 2037 | Context.BuiltinInfo.GetBuiltinNames(BuiltinNames, |
| 2038 | Context.getLangOptions().NoBuiltin); |
| 2039 | for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I) |
| 2040 | getIdentifierRef(&Table.get(BuiltinNames[I])); |
| 2041 | } |
| 2042 | |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2043 | // Build a record containing all of the tentative definitions in this file, in |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 2044 | // TentativeDefinitions order. Generally, this record will be empty for |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2045 | // headers. |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2046 | RecordData TentativeDefinitions; |
Sebastian Redl | e9d12b6 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 2047 | for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) { |
| 2048 | AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions); |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2049 | } |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2050 | |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2051 | // Build a record containing all of the static unused functions in this file. |
| 2052 | RecordData UnusedStaticFuncs; |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2053 | for (unsigned i=0, e = SemaRef.UnusedStaticFuncs.size(); i !=e; ++i) |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2054 | AddDeclRef(SemaRef.UnusedStaticFuncs[i], UnusedStaticFuncs); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2055 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2056 | // Build a record containing all of the locally-scoped external |
| 2057 | // declarations in this header file. Generally, this record will be |
| 2058 | // empty. |
| 2059 | RecordData LocallyScopedExternalDecls; |
Chris Lattner | 63d65f8 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 2060 | // FIXME: This is filling in the PCH file in densemap order which is |
| 2061 | // nondeterminstic! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2063 | TD = SemaRef.LocallyScopedExternalDecls.begin(), |
| 2064 | TDEnd = SemaRef.LocallyScopedExternalDecls.end(); |
| 2065 | TD != TDEnd; ++TD) |
| 2066 | AddDeclRef(TD->second, LocallyScopedExternalDecls); |
| 2067 | |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2068 | // Build a record containing all of the ext_vector declarations. |
| 2069 | RecordData ExtVectorDecls; |
| 2070 | for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) |
| 2071 | AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls); |
| 2072 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2073 | // Write the remaining PCH contents. |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2074 | RecordData Record; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2075 | Stream.EnterSubblock(pch::PCH_BLOCK_ID, 5); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2076 | WriteMetadata(Context, isysroot); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2077 | WriteLanguageOptions(Context.getLangOptions()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2078 | if (StatCalls && !isysroot) |
| 2079 | WriteStatCache(*StatCalls, isysroot); |
| 2080 | WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2081 | // Write the record of special types. |
| 2082 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2083 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2084 | AddTypeRef(Context.getBuiltinVaListType(), Record); |
| 2085 | AddTypeRef(Context.getObjCIdType(), Record); |
| 2086 | AddTypeRef(Context.getObjCSelType(), Record); |
| 2087 | AddTypeRef(Context.getObjCProtoType(), Record); |
| 2088 | AddTypeRef(Context.getObjCClassType(), Record); |
| 2089 | AddTypeRef(Context.getRawCFConstantStringType(), Record); |
| 2090 | AddTypeRef(Context.getRawObjCFastEnumerationStateType(), Record); |
| 2091 | AddTypeRef(Context.getFILEType(), Record); |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2092 | AddTypeRef(Context.getjmp_bufType(), Record); |
| 2093 | AddTypeRef(Context.getsigjmp_bufType(), Record); |
Douglas Gregor | d1571ac | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2094 | AddTypeRef(Context.ObjCIdRedefinitionType, Record); |
| 2095 | AddTypeRef(Context.ObjCClassRedefinitionType, Record); |
Fariborz Jahanian | 13dcd00 | 2009-11-21 19:53:08 +0000 | [diff] [blame] | 2096 | #if 0 |
| 2097 | // FIXME. Accommodate for this in several PCH/Indexer tests |
Fariborz Jahanian | 369a3bd | 2009-11-25 23:07:42 +0000 | [diff] [blame] | 2098 | AddTypeRef(Context.ObjCSelRedefinitionType, Record); |
Fariborz Jahanian | 13dcd00 | 2009-11-21 19:53:08 +0000 | [diff] [blame] | 2099 | #endif |
Mike Stump | adaaad3 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2100 | AddTypeRef(Context.getRawBlockdescriptorType(), Record); |
Mike Stump | 083c25e | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2101 | AddTypeRef(Context.getRawBlockdescriptorExtendedType(), Record); |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 2102 | Stream.EmitRecord(pch::SPECIAL_TYPES, Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2103 | |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2104 | // Keep writing types and declarations until all types and |
| 2105 | // declarations have been written. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2106 | Stream.EnterSubblock(pch::DECLTYPES_BLOCK_ID, 3); |
| 2107 | WriteDeclsBlockAbbrevs(); |
| 2108 | while (!DeclTypesToEmit.empty()) { |
| 2109 | DeclOrType DOT = DeclTypesToEmit.front(); |
| 2110 | DeclTypesToEmit.pop(); |
| 2111 | if (DOT.isType()) |
| 2112 | WriteType(DOT.getType()); |
| 2113 | else |
| 2114 | WriteDecl(Context, DOT.getDecl()); |
| 2115 | } |
| 2116 | Stream.ExitBlock(); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2117 | |
Douglas Gregor | 813a97b | 2009-10-17 17:25:45 +0000 | [diff] [blame] | 2118 | WritePreprocessor(PP); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2119 | WriteMethodPool(SemaRef); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2120 | WriteIdentifierTable(PP); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2121 | |
| 2122 | // Write the type offsets array |
| 2123 | BitCodeAbbrev *Abbrev = new BitCodeAbbrev(); |
| 2124 | Abbrev->Add(BitCodeAbbrevOp(pch::TYPE_OFFSET)); |
| 2125 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types |
| 2126 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block |
| 2127 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2128 | Record.clear(); |
| 2129 | Record.push_back(pch::TYPE_OFFSET); |
| 2130 | Record.push_back(TypeOffsets.size()); |
| 2131 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2132 | (const char *)&TypeOffsets.front(), |
Chris Lattner | c732f5a | 2009-04-27 18:24:17 +0000 | [diff] [blame] | 2133 | TypeOffsets.size() * sizeof(TypeOffsets[0])); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2134 | |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 2135 | // Write the declaration offsets array |
| 2136 | Abbrev = new BitCodeAbbrev(); |
| 2137 | Abbrev->Add(BitCodeAbbrevOp(pch::DECL_OFFSET)); |
| 2138 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations |
| 2139 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block |
| 2140 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(Abbrev); |
| 2141 | Record.clear(); |
| 2142 | Record.push_back(pch::DECL_OFFSET); |
| 2143 | Record.push_back(DeclOffsets.size()); |
| 2144 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2145 | (const char *)&DeclOffsets.front(), |
Chris Lattner | c732f5a | 2009-04-27 18:24:17 +0000 | [diff] [blame] | 2146 | DeclOffsets.size() * sizeof(DeclOffsets[0])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2147 | |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2148 | // Write the record containing external, unnamed definitions. |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2149 | if (!ExternalDefinitions.empty()) |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2150 | Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 2151 | |
| 2152 | // Write the record containing tentative definitions. |
| 2153 | if (!TentativeDefinitions.empty()) |
| 2154 | Stream.EmitRecord(pch::TENTATIVE_DEFINITIONS, TentativeDefinitions); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2155 | |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2156 | // Write the record containing unused static functions. |
| 2157 | if (!UnusedStaticFuncs.empty()) |
| 2158 | Stream.EmitRecord(pch::UNUSED_STATIC_FUNCS, UnusedStaticFuncs); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2159 | |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2160 | // Write the record containing locally-scoped external definitions. |
| 2161 | if (!LocallyScopedExternalDecls.empty()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2162 | Stream.EmitRecord(pch::LOCALLY_SCOPED_EXTERNAL_DECLS, |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2163 | LocallyScopedExternalDecls); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2164 | |
| 2165 | // Write the record containing ext_vector type names. |
| 2166 | if (!ExtVectorDecls.empty()) |
| 2167 | Stream.EmitRecord(pch::EXT_VECTOR_DECLS, ExtVectorDecls); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2169 | // Some simple statistics |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2170 | Record.clear(); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2171 | Record.push_back(NumStatements); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 2172 | Record.push_back(NumMacros); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2173 | Record.push_back(NumLexicalDeclContexts); |
| 2174 | Record.push_back(NumVisibleDeclContexts); |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2175 | Stream.EmitRecord(pch::STATISTICS, Record); |
Douglas Gregor | c9490c0 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2176 | Stream.ExitBlock(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | void PCHWriter::AddSourceLocation(SourceLocation Loc, RecordData &Record) { |
| 2180 | Record.push_back(Loc.getRawEncoding()); |
| 2181 | } |
| 2182 | |
| 2183 | void PCHWriter::AddAPInt(const llvm::APInt &Value, RecordData &Record) { |
| 2184 | Record.push_back(Value.getBitWidth()); |
| 2185 | unsigned N = Value.getNumWords(); |
| 2186 | const uint64_t* Words = Value.getRawData(); |
| 2187 | for (unsigned I = 0; I != N; ++I) |
| 2188 | Record.push_back(Words[I]); |
| 2189 | } |
| 2190 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2191 | void PCHWriter::AddAPSInt(const llvm::APSInt &Value, RecordData &Record) { |
| 2192 | Record.push_back(Value.isUnsigned()); |
| 2193 | AddAPInt(Value, Record); |
| 2194 | } |
| 2195 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 2196 | void PCHWriter::AddAPFloat(const llvm::APFloat &Value, RecordData &Record) { |
| 2197 | AddAPInt(Value.bitcastToAPInt(), Record); |
| 2198 | } |
| 2199 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2200 | void PCHWriter::AddIdentifierRef(const IdentifierInfo *II, RecordData &Record) { |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2201 | Record.push_back(getIdentifierRef(II)); |
| 2202 | } |
| 2203 | |
| 2204 | pch::IdentID PCHWriter::getIdentifierRef(const IdentifierInfo *II) { |
| 2205 | if (II == 0) |
| 2206 | return 0; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2207 | |
| 2208 | pch::IdentID &ID = IdentifierIDs[II]; |
| 2209 | if (ID == 0) |
| 2210 | ID = IdentifierIDs.size(); |
Douglas Gregor | 2deaea3 | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 2211 | return ID; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2214 | pch::IdentID PCHWriter::getMacroDefinitionID(MacroDefinition *MD) { |
| 2215 | if (MD == 0) |
| 2216 | return 0; |
| 2217 | |
| 2218 | pch::IdentID &ID = MacroDefinitions[MD]; |
| 2219 | if (ID == 0) |
| 2220 | ID = MacroDefinitions.size(); |
| 2221 | return ID; |
| 2222 | } |
| 2223 | |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2224 | void PCHWriter::AddSelectorRef(const Selector SelRef, RecordData &Record) { |
| 2225 | if (SelRef.getAsOpaquePtr() == 0) { |
| 2226 | Record.push_back(0); |
| 2227 | return; |
| 2228 | } |
| 2229 | |
| 2230 | pch::SelectorID &SID = SelectorIDs[SelRef]; |
| 2231 | if (SID == 0) { |
| 2232 | SID = SelectorIDs.size(); |
| 2233 | SelVector.push_back(SelRef); |
| 2234 | } |
| 2235 | Record.push_back(SID); |
| 2236 | } |
| 2237 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2238 | void PCHWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg, |
| 2239 | RecordData &Record) { |
| 2240 | switch (Arg.getArgument().getKind()) { |
| 2241 | case TemplateArgument::Expression: |
| 2242 | AddStmt(Arg.getLocInfo().getAsExpr()); |
| 2243 | break; |
| 2244 | case TemplateArgument::Type: |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2245 | AddTypeSourceInfo(Arg.getLocInfo().getAsTypeSourceInfo(), Record); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2246 | break; |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 2247 | case TemplateArgument::Template: |
| 2248 | Record.push_back( |
| 2249 | Arg.getTemplateQualifierRange().getBegin().getRawEncoding()); |
| 2250 | Record.push_back(Arg.getTemplateQualifierRange().getEnd().getRawEncoding()); |
| 2251 | Record.push_back(Arg.getTemplateNameLoc().getRawEncoding()); |
| 2252 | break; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 2253 | case TemplateArgument::Null: |
| 2254 | case TemplateArgument::Integral: |
| 2255 | case TemplateArgument::Declaration: |
| 2256 | case TemplateArgument::Pack: |
| 2257 | break; |
| 2258 | } |
| 2259 | } |
| 2260 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2261 | void PCHWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo, RecordData &Record) { |
| 2262 | if (TInfo == 0) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2263 | AddTypeRef(QualType(), Record); |
| 2264 | return; |
| 2265 | } |
| 2266 | |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2267 | AddTypeRef(TInfo->getType(), Record); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2268 | TypeLocWriter TLW(*this, Record); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2269 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2270 | TLW.Visit(TL); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2273 | void PCHWriter::AddTypeRef(QualType T, RecordData &Record) { |
| 2274 | if (T.isNull()) { |
| 2275 | Record.push_back(pch::PREDEF_TYPE_NULL_ID); |
| 2276 | return; |
| 2277 | } |
| 2278 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2279 | unsigned FastQuals = T.getLocalFastQualifiers(); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2280 | T.removeFastQualifiers(); |
| 2281 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2282 | if (T.hasLocalNonFastQualifiers()) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2283 | pch::TypeID &ID = TypeIDs[T]; |
| 2284 | if (ID == 0) { |
| 2285 | // We haven't seen these qualifiers applied to this type before. |
| 2286 | // Assign it a new ID. This is the only time we enqueue a |
| 2287 | // qualified type, and it has no CV qualifiers. |
| 2288 | ID = NextTypeID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2289 | DeclTypesToEmit.push(T); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2290 | } |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2291 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2292 | // Encode the type qualifiers in the type reference. |
| 2293 | Record.push_back((ID << Qualifiers::FastWidth) | FastQuals); |
| 2294 | return; |
| 2295 | } |
| 2296 | |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 2297 | assert(!T.hasLocalQualifiers()); |
Kovarththanan Rajaratnam | 11a18f1 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 2298 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2299 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2300 | pch::TypeID ID = 0; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2301 | switch (BT->getKind()) { |
| 2302 | case BuiltinType::Void: ID = pch::PREDEF_TYPE_VOID_ID; break; |
| 2303 | case BuiltinType::Bool: ID = pch::PREDEF_TYPE_BOOL_ID; break; |
| 2304 | case BuiltinType::Char_U: ID = pch::PREDEF_TYPE_CHAR_U_ID; break; |
| 2305 | case BuiltinType::UChar: ID = pch::PREDEF_TYPE_UCHAR_ID; break; |
| 2306 | case BuiltinType::UShort: ID = pch::PREDEF_TYPE_USHORT_ID; break; |
| 2307 | case BuiltinType::UInt: ID = pch::PREDEF_TYPE_UINT_ID; break; |
| 2308 | case BuiltinType::ULong: ID = pch::PREDEF_TYPE_ULONG_ID; break; |
| 2309 | case BuiltinType::ULongLong: ID = pch::PREDEF_TYPE_ULONGLONG_ID; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 2310 | case BuiltinType::UInt128: ID = pch::PREDEF_TYPE_UINT128_ID; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2311 | case BuiltinType::Char_S: ID = pch::PREDEF_TYPE_CHAR_S_ID; break; |
| 2312 | case BuiltinType::SChar: ID = pch::PREDEF_TYPE_SCHAR_ID; break; |
| 2313 | case BuiltinType::WChar: ID = pch::PREDEF_TYPE_WCHAR_ID; break; |
| 2314 | case BuiltinType::Short: ID = pch::PREDEF_TYPE_SHORT_ID; break; |
| 2315 | case BuiltinType::Int: ID = pch::PREDEF_TYPE_INT_ID; break; |
| 2316 | case BuiltinType::Long: ID = pch::PREDEF_TYPE_LONG_ID; break; |
| 2317 | case BuiltinType::LongLong: ID = pch::PREDEF_TYPE_LONGLONG_ID; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 2318 | case BuiltinType::Int128: ID = pch::PREDEF_TYPE_INT128_ID; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2319 | case BuiltinType::Float: ID = pch::PREDEF_TYPE_FLOAT_ID; break; |
| 2320 | case BuiltinType::Double: ID = pch::PREDEF_TYPE_DOUBLE_ID; break; |
| 2321 | case BuiltinType::LongDouble: ID = pch::PREDEF_TYPE_LONGDOUBLE_ID; break; |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 2322 | case BuiltinType::NullPtr: ID = pch::PREDEF_TYPE_NULLPTR_ID; break; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2323 | case BuiltinType::Char16: ID = pch::PREDEF_TYPE_CHAR16_ID; break; |
| 2324 | case BuiltinType::Char32: ID = pch::PREDEF_TYPE_CHAR32_ID; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2325 | case BuiltinType::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_ID; break; |
| 2326 | case BuiltinType::Dependent: ID = pch::PREDEF_TYPE_DEPENDENT_ID; break; |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 2327 | case BuiltinType::ObjCId: ID = pch::PREDEF_TYPE_OBJC_ID; break; |
| 2328 | case BuiltinType::ObjCClass: ID = pch::PREDEF_TYPE_OBJC_CLASS; break; |
Fariborz Jahanian | 13dcd00 | 2009-11-21 19:53:08 +0000 | [diff] [blame] | 2329 | case BuiltinType::ObjCSel: ID = pch::PREDEF_TYPE_OBJC_SEL; break; |
Anders Carlsson | e89d159 | 2009-06-26 18:41:36 +0000 | [diff] [blame] | 2330 | case BuiltinType::UndeducedAuto: |
| 2331 | assert(0 && "Should not see undeduced auto here"); |
| 2332 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2335 | Record.push_back((ID << Qualifiers::FastWidth) | FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2336 | return; |
| 2337 | } |
| 2338 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2339 | pch::TypeID &ID = TypeIDs[T]; |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2340 | if (ID == 0) { |
| 2341 | // We haven't seen this type before. Assign it a new ID and put it |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2342 | // into the queue of types to emit. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2343 | ID = NextTypeID++; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2344 | DeclTypesToEmit.push(T); |
Douglas Gregor | 366809a | 2009-04-26 03:49:13 +0000 | [diff] [blame] | 2345 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2346 | |
| 2347 | // Encode the type qualifiers in the type reference. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2348 | Record.push_back((ID << Qualifiers::FastWidth) | FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | void PCHWriter::AddDeclRef(const Decl *D, RecordData &Record) { |
| 2352 | if (D == 0) { |
| 2353 | Record.push_back(0); |
| 2354 | return; |
| 2355 | } |
| 2356 | |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2357 | pch::DeclID &ID = DeclIDs[D]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2358 | if (ID == 0) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2359 | // We haven't seen this declaration before. Give it a new ID and |
| 2360 | // enqueue it in the list of declarations to emit. |
| 2361 | ID = DeclIDs.size(); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2362 | DeclTypesToEmit.push(const_cast<Decl *>(D)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | Record.push_back(ID); |
| 2366 | } |
| 2367 | |
Douglas Gregor | 3251ceb | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2368 | pch::DeclID PCHWriter::getDeclID(const Decl *D) { |
| 2369 | if (D == 0) |
| 2370 | return 0; |
| 2371 | |
| 2372 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); |
| 2373 | return DeclIDs[D]; |
| 2374 | } |
| 2375 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2376 | void PCHWriter::AddDeclarationName(DeclarationName Name, RecordData &Record) { |
Chris Lattner | ea5ce47 | 2009-04-27 07:35:58 +0000 | [diff] [blame] | 2377 | // FIXME: Emit a stable enum for NameKind. 0 = Identifier etc. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2378 | Record.push_back(Name.getNameKind()); |
| 2379 | switch (Name.getNameKind()) { |
| 2380 | case DeclarationName::Identifier: |
| 2381 | AddIdentifierRef(Name.getAsIdentifierInfo(), Record); |
| 2382 | break; |
| 2383 | |
| 2384 | case DeclarationName::ObjCZeroArgSelector: |
| 2385 | case DeclarationName::ObjCOneArgSelector: |
| 2386 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 2387 | AddSelectorRef(Name.getObjCSelector(), Record); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | |
| 2390 | case DeclarationName::CXXConstructorName: |
| 2391 | case DeclarationName::CXXDestructorName: |
| 2392 | case DeclarationName::CXXConversionFunctionName: |
| 2393 | AddTypeRef(Name.getCXXNameType(), Record); |
| 2394 | break; |
| 2395 | |
| 2396 | case DeclarationName::CXXOperatorName: |
| 2397 | Record.push_back(Name.getCXXOverloadedOperator()); |
| 2398 | break; |
| 2399 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2400 | case DeclarationName::CXXLiteralOperatorName: |
| 2401 | AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record); |
| 2402 | break; |
| 2403 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2404 | case DeclarationName::CXXUsingDirective: |
| 2405 | // No extra data to emit |
| 2406 | break; |
| 2407 | } |
| 2408 | } |