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