blob: bb9c1a00fef1318b9eeef793df5c4d0dd3b74c67 [file] [log] [blame]
Stephen Hines593a8942011-05-10 15:29:50 -07001/*
2 * Copyright 2011, The Android Open Source Project
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
17#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_
19
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/raw_ostream.h"
22
23#include "clang/AST/Decl.h"
24
25#include "slang_assert.h"
26#include "slang_rs_context.h"
27#include "slang_rs_exportable.h"
28#include "slang_rs_export_type.h"
29
30namespace clang {
31 class FunctionDecl;
32} // namespace clang
33
34namespace slang {
35
36// Base class for reflecting control-side forEach (currently for root()
37// functions that fit appropriate criteria)
38class RSExportForEach : public RSExportable {
39 private:
40 std::string mName;
41 RSExportRecordType *mParamPacketType;
Stephen Hinesb5a89fb2011-05-17 14:48:02 -070042 RSExportType *mInType;
43 RSExportType *mOutType;
Stephen Hines593a8942011-05-10 15:29:50 -070044 size_t numParams;
45
Stephen Hines4ccf75e2011-08-16 18:21:01 -070046 unsigned int mMetadataEncoding;
47
Stephen Hinesb5a89fb2011-05-17 14:48:02 -070048 const clang::ParmVarDecl *mIn;
49 const clang::ParmVarDecl *mOut;
50 const clang::ParmVarDecl *mUsrData;
51 const clang::ParmVarDecl *mX;
52 const clang::ParmVarDecl *mY;
53 const clang::ParmVarDecl *mZ;
54 const clang::ParmVarDecl *mAr;
55
56 // TODO(all): Add support for LOD/face when we have them
Stephen Hines593a8942011-05-10 15:29:50 -070057 RSExportForEach(RSContext *Context, const llvm::StringRef &Name,
58 const clang::FunctionDecl *FD)
59 : RSExportable(Context, RSExportable::EX_FOREACH),
Stephen Hinesb5a89fb2011-05-17 14:48:02 -070060 mName(Name.data(), Name.size()), mParamPacketType(NULL), mInType(NULL),
Stephen Hines4ccf75e2011-08-16 18:21:01 -070061 mOutType(NULL), numParams(0), mMetadataEncoding(0),
62 mIn(NULL), mOut(NULL), mUsrData(NULL),
Stephen Hinesb5a89fb2011-05-17 14:48:02 -070063 mX(NULL), mY(NULL), mZ(NULL), mAr(NULL) {
Stephen Hines593a8942011-05-10 15:29:50 -070064 return;
65 }
66
Stephen Hinesb5a89fb2011-05-17 14:48:02 -070067 bool validateAndConstructParams(RSContext *Context,
68 const clang::FunctionDecl *FD);
69
Stephen Hines593a8942011-05-10 15:29:50 -070070 public:
71 static RSExportForEach *Create(RSContext *Context,
72 const clang::FunctionDecl *FD);
73
74 inline const std::string &getName() const {
75 return mName;
76 }
77
78 inline size_t getNumParameters() const {
79 return numParams;
80 }
81
Stephen Hinesb5a89fb2011-05-17 14:48:02 -070082 inline bool hasIn() const {
83 return (mIn != NULL);
84 }
85
86 inline bool hasOut() const {
87 return (mOut != NULL);
88 }
89
90 inline bool hasUsrData() const {
91 return (mUsrData != NULL);
92 }
93
94 inline const RSExportType *getInType() const {
95 return mInType;
96 }
97
98 inline const RSExportType *getOutType() const {
99 return mOutType;
100 }
101
102 inline const RSExportRecordType *getParamPacketType() const {
103 return mParamPacketType;
104 }
Stephen Hines593a8942011-05-10 15:29:50 -0700105
Stephen Hines4ccf75e2011-08-16 18:21:01 -0700106 inline unsigned int getMetadataEncoding() const {
107 return mMetadataEncoding;
108 }
109
Stephen Hines593a8942011-05-10 15:29:50 -0700110 typedef RSExportRecordType::const_field_iterator const_param_iterator;
111
112 inline const_param_iterator params_begin() const {
113 slangAssert((mParamPacketType != NULL) &&
114 "Get parameter from export foreach having no parameter!");
115 return mParamPacketType->fields_begin();
116 }
Stephen Hinesb5a89fb2011-05-17 14:48:02 -0700117
Stephen Hines593a8942011-05-10 15:29:50 -0700118 inline const_param_iterator params_end() const {
119 slangAssert((mParamPacketType != NULL) &&
120 "Get parameter from export foreach having no parameter!");
121 return mParamPacketType->fields_end();
122 }
123
124 inline static bool isInitRSFunc(const clang::FunctionDecl *FD) {
125 if (!FD) {
126 return false;
127 }
128 const llvm::StringRef Name = FD->getName();
129 static llvm::StringRef FuncInit("init");
130 return Name.equals(FuncInit);
131 }
132
133 inline static bool isRootRSFunc(const clang::FunctionDecl *FD) {
134 if (!FD) {
135 return false;
136 }
137 const llvm::StringRef Name = FD->getName();
138 static llvm::StringRef FuncRoot("root");
139 return Name.equals(FuncRoot);
140 }
141
Stephen Hines688e64b2011-08-23 16:01:25 -0700142 inline static bool isDtorRSFunc(const clang::FunctionDecl *FD) {
143 if (!FD) {
144 return false;
145 }
146 const llvm::StringRef Name = FD->getName();
147 static llvm::StringRef FuncDtor(".rs.dtor");
148 return Name.equals(FuncDtor);
149 }
150
Stephen Hinesf736d5a2011-10-26 16:18:14 -0700151 static bool isRSForEachFunc(int targetAPI, const clang::FunctionDecl *FD);
Stephen Hines593a8942011-05-10 15:29:50 -0700152
153 inline static bool isSpecialRSFunc(const clang::FunctionDecl *FD) {
Stephen Hines688e64b2011-08-23 16:01:25 -0700154 return isRootRSFunc(FD) || isInitRSFunc(FD) || isDtorRSFunc(FD);
Stephen Hines593a8942011-05-10 15:29:50 -0700155 }
156
Stephen Hinesf736d5a2011-10-26 16:18:14 -0700157 static bool validateSpecialFuncDecl(int targetAPI,
Stephen Hinesfbfd7f52011-10-27 16:09:01 -0700158 clang::DiagnosticsEngine *DiagEngine,
Stephen Hines593a8942011-05-10 15:29:50 -0700159 const clang::FunctionDecl *FD);
160}; // RSExportForEach
161
162} // namespace slang
163
164#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ NOLINT