• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #include "abc2program_driver.h"
17 #include "abc2program_options.h"
18 #include "program_dump.h"
19 
20 namespace panda::abc2program {
21 
Run(int argc,const char ** argv)22 int Abc2ProgramDriver::Run(int argc, const char **argv)
23 {
24     Abc2ProgramOptions options;
25     if (!options.Parse(argc, argv)) {
26         return 1;
27     }
28     if (Run(options.GetInputFilePath(), options.GetOutputFilePath())) {
29         return 0;
30     }
31     return 1;
32 }
33 
Run(const std::string & input_file_path,const std::string & output_file_path)34 bool Abc2ProgramDriver::Run(const std::string &input_file_path, const std::string &output_file_path)
35 {
36     return (Compile(input_file_path) && Dump(output_file_path));
37 }
38 
Compile(const std::string & input_file_path)39 bool Abc2ProgramDriver::Compile(const std::string &input_file_path)
40 {
41     input_file_path_ = input_file_path;
42     if (!compiler_.OpenAbcFile(input_file_path)) {
43         return false;
44     }
45     program_ = std::move(*compiler_.CompileAbcFile());
46     return true;
47 }
48 
Dump(const std::string & output_file_path)49 bool Abc2ProgramDriver::Dump(const std::string &output_file_path)
50 {
51     // program dump logic
52     std::ofstream ofs;
53     ofs.open(output_file_path, std::ios::trunc | std::ios::out);
54     PandasmProgramDumper dumper;
55     dumper.SetAbcFilePath(input_file_path_);
56     dumper.Dump(ofs, program_);
57     ofs.close();
58     return true;
59 }
60 
GetProgram() const61 const pandasm::Program &Abc2ProgramDriver::GetProgram() const
62 {
63     return program_;
64 }
65 
66 }  // namespace panda::abc2program