• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "codegen/code_emitter.h"
13 
14 namespace OHOS {
15 namespace HDI {
16 using CodeEmitMap = std::unordered_map<std::string, AutoPtr<CodeEmitter>>;
17 class CodeGenerator : public LightRefCountBase {
18 public:
19     using StrAstMap = std::unordered_map<std::string, AutoPtr<AST>>;
CodeGenerator(const StrAstMap & allAst)20     explicit CodeGenerator(const StrAstMap &allAst) : LightRefCountBase(), allAst_(allAst), targetDirectory_() {}
21 
22     bool Generate();
23 
24 private:
25     void GenerateCCode(const AutoPtr<AST> &ast, const std::string &outDir, const std::string &codePart, bool isKernel);
26     void GenerateCppCode(const AutoPtr<AST> &ast, const std::string &outDir, const std::string &codePart);
27     void GenerateJavaCode(const AutoPtr<AST> &ast, const std::string &outDir, const std::string &codePart);
28 
29     const StrAstMap &allAst_;
30     std::string targetDirectory_;
31 
32     static CodeEmitMap cCodeEmitters_;
33     static CodeEmitMap cppCodeEmitters_;
34     static CodeEmitMap javaCodeEmitters_;
35 };
36 } // namespace HDI
37 } // namespace OHOS
38 
39 #endif // OHOS_HDI_CODEGENERATOR_H