• 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 "bytecode_gen.h"
10 #include "decompile.h"
11 #include "macro_gen.h"
12 #include "option.h"
13 #include "parser.h"
14 #include "text_gen.h"
15 
16 using namespace OHOS::Hardware;
17 
main(int argc,char * argv[])18 int main(int argc, char *argv[])
19 {
20     auto option = Option::Instance().Parse(argc, argv);
21     if (option.OptionError()) {
22         return EFAIL;
23     }
24 
25     if (option.ShouldShowUsage()) {
26         option.ShowUsage();
27         return option.OptionError();
28     }
29 
30     if (option.ShouldShowVersion()) {
31         option.ShowVersion();
32         return 0;
33     }
34 
35     if (option.ShouldDecompile()) {
36         Decompile decompile(option.GetSourceName());
37         return decompile.DoDecompile() ? 0 : EFAIL;
38     }
39 
40     Parser parser;
41     if (!parser.Parse()) {
42         return EFAIL;
43     }
44 
45     if (option.ShouldGenBinaryConfig()) {
46         if (!ByteCodeGen(parser.GetAst()).Output()) {
47             return EFAIL;
48         }
49         return 0;
50     }
51 
52     if (option.ShouldGenTextConfig()) {
53         if (!TextGen(parser.GetAst()).Output()) {
54             return EFAIL;
55         }
56     }
57     if (option.ShouldGenMacroConfig()) {
58         if (!MacroGen(parser.GetAst()).Output()) {
59             return EFAIL;
60         }
61     }
62 
63     return 0;
64 }
65