blob: 08bd3813b3ad84ee299f85d7ea2bfa365dcdef6e [file] [log] [blame]
zonr6315f762010-10-05 15:35:14 +08001#ifndef _SLANG_COMPILER_RS_EXPORT_FUNC_H
2#define _SLANG_COMPILER_RS_EXPORT_FUNC_H
Shih-wei Liao462aefd2010-06-04 15:32:04 -07003
4#include <list>
5#include <string>
6
zonr6315f762010-10-05 15:35:14 +08007#include "llvm/ADT/StringRef.h"
8
Zonr Chang0da0a7d2010-10-05 21:26:37 +08009#include "slang_rs_export_type.h"
10
11namespace llvm {
12 class StructType;
13}
14
Shih-wei Liao462aefd2010-06-04 15:32:04 -070015namespace clang {
zonr6315f762010-10-05 15:35:14 +080016 class FunctionDecl;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070017} // namespace clang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070018
19namespace slang {
20
Zonr Chang0da0a7d2010-10-05 21:26:37 +080021class RSContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070022
23class RSExportFunc {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070024 friend class RSContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070025
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070026 private:
27 RSContext *mContext;
28 std::string mName;
Zonr Chang0da0a7d2010-10-05 21:26:37 +080029 RSExportRecordType *mParamPacketType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070030
zonr6315f762010-10-05 15:35:14 +080031 RSExportFunc(RSContext *Context, const llvm::StringRef &Name)
Zonr Chang0da0a7d2010-10-05 21:26:37 +080032 : mContext(Context),
33 mName(Name.data(), Name.size()),
34 mParamPacketType(NULL) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070035 return;
36 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070037
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070038 public:
39 static RSExportFunc *Create(RSContext *Context,
40 const clang::FunctionDecl *FD);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070041
Zonr Chang0da0a7d2010-10-05 21:26:37 +080042 typedef RSExportRecordType::const_field_iterator const_param_iterator;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070043
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070044 inline const_param_iterator params_begin() const {
Zonr Chang0da0a7d2010-10-05 21:26:37 +080045 assert((mParamPacketType != NULL) &&
46 "Get parameter from export function without parameter!");
47 return mParamPacketType->fields_begin();
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070048 }
49 inline const_param_iterator params_end() const {
Zonr Chang0da0a7d2010-10-05 21:26:37 +080050 assert((mParamPacketType != NULL) &&
51 "Get parameter from export function without parameter!");
52 return mParamPacketType->fields_end();
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070053 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070054
Zonr Chang0da0a7d2010-10-05 21:26:37 +080055 inline const std::string &getName() const { return mName; }
56 inline RSContext *getRSContext() const { return mContext; }
Shih-wei Liao462aefd2010-06-04 15:32:04 -070057
Zonr Chang0da0a7d2010-10-05 21:26:37 +080058 inline bool hasParam() const
59 { return (mParamPacketType && !mParamPacketType->getFields().empty()); }
60 inline size_t getNumParameters() const
61 { return ((mParamPacketType) ? mParamPacketType->getFields().size() : 0); }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070062
Zonr Chang0da0a7d2010-10-05 21:26:37 +080063 inline const RSExportRecordType *getParamPacketType() const
64 { return mParamPacketType; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070065
Zonr Chang0da0a7d2010-10-05 21:26:37 +080066 // 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;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070070}; // RSExportFunc
Shih-wei Liao462aefd2010-06-04 15:32:04 -070071
Zonr Chang0da0a7d2010-10-05 21:26:37 +080072
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070073} // namespace slang
Shih-wei Liao462aefd2010-06-04 15:32:04 -070074
zonr6315f762010-10-05 15:35:14 +080075#endif // _SLANG_COMPILER_RS_EXPORT_FUNC_H