forked from YahooArchive/http-filters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assembler.h
174 lines (117 loc) · 4.94 KB
/
assembler.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Copyright (c) 2015, Yahoo Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
#ifndef ASSEMBLER_H
#define ASSEMBLER_H
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include "opcodes.h"
#include "vm.h"
namespace http {
namespace filters {
typedef std::map< std::string, uint32_t > Labels;
struct Assembler {
typedef std::vector< Instruction > Instructions;
typedef std::vector< char > RawMemory;
Instructions instructions_;
RawMemory memory_;
Labels memoryUnifier_;
Labels labels_;
Assembler(void) {
memory_.push_back('\0');
}
uint32_t operator [](const char * const) const;
uint32_t label(const char * const);
inline void pushHalt(void) { push(Opcodes::kHalt, 0, 0, 0); }
inline void pushSkip(const char * const a = NULL) {
const uint32_t b = a != NULL ? pushMemory(a) : 0;
push(Opcodes::kSkip, b, 0, 0);
}
void pushExecute(const ExecutionMode::MODES,
const uint32_t, const uint32_t c = 0);
inline void pushReturn(void) { push(Opcodes::kReturn, 0, 0, 0); }
inline void pushNone(void) { push(Opcodes::kNone, 0, 0, 0); }
inline void pushAnd(void) { push(Opcodes::kAnd, 0, 0, 0); }
inline void pushOr(void) { push(Opcodes::kOr, 0, 0, 0); }
inline void pushNot(void) { push(Opcodes::kNot, 0, 0, 0); }
inline void pushTrue(void) { push(Opcodes::kTrue, 0, 0, 0); }
inline void pushFalse(void) { push(Opcodes::kFalse, 0, 0, 0); }
void push(const uint32_t, const uint32_t,
const uint32_t, const uint32_t);
uint32_t pushMemory(const char * const);
void pushPrintDebug(const char * const, const char * const b = NULL,
const ExecutionMode::MODES c = ExecutionMode::kNone);
void pushPrintError(const char * const, const char * const b = NULL,
const ExecutionMode::MODES = ExecutionMode::kNone);
inline Code code(void) const { return Code(
reinterpret_cast< Code::Type * >(instructions_.data()),
instructions_.size() * (sizeof(Instruction) / sizeof(Code::Type))); }
inline Memory memory(void) const {
return Memory(memory_.data(), memory_.size()); }
inline uint32_t codeSize(void) const {
return instructions_.size(); }
void pushIsMethod(const char * const, const uint32_t);
void pushIsScheme(const char * const, const uint32_t);
/*
* Domain
*/
void pushContainsDomain(const char * const, const uint32_t);
void pushEqualDomain(const char * const, const uint32_t);
void pushNotEqualDomain(const char * const, const uint32_t);
void pushStartsWithDomain(const char * const, const uint32_t, const uint32_t);
/*
* Path
*/
void pushContainsPath(const char * const, const uint32_t);
void pushEqualPath(const char * const, const uint32_t);
void pushNotEqualPath(const char * const, const uint32_t);
void pushStartsWithPath(const char * const, const uint32_t, const uint32_t);
/*
* Query Parameters
*/
void pushContainsQueryParameter(const char * const, const char * const);
void pushEqualQueryParameter(const char * const, const char * const);
void pushExistsQueryParameter(const char * const);
void pushGreaterThanQueryParameter(const char * const, const uint32_t);
void pushGreaterThanAfterQueryParameter(const char * const,
const char * const, const uint32_t);
void pushLessThanQueryParameter(const char * const, const uint32_t);
void pushLessThanAfterQueryParameter(const char * const,
const char * const, const uint32_t);
void pushNotEqualQueryParameter(const char * const, const char * const);
void pushStartsWithQueryParameter(const char * const, const char * const, const uint32_t);
/*
* Headers
*/
void pushContainsHeader(const char * const, const char * const);
void pushEqualHeader(const char * const, const char * const);
void pushExistsHeader(const char * const);
void pushGreaterThanHeader(const char * const, const uint32_t);
void pushGreaterThanAfterHeader(const char * const, const char * const,
const uint32_t);
void pushLessThanHeader(const char * const, const uint32_t);
void pushLessThanAfterHeader(const char * const, const char * const,
const uint32_t);
void pushNotEqualHeader(const char * const, const char * const);
void pushStartsWithHeader(const char * const, const char * const, const uint32_t);
/*
* Cookies
*/
void pushContainsCookie(const char * const, const char * const);
void pushEqualCookie(const char * const, const char * const);
void pushExistsCookie(const char * const);
void pushGreaterThanCookie(const char * const, const uint32_t);
void pushGreaterThanAfterCookie(const char * const, const char * const,
const uint32_t);
void pushLessThanCookie(const char * const, const uint32_t);
void pushLessThanAfterCookie(const char * const, const char * const,
const uint32_t);
void pushNotEqualCookie(const char * const, const char * const);
};
} //end of filters namespace
} //end of http namespace
#endif //ASSEMBLER_H