zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 1 | #ifndef _SLANG_COMPILER_RS_EXPORT_FUNC_H |
| 2 | #define _SLANG_COMPILER_RS_EXPORT_FUNC_H |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 3 | |
| 4 | #include <list> |
| 5 | #include <string> |
| 6 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 7 | #include "llvm/ADT/StringRef.h" |
| 8 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 9 | #include "slang_rs_export_type.h" |
| 10 | |
| 11 | namespace llvm { |
| 12 | class StructType; |
| 13 | } |
| 14 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 15 | namespace clang { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 16 | class FunctionDecl; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 17 | } // namespace clang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 18 | |
| 19 | namespace slang { |
| 20 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 21 | class RSContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 22 | |
| 23 | class RSExportFunc { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 24 | friend class RSContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 25 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 26 | private: |
| 27 | RSContext *mContext; |
| 28 | std::string mName; |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 29 | RSExportRecordType *mParamPacketType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 30 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 31 | RSExportFunc(RSContext *Context, const llvm::StringRef &Name) |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 32 | : mContext(Context), |
| 33 | mName(Name.data(), Name.size()), |
| 34 | mParamPacketType(NULL) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 35 | return; |
| 36 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 37 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 38 | public: |
| 39 | static RSExportFunc *Create(RSContext *Context, |
| 40 | const clang::FunctionDecl *FD); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 41 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 42 | typedef RSExportRecordType::const_field_iterator const_param_iterator; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 43 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 44 | inline const_param_iterator params_begin() const { |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 45 | assert((mParamPacketType != NULL) && |
| 46 | "Get parameter from export function without parameter!"); |
| 47 | return mParamPacketType->fields_begin(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 48 | } |
| 49 | inline const_param_iterator params_end() const { |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 50 | assert((mParamPacketType != NULL) && |
| 51 | "Get parameter from export function without parameter!"); |
| 52 | return mParamPacketType->fields_end(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 53 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 54 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 55 | inline const std::string &getName() const { return mName; } |
| 56 | inline RSContext *getRSContext() const { return mContext; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 57 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 58 | 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 Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 62 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 63 | inline const RSExportRecordType *getParamPacketType() const |
| 64 | { return mParamPacketType; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 65 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 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; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 70 | }; // RSExportFunc |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 71 | |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 72 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 73 | } // namespace slang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 74 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 75 | #endif // _SLANG_COMPILER_RS_EXPORT_FUNC_H |