Home | History | Annotate | Download | only in slang
      1 /*
      2  * Copyright 2010-2012, 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 
     17 #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_  // NOLINT
     18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_
     19 
     20 #include "slang.h"
     21 
     22 #include <list>
     23 #include <string>
     24 #include <utility>
     25 #include <vector>
     26 
     27 #include "llvm/ADT/StringMap.h"
     28 
     29 #include "slang_rs_reflect_utils.h"
     30 #include "slang_version.h"
     31 
     32 namespace slang {
     33   class RSCCOptions;
     34   class RSContext;
     35   class RSExportRecordType;
     36 
     37 class SlangRS : public Slang {
     38  private:
     39   // Context for Renderscript
     40   RSContext *mRSContext;
     41 
     42   bool mAllowRSPrefix;
     43 
     44   unsigned int mTargetAPI;
     45 
     46   bool mVerbose;
     47 
     48   bool mIsFilterscript;
     49 
     50   // Custom diagnostic identifiers
     51   unsigned mDiagErrorInvalidOutputDepParameter;
     52   unsigned mDiagErrorODR;
     53   unsigned mDiagErrorTargetAPIRange;
     54 
     55   // Collect generated filenames (without the .java) for dependency generation
     56   std::vector<std::string> mGeneratedFileNames;
     57 
     58   // FIXME: Should be std::list<RSExportable *> here. But currently we only
     59   //        check ODR on record type.
     60   //
     61   // ReflectedDefinitions maps record type name to a pair:
     62   //  <its RSExportRecordType instance,
     63   //   the first file contains this record type definition>
     64   typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy;
     65   typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy;
     66   ReflectedDefinitionListTy ReflectedDefinitions;
     67 
     68   bool generateJavaBitcodeAccessor(const std::string &OutputPathBase,
     69                                    const std::string &PackageName,
     70                                    const std::string *LicenseNote);
     71 
     72   // CurInputFile is the pointer to a char array holding the input filename
     73   // and is valid before compile() ends.
     74   bool checkODR(const char *CurInputFile);
     75 
     76   // Returns true if this is a Filterscript file.
     77   static bool isFilterscript(const char *Filename);
     78 
     79  protected:
     80   virtual void initDiagnostic();
     81   virtual void initPreprocessor();
     82   virtual void initASTContext();
     83 
     84   virtual clang::ASTConsumer
     85   *createBackend(const clang::CodeGenOptions& CodeGenOpts,
     86                  llvm::raw_ostream *OS,
     87                  Slang::OutputType OT);
     88 
     89 
     90  public:
     91   static bool IsRSHeaderFile(const char *File);
     92   // FIXME: Determine whether a location is in RS header (i.e., one of the RS
     93   //        built-in APIs) should only need its names (we need a "list" of RS
     94   //        built-in APIs).
     95   static bool IsLocInRSHeaderFile(const clang::SourceLocation &Loc,
     96                                   const clang::SourceManager &SourceMgr);
     97 
     98   SlangRS();
     99 
    100   // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if
    101   // all given input files are successfully compiled without errors.
    102   //
    103   // @IOFiles - List of pairs of <input file path, output file path>.
    104   //
    105   // @DepFiles - List of pairs of <output dep. file path, dependent bitcode
    106   //             target>. If @OutputDep is true, this parameter must be given
    107   //             with the same number of pairs given in @IOFiles.
    108   //
    109   // @Opts - Selection of options defined from invoking llvm-rs-cc
    110   bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles64,
    111                const std::list<std::pair<const char*, const char*> > &IOFiles32,
    112                const std::list<std::pair<const char*, const char*> > &DepFiles,
    113                const RSCCOptions &Opts);
    114 
    115   virtual void reset(bool SuppressWarnings = false);
    116 
    117   virtual ~SlangRS();
    118 
    119   virtual void makeModuleVisible(clang::Module *Mod,
    120                                  clang::Module::NameVisibilityKind Visibility,
    121                                  clang::SourceLocation ImportLoc,
    122                                  bool Complain = false) { }
    123 
    124   virtual clang::GlobalModuleIndex *loadGlobalModuleIndex(
    125       clang::SourceLocation TriggerLoc) { }
    126 
    127   virtual bool lookupMissingImports(llvm::StringRef Name,
    128                                     clang::SourceLocation TriggerLoc) { }
    129 };
    130 }  // namespace slang
    131 
    132 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_  NOLINT
    133