blob: 7105b5ca6fc6fae87e954fa208ce2c21b7ad5602 [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
2 * Copyright 2010, 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
Stephen Hinese639eb52010-11-08 19:27:20 -080017#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FUNC_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FUNC_H_
Shih-wei Liao462aefd2010-06-04 15:32:04 -070019
20#include <list>
21#include <string>
22
zonr6315f762010-10-05 15:35:14 +080023#include "llvm/ADT/StringRef.h"
24
Zonr Chang0da0a7d2010-10-05 21:26:37 +080025#include "slang_rs_export_type.h"
Stephen Hinese639eb52010-11-08 19:27:20 -080026#include "slang_rs_exportable.h"
Zonr Chang0da0a7d2010-10-05 21:26:37 +080027
28namespace llvm {
29 class StructType;
30}
31
Shih-wei Liao462aefd2010-06-04 15:32:04 -070032namespace clang {
zonr6315f762010-10-05 15:35:14 +080033 class FunctionDecl;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070034} // namespace clang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070035
36namespace slang {
37
Zonr Chang0da0a7d2010-10-05 21:26:37 +080038class RSContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070039
Zonr Changa41ce1d2010-10-06 02:23:12 +080040class RSExportFunc : public RSExportable {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070041 friend class RSContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070042
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070043 private:
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070044 std::string mName;
Zonr Chang0da0a7d2010-10-05 21:26:37 +080045 RSExportRecordType *mParamPacketType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070046
zonr6315f762010-10-05 15:35:14 +080047 RSExportFunc(RSContext *Context, const llvm::StringRef &Name)
Zonr Changa41ce1d2010-10-06 02:23:12 +080048 : RSExportable(Context, RSExportable::EX_FUNC),
Zonr Chang0da0a7d2010-10-05 21:26:37 +080049 mName(Name.data(), Name.size()),
50 mParamPacketType(NULL) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070051 return;
52 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070053
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070054 public:
55 static RSExportFunc *Create(RSContext *Context,
56 const clang::FunctionDecl *FD);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070057
Zonr Chang0da0a7d2010-10-05 21:26:37 +080058 typedef RSExportRecordType::const_field_iterator const_param_iterator;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070059
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070060 inline const_param_iterator params_begin() const {
Zonr Chang0da0a7d2010-10-05 21:26:37 +080061 assert((mParamPacketType != NULL) &&
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080062 "Get parameter from export function having no parameter!");
Zonr Chang0da0a7d2010-10-05 21:26:37 +080063 return mParamPacketType->fields_begin();
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070064 }
65 inline const_param_iterator params_end() const {
Zonr Chang0da0a7d2010-10-05 21:26:37 +080066 assert((mParamPacketType != NULL) &&
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080067 "Get parameter from export function having no parameter!");
Zonr Chang0da0a7d2010-10-05 21:26:37 +080068 return mParamPacketType->fields_end();
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070069 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070070
Zonr Chang0da0a7d2010-10-05 21:26:37 +080071 inline const std::string &getName() const { return mName; }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070072
Zonr Chang0da0a7d2010-10-05 21:26:37 +080073 inline bool hasParam() const
74 { return (mParamPacketType && !mParamPacketType->getFields().empty()); }
75 inline size_t getNumParameters() const
76 { return ((mParamPacketType) ? mParamPacketType->getFields().size() : 0); }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070077
Zonr Chang0da0a7d2010-10-05 21:26:37 +080078 inline const RSExportRecordType *getParamPacketType() const
79 { return mParamPacketType; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070080
Zonr Chang0da0a7d2010-10-05 21:26:37 +080081 // Check whether the given ParamsPacket type (in LLVM type) is "size
82 // equivalent" to the one obtained from getParamPacketType(). If the @Params
83 // is NULL, means there must be no any parameters.
84 bool checkParameterPacketType(const llvm::StructType *ParamTy) const;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070085}; // RSExportFunc
Shih-wei Liao462aefd2010-06-04 15:32:04 -070086
Zonr Chang0da0a7d2010-10-05 21:26:37 +080087
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070088} // namespace slang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070089
Stephen Hinese639eb52010-11-08 19:27:20 -080090#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FUNC_H_ NOLINT