• 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/parser.h"
11 #include "preprocessor/preprocessor.h"
12 #include "util/file.h"
13 #include "util/logger.h"
14 #include "util/options.h"
15 #include "hash/hash.h"
16 
17 using namespace OHOS::HDI;
18 
main(int argc,char ** argv)19 int main(int argc, char **argv)
20 {
21     Options &options = Options::GetInstance();
22     if (!options.Parse(argc, argv)) {
23         return -1;
24     }
25 
26     if (options.DoShowUsage()) {
27         options.ShowUsage();
28         return 0;
29     }
30     if (options.DoShowVersion()) {
31         options.ShowVersion();
32         return 0;
33     }
34 
35     if (options.DoGetHashKey()) {
36         return Hash::GenHashKey() ? 0 : -1;
37     }
38 
39     if (!options.DoCompile()) {
40         return 0;
41     }
42 
43     std::vector<FileDetail> fileDetails;
44     if (!Preprocessor::Preprocess(fileDetails)) {
45         Logger::E("MAIN", "failed to preprocess");
46         return -1;
47     }
48 
49     Parser parser;
50     if (!parser.Parse(fileDetails)) {
51         Logger::E("MAIN", "failed to parse file");
52         return -1;
53     }
54 
55     if (options.DoDumpAST()) {
56         for (const auto &astPair : parser.GetAllAst()) {
57             printf("%s\n", astPair.second->Dump("").c_str());
58         }
59     }
60 
61     if (!options.DoGenerateCode()) {
62         return 0;
63     }
64 
65     if (!CodeGenerator().Generate(parser.GetAllAst())) {
66         Logger::E("hdi-gen", "failed to generate code");
67         return -1;
68     }
69     return 0;
70 }