slang_rs_export_func.h revision 0da0a7dc51c25943fe31d0bfccbdfee326a3199c
1#ifndef _SLANG_COMPILER_RS_EXPORT_FUNC_H
2#define _SLANG_COMPILER_RS_EXPORT_FUNC_H
3
4#include <list>
5#include <string>
6
7#include "llvm/ADT/StringRef.h"
8
9#include "slang_rs_export_type.h"
10
11namespace llvm {
12  class StructType;
13}
14
15namespace clang {
16  class FunctionDecl;
17}   // namespace clang
18
19namespace slang {
20
21class RSContext;
22
23class RSExportFunc {
24  friend class RSContext;
25
26 private:
27  RSContext *mContext;
28  std::string mName;
29  RSExportRecordType *mParamPacketType;
30
31  RSExportFunc(RSContext *Context, const llvm::StringRef &Name)
32    : mContext(Context),
33      mName(Name.data(), Name.size()),
34      mParamPacketType(NULL) {
35    return;
36  }
37
38 public:
39  static RSExportFunc *Create(RSContext *Context,
40                              const clang::FunctionDecl *FD);
41
42  typedef RSExportRecordType::const_field_iterator const_param_iterator;
43
44  inline const_param_iterator params_begin() const {
45    assert((mParamPacketType != NULL) &&
46           "Get parameter from export function without parameter!");
47    return mParamPacketType->fields_begin();
48  }
49  inline const_param_iterator params_end() const {
50    assert((mParamPacketType != NULL) &&
51           "Get parameter from export function without parameter!");
52    return mParamPacketType->fields_end();
53  }
54
55  inline const std::string &getName() const { return mName; }
56  inline RSContext *getRSContext() const { return mContext; }
57
58  inline bool hasParam() const
59    { return (mParamPacketType && !mParamPacketType->getFields().empty()); }
60  inline size_t getNumParameters() const
61    { return ((mParamPacketType) ? mParamPacketType->getFields().size() : 0); }
62
63  inline const RSExportRecordType *getParamPacketType() const
64    { return mParamPacketType; }
65
66  // Check whether the given ParamsPacket type (in LLVM type) is "size
67  // equivalent" to the one obtained from getParamPacketType(). If the @Params
68  // is NULL, means there must be no any parameters.
69  bool checkParameterPacketType(const llvm::StructType *ParamTy) const;
70};  // RSExportFunc
71
72
73}   // namespace slang
74
75#endif  // _SLANG_COMPILER_RS_EXPORT_FUNC_H
76