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