1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef OHOS_HDI_CODEGENERATOR_H 10 #define OHOS_HDI_CODEGENERATOR_H 11 12 #include <functional> 13 #include <map> 14 #include <string> 15 16 #include "codegen/code_emitter.h" 17 18 namespace OHOS { 19 namespace HDI { 20 using CodeEmitMap = std::unordered_map<std::string, AutoPtr<CodeEmitter>>; 21 using CodeGenFunc = std::function<void(const AutoPtr<AST>&, const std::string&)>; 22 using GeneratePolicies = std::map<SystemLevel, std::map<GenMode, std::map<Language, CodeGenFunc>>>; 23 24 class CodeGenerator : public LightRefCountBase { 25 public: 26 using StrAstMap = std::unordered_map<std::string, AutoPtr<AST>>; 27 28 bool Generate(const StrAstMap &allAst); 29 30 private: 31 static CodeGenFunc GetCodeGenPoilcy(); 32 33 static void GenIpcCCode(const AutoPtr<AST> &ast, const std::string &outDir); 34 35 static void GenIpcCppCode(const AutoPtr<AST> &ast, const std::string &outDir); 36 37 static void GenIpcJavaCode(const AutoPtr<AST> &ast, const std::string &outDir); 38 39 static void GenPassthroughCCode(const AutoPtr<AST> &ast, const std::string &outDir); 40 41 static void GenPassthroughCppCode(const AutoPtr<AST> &ast, const std::string &outDir); 42 43 static void GenKernelCode(const AutoPtr<AST> &ast, const std::string &outDir); 44 45 static void GenLowCCode(const AutoPtr<AST> &ast, const std::string &outDir); 46 47 static GeneratePolicies policies_; 48 static CodeEmitMap cCodeEmitters_; 49 static CodeEmitMap cppCodeEmitters_; 50 static CodeEmitMap javaCodeEmitters_; 51 }; 52 } // namespace HDI 53 } // namespace OHOS 54 55 #endif // OHOS_HDI_CODEGENERATOR_H