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.h"
16 #include "compiler_options.h"
17 #include "irtoc_options.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 paParser;
25 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
26 panda::irtoc::g_options.AddOptions(&paParser);
27 base_options::Options baseOptions("");
28 baseOptions.AddOptions(&paParser);
29 panda::compiler::g_options.AddOptions(&paParser);
30 #ifdef PANDA_LLVM_IRTOC
31 panda::llvmbackend::g_options.AddOptions(&paParser);
32 #endif
33 if (!paParser.Parse(argc, argv)) {
34 std::cerr << "Error: " << paParser.GetErrorString() << "\n";
35 return -1;
36 }
37
38 Logger::Initialize(baseOptions);
39
40 panda::compiler::CompilerLogger::SetComponents(panda::compiler::g_options.GetCompilerLog());
41
42 if (std::getenv("IRTOC_VERBOSE") != nullptr) {
43 Logger::SetLevel(Logger::Level::DEBUG);
44 Logger::ResetComponentMask();
45 Logger::EnableComponent(Logger::Component::IRTOC);
46 }
47
48 auto res = Compilation().Run();
49 if (!res.HasValue()) {
50 std::cerr << res.Error() << std::endl;
51 return 1;
52 }
53 return 0;
54 }
55
56 } // namespace panda::irtoc
57
main(int argc,const char ** argv)58 int main(int argc, const char **argv)
59 {
60 return panda::irtoc::Run(argc, argv);
61 }
62