llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
symbol_table.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/ilist.h>
8 #include <llvm/ADT/simple_ilist.h>
9 
10 class Func;
11 class Prog;
12 class Block;
13 class Atom;
14 class Extern;
15 class Data;
16 class Global;
17 class Object;
18 template <typename T> class SymbolTableList;
19 
20 
21 
22 // Parent types for all global symbols.
23 template <typename T> struct SymbolTableListParentType {};
24 template <> struct SymbolTableListParentType<Func> { using type = Prog; };
25 template <> struct SymbolTableListParentType<Atom> { using type = Object; };
26 template <> struct SymbolTableListParentType<Extern> { using type = Prog; };
27 template <> struct SymbolTableListParentType<Block> { using type = Func; };
28 
32 template <typename T>
33 class SymbolTableListTraits : public llvm::ilist_alloc_traits<T> {
34 private:
35  using ListTy = SymbolTableList<T>;
36  using iterator = typename llvm::simple_ilist<T>::iterator;
37  using ParentTy = typename SymbolTableListParentType<T>::type;
38 
39 public:
40  ParentTy *getParent();
41 
42  void addNodeToList(T *V);
43  void removeNodeFromList(T *V);
44  void transferNodesFromList(
46  iterator first,
47  iterator last
48  );
49 };
50 
51 
55 template <>
56 class SymbolTableListTraits<Func> : public llvm::ilist_alloc_traits<Func> {
57 private:
58  using iterator = typename llvm::simple_ilist<Func>::iterator;
59 
60 public:
61  Prog *getParent();
62 
63  void addNodeToList(Func *V);
64  void removeNodeFromList(Func *V);
65  void transferNodesFromList(
67  iterator first,
68  iterator last
69  );
70 };
71 
72 
76 template <class T>
77 class SymbolTableList
78  : public llvm::iplist_impl<llvm::simple_ilist<T>, SymbolTableListTraits<T>>
79 {
80 };
Func
Definition: func.h:30
SymbolTableList
Definition: symbol_table.h:18
Atom
Definition: atom.h:23
Data
Definition: data.h:47
Object
Definition: object.h:43
SymbolTableListTraits
Definition: symbol_table.h:33
Prog
Definition: prog.h:33
SymbolTableListParentType
Definition: symbol_table.h:23
Block
Definition: block.h:29
Extern
Definition: extern.h:20
Global
Definition: global.h:23