Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 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 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 17 | #ifndef _SLANG_COMPILER_SLANG_RS_HPP |
| 18 | #define _SLANG_COMPILER_SLANG_RS_HPP |
| 19 | |
| 20 | #include "slang.h" |
| 21 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 22 | #include <list> |
| 23 | #include <vector> |
| 24 | #include <string> |
| 25 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 26 | #include "llvm/ADT/StringMap.h" |
| 27 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 28 | #include "slang_rs_reflect_utils.h" |
| 29 | |
Stephen Hines | fcda235 | 2010-10-19 16:49:32 -0700 | [diff] [blame^] | 30 | namespace clang { |
| 31 | class FunctionDecl; |
| 32 | } |
| 33 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 34 | namespace slang { |
| 35 | class RSContext; |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 36 | class RSExportRecordType; |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 37 | |
| 38 | class SlangRS : public Slang { |
| 39 | private: |
| 40 | // Context for RenderScript |
| 41 | RSContext *mRSContext; |
| 42 | |
| 43 | bool mAllowRSPrefix; |
| 44 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 45 | // Custom diagnostic identifiers |
| 46 | unsigned mDiagErrorInvalidOutputDepParameter; |
| 47 | unsigned mDiagErrorODR; |
| 48 | |
| 49 | // FIXME: Should be std::list<RSExportable *> here. But currently we only |
| 50 | // check ODR on record type. |
| 51 | // |
| 52 | // ReflectedDefinitions maps record type name to a pair: |
| 53 | // <its RSExportRecordType instance, |
| 54 | // the first file contains this record type definition> |
| 55 | typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy; |
| 56 | typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy; |
| 57 | ReflectedDefinitionListTy ReflectedDefinitions; |
| 58 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 59 | // The package name that's really applied will be filled in RealPackageName. |
| 60 | bool reflectToJava(const std::string &OutputPathBase, |
| 61 | const std::string &OutputPackageName, |
| 62 | std::string *RealPackageName); |
| 63 | |
| 64 | bool generateBitcodeAccessor(const std::string &OutputPathBase, |
| 65 | const std::string &PackageName); |
| 66 | |
Zonr Chang | e86245a | 2010-10-12 21:42:13 +0800 | [diff] [blame] | 67 | // CurInputFile is the pointer to a char array holding the input filename |
| 68 | // and is valid before compile() ends. |
| 69 | bool checkODR(const char *CurInputFile); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 70 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 71 | protected: |
| 72 | virtual void initDiagnostic(); |
| 73 | virtual void initPreprocessor(); |
| 74 | virtual void initASTContext(); |
| 75 | |
| 76 | virtual clang::ASTConsumer |
| 77 | *createBackend(const clang::CodeGenOptions& CodeGenOpts, |
| 78 | llvm::raw_ostream *OS, |
| 79 | Slang::OutputType OT); |
| 80 | |
| 81 | |
| 82 | public: |
Zonr Chang | 592a954 | 2010-10-07 20:03:58 +0800 | [diff] [blame] | 83 | static bool IsRSHeaderFile(const char *File); |
Stephen Hines | fcda235 | 2010-10-19 16:49:32 -0700 | [diff] [blame^] | 84 | // FIXME: Determine whether a function is in RS header (i.e., one of the RS |
| 85 | // built-in APIs) should only need its names (we need a "list" of RS |
| 86 | // built-in APIs). |
| 87 | static bool IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD, |
| 88 | const clang::SourceManager &SourceMgr); |
Zonr Chang | 592a954 | 2010-10-07 20:03:58 +0800 | [diff] [blame] | 89 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 90 | SlangRS(); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 91 | |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 92 | // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if |
| 93 | // all given input files are successfully compiled without errors. |
| 94 | // |
| 95 | // @IOFiles - List of pairs of <input file path, output file path>. |
| 96 | // |
| 97 | // @DepFiles - List of pairs of <output dep. file path, dependent bitcode |
| 98 | // target>. If @OutputDep is true, this parameter must be given |
| 99 | // with the same number of pairs given in @IOFiles. |
| 100 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 101 | // @IncludePaths - User-defined include paths. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 102 | // |
| 103 | // @AdditionalDepTargets - User-defined files added to the dependencies. |
| 104 | // |
| 105 | // @OutputType - See Slang::OutputType. |
| 106 | // |
| 107 | // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp. |
| 108 | // |
| 109 | // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'. |
| 110 | // |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 111 | // @OutputDep - true if output dependecies file for each input file. |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 112 | // |
| 113 | // @JavaReflectionPathBase - The path base for storing reflection files. |
| 114 | // |
| 115 | // @JavaReflectionPackageName - The package name given by user in command |
| 116 | // line. This may override the package name |
| 117 | // specified in the .rs using #pragma. |
| 118 | // |
| 119 | bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles, |
| 120 | const std::list<std::pair<const char*, const char*> > &DepFiles, |
| 121 | const std::vector<std::string> &IncludePaths, |
| 122 | const std::vector<std::string> &AdditionalDepTargets, |
| 123 | Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage, |
| 124 | bool AllowRSPrefix, bool OutputDep, |
| 125 | const std::string &JavaReflectionPathBase, |
| 126 | const std::string &JavaReflectionPackageName); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 127 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 128 | virtual void reset(); |
| 129 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 130 | virtual ~SlangRS(); |
| 131 | }; |
| 132 | } |
| 133 | |
| 134 | #endif // _SLANG_COMPILER_SLANG_RS_HPP |