slang_rs.h revision e86245a09bb8b9e72f5dc68083444ec938865798
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/* 2c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Copyright 2010, The Android Open Source Project 3c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 4c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License"); 5c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * you may not use this file except in compliance with the License. 6c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * You may obtain a copy of the License at 7c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 8c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * http://www.apache.org/licenses/LICENSE-2.0 9c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 10c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Unless required by applicable law or agreed to in writing, software 11c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS, 12c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * See the License for the specific language governing permissions and 14c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * limitations under the License. 15c383a500aa59423264811be3874461bf8adbfea0Zonr Chang */ 16c383a500aa59423264811be3874461bf8adbfea0Zonr Chang 173a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#ifndef _SLANG_COMPILER_SLANG_RS_HPP 183a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#define _SLANG_COMPILER_SLANG_RS_HPP 193a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 203a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#include "slang.h" 213a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 22cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang#include <list> 23cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang#include <vector> 24cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang#include <string> 25cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang 26641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang#include "llvm/ADT/StringMap.h" 27641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 28cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang#include "slang_rs_reflect_utils.h" 29cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang 303a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changnamespace slang { 313a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang class RSContext; 32641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang class RSExportRecordType; 333a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 343a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changclass SlangRS : public Slang { 353a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang private: 363a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang // Context for RenderScript 373a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang RSContext *mRSContext; 383a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 393a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang bool mAllowRSPrefix; 403a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 41641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // Custom diagnostic identifiers 42641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang unsigned mDiagErrorInvalidOutputDepParameter; 43641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang unsigned mDiagErrorODR; 44641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 45641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // FIXME: Should be std::list<RSExportable *> here. But currently we only 46641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // check ODR on record type. 47641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // 48641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // ReflectedDefinitions maps record type name to a pair: 49641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // <its RSExportRecordType instance, 50641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // the first file contains this record type definition> 51641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy; 52641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy; 53641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang ReflectedDefinitionListTy ReflectedDefinitions; 54641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 55cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // The package name that's really applied will be filled in RealPackageName. 56cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang bool reflectToJava(const std::string &OutputPathBase, 57cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang const std::string &OutputPackageName, 58cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang std::string *RealPackageName); 59cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang 60cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang bool generateBitcodeAccessor(const std::string &OutputPathBase, 61cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang const std::string &PackageName); 62cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang 63e86245a09bb8b9e72f5dc68083444ec938865798Zonr Chang // CurInputFile is the pointer to a char array holding the input filename 64e86245a09bb8b9e72f5dc68083444ec938865798Zonr Chang // and is valid before compile() ends. 65e86245a09bb8b9e72f5dc68083444ec938865798Zonr Chang bool checkODR(const char *CurInputFile); 66641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 673a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang protected: 683a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang virtual void initDiagnostic(); 693a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang virtual void initPreprocessor(); 703a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang virtual void initASTContext(); 713a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 723a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang virtual clang::ASTConsumer 733a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang *createBackend(const clang::CodeGenOptions& CodeGenOpts, 743a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang llvm::raw_ostream *OS, 753a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang Slang::OutputType OT); 763a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 773a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 783a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang public: 79592a954aae4cb946970b557e94afd5ee453fd57eZonr Chang static bool IsRSHeaderFile(const char *File); 80592a954aae4cb946970b557e94afd5ee453fd57eZonr Chang 81641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang SlangRS(); 823a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 83cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if 84cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // all given input files are successfully compiled without errors. 85cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 86cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @IOFiles - List of pairs of <input file path, output file path>. 87cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 88cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @DepFiles - List of pairs of <output dep. file path, dependent bitcode 89cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // target>. If @OutputDep is true, this parameter must be given 90cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // with the same number of pairs given in @IOFiles. 91cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 92641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // @IncludePaths - User-defined include paths. 93cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 94cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @AdditionalDepTargets - User-defined files added to the dependencies. 95cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 96cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @OutputType - See Slang::OutputType. 97cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 98cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp. 99cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 100cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'. 101cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 102641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang // @OutputDep - true if output dependecies file for each input file. 103cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 104cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @JavaReflectionPathBase - The path base for storing reflection files. 105cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 106cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // @JavaReflectionPackageName - The package name given by user in command 107cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // line. This may override the package name 108cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // specified in the .rs using #pragma. 109cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang // 110cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles, 111cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang const std::list<std::pair<const char*, const char*> > &DepFiles, 112cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang const std::vector<std::string> &IncludePaths, 113cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang const std::vector<std::string> &AdditionalDepTargets, 114cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage, 115cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang bool AllowRSPrefix, bool OutputDep, 116cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang const std::string &JavaReflectionPathBase, 117cf6af6abc1de499920571308b14a27e19cf57097Zonr Chang const std::string &JavaReflectionPackageName); 1183a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 119641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang virtual void reset(); 120641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 1213a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang virtual ~SlangRS(); 1223a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang}; 1233a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang} 1243a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 1253a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#endif // _SLANG_COMPILER_SLANG_RS_HPP 126