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 17 #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ // NOLINT 18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ 19 20 #include "slang.h" 21 22 #include <list> 23 #include <string> 24 #include <utility> 25 #include <vector> 26 27 #include "llvm/ADT/StringMap.h" 28 29 #include "slang_rs_reflect_utils.h" 30 #include "slang_version.h" 31 32 namespace clang { 33 class FunctionDecl; 34 } 35 36 namespace slang { 37 class RSContext; 38 class RSExportRecordType; 39 40 class SlangRS : public Slang { 41 private: 42 // Context for Renderscript 43 RSContext *mRSContext; 44 45 bool mAllowRSPrefix; 46 47 unsigned int mTargetAPI; 48 49 // Custom diagnostic identifiers 50 unsigned mDiagErrorInvalidOutputDepParameter; 51 unsigned mDiagErrorODR; 52 unsigned mDiagErrorTargetAPIRange; 53 54 // Collect generated filenames (without the .java) for dependency generation 55 std::vector<std::string> mGeneratedFileNames; 56 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 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, 70 std::string *RealPackageName); 71 72 bool generateBitcodeAccessor(const std::string &OutputPathBase, 73 const std::string &PackageName); 74 75 // CurInputFile is the pointer to a char array holding the input filename 76 // and is valid before compile() ends. 77 bool checkODR(const char *CurInputFile); 78 79 protected: 80 virtual void initDiagnostic(); 81 virtual void initPreprocessor(); 82 virtual void initASTContext(); 83 84 virtual clang::ASTConsumer 85 *createBackend(const clang::CodeGenOptions& CodeGenOpts, 86 llvm::raw_ostream *OS, 87 Slang::OutputType OT); 88 89 90 public: 91 static bool IsRSHeaderFile(const char *File); 92 // FIXME: Determine whether a function is in RS header (i.e., one of the RS 93 // built-in APIs) should only need its names (we need a "list" of RS 94 // built-in APIs). 95 static bool IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD, 96 const clang::SourceManager &SourceMgr); 97 98 SlangRS(); 99 100 // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if 101 // all given input files are successfully compiled without errors. 102 // 103 // @IOFiles - List of pairs of <input file path, output file path>. 104 // 105 // @DepFiles - List of pairs of <output dep. file path, dependent bitcode 106 // target>. If @OutputDep is true, this parameter must be given 107 // with the same number of pairs given in @IOFiles. 108 // 109 // @IncludePaths - User-defined include paths. 110 // 111 // @AdditionalDepTargets - User-defined files added to the dependencies. 112 // 113 // @OutputType - See Slang::OutputType. 114 // 115 // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp. 116 // 117 // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'. 118 // 119 // @OutputDep - true if output dependecies file for each input file. 120 // 121 // @JavaReflectionPathBase - The path base for storing reflection files. 122 // 123 // @EmitDebug - true to allow debug metadata emission 124 // 125 // @OptimizationLevel - code generation optimization level: None is recommended for 126 // interactive debugging. The default is Aggresive. 127 // 128 // @JavaReflectionPackageName - The package name given by user in command 129 // line. This may override the package name 130 // specified in the .rs using #pragma. 131 // 132 bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles, 133 const std::list<std::pair<const char*, const char*> > &DepFiles, 134 const std::vector<std::string> &IncludePaths, 135 const std::vector<std::string> &AdditionalDepTargets, 136 Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage, 137 bool AllowRSPrefix, bool OutputDep, 138 unsigned int TargetAPI, bool EmitDebug, 139 llvm::CodeGenOpt::Level OptimizationLevel, 140 const std::string &JavaReflectionPathBase, 141 const std::string &JavaReflectionPackageName); 142 143 virtual void reset(); 144 145 virtual ~SlangRS(); 146 }; 147 } // namespace slang 148 149 #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ NOLINT 150