zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 1 | #ifndef _SLANG_COMPILER_SLANG_REFLECT_UTILS_H |
| 2 | #define _SLANG_COMPILER_SLANG_REFLECT_UTILS_H |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | namespace slang { |
| 7 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 8 | // BitCode storage type |
| 9 | enum BitCodeStorageType { |
| 10 | BCST_APK_RESOURCE, |
| 11 | BCST_JAVA_CODE |
| 12 | }; |
| 13 | |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 14 | class RSSlangReflectUtils { |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 15 | public: |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 16 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 17 | // Encode a binary bitcode file into a Java source file. |
| 18 | // rsFileName: the original .rs file name (with or without path). |
| 19 | // bcFileName: where is the bit code file |
| 20 | // reflectPath: where to output the generated Java file, no package name in |
| 21 | // it. |
| 22 | // packageName: the package of the output Java file. |
| 23 | struct BitCodeAccessorContext { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 24 | const char *rsFileName; |
| 25 | const char *bcFileName; |
| 26 | const char *reflectPath; |
| 27 | const char *packageName; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 28 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 29 | BitCodeStorageType bcStorage; |
| 30 | }; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 31 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 32 | // Compuate a Java source file path from a given prefixPath and its package. |
| 33 | // Eg, given prefixPath=./foo/bar and packageName=com.x.y, then it returns |
| 34 | // ./foo/bar/com/x/y |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 35 | static std::string ComputePackagedPath(const char *prefixPath, |
| 36 | const char *packageName); |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 37 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 38 | // Compute Java class name from a .rs file name. |
Stephen Hines | d417640 | 2010-09-16 17:14:35 -0700 | [diff] [blame] | 39 | // Any non-alnum, non-underscore characters will be discarded. |
| 40 | // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns |
| 41 | // "myRenderscript_file". |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 42 | // rsFileName: the input .rs file name (with or without path). |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 43 | static std::string JavaClassNameFromRSFileName(const char *rsFileName); |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 44 | |
| 45 | // Compute a bitcode file name (no extension) from a .rs file name. |
| 46 | // Because the bitcode file name may be used as Resource ID in the generated |
Stephen Hines | d417640 | 2010-09-16 17:14:35 -0700 | [diff] [blame] | 47 | // class (something like R.raw.<bitcode_filename>), Any non-alnum, |
| 48 | // non-underscore character will be discarded. |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 49 | // The difference from JavaClassNameFromRSFileName() is that the result is |
Stephen Hines | d417640 | 2010-09-16 17:14:35 -0700 | [diff] [blame] | 50 | // converted to lowercase. |
| 51 | // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns |
| 52 | // "myrenderscript_file" |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 53 | // rsFileName: the input .rs file name (with or without path). |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 54 | static std::string BCFileNameFromRSFileName(const char *rsFileName); |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 55 | |
| 56 | // "mkdir -p" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 57 | static bool mkdir_p(const char *path); |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 58 | |
| 59 | |
| 60 | // Generate the bit code accessor Java source file. |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 61 | static bool GenerateBitCodeAccessor(const BitCodeAccessorContext &context); |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 62 | }; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 63 | } |
| 64 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame^] | 65 | #endif // _SLANG_COMPILER_SLANG_REFLECT_UTILS_H |