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