slang_rs.h revision e639eb5caa2c386b4a60659a4929e8a6141a2cbe
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 31namespace clang { 32 class FunctionDecl; 33} 34 35namespace slang { 36 class RSContext; 37 class RSExportRecordType; 38 39class SlangRS : public Slang { 40 private: 41 // Context for RenderScript 42 RSContext *mRSContext; 43 44 bool mAllowRSPrefix; 45 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 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 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); 71 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: 84 static bool IsRSHeaderFile(const char *File); 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); 90 91 SlangRS(); 92 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 // 102 // @IncludePaths - User-defined include paths. 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 // 112 // @OutputDep - true if output dependecies file for each input file. 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); 128 129 virtual void reset(); 130 131 virtual ~SlangRS(); 132}; 133} 134 135#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ NOLINT 136