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