llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
util.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <llvm/ADT/StringRef.h>
8 #include <llvm/ADT/SmallVector.h>
9 #include <llvm/Support/Endian.h>
10 
11 class Prog;
12 
13 
14 
16 constexpr uint32_t kLLIRMagic = 0x52494C4C;
18 bool IsLLIRObject(llvm::StringRef buffer);
19 
20 
24 template<int N>
25 struct sized_uint {};
26 template<> struct sized_uint<1> { typedef uint8_t type; };
27 template<> struct sized_uint<2> { typedef uint16_t type; };
28 template<> struct sized_uint<4> { typedef uint32_t type; };
29 template<> struct sized_uint<8> { typedef uint64_t type; };
30 
31 
35 template<typename T> T ReadData(llvm::StringRef buffer, uint64_t offset)
36 {
37  namespace endian = llvm::support::endian;
38  if (offset + sizeof(T) > buffer.size()) {
39  llvm::report_fatal_error("invalid bitcode file");
40  }
41 
42  auto *data = buffer.data() + offset;
43  return endian::read<T, llvm::support::little, 1>(data);
44 }
45 
46 
50 std::unique_ptr<Prog> Parse(llvm::StringRef buffer, std::string_view name);
51 
55 std::string Abspath(llvm::StringRef path);
56 
60 std::string ParseToolName(llvm::StringRef argv0, const char *tool);
sized_uint
Definition: util.h:25
Prog
Definition: prog.h:33