blob: 7f3cd3ff85617b8c5b4e3a9c31233db9fb8472e2 [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
Stephen Hines0a813a32012-08-03 16:52:40 -07002 * Copyright 2010-2012, The Android Open Source Project
Zonr Changc383a502010-10-12 01:52:08 +08003 *
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
Stephen Hinese639eb52010-11-08 19:27:20 -080017#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080019
20#include "slang.h"
21
Zonr Changcf6af6a2010-10-12 12:38:51 +080022#include <list>
Zonr Changcf6af6a2010-10-12 12:38:51 +080023#include <string>
Stephen Hinese639eb52010-11-08 19:27:20 -080024#include <utility>
25#include <vector>
Zonr Changcf6af6a2010-10-12 12:38:51 +080026
Zonr Chang641558f2010-10-12 21:07:06 +080027#include "llvm/ADT/StringMap.h"
28
Zonr Changcf6af6a2010-10-12 12:38:51 +080029#include "slang_rs_reflect_utils.h"
Stephen Hines4cc499d2011-08-24 19:06:17 -070030#include "slang_version.h"
Stephen Hines2e35b132011-07-22 02:50:19 -070031
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080032namespace slang {
33 class RSContext;
Zonr Chang641558f2010-10-12 21:07:06 +080034 class RSExportRecordType;
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080035
36class SlangRS : public Slang {
37 private:
Stephen Hinesb7d12692011-09-02 18:16:19 -070038 // Context for Renderscript
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080039 RSContext *mRSContext;
40
41 bool mAllowRSPrefix;
42
Stephen Hines2e35b132011-07-22 02:50:19 -070043 unsigned int mTargetAPI;
44
Stephen Hines11274a72012-09-26 19:14:20 -070045 bool mIsFilterscript;
46
Zonr Chang641558f2010-10-12 21:07:06 +080047 // Custom diagnostic identifiers
48 unsigned mDiagErrorInvalidOutputDepParameter;
49 unsigned mDiagErrorODR;
Stephen Hines2e35b132011-07-22 02:50:19 -070050 unsigned mDiagErrorTargetAPIRange;
Zonr Chang641558f2010-10-12 21:07:06 +080051
Stephen Hines4cc67fc2011-01-31 16:48:57 -080052 // Collect generated filenames (without the .java) for dependency generation
53 std::vector<std::string> mGeneratedFileNames;
54
Zonr Chang641558f2010-10-12 21:07:06 +080055 // FIXME: Should be std::list<RSExportable *> here. But currently we only
56 // check ODR on record type.
57 //
58 // ReflectedDefinitions maps record type name to a pair:
59 // <its RSExportRecordType instance,
60 // the first file contains this record type definition>
61 typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy;
62 typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy;
63 ReflectedDefinitionListTy ReflectedDefinitions;
64
Zonr Changcf6af6a2010-10-12 12:38:51 +080065 bool reflectToJava(const std::string &OutputPathBase,
Stephen Hines925879f2013-07-19 18:19:04 -070066 const std::string &RSPackageName);
Zonr Changcf6af6a2010-10-12 12:38:51 +080067
68 bool generateBitcodeAccessor(const std::string &OutputPathBase,
69 const std::string &PackageName);
70
Zonr Change86245a2010-10-12 21:42:13 +080071 // CurInputFile is the pointer to a char array holding the input filename
72 // and is valid before compile() ends.
73 bool checkODR(const char *CurInputFile);
Zonr Chang641558f2010-10-12 21:07:06 +080074
Stephen Hines11274a72012-09-26 19:14:20 -070075 // Returns true if this is a Filterscript file.
76 static bool isFilterscript(const char *Filename);
77
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080078 protected:
79 virtual void initDiagnostic();
80 virtual void initPreprocessor();
81 virtual void initASTContext();
82
83 virtual clang::ASTConsumer
84 *createBackend(const clang::CodeGenOptions& CodeGenOpts,
85 llvm::raw_ostream *OS,
86 Slang::OutputType OT);
87
88
89 public:
Zonr Chang592a9542010-10-07 20:03:58 +080090 static bool IsRSHeaderFile(const char *File);
Stephen Hines11274a72012-09-26 19:14:20 -070091 // FIXME: Determine whether a location is in RS header (i.e., one of the RS
Stephen Hinesfcda2352010-10-19 16:49:32 -070092 // built-in APIs) should only need its names (we need a "list" of RS
93 // built-in APIs).
Stephen Hines11274a72012-09-26 19:14:20 -070094 static bool IsLocInRSHeaderFile(const clang::SourceLocation &Loc,
95 const clang::SourceManager &SourceMgr);
Zonr Chang592a9542010-10-07 20:03:58 +080096
Zonr Chang641558f2010-10-12 21:07:06 +080097 SlangRS();
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080098
Zonr Changcf6af6a2010-10-12 12:38:51 +080099 // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if
100 // all given input files are successfully compiled without errors.
101 //
102 // @IOFiles - List of pairs of <input file path, output file path>.
103 //
104 // @DepFiles - List of pairs of <output dep. file path, dependent bitcode
105 // target>. If @OutputDep is true, this parameter must be given
106 // with the same number of pairs given in @IOFiles.
107 //
Zonr Chang641558f2010-10-12 21:07:06 +0800108 // @IncludePaths - User-defined include paths.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800109 //
110 // @AdditionalDepTargets - User-defined files added to the dependencies.
111 //
112 // @OutputType - See Slang::OutputType.
113 //
114 // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp.
115 //
116 // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'.
117 //
Zonr Chang641558f2010-10-12 21:07:06 +0800118 // @OutputDep - true if output dependecies file for each input file.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800119 //
120 // @JavaReflectionPathBase - The path base for storing reflection files.
121 //
mkopec1c460b372012-01-09 11:21:50 -0500122 // @EmitDebug - true to allow debug metadata emission
123 //
124 // @OptimizationLevel - code generation optimization level: None is recommended for
125 // interactive debugging. The default is Aggresive.
126 //
Zonr Changcf6af6a2010-10-12 12:38:51 +0800127 // @JavaReflectionPackageName - The package name given by user in command
128 // line. This may override the package name
129 // specified in the .rs using #pragma.
130 //
Stephen Hines0a813a32012-08-03 16:52:40 -0700131 // @RSPackageName - The RS package name supplied by the command line. This
132 // can override the default value of
133 // "android.renderscript" used by the normal APIs.
134 //
Zonr Changcf6af6a2010-10-12 12:38:51 +0800135 bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles,
136 const std::list<std::pair<const char*, const char*> > &DepFiles,
137 const std::vector<std::string> &IncludePaths,
138 const std::vector<std::string> &AdditionalDepTargets,
139 Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage,
140 bool AllowRSPrefix, bool OutputDep,
mkopec1c460b372012-01-09 11:21:50 -0500141 unsigned int TargetAPI, bool EmitDebug,
142 llvm::CodeGenOpt::Level OptimizationLevel,
Zonr Changcf6af6a2010-10-12 12:38:51 +0800143 const std::string &JavaReflectionPathBase,
Stephen Hines0a813a32012-08-03 16:52:40 -0700144 const std::string &JavaReflectionPackageName,
145 const std::string &RSPackageName);
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800146
Zonr Chang641558f2010-10-12 21:07:06 +0800147 virtual void reset();
148
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800149 virtual ~SlangRS();
Stephen Hines0da7f6c2013-03-05 15:19:02 -0800150
151 virtual void makeModuleVisible(clang::Module *Mod,
152 clang::Module::NameVisibilityKind Visibility,
Stephen Hines4b3f3ba2013-05-06 16:18:56 -0700153 clang::SourceLocation ImportLoc,
154 bool Complain = false) { }
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800155};
Stephen Hinese67239d2012-02-24 15:08:36 -0800156} // namespace slang
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800157
Stephen Hinese639eb52010-11-08 19:27:20 -0800158#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ NOLINT