slang_rs_export_func.h revision 641558f02fe6ce0ee3ae5076eb366c25e2ad5903
1/*
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
17#ifndef _SLANG_COMPILER_RS_EXPORT_FUNC_H
18#define _SLANG_COMPILER_RS_EXPORT_FUNC_H
19
20#include <list>
21#include <string>
22
23#include "llvm/ADT/StringRef.h"
24
25#include "slang_rs_exportable.h"
26#include "slang_rs_export_type.h"
27
28namespace llvm {
29  class StructType;
30}
31
32namespace clang {
33  class FunctionDecl;
34}   // namespace clang
35
36namespace slang {
37
38class RSContext;
39
40class RSExportFunc : public RSExportable {
41  friend class RSContext;
42
43 private:
44  std::string mName;
45  RSExportRecordType *mParamPacketType;
46
47  RSExportFunc(RSContext *Context, const llvm::StringRef &Name)
48    : RSExportable(Context, RSExportable::EX_FUNC),
49      mName(Name.data(), Name.size()),
50      mParamPacketType(NULL) {
51    return;
52  }
53
54 public:
55  static RSExportFunc *Create(RSContext *Context,
56                              const clang::FunctionDecl *FD);
57
58  typedef RSExportRecordType::const_field_iterator const_param_iterator;
59
60  inline const_param_iterator params_begin() const {
61    assert((mParamPacketType != NULL) &&
62           "Get parameter from export function having no parameter!");
63    return mParamPacketType->fields_begin();
64  }
65  inline const_param_iterator params_end() const {
66    assert((mParamPacketType != NULL) &&
67           "Get parameter from export function having no parameter!");
68    return mParamPacketType->fields_end();
69  }
70
71  inline const std::string &getName() const { return mName; }
72
73  inline bool hasParam() const
74    { return (mParamPacketType && !mParamPacketType->getFields().empty()); }
75  inline size_t getNumParameters() const
76    { return ((mParamPacketType) ? mParamPacketType->getFields().size() : 0); }
77
78  inline const RSExportRecordType *getParamPacketType() const
79    { return mParamPacketType; }
80
81  // 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;
85};  // RSExportFunc
86
87
88}   // namespace slang
89
90#endif  // _SLANG_COMPILER_RS_EXPORT_FUNC_H
91