• 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 #include "codegen/code_generator.h"
10 #include "parser/module_parser.h"
11 #include "util/file.h"
12 #include "util/logger.h"
13 #include "util/options.h"
14 
15 using namespace OHOS::HDI;
16 
main(int argc,char ** argv)17 int main(int argc, char** argv)
18 {
19     Options& options = Options::GetInstance().Parse(argc, argv);
20     if (options.HasErrors()) {
21         options.ShowErrors();
22         return 0;
23     }
24 
25     if (options.DoShowUsage()) {
26         options.ShowUsage();
27         return 0;
28     }
29 
30     if (options.DoShowVersion()) {
31         options.ShowVersion();
32         return 0;
33     }
34 
35     if (!options.DoCompile()) {
36         return 0;
37     }
38 
39     if (options.DoGetHashKey()) {
40         for (const auto& sourceFile : options.GetSourceFiles()) {
41             std::unique_ptr<File> idlFile = std::make_unique<File>(sourceFile, int(File::READ));
42             if (!idlFile->IsValid()) {
43                 Logger::E("hdi-gen", "open idl file failed!");
44                 return -1;
45             }
46             printf("%s:%lu\n", idlFile->GetPath().string(), idlFile->GetHashKey());
47         }
48         return 0;
49     }
50 
51     ModuleParser moduleParser(options);
52     AutoPtr<ASTModule> astModule = moduleParser.Parse();
53     if (astModule == nullptr) {
54         return -1;
55     }
56 
57     if (!options.DoGenerateCode()) {
58         return 0;
59     }
60 
61     if (!CodeGenerator(astModule).Generate()) {
62         Logger::E("hdi-gen", "Generate \"%s\" codes failed.", options.GetTargetLanguage().string());
63         return -1;
64     }
65     return 0;
66 }