Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 2 | * Copyright 2010-2012, The Android Open Source Project |
Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 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" |
Stephen Hines | 4cc499d | 2011-08-24 19:06:17 -0700 | [diff] [blame] | 30 | #include "slang_version.h" |
Stephen Hines | 2e35b13 | 2011-07-22 02:50:19 -0700 | [diff] [blame] | 31 | |
Stephen Hines | fcda235 | 2010-10-19 16:49:32 -0700 | [diff] [blame] | 32 | namespace clang { |
| 33 | class FunctionDecl; |
| 34 | } |
| 35 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 36 | namespace slang { |
| 37 | class RSContext; |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 38 | class RSExportRecordType; |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 39 | |
| 40 | class SlangRS : public Slang { |
| 41 | private: |
Stephen Hines | b7d1269 | 2011-09-02 18:16:19 -0700 | [diff] [blame] | 42 | // Context for Renderscript |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 43 | RSContext *mRSContext; |
| 44 | |
| 45 | bool mAllowRSPrefix; |
| 46 | |
Stephen Hines | 2e35b13 | 2011-07-22 02:50:19 -0700 | [diff] [blame] | 47 | unsigned int mTargetAPI; |
| 48 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 49 | // Custom diagnostic identifiers |
| 50 | unsigned mDiagErrorInvalidOutputDepParameter; |
| 51 | unsigned mDiagErrorODR; |
Stephen Hines | 2e35b13 | 2011-07-22 02:50:19 -0700 | [diff] [blame] | 52 | unsigned mDiagErrorTargetAPIRange; |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 53 | |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 54 | // Collect generated filenames (without the .java) for dependency generation |
| 55 | std::vector<std::string> mGeneratedFileNames; |
| 56 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 57 | // FIXME: Should be std::list<RSExportable *> here. But currently we only |
| 58 | // check ODR on record type. |
| 59 | // |
| 60 | // ReflectedDefinitions maps record type name to a pair: |
| 61 | // <its RSExportRecordType instance, |
| 62 | // the first file contains this record type definition> |
| 63 | typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy; |
| 64 | typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy; |
| 65 | ReflectedDefinitionListTy ReflectedDefinitions; |
| 66 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 67 | // The package name that's really applied will be filled in RealPackageName. |
| 68 | bool reflectToJava(const std::string &OutputPathBase, |
| 69 | const std::string &OutputPackageName, |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 70 | const std::string &RSPackageName, |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 71 | std::string *RealPackageName); |
| 72 | |
| 73 | bool generateBitcodeAccessor(const std::string &OutputPathBase, |
| 74 | const std::string &PackageName); |
| 75 | |
Zonr Chang | e86245a | 2010-10-12 21:42:13 +0800 | [diff] [blame] | 76 | // CurInputFile is the pointer to a char array holding the input filename |
| 77 | // and is valid before compile() ends. |
| 78 | bool checkODR(const char *CurInputFile); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 79 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 80 | protected: |
| 81 | virtual void initDiagnostic(); |
| 82 | virtual void initPreprocessor(); |
| 83 | virtual void initASTContext(); |
| 84 | |
| 85 | virtual clang::ASTConsumer |
| 86 | *createBackend(const clang::CodeGenOptions& CodeGenOpts, |
| 87 | llvm::raw_ostream *OS, |
| 88 | Slang::OutputType OT); |
| 89 | |
| 90 | |
| 91 | public: |
Zonr Chang | 592a954 | 2010-10-07 20:03:58 +0800 | [diff] [blame] | 92 | static bool IsRSHeaderFile(const char *File); |
Stephen Hines | fcda235 | 2010-10-19 16:49:32 -0700 | [diff] [blame] | 93 | // FIXME: Determine whether a function is in RS header (i.e., one of the RS |
| 94 | // built-in APIs) should only need its names (we need a "list" of RS |
| 95 | // built-in APIs). |
| 96 | static bool IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD, |
| 97 | const clang::SourceManager &SourceMgr); |
Zonr Chang | 592a954 | 2010-10-07 20:03:58 +0800 | [diff] [blame] | 98 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 99 | SlangRS(); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 100 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 101 | // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if |
| 102 | // all given input files are successfully compiled without errors. |
| 103 | // |
| 104 | // @IOFiles - List of pairs of <input file path, output file path>. |
| 105 | // |
| 106 | // @DepFiles - List of pairs of <output dep. file path, dependent bitcode |
| 107 | // target>. If @OutputDep is true, this parameter must be given |
| 108 | // with the same number of pairs given in @IOFiles. |
| 109 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 110 | // @IncludePaths - User-defined include paths. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 111 | // |
| 112 | // @AdditionalDepTargets - User-defined files added to the dependencies. |
| 113 | // |
| 114 | // @OutputType - See Slang::OutputType. |
| 115 | // |
| 116 | // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp. |
| 117 | // |
| 118 | // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'. |
| 119 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 120 | // @OutputDep - true if output dependecies file for each input file. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 121 | // |
| 122 | // @JavaReflectionPathBase - The path base for storing reflection files. |
| 123 | // |
mkopec1 | c460b37 | 2012-01-09 11:21:50 -0500 | [diff] [blame] | 124 | // @EmitDebug - true to allow debug metadata emission |
| 125 | // |
| 126 | // @OptimizationLevel - code generation optimization level: None is recommended for |
| 127 | // interactive debugging. The default is Aggresive. |
| 128 | // |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 129 | // @JavaReflectionPackageName - The package name given by user in command |
| 130 | // line. This may override the package name |
| 131 | // specified in the .rs using #pragma. |
| 132 | // |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 133 | // @RSPackageName - The RS package name supplied by the command line. This |
| 134 | // can override the default value of |
| 135 | // "android.renderscript" used by the normal APIs. |
| 136 | // |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 137 | bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles, |
| 138 | const std::list<std::pair<const char*, const char*> > &DepFiles, |
| 139 | const std::vector<std::string> &IncludePaths, |
| 140 | const std::vector<std::string> &AdditionalDepTargets, |
| 141 | Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage, |
| 142 | bool AllowRSPrefix, bool OutputDep, |
mkopec1 | c460b37 | 2012-01-09 11:21:50 -0500 | [diff] [blame] | 143 | unsigned int TargetAPI, bool EmitDebug, |
| 144 | llvm::CodeGenOpt::Level OptimizationLevel, |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 145 | const std::string &JavaReflectionPathBase, |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 146 | const std::string &JavaReflectionPackageName, |
| 147 | const std::string &RSPackageName); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 148 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 149 | virtual void reset(); |
| 150 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 151 | virtual ~SlangRS(); |
| 152 | }; |
Stephen Hines | e67239d | 2012-02-24 15:08:36 -0800 | [diff] [blame] | 153 | } // namespace slang |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 154 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 155 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ NOLINT |