slang_rs.h revision e86245a09bb8b9e72f5dc68083444ec938865798
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 _SLANG_COMPILER_SLANG_RS_HPP 18#define _SLANG_COMPILER_SLANG_RS_HPP 19 20#include "slang.h" 21 22#include <list> 23#include <vector> 24#include <string> 25 26#include "llvm/ADT/StringMap.h" 27 28#include "slang_rs_reflect_utils.h" 29 30namespace slang { 31 class RSContext; 32 class RSExportRecordType; 33 34class SlangRS : public Slang { 35 private: 36 // Context for RenderScript 37 RSContext *mRSContext; 38 39 bool mAllowRSPrefix; 40 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 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 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); 66 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: 79 static bool IsRSHeaderFile(const char *File); 80 81 SlangRS(); 82 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 // 92 // @IncludePaths - User-defined include paths. 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 // 102 // @OutputDep - true if output dependecies file for each input file. 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); 118 119 virtual void reset(); 120 121 virtual ~SlangRS(); 122}; 123} 124 125#endif // _SLANG_COMPILER_SLANG_RS_HPP 126