Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 2 | * Copyright 2010-2012, The Android Open Source Project |
Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 17 | #include "slang_rs_context.h" |
| 18 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 19 | #include <string> |
| 20 | |
| 21 | #include "clang/AST/ASTContext.h" |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 22 | #include "clang/AST/Attr.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 23 | #include "clang/AST/Decl.h" |
| 24 | #include "clang/AST/DeclBase.h" |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 25 | #include "clang/AST/Mangle.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
| 27 | |
| 28 | #include "clang/Basic/Linkage.h" |
| 29 | #include "clang/Basic/TargetInfo.h" |
| 30 | |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 31 | #include "llvm/IR/LLVMContext.h" |
| 32 | #include "llvm/IR/DataLayout.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 33 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 34 | #include "slang.h" |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 35 | #include "slang_assert.h" |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 36 | #include "slang_rs_export_foreach.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 37 | #include "slang_rs_export_func.h" |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 38 | #include "slang_rs_export_reduce.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 39 | #include "slang_rs_export_type.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 40 | #include "slang_rs_export_var.h" |
| 41 | #include "slang_rs_exportable.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 42 | #include "slang_rs_pragma_handler.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 43 | #include "slang_rs_reflection.h" |
Matt Wala | eae0b7a | 2015-06-16 14:06:25 -0700 | [diff] [blame] | 44 | #include "slang_rs_special_func.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 45 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 46 | namespace slang { |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 47 | |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 48 | RSContext::RSContext(clang::Preprocessor &PP, |
| 49 | clang::ASTContext &Ctx, |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 50 | const clang::TargetInfo &Target, |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 51 | PragmaList *Pragmas, |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 52 | unsigned int TargetAPI, |
| 53 | bool Verbose) |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 54 | : mPP(PP), |
| 55 | mCtx(Ctx), |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 56 | mPragmas(Pragmas), |
Stephen Hines | 4a4bf92 | 2011-08-18 17:20:33 -0700 | [diff] [blame] | 57 | mTargetAPI(TargetAPI), |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 58 | mVerbose(Verbose), |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 59 | mDataLayout(nullptr), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 60 | mLLVMContext(llvm::getGlobalContext()), |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 61 | mLicenseNote(nullptr), |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 62 | mRSPackageName("android.renderscript"), |
Shih-wei Liao | 3fa286b | 2011-02-10 11:04:44 -0800 | [diff] [blame] | 63 | version(0), |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 64 | mMangleCtx(Ctx.createMangleContext()), |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 65 | mIs64Bit(Target.getPointerWidth(0) == 64), |
| 66 | mNextSlot(1) { |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 67 | |
Jean-Luc Brouillet | 109e90a | 2014-07-07 17:36:07 -0700 | [diff] [blame] | 68 | AddPragmaHandlers(PP, this); |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 69 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 70 | // Prepare target data |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 71 | mDataLayout = new llvm::DataLayout(Target.getTargetDescription()); |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 72 | |
| 73 | // Reserve slot 0 for the root kernel. |
| 74 | mExportForEach.push_back(nullptr); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 77 | bool RSContext::processExportVar(const clang::VarDecl *VD) { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 78 | slangAssert(!VD->getName().empty() && "Variable name should not be empty"); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 79 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 80 | RSExportType *ET = RSExportType::CreateFromDecl(this, VD); |
| 81 | if (!ET) |
| 82 | return false; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 83 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 84 | RSExportVar *EV = new RSExportVar(this, VD, ET); |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 85 | if (EV == nullptr) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 86 | return false; |
| 87 | else |
| 88 | mExportVars.push_back(EV); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 89 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 90 | return true; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 93 | int RSContext::getForEachSlotNumber(const clang::FunctionDecl* FD) { |
| 94 | const clang::StringRef& funcName = FD->getName(); |
| 95 | return getForEachSlotNumber(funcName); |
| 96 | } |
| 97 | |
| 98 | int RSContext::getForEachSlotNumber(const clang::StringRef& funcName) { |
| 99 | auto it = mExportForEachMap.find(funcName); |
| 100 | if (it == mExportForEachMap.end()) { |
| 101 | return -1; |
| 102 | } |
| 103 | return it->second; |
| 104 | } |
| 105 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 106 | bool RSContext::processExportFunc(const clang::FunctionDecl *FD) { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 107 | slangAssert(!FD->getName().empty() && "Function name should not be empty"); |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 108 | |
Stephen Hines | 3fbe68a | 2010-11-17 17:28:59 -0800 | [diff] [blame] | 109 | if (!FD->isThisDeclarationADefinition()) { |
| 110 | return true; |
| 111 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 112 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 113 | if (FD->getStorageClass() != clang::SC_None) { |
| 114 | fprintf(stderr, "RSContext::processExportFunc : cannot export extern or " |
| 115 | "static function '%s'\n", FD->getName().str().c_str()); |
| 116 | return false; |
| 117 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 118 | |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 119 | // Specialized function |
Matt Wala | eae0b7a | 2015-06-16 14:06:25 -0700 | [diff] [blame] | 120 | if (RSSpecialFunc::isSpecialRSFunc(mTargetAPI, FD)) { |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 121 | // Do not reflect specialized functions like init, dtor, or graphics root. |
Matt Wala | eae0b7a | 2015-06-16 14:06:25 -0700 | [diff] [blame] | 122 | return RSSpecialFunc::validateSpecialFuncDecl(mTargetAPI, this, FD); |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | // Foreach kernel |
| 126 | if (RSExportForEach::isRSForEachFunc(mTargetAPI, FD)) { |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 127 | RSExportForEach *EFE = RSExportForEach::Create(this, FD); |
| 128 | if (EFE == nullptr) { |
| 129 | return false; |
Stephen Hines | 5d9263d | 2015-10-13 20:07:52 +0000 | [diff] [blame] | 130 | } |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 131 | const llvm::StringRef& funcName = FD->getName(); |
| 132 | if (funcName.equals("root")) { |
| 133 | mExportForEach[0] = EFE; |
| 134 | } else { |
| 135 | mExportForEach.push_back(EFE); |
| 136 | } |
| 137 | return true; |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | // Reduce kernel |
| 141 | if (RSExportReduce::isRSReduceFunc(mTargetAPI, FD)) { |
| 142 | if (auto *ER = RSExportReduce::Create(this, FD)) { |
| 143 | mExportReduce.push_back(ER); |
| 144 | return true; |
| 145 | } |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | // Invokable |
| 150 | if (auto *EF = RSExportFunc::Create(this, FD)) { |
| 151 | mExportFuncs.push_back(EF); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 152 | return true; |
Stephen Hines | 3fbe68a | 2010-11-17 17:28:59 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 155 | return false; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 158 | bool RSContext::addForEach(const clang::FunctionDecl* FD) { |
| 159 | const llvm::StringRef& funcName = FD->getName(); |
| 160 | |
| 161 | if (funcName.equals("root")) { |
| 162 | // The root kernel should always be in slot 0. |
| 163 | mExportForEachMap.insert(std::make_pair(funcName, 0)); |
| 164 | } else { |
| 165 | mExportForEachMap.insert(std::make_pair(funcName, mNextSlot++)); |
| 166 | } |
| 167 | |
| 168 | return true; |
| 169 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 170 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 171 | bool RSContext::processExportType(const llvm::StringRef &Name) { |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 172 | clang::TranslationUnitDecl *TUDecl = mCtx.getTranslationUnitDecl(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 173 | |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 174 | slangAssert(TUDecl != nullptr && "Translation unit declaration (top-level " |
| 175 | "declaration) is null object"); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 176 | |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 177 | const clang::IdentifierInfo *II = mPP.getIdentifierInfo(Name); |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 178 | if (II == nullptr) |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 179 | // TODO(zonr): alert identifier @Name mark as an exportable type cannot be |
| 180 | // found |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 181 | return false; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 182 | |
Stephen Hines | c706907 | 2015-03-18 14:53:14 -0700 | [diff] [blame] | 183 | clang::DeclContext::lookup_result R = TUDecl->lookup(II); |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 184 | RSExportType *ET = nullptr; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 185 | |
Stephen Hines | c706907 | 2015-03-18 14:53:14 -0700 | [diff] [blame] | 186 | for (clang::DeclContext::lookup_iterator I = R.begin(), E = R.end(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 187 | I != E; |
| 188 | I++) { |
| 189 | clang::NamedDecl *const ND = *I; |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 190 | const clang::Type *T = nullptr; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 191 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 192 | switch (ND->getKind()) { |
| 193 | case clang::Decl::Typedef: { |
| 194 | T = static_cast<const clang::TypedefDecl*>( |
| 195 | ND)->getCanonicalDecl()->getUnderlyingType().getTypePtr(); |
| 196 | break; |
| 197 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 198 | case clang::Decl::Record: { |
| 199 | T = static_cast<const clang::RecordDecl*>(ND)->getTypeForDecl(); |
| 200 | break; |
| 201 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 202 | default: { |
| 203 | // unsupported, skip |
| 204 | break; |
Shih-wei Liao | ac91815 | 2010-08-29 02:43:24 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 207 | |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 208 | if (T != nullptr) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 209 | ET = RSExportType::Create(this, T); |
| 210 | } |
| 211 | |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 212 | return (ET != nullptr); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 215 | bool RSContext::processExports() { |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 216 | bool valid = true; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 217 | |
| 218 | if (getDiagnostics()->hasErrorOccurred()) { |
| 219 | return false; |
| 220 | } |
| 221 | |
Stephen Hines | 5d9263d | 2015-10-13 20:07:52 +0000 | [diff] [blame] | 222 | clang::TranslationUnitDecl *TUDecl = mCtx.getTranslationUnitDecl(); |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 223 | for (auto I = TUDecl->decls_begin(), E = TUDecl->decls_end(); I != E; I++) { |
| 224 | clang::Decl* D = *I; |
| 225 | switch (D->getKind()) { |
| 226 | case clang::Decl::Var: { |
| 227 | clang::VarDecl* VD = llvm::dyn_cast<clang::VarDecl>(D); |
Stephen Hines | a5d846d | 2015-10-08 20:06:26 -0700 | [diff] [blame] | 228 | bool ShouldExportVariable = true; |
Stephen Hines | 5d9263d | 2015-10-13 20:07:52 +0000 | [diff] [blame] | 229 | if (VD->getFormalLinkage() == clang::ExternalLinkage) { |
Stephen Hines | a5d846d | 2015-10-08 20:06:26 -0700 | [diff] [blame] | 230 | clang::QualType QT = VD->getTypeSourceInfo()->getType(); |
| 231 | if (QT.isConstQualified() && !VD->hasInit()) { |
| 232 | if (Slang::IsLocInRSHeaderFile(VD->getLocation(), |
| 233 | *getSourceManager())) { |
| 234 | // We don't export variables internal to the runtime's |
| 235 | // implementation. |
| 236 | ShouldExportVariable = false; |
| 237 | } else { |
| 238 | clang::DiagnosticsEngine *DiagEngine = getDiagnostics(); |
| 239 | DiagEngine->Report(VD->getLocation(), DiagEngine->getCustomDiagID( |
| 240 | clang::DiagnosticsEngine::Error, |
| 241 | "invalid declaration of uninitialized constant variable '%0'")) |
| 242 | << VD->getName(); |
| 243 | valid = false; |
| 244 | } |
| 245 | } |
| 246 | if (valid && ShouldExportVariable && !processExportVar(VD)) { |
Stephen Hines | 5d9263d | 2015-10-13 20:07:52 +0000 | [diff] [blame] | 247 | valid = false; |
| 248 | } |
| 249 | } |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 250 | break; |
| 251 | } |
| 252 | case clang::Decl::Function: { |
| 253 | clang::FunctionDecl* FD = llvm::dyn_cast<clang::FunctionDecl>(D); |
Stephen Hines | 5d9263d | 2015-10-13 20:07:52 +0000 | [diff] [blame] | 254 | if (FD->getFormalLinkage() == clang::ExternalLinkage) { |
| 255 | if (!processExportFunc(FD)) { |
| 256 | valid = false; |
| 257 | } |
| 258 | } |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 259 | break; |
| 260 | } |
| 261 | default: |
| 262 | break; |
Stephen Hines | 5d9263d | 2015-10-13 20:07:52 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 266 | // Create a dummy root in slot 0 if a root kernel is not seen. |
| 267 | if (valid && mExportForEach[0] == nullptr) { |
| 268 | mExportForEach[0] = RSExportForEach::CreateDummyRoot(this); |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 271 | // Finally, export type forcely set to be exported by user |
| 272 | for (NeedExportTypeSet::const_iterator EI = mNeedExportTypes.begin(), |
| 273 | EE = mNeedExportTypes.end(); |
| 274 | EI != EE; |
| 275 | EI++) { |
| 276 | if (!processExportType(EI->getKey())) { |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 277 | valid = false; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 278 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 279 | } |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 280 | |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 281 | return valid; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 284 | bool RSContext::insertExportType(const llvm::StringRef &TypeName, |
| 285 | RSExportType *ET) { |
| 286 | ExportTypeMap::value_type *NewItem = |
Stephen Hines | 2eb9a3f | 2014-07-15 16:50:03 -0700 | [diff] [blame] | 287 | ExportTypeMap::value_type::Create(TypeName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 288 | mExportTypes.getAllocator(), |
| 289 | ET); |
Shih-wei Liao | 6de8927 | 2010-07-15 15:26:20 -0700 | [diff] [blame] | 290 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 291 | if (mExportTypes.insert(NewItem)) { |
Shih-wei Liao | 6de8927 | 2010-07-15 15:26:20 -0700 | [diff] [blame] | 292 | return true; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 293 | } else { |
Matt Wala | 3f45a25 | 2015-06-30 11:24:19 -0700 | [diff] [blame] | 294 | NewItem->Destroy(mExportTypes.getAllocator()); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 299 | RSContext::~RSContext() { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 300 | delete mLicenseNote; |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 301 | delete mDataLayout; |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 302 | for (ExportableList::iterator I = mExportables.begin(), |
| 303 | E = mExportables.end(); |
| 304 | I != E; |
| 305 | I++) { |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 306 | if (!(*I)->isKeep()) |
| 307 | delete *I; |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 308 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 309 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 310 | |
| 311 | } // namespace slang |