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 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 17 | #ifndef _SLANG_COMPILER_SLANG_RS_HPP |
| 18 | #define _SLANG_COMPILER_SLANG_RS_HPP |
| 19 | |
| 20 | #include "slang.h" |
| 21 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 22 | #include <list> |
| 23 | #include <vector> |
| 24 | #include <string> |
| 25 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 26 | #include "llvm/ADT/StringMap.h" |
| 27 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 28 | #include "slang_rs_reflect_utils.h" |
| 29 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 30 | namespace slang { |
| 31 | class RSContext; |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 32 | class RSExportRecordType; |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 33 | |
| 34 | class SlangRS : public Slang { |
| 35 | private: |
| 36 | // Context for RenderScript |
| 37 | RSContext *mRSContext; |
| 38 | |
| 39 | bool mAllowRSPrefix; |
| 40 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 41 | // Custom diagnostic identifiers |
| 42 | unsigned mDiagErrorInvalidOutputDepParameter; |
| 43 | unsigned mDiagErrorODR; |
| 44 | |
| 45 | // FIXME: Should be std::list<RSExportable *> here. But currently we only |
| 46 | // check ODR on record type. |
| 47 | // |
| 48 | // ReflectedDefinitions maps record type name to a pair: |
| 49 | // <its RSExportRecordType instance, |
| 50 | // the first file contains this record type definition> |
| 51 | typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy; |
| 52 | typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy; |
| 53 | ReflectedDefinitionListTy ReflectedDefinitions; |
| 54 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 55 | // The package name that's really applied will be filled in RealPackageName. |
| 56 | bool reflectToJava(const std::string &OutputPathBase, |
| 57 | const std::string &OutputPackageName, |
| 58 | std::string *RealPackageName); |
| 59 | |
| 60 | bool generateBitcodeAccessor(const std::string &OutputPathBase, |
| 61 | const std::string &PackageName); |
| 62 | |
Zonr Chang | e86245a | 2010-10-12 21:42:13 +0800 | [diff] [blame^] | 63 | // CurInputFile is the pointer to a char array holding the input filename |
| 64 | // and is valid before compile() ends. |
| 65 | bool checkODR(const char *CurInputFile); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 66 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 67 | protected: |
| 68 | virtual void initDiagnostic(); |
| 69 | virtual void initPreprocessor(); |
| 70 | virtual void initASTContext(); |
| 71 | |
| 72 | virtual clang::ASTConsumer |
| 73 | *createBackend(const clang::CodeGenOptions& CodeGenOpts, |
| 74 | llvm::raw_ostream *OS, |
| 75 | Slang::OutputType OT); |
| 76 | |
| 77 | |
| 78 | public: |
Zonr Chang | 592a954 | 2010-10-07 20:03:58 +0800 | [diff] [blame] | 79 | static bool IsRSHeaderFile(const char *File); |
| 80 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 81 | SlangRS(); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 82 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 83 | // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if |
| 84 | // all given input files are successfully compiled without errors. |
| 85 | // |
| 86 | // @IOFiles - List of pairs of <input file path, output file path>. |
| 87 | // |
| 88 | // @DepFiles - List of pairs of <output dep. file path, dependent bitcode |
| 89 | // target>. If @OutputDep is true, this parameter must be given |
| 90 | // with the same number of pairs given in @IOFiles. |
| 91 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 92 | // @IncludePaths - User-defined include paths. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 93 | // |
| 94 | // @AdditionalDepTargets - User-defined files added to the dependencies. |
| 95 | // |
| 96 | // @OutputType - See Slang::OutputType. |
| 97 | // |
| 98 | // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp. |
| 99 | // |
| 100 | // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'. |
| 101 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 102 | // @OutputDep - true if output dependecies file for each input file. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 103 | // |
| 104 | // @JavaReflectionPathBase - The path base for storing reflection files. |
| 105 | // |
| 106 | // @JavaReflectionPackageName - The package name given by user in command |
| 107 | // line. This may override the package name |
| 108 | // specified in the .rs using #pragma. |
| 109 | // |
| 110 | bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles, |
| 111 | const std::list<std::pair<const char*, const char*> > &DepFiles, |
| 112 | const std::vector<std::string> &IncludePaths, |
| 113 | const std::vector<std::string> &AdditionalDepTargets, |
| 114 | Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage, |
| 115 | bool AllowRSPrefix, bool OutputDep, |
| 116 | const std::string &JavaReflectionPathBase, |
| 117 | const std::string &JavaReflectionPackageName); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 118 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 119 | virtual void reset(); |
| 120 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 121 | virtual ~SlangRS(); |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | #endif // _SLANG_COMPILER_SLANG_RS_HPP |