llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
data_printer.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 <map>
8 
9 #include <llvm/Pass.h>
10 #include <llvm/IR/DataLayout.h>
11 #include <llvm/MC/MCObjectFileInfo.h>
12 #include <llvm/MC/MCStreamer.h>
13 
14 #include "core/visibility.h"
15 
16 class Prog;
17 class Data;
18 class Atom;
19 class Object;
20 class ISelMapping;
21 
22 
23 
27 class DataPrinter final : public llvm::ModulePass {
28 public:
29  static char ID;
30 
33  const Prog &Prog,
34  ISelMapping *isel,
35  llvm::MCContext *ctx,
36  llvm::MCStreamer *os,
37  const llvm::MCObjectFileInfo *objInfo,
38  const llvm::DataLayout &layout,
39  bool shared
40  );
41 
42 private:
44  bool runOnModule(llvm::Module &M) override;
46  llvm::StringRef getPassName() const override;
48  void getAnalysisUsage(llvm::AnalysisUsage &AU) const override;
49 
50 private:
52  void LowerExtern(const Extern &ext);
54  void LowerSection(const Data &data);
56  void LowerObject(const Object &object);
58  void LowerAtom(const Atom &atom);
60  llvm::MCSymbol *LowerSymbol(const std::string_view name);
62  void EmitVisibility(llvm::MCSymbol *sym, Visibility visibility);
63 
65  using XtorMap = std::map<int, std::vector<const Func *>>;
67  void LowerXtors(const XtorMap &map, const std::string &name);
68 
69 private:
71  llvm::MCSection *GetSection(const Data &data);
72 
73 private:
75  const Prog &prog_;
77  ISelMapping *isel_;
79  llvm::MCContext *ctx_;
81  llvm::MCStreamer *os_;
83  const llvm::MCObjectFileInfo *objInfo_;
85  const llvm::DataLayout &layout_;
87  bool shared_;
88 };
Atom
Definition: atom.h:23
ISelMapping
Definition: isel_mapping.h:22
Data
Definition: data.h:47
ID
Definition: id.h:19
Object
Definition: object.h:43
DataPrinter
Definition: data_printer.h:27
DataPrinter::DataPrinter
DataPrinter(const Prog &Prog, ISelMapping *isel, llvm::MCContext *ctx, llvm::MCStreamer *os, const llvm::MCObjectFileInfo *objInfo, const llvm::DataLayout &layout, bool shared)
Initialises the pass which prints data sections.
Definition: data_printer.cpp:27
Prog
Definition: prog.h:33
Extern
Definition: extern.h:20