OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SANDBOX_LINUX_BPF_DSL_CODEGEN_H__ | 5 #ifndef SANDBOX_LINUX_BPF_DSL_CODEGEN_H__ |
6 #define SANDBOX_LINUX_BPF_DSL_CODEGEN_H__ | 6 #define SANDBOX_LINUX_BPF_DSL_CODEGEN_H__ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 Node MakeInstruction(uint16_t code, | 74 Node MakeInstruction(uint16_t code, |
75 uint32_t k, | 75 uint32_t k, |
76 Node jt = kNullNode, | 76 Node jt = kNullNode, |
77 Node jf = kNullNode); | 77 Node jf = kNullNode); |
78 | 78 |
79 // Compile linearizes the instruction DAG rooted at |head| into a | 79 // Compile linearizes the instruction DAG rooted at |head| into a |
80 // program that can be executed by a BPF virtual machine. | 80 // program that can be executed by a BPF virtual machine. |
81 void Compile(Node head, Program* program); | 81 void Compile(Node head, Program* program); |
82 | 82 |
83 private: | 83 private: |
84 using MemoKey = Tuple<uint16_t, uint32_t, Node, Node>; | 84 using MemoKey = base::Tuple<uint16_t, uint32_t, Node, Node>; |
85 struct MemoKeyLess { | 85 struct MemoKeyLess { |
86 bool operator()(const MemoKey& lhs, const MemoKey& rhs) const; | 86 bool operator()(const MemoKey& lhs, const MemoKey& rhs) const; |
87 }; | 87 }; |
88 | 88 |
89 // AppendInstruction adds a new instruction, ensuring that |jt| and | 89 // AppendInstruction adds a new instruction, ensuring that |jt| and |
90 // |jf| are within range as necessary for |code|. | 90 // |jf| are within range as necessary for |code|. |
91 Node AppendInstruction(uint16_t code, uint32_t k, Node jt, Node jf); | 91 Node AppendInstruction(uint16_t code, uint32_t k, Node jt, Node jf); |
92 | 92 |
93 // WithinRange returns a node equivalent to |next| that is at most | 93 // WithinRange returns a node equivalent to |next| that is at most |
94 // |range| instructions away from the (logical) beginning of the | 94 // |range| instructions away from the (logical) beginning of the |
(...skipping 19 matching lines...) Expand all Loading... |
114 std::vector<Node> equivalent_; | 114 std::vector<Node> equivalent_; |
115 | 115 |
116 std::map<MemoKey, Node, MemoKeyLess> memos_; | 116 std::map<MemoKey, Node, MemoKeyLess> memos_; |
117 | 117 |
118 DISALLOW_COPY_AND_ASSIGN(CodeGen); | 118 DISALLOW_COPY_AND_ASSIGN(CodeGen); |
119 }; | 119 }; |
120 | 120 |
121 } // namespace sandbox | 121 } // namespace sandbox |
122 | 122 |
123 #endif // SANDBOX_LINUX_BPF_DSL_CODEGEN_H__ | 123 #endif // SANDBOX_LINUX_BPF_DSL_CODEGEN_H__ |
OLD | NEW |