blob: 6ec4d02d8f4ed58afdbe1ba644146262cf84bc46 [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
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
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"
30
Stephen Hinesfcda2352010-10-19 16:49:32 -070031namespace clang {
32 class FunctionDecl;
33}
34
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080035namespace slang {
36 class RSContext;
Zonr Chang641558f2010-10-12 21:07:06 +080037 class RSExportRecordType;
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080038
39class SlangRS : public Slang {
40 private:
41 // Context for RenderScript
42 RSContext *mRSContext;
43
44 bool mAllowRSPrefix;
45
Zonr Chang641558f2010-10-12 21:07:06 +080046 // Custom diagnostic identifiers
47 unsigned mDiagErrorInvalidOutputDepParameter;
48 unsigned mDiagErrorODR;
49
Stephen Hines4cc67fc2011-01-31 16:48:57 -080050 // Collect generated filenames (without the .java) for dependency generation
51 std::vector<std::string> mGeneratedFileNames;
52
Zonr Chang641558f2010-10-12 21:07:06 +080053 // FIXME: Should be std::list<RSExportable *> here. But currently we only
54 // check ODR on record type.
55 //
56 // ReflectedDefinitions maps record type name to a pair:
57 // <its RSExportRecordType instance,
58 // the first file contains this record type definition>
59 typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy;
60 typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy;
61 ReflectedDefinitionListTy ReflectedDefinitions;
62
Zonr Changcf6af6a2010-10-12 12:38:51 +080063 // The package name that's really applied will be filled in RealPackageName.
64 bool reflectToJava(const std::string &OutputPathBase,
65 const std::string &OutputPackageName,
66 std::string *RealPackageName);
67
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
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080075 protected:
76 virtual void initDiagnostic();
77 virtual void initPreprocessor();
78 virtual void initASTContext();
79
80 virtual clang::ASTConsumer
81 *createBackend(const clang::CodeGenOptions& CodeGenOpts,
82 llvm::raw_ostream *OS,
83 Slang::OutputType OT);
84
85
86 public:
Zonr Chang592a9542010-10-07 20:03:58 +080087 static bool IsRSHeaderFile(const char *File);
Stephen Hinesfcda2352010-10-19 16:49:32 -070088 // FIXME: Determine whether a function is in RS header (i.e., one of the RS
89 // built-in APIs) should only need its names (we need a "list" of RS
90 // built-in APIs).
91 static bool IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD,
92 const clang::SourceManager &SourceMgr);
Zonr Chang592a9542010-10-07 20:03:58 +080093
Zonr Chang641558f2010-10-12 21:07:06 +080094 SlangRS();
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080095
Zonr Changcf6af6a2010-10-12 12:38:51 +080096 // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if
97 // all given input files are successfully compiled without errors.
98 //
99 // @IOFiles - List of pairs of <input file path, output file path>.
100 //
101 // @DepFiles - List of pairs of <output dep. file path, dependent bitcode
102 // target>. If @OutputDep is true, this parameter must be given
103 // with the same number of pairs given in @IOFiles.
104 //
Zonr Chang641558f2010-10-12 21:07:06 +0800105 // @IncludePaths - User-defined include paths.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800106 //
107 // @AdditionalDepTargets - User-defined files added to the dependencies.
108 //
109 // @OutputType - See Slang::OutputType.
110 //
111 // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp.
112 //
113 // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'.
114 //
Zonr Chang641558f2010-10-12 21:07:06 +0800115 // @OutputDep - true if output dependecies file for each input file.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800116 //
117 // @JavaReflectionPathBase - The path base for storing reflection files.
118 //
119 // @JavaReflectionPackageName - The package name given by user in command
120 // line. This may override the package name
121 // specified in the .rs using #pragma.
122 //
123 bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles,
124 const std::list<std::pair<const char*, const char*> > &DepFiles,
125 const std::vector<std::string> &IncludePaths,
126 const std::vector<std::string> &AdditionalDepTargets,
127 Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage,
128 bool AllowRSPrefix, bool OutputDep,
129 const std::string &JavaReflectionPathBase,
130 const std::string &JavaReflectionPackageName);
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800131
Zonr Chang641558f2010-10-12 21:07:06 +0800132 virtual void reset();
133
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800134 virtual ~SlangRS();
135};
136}
137
Stephen Hinese639eb52010-11-08 19:27:20 -0800138#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ NOLINT