1 //===- RemarkUtilHelpers.h ------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Helpers for remark utilites 10 // 11 //===----------------------------------------------------------------------===// 12 #include "llvm-c/Remarks.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/Remarks/Remark.h" 15 #include "llvm/Remarks/RemarkFormat.h" 16 #include "llvm/Remarks/RemarkParser.h" 17 #include "llvm/Remarks/YAMLRemarkSerializer.h" 18 #include "llvm/Support/Error.h" 19 #include "llvm/Support/FileSystem.h" 20 #include "llvm/Support/MemoryBuffer.h" 21 #include "llvm/Support/ToolOutputFile.h" 22 23 // Keep input + output help + names consistent across the various modes via a 24 // hideous macro. 25 #define INPUT_OUTPUT_COMMAND_LINE_OPTIONS(SUBOPT) \ 26 static cl::opt<std::string> InputFileName(cl::Positional, cl::init("-"), \ 27 cl::desc("<input file>"), \ 28 cl::sub(SUBOPT)); \ 29 static cl::opt<std::string> OutputFileName( \ 30 "o", cl::init("-"), cl::desc("Output"), cl::value_desc("filename"), \ 31 cl::sub(SUBOPT)); 32 33 // Keep Input format and names consistent accross the modes via a macro. 34 #define INPUT_FORMAT_COMMAND_LINE_OPTIONS(SUBOPT) \ 35 static cl::opt<Format> InputFormat( \ 36 "parser", cl::desc("Input remark format to parse"), \ 37 cl::values(clEnumValN(Format::YAML, "yaml", "YAML"), \ 38 clEnumValN(Format::Bitstream, "bitstream", "Bitstream")), \ 39 cl::sub(SUBOPT)); 40 41 #define DEBUG_LOC_INFO_COMMAND_LINE_OPTIONS(SUBOPT) \ 42 static cl::opt<bool> UseDebugLoc( \ 43 "use-debug-loc", \ 44 cl::desc( \ 45 "Add debug loc information when generating tables for " \ 46 "functions. The loc is represented as (path:line number:column " \ 47 "number)"), \ 48 cl::init(false), cl::sub(SUBOPT)); 49 50 namespace llvm { 51 namespace remarks { 52 Expected<std::unique_ptr<MemoryBuffer>> 53 getInputMemoryBuffer(StringRef InputFileName); 54 Expected<std::unique_ptr<ToolOutputFile>> 55 getOutputFileWithFlags(StringRef OutputFileName, sys::fs::OpenFlags Flags); 56 Expected<std::unique_ptr<ToolOutputFile>> 57 getOutputFileForRemarks(StringRef OutputFileName, Format OutputFormat); 58 } // namespace remarks 59 } // namespace llvm 60