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