1 // Copyright (C) 2019 The Android Open Source Project 2 // 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 "repr/ir_reader.h" 16 17 #include "repr/ir_representation.h" 18 #include "repr/json/api.h" 19 #include "repr/protobuf/api.h" 20 21 #include <list> 22 #include <memory> 23 #include <set> 24 #include <string> 25 26 #include <llvm/Support/raw_ostream.h> 27 28 29 namespace header_checker { 30 namespace repr { 31 32 CreateIRReader(TextFormatIR text_format,std::unique_ptr<ModuleIR> module_ir)33std::unique_ptr<IRReader> IRReader::CreateIRReader( 34 TextFormatIR text_format, std::unique_ptr<ModuleIR> module_ir) { 35 if (module_ir == nullptr) { 36 module_ir = std::make_unique<ModuleIR>(); 37 } 38 switch (text_format) { 39 case TextFormatIR::ProtobufTextFormat: 40 return CreateProtobufIRReader(std::move(module_ir)); 41 case TextFormatIR::Json: 42 return CreateJsonIRReader(std::move(module_ir)); 43 default: 44 llvm::errs() << "Text format not supported yet\n"; 45 return nullptr; 46 } 47 } 48 ReadDump(const std::string & dump_file)49bool IRReader::ReadDump(const std::string &dump_file) { 50 module_->SetCompilationUnitPath(dump_file); 51 return ReadDumpImpl(dump_file); 52 } 53 54 55 } // namespace repr 56 } // header_checker 57