forked from llvm-class/project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool.h
54 lines (42 loc) · 1.22 KB
/
pool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#ifndef POOL_H
#define POOL_H
#include "runtime.h"
namespace rift {
/** The constant pool holds symbols, strings and all compiled functions.*/
class Pool {
public:
/** Returns the number of compiled functions. */
static unsigned functionsCount() {
return f_.size();
}
/** Returns function at index. */
static RFun * getFunction(int index) {
return f_[index];
}
/** Adds function to compiled functions, returns its index. */
static int addFunction(ast::Fun * fun, llvm::Function * bitcode) {
RFun * f = new RFun(fun, bitcode);
f_.push_back(f);
return f_.size() - 1;
}
/** Returns string at index. */
static std::string const & getPoolObject(unsigned index) {
return pool_[index];
}
/** Adds string to the constant pool. */
static int addToPool(std::string const & s) {
for (unsigned i = 0; i < pool_.size(); ++i)
if (pool_[i] == s)
return i;
pool_.push_back(s);
return pool_.size() - 1;
}
private:
/** Compiled functions. */
static std::vector<RFun *> f_;
/** Strings. */
static std::vector<std::string> pool_;
};
}
#endif // POOL_H