• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright 2022-2023 Google LLC
5 //
6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the
7 // "License"); you may not use this file except in compliance with the
8 // License.  You may obtain a copy of the License at
9 //
10 //     https://llvm.org/LICENSE.txt
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // Author: Giuliano Procida
19 
20 #include "input.h"
21 
22 #include <memory>
23 #include <sstream>
24 
25 #include "abigail_reader.h"
26 #include "btf_reader.h"
27 #include "elf_reader.h"
28 #include "error.h"
29 #include "filter.h"
30 #include "graph.h"
31 #include "proto_reader.h"
32 #include "reader_options.h"
33 #include "runtime.h"
34 
35 namespace stg {
36 
37 namespace {
38 
ReadInternal(Runtime & runtime,Graph & graph,InputFormat format,const char * input,ReadOptions options,const std::unique_ptr<Filter> & file_filter)39 Id ReadInternal(Runtime& runtime, Graph& graph, InputFormat format,
40                 const char* input, ReadOptions options,
41                 const std::unique_ptr<Filter>& file_filter) {
42   switch (format) {
43     case InputFormat::ABI: {
44       const Time read(runtime, "read ABI");
45       return abixml::Read(runtime, graph, input);
46     }
47     case InputFormat::BTF: {
48       const Time read(runtime, "read BTF");
49       return btf::ReadFile(graph, input, options);
50     }
51     case InputFormat::ELF: {
52       const Time read(runtime, "read ELF");
53       return elf::Read(runtime, graph, input, options, file_filter);
54     }
55     case InputFormat::STG: {
56       const Time read(runtime, "read STG");
57       return proto::Read(graph, input);
58     }
59   }
60 }
61 
62 }  // namespace
63 
Read(Runtime & runtime,Graph & graph,InputFormat format,const char * input,ReadOptions options,const std::unique_ptr<Filter> & file_filter)64 Id Read(Runtime& runtime, Graph& graph, InputFormat format, const char* input,
65         ReadOptions options, const std::unique_ptr<Filter>& file_filter) {
66   try {
67     return ReadInternal(runtime, graph, format, input, options, file_filter);
68   } catch (Exception& e) {
69     std::ostringstream os;
70     os << "processing file '" << input << '\'';
71     e.Add(os.str());
72     throw;
73   }
74 }
75 
76 }  // namespace stg
77