1 /**
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "compilation_unit.h"
16 #include "compiler_options.h"
17 #include "generated/irtoc_options_gen.h"
18 #include "generated/base_options.h"
19
20 namespace panda::irtoc {
21
Run(int argc,const char ** argv)22 int Run(int argc, const char **argv)
23 {
24 panda::PandArgParser pa_parser;
25 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
26 panda::irtoc::Options irtoc_options(argv[0]);
27 irtoc_options.AddOptions(&pa_parser);
28 base_options::Options base_options("");
29 base_options.AddOptions(&pa_parser);
30 panda::compiler::options.AddOptions(&pa_parser);
31 if (!pa_parser.Parse(argc, argv)) {
32 std::cerr << "Error: " << pa_parser.GetErrorString() << "\n";
33 return -1;
34 }
35
36 Logger::Initialize(base_options);
37
38 panda::compiler::CompilerLogger::SetComponents(panda::compiler::options.GetCompilerLog());
39
40 if (std::getenv("IRTOC_VERBOSE") != nullptr) {
41 Logger::SetLevel(Logger::Level::DEBUG);
42 Logger::EnableComponent(Logger::Component::IRTOC);
43 }
44
45 auto res = Compilation().Run(irtoc_options.GetIrtocOutput());
46 if (!res.HasValue()) {
47 std::cerr << res.Error() << std::endl;
48 return 1;
49 }
50 return 0;
51 }
52
53 } // namespace panda::irtoc
54
main(int argc,const char ** argv)55 int main(int argc, const char **argv)
56 {
57 return panda::irtoc::Run(argc, argv);
58 }
59