blob: 025861df3e4da7d87b1fc8ba22ade8371b6deba4 [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
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080017#ifndef _SLANG_COMPILER_SLANG_RS_HPP
18#define _SLANG_COMPILER_SLANG_RS_HPP
19
20#include "slang.h"
21
Zonr Changcf6af6a2010-10-12 12:38:51 +080022#include <list>
23#include <vector>
24#include <string>
25
Zonr Chang641558f2010-10-12 21:07:06 +080026#include "llvm/ADT/StringMap.h"
27
Zonr Changcf6af6a2010-10-12 12:38:51 +080028#include "slang_rs_reflect_utils.h"
29
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080030namespace slang {
31 class RSContext;
Zonr Chang641558f2010-10-12 21:07:06 +080032 class RSExportRecordType;
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080033
34class SlangRS : public Slang {
35 private:
36 // Context for RenderScript
37 RSContext *mRSContext;
38
39 bool mAllowRSPrefix;
40
Zonr Chang641558f2010-10-12 21:07:06 +080041 // Custom diagnostic identifiers
42 unsigned mDiagErrorInvalidOutputDepParameter;
43 unsigned mDiagErrorODR;
44
45 // FIXME: Should be std::list<RSExportable *> here. But currently we only
46 // check ODR on record type.
47 //
48 // ReflectedDefinitions maps record type name to a pair:
49 // <its RSExportRecordType instance,
50 // the first file contains this record type definition>
51 typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy;
52 typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy;
53 ReflectedDefinitionListTy ReflectedDefinitions;
54
Zonr Changcf6af6a2010-10-12 12:38:51 +080055 // The package name that's really applied will be filled in RealPackageName.
56 bool reflectToJava(const std::string &OutputPathBase,
57 const std::string &OutputPackageName,
58 std::string *RealPackageName);
59
60 bool generateBitcodeAccessor(const std::string &OutputPathBase,
61 const std::string &PackageName);
62
Zonr Change86245a2010-10-12 21:42:13 +080063 // CurInputFile is the pointer to a char array holding the input filename
64 // and is valid before compile() ends.
65 bool checkODR(const char *CurInputFile);
Zonr Chang641558f2010-10-12 21:07:06 +080066
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080067 protected:
68 virtual void initDiagnostic();
69 virtual void initPreprocessor();
70 virtual void initASTContext();
71
72 virtual clang::ASTConsumer
73 *createBackend(const clang::CodeGenOptions& CodeGenOpts,
74 llvm::raw_ostream *OS,
75 Slang::OutputType OT);
76
77
78 public:
Zonr Chang592a9542010-10-07 20:03:58 +080079 static bool IsRSHeaderFile(const char *File);
80
Zonr Chang641558f2010-10-12 21:07:06 +080081 SlangRS();
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080082
Zonr Changcf6af6a2010-10-12 12:38:51 +080083 // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if
84 // all given input files are successfully compiled without errors.
85 //
86 // @IOFiles - List of pairs of <input file path, output file path>.
87 //
88 // @DepFiles - List of pairs of <output dep. file path, dependent bitcode
89 // target>. If @OutputDep is true, this parameter must be given
90 // with the same number of pairs given in @IOFiles.
91 //
Zonr Chang641558f2010-10-12 21:07:06 +080092 // @IncludePaths - User-defined include paths.
Zonr Changcf6af6a2010-10-12 12:38:51 +080093 //
94 // @AdditionalDepTargets - User-defined files added to the dependencies.
95 //
96 // @OutputType - See Slang::OutputType.
97 //
98 // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp.
99 //
100 // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'.
101 //
Zonr Chang641558f2010-10-12 21:07:06 +0800102 // @OutputDep - true if output dependecies file for each input file.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800103 //
104 // @JavaReflectionPathBase - The path base for storing reflection files.
105 //
106 // @JavaReflectionPackageName - The package name given by user in command
107 // line. This may override the package name
108 // specified in the .rs using #pragma.
109 //
110 bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles,
111 const std::list<std::pair<const char*, const char*> > &DepFiles,
112 const std::vector<std::string> &IncludePaths,
113 const std::vector<std::string> &AdditionalDepTargets,
114 Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage,
115 bool AllowRSPrefix, bool OutputDep,
116 const std::string &JavaReflectionPathBase,
117 const std::string &JavaReflectionPackageName);
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800118
Zonr Chang641558f2010-10-12 21:07:06 +0800119 virtual void reset();
120
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800121 virtual ~SlangRS();
122};
123}
124
125#endif // _SLANG_COMPILER_SLANG_RS_HPP