slang_rs_context.h revision 8ee018bdb53fc5abdc430878e2bec0c0c0aa560f
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/* 20a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines * Copyright 2010-2012, The Android Open Source Project 3c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 4c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License"); 5c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * you may not use this file except in compliance with the License. 6c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * You may obtain a copy of the License at 7c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 8c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * http://www.apache.org/licenses/LICENSE-2.0 9c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 10c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Unless required by applicable law or agreed to in writing, software 11c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS, 12c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * See the License for the specific language governing permissions and 14c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * limitations under the License. 15c383a500aa59423264811be3874461bf8adbfea0Zonr Chang */ 16c383a500aa59423264811be3874461bf8adbfea0Zonr Chang 17e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_ // NOLINT 18e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_ 19462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 20e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <cstdio> 21462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#include <list> 22e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <map> 235e306b944425a952fe744f59d828538137a59375David Gross#include <set> 24462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#include <string> 2565f23ed862e1a1e16477ba740f295ff4a83ac822David Gross#include <unordered_set> 26fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni#include <vector> 27e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 28e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/Lex/Preprocessor.h" 29be27482cdeaf08576bc39b72a15d35d13014a636Logan#include "clang/AST/Mangle.h" 30462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include "llvm/ADT/StringSet.h" 329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include "llvm/ADT/StringMap.h" 33462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3434e6205f1d5ceb90a73192cee8b215fa0b7ab306David Gross#include "slang_pragma_list.h" 353fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines 36462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm { 376315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class LLVMContext; 3823c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines class DataLayout; 399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao} // namespace llvm 40462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 41462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace clang { 426315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class VarDecl; 436315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class ASTContext; 446315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class TargetInfo; 456315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class FunctionDecl; 46fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni class QualType; 476315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr class SourceManager; 48fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni class TypeDecl; 4965f23ed862e1a1e16477ba740f295ff4a83ac822David Gross class FunctionDecl; 509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao} // namespace clang 51462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 52462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang { 535e306b944425a952fe744f59d828538137a59375David Gross class Backend; 54a41ce1d98094da84643995d40d71c529905123fcZonr Chang class RSExportable; 55a41ce1d98094da84643995d40d71c529905123fcZonr Chang class RSExportVar; 56a41ce1d98094da84643995d40d71c529905123fcZonr Chang class RSExportFunc; 57593a894650e81be54173106ec266f0311cebebd3Stephen Hines class RSExportForEach; 58c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala class RSExportReduce; 59a41ce1d98094da84643995d40d71c529905123fcZonr Chang class RSExportType; 60462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 61462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSContext { 629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef llvm::StringSet<> NeedExportVarSet; 639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef llvm::StringSet<> NeedExportFuncSet; 649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef llvm::StringSet<> NeedExportTypeSet; 659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 67a41ce1d98094da84643995d40d71c529905123fcZonr Chang typedef std::list<RSExportable*> ExportableList; 689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef std::list<RSExportVar*> ExportVarList; 699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef std::list<RSExportFunc*> ExportFuncList; 70fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni typedef std::vector<RSExportForEach*> ExportForEachVector; 71c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala typedef std::list<RSExportReduce*> ExportReduceList; 7265f23ed862e1a1e16477ba740f295ff4a83ac822David Gross 7365f23ed862e1a1e16477ba740f295ff4a83ac822David Gross // WARNING: Sorted by pointer value, resulting in unpredictable order 748ee018bdb53fc5abdc430878e2bec0c0c0aa560fDavid Gross typedef std::unordered_set<RSExportType*> ExportReduceResultTypeSet; 7565f23ed862e1a1e16477ba740f295ff4a83ac822David Gross 769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef llvm::StringMap<RSExportType*> ExportTypeMap; 779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private: 799e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines clang::Preprocessor &mPP; 809e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines clang::ASTContext &mCtx; 813fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines PragmaList *mPragmas; 82109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet // Precision specified via pragma, either rs_fp_full or rs_fp_relaxed. If 83109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet // empty, rs_fp_full is assumed. 84109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet std::string mPrecision; 85c9454afec1649846512993d0ef65a9f868976bb4Chris Wailes unsigned int mTargetAPI; 86fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines bool mVerbose; 879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 8823c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines llvm::DataLayout *mDataLayout; 899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao llvm::LLVMContext &mLLVMContext; 909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 91a41ce1d98094da84643995d40d71c529905123fcZonr Chang ExportableList mExportables; 92a41ce1d98094da84643995d40d71c529905123fcZonr Chang 939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao NeedExportTypeSet mNeedExportTypes; 949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string *mLicenseNote; 969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string mReflectJavaPackageName; 979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string mReflectJavaPathName; 989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 990a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines std::string mRSPackageName; 1000a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines 10196ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines int version; 10282754d87921c94e70562aa977cc92e28fc38b1d0Stephen Hines 1032eb9a3f7c48fe54eb4e813d80e3363bc79553a1eStephen Hines std::unique_ptr<clang::MangleContext> mMangleCtx; 10496ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines 1059ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines bool mIs64Bit; 1069ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines 1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool processExportVar(const clang::VarDecl *VD); 1089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool processExportFunc(const clang::FunctionDecl *FD); 1099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool processExportType(const llvm::StringRef &Name); 1109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 111fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni int getForEachSlotNumber(const clang::StringRef& funcName); 112fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni unsigned mNextSlot; 113c17e198ffcd37bfc57e3add1f6eee952ae2a2eabStephen Hines 1149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportVarList mExportVars; 1159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportFuncList mExportFuncs; 116fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni std::map<llvm::StringRef, unsigned> mExportForEachMap; 117fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni ExportForEachVector mExportForEach; 11840bac5d72af8fe32ab3d0bb38aafb5c65d8d9dfaYang Ni ExportForEachVector::iterator mFirstOldStyleKernel; 119c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala ExportReduceList mExportReduce; 1208ee018bdb53fc5abdc430878e2bec0c0c0aa560fDavid Gross ExportReduceResultTypeSet mExportReduceResultType; 1219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ExportTypeMap mExportTypes; 1229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 123fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni clang::QualType mAllocationType; 1242615f383dfc1542a05f19aee23b03a09bd018f4eYang Ni clang::QualType mScriptCallType; 125fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni 1265e306b944425a952fe744f59d828538137a59375David Gross std::set<const clang::FunctionDecl *> mUsedByReducePragmaFns; 1275e306b944425a952fe744f59d828538137a59375David Gross 1285e306b944425a952fe744f59d828538137a59375David Gross // Populated by markUsedByReducePragma(). 1295e306b944425a952fe744f59d828538137a59375David Gross // Consumed by processReducePragmas(). 1305e306b944425a952fe744f59d828538137a59375David Gross std::vector<clang::VarDecl *> mUsedByReducePragmaDummyVars; 1315e306b944425a952fe744f59d828538137a59375David Gross 1329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public: 1339e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines RSContext(clang::Preprocessor &PP, 1349e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines clang::ASTContext &Ctx, 1353fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines const clang::TargetInfo &Target, 1364cc67fce91f43215d61b2695746eab102a3db516Stephen Hines PragmaList *Pragmas, 137fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines unsigned int TargetAPI, 138fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines bool Verbose); 1399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1405e306b944425a952fe744f59d828538137a59375David Gross enum CheckName { CheckNameNo, CheckNameYes }; 1415e306b944425a952fe744f59d828538137a59375David Gross 1425e306b944425a952fe744f59d828538137a59375David Gross static bool isSyntheticName(const llvm::StringRef Name) { return Name.startswith(".rs."); } 1435e306b944425a952fe744f59d828538137a59375David Gross 1449e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines inline clang::Preprocessor &getPreprocessor() const { return mPP; } 1459e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines inline clang::ASTContext &getASTContext() const { return mCtx; } 146be27482cdeaf08576bc39b72a15d35d13014a636Logan inline clang::MangleContext &getMangleContext() const { 147be27482cdeaf08576bc39b72a15d35d13014a636Logan return *mMangleCtx; 148f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines } 14923c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines inline const llvm::DataLayout *getDataLayout() const { return mDataLayout; } 1509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline llvm::LLVMContext &getLLVMContext() const { return mLLVMContext; } 1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const clang::SourceManager *getSourceManager() const { 1529e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines return &mPP.getSourceManager(); 1539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 1549207a2e495c8363606861e4f034504ec5c153dabLogan Chien inline clang::DiagnosticsEngine *getDiagnostics() const { 1552ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines return &mPP.getDiagnostics(); 1562ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines } 157c9454afec1649846512993d0ef65a9f868976bb4Chris Wailes inline unsigned int getTargetAPI() const { 1584a4bf92a8add68629a7e6e59ef81c3c3fe603a75Stephen Hines return mTargetAPI; 1594a4bf92a8add68629a7e6e59ef81c3c3fe603a75Stephen Hines } 1609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 161fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines inline bool getVerbose() const { 162fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines return mVerbose; 163fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines } 1649ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines inline bool is64Bit() const { 1659ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines return mIs64Bit; 1669ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines } 167fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines 1689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline void setLicenseNote(const std::string &S) { 1699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mLicenseNote = new std::string(S); 1709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 1719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline const std::string *getLicenseNote() const { return mLicenseNote; } 1729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline void addExportType(const std::string &S) { 1749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mNeedExportTypes.insert(S); 1759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 1769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline void setReflectJavaPackageName(const std::string &S) { 1789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mReflectJavaPackageName = S; 1799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 180dde98533fad4c6534af537ae583aa4db35a1c699Tim Murray inline const std::string &getReflectJavaPackageName() const { 1814cc67fce91f43215d61b2695746eab102a3db516Stephen Hines return mReflectJavaPackageName; 1824cc67fce91f43215d61b2695746eab102a3db516Stephen Hines } 1839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 1840a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines inline void setRSPackageName(const std::string &S) { 1850a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines mRSPackageName = S; 1860a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines } 18712fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet 18812fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet inline const std::string &getRSPackageName() const { return mRSPackageName; } 1890a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines 19088f21e16250d2e52a75607b7f0c396e1c2a34201Yang Ni void setAllocationType(const clang::TypeDecl* TD); 19188f21e16250d2e52a75607b7f0c396e1c2a34201Yang Ni inline const clang::QualType& getAllocationType() const { 19288f21e16250d2e52a75607b7f0c396e1c2a34201Yang Ni return mAllocationType; 19388f21e16250d2e52a75607b7f0c396e1c2a34201Yang Ni } 19488f21e16250d2e52a75607b7f0c396e1c2a34201Yang Ni 1952615f383dfc1542a05f19aee23b03a09bd018f4eYang Ni void setScriptCallType(const clang::TypeDecl* TD); 1962615f383dfc1542a05f19aee23b03a09bd018f4eYang Ni inline const clang::QualType& getScriptCallType() const { 1972615f383dfc1542a05f19aee23b03a09bd018f4eYang Ni return mScriptCallType; 1982615f383dfc1542a05f19aee23b03a09bd018f4eYang Ni } 1992615f383dfc1542a05f19aee23b03a09bd018f4eYang Ni 200fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni bool addForEach(const clang::FunctionDecl* FD); 201fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni bool processExports(); 202a41ce1d98094da84643995d40d71c529905123fcZonr Chang inline void newExportable(RSExportable *E) { 2035abbe0e9ca2508260b627ffef2bf01e2554e8357Chris Wailes if (E != nullptr) 204a41ce1d98094da84643995d40d71c529905123fcZonr Chang mExportables.push_back(E); 205a41ce1d98094da84643995d40d71c529905123fcZonr Chang } 206641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang typedef ExportableList::iterator exportable_iterator; 207641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang exportable_iterator exportable_begin() { 208641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang return mExportables.begin(); 209641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang } 210641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang exportable_iterator exportable_end() { 211641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang return mExportables.end(); 212641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang } 2139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef ExportVarList::const_iterator const_export_var_iterator; 2159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const_export_var_iterator export_vars_begin() const { 2169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportVars.begin(); 2179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const_export_var_iterator export_vars_end() const { 2199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportVars.end(); 2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool hasExportVar() const { 2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return !mExportVars.empty(); 2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef ExportFuncList::const_iterator const_export_func_iterator; 2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const_export_func_iterator export_funcs_begin() const { 2279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportFuncs.begin(); 2289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const_export_func_iterator export_funcs_end() const { 2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportFuncs.end(); 2319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool hasExportFunc() const { return !mExportFuncs.empty(); } 2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 234fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni typedef ExportForEachVector::const_iterator const_export_foreach_iterator; 235593a894650e81be54173106ec266f0311cebebd3Stephen Hines const_export_foreach_iterator export_foreach_begin() const { 236593a894650e81be54173106ec266f0311cebebd3Stephen Hines return mExportForEach.begin(); 237593a894650e81be54173106ec266f0311cebebd3Stephen Hines } 238593a894650e81be54173106ec266f0311cebebd3Stephen Hines const_export_foreach_iterator export_foreach_end() const { 239593a894650e81be54173106ec266f0311cebebd3Stephen Hines return mExportForEach.end(); 240593a894650e81be54173106ec266f0311cebebd3Stephen Hines } 241593a894650e81be54173106ec266f0311cebebd3Stephen Hines inline bool hasExportForEach() const { return !mExportForEach.empty(); } 242fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni int getForEachSlotNumber(const clang::FunctionDecl* FD); 243593a894650e81be54173106ec266f0311cebebd3Stephen Hines 244c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala typedef ExportReduceList::const_iterator const_export_reduce_iterator; 245c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala const_export_reduce_iterator export_reduce_begin() const { 246c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala return mExportReduce.begin(); 247c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala } 248c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala const_export_reduce_iterator export_reduce_end() const { 249c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala return mExportReduce.end(); 250c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala } 251c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala inline bool hasExportReduce() const { return !mExportReduce.empty(); } 2528ee018bdb53fc5abdc430878e2bec0c0c0aa560fDavid Gross void addExportReduce(RSExportReduce *Reduce) { 2538ee018bdb53fc5abdc430878e2bec0c0c0aa560fDavid Gross mExportReduce.push_back(Reduce); 25415e44e66adc350adb4fe0533a442092c64333ab5David Gross } 2555e306b944425a952fe744f59d828538137a59375David Gross bool processReducePragmas(Backend *BE); 2565e306b944425a952fe744f59d828538137a59375David Gross void markUsedByReducePragma(clang::FunctionDecl *FD, CheckName Check); 25765f23ed862e1a1e16477ba740f295ff4a83ac822David Gross 25865f23ed862e1a1e16477ba740f295ff4a83ac822David Gross // If the type has already been inserted, has no effect. 2598ee018bdb53fc5abdc430878e2bec0c0c0aa560fDavid Gross void insertExportReduceResultType(RSExportType *Type) { mExportReduceResultType.insert(Type); } 26065f23ed862e1a1e16477ba740f295ff4a83ac822David Gross 261277fd5e6545c8ba1272027ee6e6bc55a96316dc0David Gross template <class FilterIn, class Compare> 2628ee018bdb53fc5abdc430878e2bec0c0c0aa560fDavid Gross std::vector<RSExportType *> getReduceResultTypes(FilterIn Filt, Compare Comp) const { 263277fd5e6545c8ba1272027ee6e6bc55a96316dc0David Gross std::vector<RSExportType *> Return; 2648ee018bdb53fc5abdc430878e2bec0c0c0aa560fDavid Gross std::copy_if(mExportReduceResultType.begin(), mExportReduceResultType.end(), std::back_inserter(Return), Filt); 26565f23ed862e1a1e16477ba740f295ff4a83ac822David Gross std::sort(Return.begin(), Return.end(), Comp); 266812dcd0b28c68363bba2f132ff2bdff6577ba9b7David Gross auto ReturnNewEndIter = std::unique(Return.begin(), Return.end(), 267812dcd0b28c68363bba2f132ff2bdff6577ba9b7David Gross [Comp](const RSExportType *a, const RSExportType *b) { 268812dcd0b28c68363bba2f132ff2bdff6577ba9b7David Gross return !Comp(a, b) && !Comp(b, a); 269812dcd0b28c68363bba2f132ff2bdff6577ba9b7David Gross }); 270812dcd0b28c68363bba2f132ff2bdff6577ba9b7David Gross Return.erase(ReturnNewEndIter, Return.end()); 27165f23ed862e1a1e16477ba740f295ff4a83ac822David Gross return Return; 27265f23ed862e1a1e16477ba740f295ff4a83ac822David Gross } 27315e44e66adc350adb4fe0533a442092c64333ab5David Gross 2749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef ExportTypeMap::iterator export_type_iterator; 2759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao typedef ExportTypeMap::const_iterator const_export_type_iterator; 2769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao export_type_iterator export_types_begin() { return mExportTypes.begin(); } 2779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao export_type_iterator export_types_end() { return mExportTypes.end(); } 2789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const_export_type_iterator export_types_begin() const { 2799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportTypes.begin(); 2809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const_export_type_iterator export_types_end() const { 2829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportTypes.end(); 2839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao inline bool hasExportType() const { return !mExportTypes.empty(); } 2859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao export_type_iterator findExportType(const llvm::StringRef &TypeName) { 2869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportTypes.find(TypeName); 2879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const_export_type_iterator findExportType(const llvm::StringRef &TypeName) 2899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const { 2909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return mExportTypes.find(TypeName); 2919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Insert the specified Typename/Type pair into the map. If the key already 2949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // exists in the map, return false and ignore the request, otherwise insert it 2959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // and return true. 2969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao bool insertExportType(const llvm::StringRef &TypeName, RSExportType *Type); 2979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 29896ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines int getVersion() const { return version; } 29996ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines void setVersion(int v) { 30096ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines version = v; 30196ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines } 30296ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines 30312fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet bool isCompatLib() const { 30412fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet // If we are not targeting the actual Android Renderscript classes, 30512fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet // we should reflect code that works with the compatibility library. 30612fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet return (mRSPackageName.compare("android.renderscript") != 0); 30712fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet } 30882754d87921c94e70562aa977cc92e28fc38b1d0Stephen Hines 3093fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines void addPragma(const std::string &T, const std::string &V) { 3103fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines mPragmas->push_back(make_pair(T, V)); 3113fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines } 312109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet void setPrecision(const std::string &P) { mPrecision = P; } 313109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet std::string getPrecision() { return mPrecision; } 3143fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines 315d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet // Report an error or a warning to the user. 316ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray template <unsigned N> 317d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level, 318ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray const char (&Message)[N]) { 319ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray clang::DiagnosticsEngine *DiagEngine = getDiagnostics(); 320ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray return DiagEngine->Report(DiagEngine->getCustomDiagID(Level, Message)); 3215e306b944425a952fe744f59d828538137a59375David Gross } 322ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray 323ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray template <unsigned N> 324d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level, 325ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray const clang::SourceLocation Loc, 326ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray const char (&Message)[N]) { 327ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray clang::DiagnosticsEngine *DiagEngine = getDiagnostics(); 328ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray const clang::SourceManager *SM = getSourceManager(); 329ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray return DiagEngine->Report(clang::FullSourceLoc(Loc, *SM), 330ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray DiagEngine->getCustomDiagID(Level, Message)); 3315e306b944425a952fe744f59d828538137a59375David Gross } 332d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet 333d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet // Utility functions to report errors and warnings to make the calling code 334d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet // easier to read. 335ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray template <unsigned N> 336ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray clang::DiagnosticBuilder ReportError(const char (&Message)[N]) { 337ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray return Report<N>(clang::DiagnosticsEngine::Error, Message); 338d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet } 339ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray 340ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray template <unsigned N> 341d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet clang::DiagnosticBuilder ReportError(const clang::SourceLocation Loc, 342ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray const char (&Message)[N]) { 343ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray return Report<N>(clang::DiagnosticsEngine::Error, Loc, Message); 344d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet } 345ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray 346ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray template <unsigned N> 347ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray clang::DiagnosticBuilder ReportWarning(const char (&Message)[N]) { 348ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray return Report<N>(clang::DiagnosticsEngine::Warning, Message); 349d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet } 350ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray 351ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray template <unsigned N> 352d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet clang::DiagnosticBuilder ReportWarning(const clang::SourceLocation Loc, 353ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray const char (&Message)[N]) { 354ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray return Report<N>(clang::DiagnosticsEngine::Warning, Loc, Message); 355d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet } 356d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet 3579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ~RSContext(); 358462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao}; 359462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao} // namespace slang 361462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 362e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_ NOLINT 363