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" |
| 22 | #include "clang/AST/Decl.h" |
| 23 | #include "clang/AST/DeclBase.h" |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 24 | #include "clang/AST/Mangle.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 25 | #include "clang/AST/Type.h" |
| 26 | |
| 27 | #include "clang/Basic/Linkage.h" |
| 28 | #include "clang/Basic/TargetInfo.h" |
| 29 | |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 30 | #include "llvm/IR/LLVMContext.h" |
| 31 | #include "llvm/IR/DataLayout.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 32 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 33 | #include "slang.h" |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 34 | #include "slang_assert.h" |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 35 | #include "slang_rs_export_foreach.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 36 | #include "slang_rs_export_func.h" |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 37 | #include "slang_rs_export_reduce.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 38 | #include "slang_rs_export_type.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 39 | #include "slang_rs_export_var.h" |
| 40 | #include "slang_rs_exportable.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 41 | #include "slang_rs_pragma_handler.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 42 | #include "slang_rs_reflection.h" |
Matt Wala | eae0b7a | 2015-06-16 14:06:25 -0700 | [diff] [blame] | 43 | #include "slang_rs_special_func.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 44 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 45 | namespace slang { |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 46 | |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 47 | RSContext::RSContext(clang::Preprocessor &PP, |
| 48 | clang::ASTContext &Ctx, |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 49 | const clang::TargetInfo &Target, |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 50 | PragmaList *Pragmas, |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 51 | unsigned int TargetAPI, |
| 52 | bool Verbose) |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 53 | : mPP(PP), |
| 54 | mCtx(Ctx), |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 55 | mPragmas(Pragmas), |
Stephen Hines | 4a4bf92 | 2011-08-18 17:20:33 -0700 | [diff] [blame] | 56 | mTargetAPI(TargetAPI), |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 57 | mVerbose(Verbose), |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 58 | mDataLayout(nullptr), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 59 | mLLVMContext(llvm::getGlobalContext()), |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 60 | mLicenseNote(nullptr), |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 61 | mRSPackageName("android.renderscript"), |
Shih-wei Liao | 3fa286b | 2011-02-10 11:04:44 -0800 | [diff] [blame] | 62 | version(0), |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 63 | mMangleCtx(Ctx.createMangleContext()), |
| 64 | mIs64Bit(Target.getPointerWidth(0) == 64) { |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 65 | |
Jean-Luc Brouillet | 109e90a | 2014-07-07 17:36:07 -0700 | [diff] [blame] | 66 | AddPragmaHandlers(PP, this); |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 67 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 68 | // Prepare target data |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 69 | mDataLayout = new llvm::DataLayout(Target.getTargetDescription()); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 72 | bool RSContext::processExportVar(const clang::VarDecl *VD) { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 73 | slangAssert(!VD->getName().empty() && "Variable name should not be empty"); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 74 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 75 | // TODO(zonr): some check on variable |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 76 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 77 | RSExportType *ET = RSExportType::CreateFromDecl(this, VD); |
| 78 | if (!ET) |
| 79 | return false; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 80 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 81 | RSExportVar *EV = new RSExportVar(this, VD, ET); |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 82 | if (EV == nullptr) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 83 | return false; |
| 84 | else |
| 85 | mExportVars.push_back(EV); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 86 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 87 | return true; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 88 | } |
| 89 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 90 | bool RSContext::processExportFunc(const clang::FunctionDecl *FD) { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 91 | slangAssert(!FD->getName().empty() && "Function name should not be empty"); |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 92 | |
Stephen Hines | 3fbe68a | 2010-11-17 17:28:59 -0800 | [diff] [blame] | 93 | if (!FD->isThisDeclarationADefinition()) { |
| 94 | return true; |
| 95 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 96 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 97 | if (FD->getStorageClass() != clang::SC_None) { |
| 98 | fprintf(stderr, "RSContext::processExportFunc : cannot export extern or " |
| 99 | "static function '%s'\n", FD->getName().str().c_str()); |
| 100 | return false; |
| 101 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 102 | |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 103 | // Specialized function |
Matt Wala | eae0b7a | 2015-06-16 14:06:25 -0700 | [diff] [blame] | 104 | if (RSSpecialFunc::isSpecialRSFunc(mTargetAPI, FD)) { |
Stephen Hines | 9999ec3 | 2012-02-10 18:22:14 -0800 | [diff] [blame] | 105 | // Do not reflect specialized functions like init, dtor, or graphics root. |
Matt Wala | eae0b7a | 2015-06-16 14:06:25 -0700 | [diff] [blame] | 106 | return RSSpecialFunc::validateSpecialFuncDecl(mTargetAPI, this, FD); |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // Foreach kernel |
| 110 | if (RSExportForEach::isRSForEachFunc(mTargetAPI, FD)) { |
| 111 | if (auto *EFE = RSExportForEach::Create(this, FD)) { |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 112 | mExportForEach.push_back(EFE); |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 113 | return true; |
| 114 | } |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | // Reduce kernel |
| 119 | if (RSExportReduce::isRSReduceFunc(mTargetAPI, FD)) { |
| 120 | if (auto *ER = RSExportReduce::Create(this, FD)) { |
| 121 | mExportReduce.push_back(ER); |
| 122 | return true; |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | // Invokable |
| 128 | if (auto *EF = RSExportFunc::Create(this, FD)) { |
| 129 | mExportFuncs.push_back(EF); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 130 | return true; |
Stephen Hines | 3fbe68a | 2010-11-17 17:28:59 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 133 | return false; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 137 | bool RSContext::processExportType(const llvm::StringRef &Name) { |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 138 | clang::TranslationUnitDecl *TUDecl = mCtx.getTranslationUnitDecl(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 139 | |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 140 | slangAssert(TUDecl != nullptr && "Translation unit declaration (top-level " |
| 141 | "declaration) is null object"); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 142 | |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 143 | const clang::IdentifierInfo *II = mPP.getIdentifierInfo(Name); |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 144 | if (II == nullptr) |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 145 | // TODO(zonr): alert identifier @Name mark as an exportable type cannot be |
| 146 | // found |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 147 | return false; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 148 | |
Stephen Hines | c706907 | 2015-03-18 14:53:14 -0700 | [diff] [blame] | 149 | clang::DeclContext::lookup_result R = TUDecl->lookup(II); |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 150 | RSExportType *ET = nullptr; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 151 | |
Stephen Hines | c706907 | 2015-03-18 14:53:14 -0700 | [diff] [blame] | 152 | for (clang::DeclContext::lookup_iterator I = R.begin(), E = R.end(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 153 | I != E; |
| 154 | I++) { |
| 155 | clang::NamedDecl *const ND = *I; |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 156 | const clang::Type *T = nullptr; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 157 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 158 | switch (ND->getKind()) { |
| 159 | case clang::Decl::Typedef: { |
| 160 | T = static_cast<const clang::TypedefDecl*>( |
| 161 | ND)->getCanonicalDecl()->getUnderlyingType().getTypePtr(); |
| 162 | break; |
| 163 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 164 | case clang::Decl::Record: { |
| 165 | T = static_cast<const clang::RecordDecl*>(ND)->getTypeForDecl(); |
| 166 | break; |
| 167 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 168 | default: { |
| 169 | // unsupported, skip |
| 170 | break; |
Shih-wei Liao | ac91815 | 2010-08-29 02:43:24 -0700 | [diff] [blame] | 171 | } |
| 172 | } |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 173 | |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 174 | if (T != nullptr) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 175 | ET = RSExportType::Create(this, T); |
| 176 | } |
| 177 | |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 178 | return (ET != nullptr); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 181 | |
| 182 | // Possibly re-order ForEach exports (maybe generating a dummy "root" function). |
| 183 | // We require "root" to be listed as slot 0 of our exported compute kernels, |
| 184 | // so this only needs to be created if we have other non-root kernels. |
| 185 | void RSContext::cleanupForEach() { |
| 186 | bool foundNonRoot = false; |
| 187 | ExportForEachList::iterator begin = mExportForEach.begin(); |
| 188 | |
| 189 | for (ExportForEachList::iterator I = begin, E = mExportForEach.end(); |
| 190 | I != E; |
| 191 | I++) { |
| 192 | RSExportForEach *EFE = *I; |
| 193 | if (!EFE->getName().compare("root")) { |
| 194 | if (I == begin) { |
| 195 | // Nothing to do, since it is the first function |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | mExportForEach.erase(I); |
| 200 | mExportForEach.push_front(EFE); |
| 201 | return; |
| 202 | } else { |
| 203 | foundNonRoot = true; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // If we found a non-root kernel, but no root() function, we need to add a |
| 208 | // dummy version (so that script->script calls of rsForEach don't behave |
| 209 | // erratically). |
| 210 | if (foundNonRoot) { |
| 211 | RSExportForEach *DummyRoot = RSExportForEach::CreateDummyRoot(this); |
| 212 | mExportForEach.push_front(DummyRoot); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | |
Stephen Hines | c808a99 | 2010-11-29 17:20:42 -0800 | [diff] [blame] | 217 | bool RSContext::processExport() { |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 218 | bool valid = true; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 219 | |
| 220 | if (getDiagnostics()->hasErrorOccurred()) { |
| 221 | return false; |
| 222 | } |
| 223 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 224 | // Export variable |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 225 | clang::TranslationUnitDecl *TUDecl = mCtx.getTranslationUnitDecl(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 226 | for (clang::DeclContext::decl_iterator DI = TUDecl->decls_begin(), |
| 227 | DE = TUDecl->decls_end(); |
Stephen Hines | c97a333 | 2010-11-30 15:31:08 -0800 | [diff] [blame] | 228 | DI != DE; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 229 | DI++) { |
| 230 | if (DI->getKind() == clang::Decl::Var) { |
| 231 | clang::VarDecl *VD = (clang::VarDecl*) (*DI); |
Stephen Hines | 44f1006 | 2013-06-13 00:33:23 -0700 | [diff] [blame] | 232 | if (VD->getFormalLinkage() == clang::ExternalLinkage) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 233 | if (!processExportVar(VD)) { |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 234 | valid = false; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 235 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 236 | } |
| 237 | } else if (DI->getKind() == clang::Decl::Function) { |
| 238 | // Export functions |
| 239 | clang::FunctionDecl *FD = (clang::FunctionDecl*) (*DI); |
Stephen Hines | 44f1006 | 2013-06-13 00:33:23 -0700 | [diff] [blame] | 240 | if (FD->getFormalLinkage() == clang::ExternalLinkage) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 241 | if (!processExportFunc(FD)) { |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 242 | valid = false; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 243 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 244 | } |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 245 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 246 | } |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 247 | |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 248 | if (valid) { |
| 249 | cleanupForEach(); |
| 250 | } |
| 251 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 252 | // Finally, export type forcely set to be exported by user |
| 253 | for (NeedExportTypeSet::const_iterator EI = mNeedExportTypes.begin(), |
| 254 | EE = mNeedExportTypes.end(); |
| 255 | EI != EE; |
| 256 | EI++) { |
| 257 | if (!processExportType(EI->getKey())) { |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 258 | valid = false; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 259 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 260 | } |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 261 | |
Stephen Hines | b6809ed | 2011-05-09 13:05:04 -0700 | [diff] [blame] | 262 | return valid; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 265 | bool RSContext::insertExportType(const llvm::StringRef &TypeName, |
| 266 | RSExportType *ET) { |
| 267 | ExportTypeMap::value_type *NewItem = |
Stephen Hines | 2eb9a3f | 2014-07-15 16:50:03 -0700 | [diff] [blame] | 268 | ExportTypeMap::value_type::Create(TypeName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 269 | mExportTypes.getAllocator(), |
| 270 | ET); |
Shih-wei Liao | 6de8927 | 2010-07-15 15:26:20 -0700 | [diff] [blame] | 271 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 272 | if (mExportTypes.insert(NewItem)) { |
Shih-wei Liao | 6de8927 | 2010-07-15 15:26:20 -0700 | [diff] [blame] | 273 | return true; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 274 | } else { |
Matt Wala | 3f45a25 | 2015-06-30 11:24:19 -0700 | [diff] [blame] | 275 | NewItem->Destroy(mExportTypes.getAllocator()); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 276 | return false; |
| 277 | } |
| 278 | } |
| 279 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 280 | RSContext::~RSContext() { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 281 | delete mLicenseNote; |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 282 | delete mDataLayout; |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 283 | for (ExportableList::iterator I = mExportables.begin(), |
| 284 | E = mExportables.end(); |
| 285 | I != E; |
| 286 | I++) { |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 287 | if (!(*I)->isKeep()) |
| 288 | delete *I; |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 289 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 290 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 291 | |
| 292 | } // namespace slang |