Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame^] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 19 | |
| 20 | #include "slang.h" |
| 21 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 22 | #include <list> |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 23 | #include <string> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame^] | 24 | #include <utility> |
| 25 | #include <vector> |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 26 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 27 | #include "llvm/ADT/StringMap.h" |
| 28 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 29 | #include "slang_rs_reflect_utils.h" |
| 30 | |
Stephen Hines | fcda235 | 2010-10-19 16:49:32 -0700 | [diff] [blame] | 31 | namespace clang { |
| 32 | class FunctionDecl; |
| 33 | } |
| 34 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 35 | namespace slang { |
| 36 | class RSContext; |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 37 | class RSExportRecordType; |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 38 | |
| 39 | class SlangRS : public Slang { |
| 40 | private: |
| 41 | // Context for RenderScript |
| 42 | RSContext *mRSContext; |
| 43 | |
| 44 | bool mAllowRSPrefix; |
| 45 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 46 | // Custom diagnostic identifiers |
| 47 | unsigned mDiagErrorInvalidOutputDepParameter; |
| 48 | unsigned mDiagErrorODR; |
| 49 | |
| 50 | // FIXME: Should be std::list<RSExportable *> here. But currently we only |
| 51 | // check ODR on record type. |
| 52 | // |
| 53 | // ReflectedDefinitions maps record type name to a pair: |
| 54 | // <its RSExportRecordType instance, |
| 55 | // the first file contains this record type definition> |
| 56 | typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy; |
| 57 | typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy; |
| 58 | ReflectedDefinitionListTy ReflectedDefinitions; |
| 59 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 60 | // The package name that's really applied will be filled in RealPackageName. |
| 61 | bool reflectToJava(const std::string &OutputPathBase, |
| 62 | const std::string &OutputPackageName, |
| 63 | std::string *RealPackageName); |
| 64 | |
| 65 | bool generateBitcodeAccessor(const std::string &OutputPathBase, |
| 66 | const std::string &PackageName); |
| 67 | |
Zonr Chang | e86245a | 2010-10-12 21:42:13 +0800 | [diff] [blame] | 68 | // CurInputFile is the pointer to a char array holding the input filename |
| 69 | // and is valid before compile() ends. |
| 70 | bool checkODR(const char *CurInputFile); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 71 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 72 | protected: |
| 73 | virtual void initDiagnostic(); |
| 74 | virtual void initPreprocessor(); |
| 75 | virtual void initASTContext(); |
| 76 | |
| 77 | virtual clang::ASTConsumer |
| 78 | *createBackend(const clang::CodeGenOptions& CodeGenOpts, |
| 79 | llvm::raw_ostream *OS, |
| 80 | Slang::OutputType OT); |
| 81 | |
| 82 | |
| 83 | public: |
Zonr Chang | 592a954 | 2010-10-07 20:03:58 +0800 | [diff] [blame] | 84 | static bool IsRSHeaderFile(const char *File); |
Stephen Hines | fcda235 | 2010-10-19 16:49:32 -0700 | [diff] [blame] | 85 | // FIXME: Determine whether a function is in RS header (i.e., one of the RS |
| 86 | // built-in APIs) should only need its names (we need a "list" of RS |
| 87 | // built-in APIs). |
| 88 | static bool IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD, |
| 89 | const clang::SourceManager &SourceMgr); |
Zonr Chang | 592a954 | 2010-10-07 20:03:58 +0800 | [diff] [blame] | 90 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 91 | SlangRS(); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 92 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 93 | // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if |
| 94 | // all given input files are successfully compiled without errors. |
| 95 | // |
| 96 | // @IOFiles - List of pairs of <input file path, output file path>. |
| 97 | // |
| 98 | // @DepFiles - List of pairs of <output dep. file path, dependent bitcode |
| 99 | // target>. If @OutputDep is true, this parameter must be given |
| 100 | // with the same number of pairs given in @IOFiles. |
| 101 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 102 | // @IncludePaths - User-defined include paths. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 103 | // |
| 104 | // @AdditionalDepTargets - User-defined files added to the dependencies. |
| 105 | // |
| 106 | // @OutputType - See Slang::OutputType. |
| 107 | // |
| 108 | // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp. |
| 109 | // |
| 110 | // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'. |
| 111 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 112 | // @OutputDep - true if output dependecies file for each input file. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 113 | // |
| 114 | // @JavaReflectionPathBase - The path base for storing reflection files. |
| 115 | // |
| 116 | // @JavaReflectionPackageName - The package name given by user in command |
| 117 | // line. This may override the package name |
| 118 | // specified in the .rs using #pragma. |
| 119 | // |
| 120 | bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles, |
| 121 | const std::list<std::pair<const char*, const char*> > &DepFiles, |
| 122 | const std::vector<std::string> &IncludePaths, |
| 123 | const std::vector<std::string> &AdditionalDepTargets, |
| 124 | Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage, |
| 125 | bool AllowRSPrefix, bool OutputDep, |
| 126 | const std::string &JavaReflectionPathBase, |
| 127 | const std::string &JavaReflectionPackageName); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 128 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 129 | virtual void reset(); |
| 130 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 131 | virtual ~SlangRS(); |
| 132 | }; |
| 133 | } |
| 134 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame^] | 135 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ NOLINT |