2828namespace ngu ::pvm {
2929 // / @brief Bytecode decoding mode.
3030 // / @c RUNTIME - stores only instruction offsets; used by the interpreter at runtime. @n
31- // / @c COMPILE_TIME - additionally stores opcodes, immediates and metadata; builds a label table.
31+ // / @c COMPILE_TIME - additionally stores opcodes, immediates and metadata; builds a label
32+ // / table.
3233 enum decode_time { RUNTIME, COMPILE_TIME };
3334
3435 /* *
@@ -64,8 +65,7 @@ namespace ngu::pvm {
6465 std::conditional_t <DecodeTime == COMPILE_TIME, extension_data_ct, empty> data_ct{};
6566 };
6667
67- template <decode_time DecodeTime>
68- using insn_entry = instruction_entry<DecodeTime>;
68+ template <decode_time DecodeTime> using insn_entry = instruction_entry<DecodeTime>;
6969
7070 using insn_entry_rt = insn_entry<RUNTIME>;
7171 using insn_entry_ct = insn_entry<COMPILE_TIME>;
@@ -74,7 +74,8 @@ namespace ngu::pvm {
7474 * @brief A single entry in the label table.
7575 *
7676 * @c label_id - label identifier (immediate value from @c OP_LABEL). @n
77- * @c target_index - index of the next real instruction after the label (meta-instructions are not counted). @n
77+ * @c target_index - index of the next real instruction after the label (meta-instructions are
78+ * not counted). @n
7879 * @c target - pointer to the next instruction entry in the stream.
7980 */
8081 struct label_entry {
@@ -84,14 +85,12 @@ namespace ngu::pvm {
8485 };
8586
8687 // / @brief View over the decoder instruction stream. @tparam DecodeTime Decoding mode.
87- template <decode_time DecodeTime> class instruction_stream :
88- public indexed_view<instruction_stream<DecodeTime>> {
88+ template <decode_time DecodeTime> class instruction_stream : public indexed_view <instruction_stream<DecodeTime>> {
8989 public:
9090 using value_type = instruction_entry<DecodeTime>;
9191
92- constexpr instruction_stream (const value_type* data,
93- const std::size_t count)
94- : data_(data), count_(count) {}
92+ constexpr instruction_stream (const value_type* data, const std::size_t count) : data_(data), count_(count) {
93+ }
9594
9695 constexpr const value_type& at_impl (std::size_t i) const {
9796 return data_[i];
@@ -106,8 +105,7 @@ namespace ngu::pvm {
106105 std::size_t count_;
107106 };
108107
109- template <decode_time DecodeTime>
110- using insn_stream = instruction_stream<DecodeTime>;
108+ template <decode_time DecodeTime> using insn_stream = instruction_stream<DecodeTime>;
111109
112110 using insn_stream_rt = insn_stream<RUNTIME>;
113111 using insn_stream_ct = insn_stream<COMPILE_TIME>;
@@ -116,9 +114,8 @@ namespace ngu::pvm {
116114 struct label_table : public indexed_view <label_table> {
117115 using value_type = label_entry;
118116
119- constexpr label_table (const value_type* data,
120- const std::size_t count)
121- : data_(data), count_(count) {}
117+ constexpr label_table (const value_type* data, const std::size_t count) : data_(data), count_(count) {
118+ }
122119
123120 constexpr const value_type& at_impl (std::size_t i) const {
124121 return data_[i];
@@ -146,9 +143,10 @@ namespace ngu::pvm {
146143 template <decode_time DecodeTime, std::size_t N> class bytecode_decoder {
147144 static constexpr std::size_t MAX_INSN = (N + 3 ) / 4 ; // (N + divisor - 1) / divisor
148145 public:
149- constexpr explicit bytecode_decoder (const bytecode<N> & code);
146+ constexpr explicit bytecode_decoder (const bytecode<N>& code);
150147
151- // / @brief Returns the instruction stream. @return @ref insn_stream for the given @c DecodeTime.
148+ // / @brief Returns the instruction stream. @return @ref insn_stream for the given @c
149+ // / DecodeTime.
152150 constexpr insn_stream<DecodeTime> get_instruction_stream () const {
153151 return insn_stream{insns_, insn_count_};
154152 }
@@ -169,10 +167,11 @@ namespace ngu::pvm {
169167 }
170168
171169 private:
172- // Iterates over bytecode bytes and fills insns_[]. In COMPILE_TIME mode also extracts opcodes, immediates and meta flags.
170+ // Iterates over bytecode bytes and fills insns_[]. In COMPILE_TIME mode also extracts
171+ // opcodes, immediates and meta flags.
173172 constexpr void build_instruction_stream () {
174- const std::uint8_t * pc{ code_.bytes };
175- const std::uint8_t * end{ code_.bytes + code_.size () };
173+ const std::uint8_t * pc{code_.bytes };
174+ const std::uint8_t * end{code_.bytes + code_.size ()};
176175 std::size_t index{};
177176
178177 while (pc < end && index < MAX_INSN) {
@@ -198,7 +197,8 @@ namespace ngu::pvm {
198197 insn_count_ = index;
199198 }
200199
201- // Scans insns_[] for OP_LABEL entries and fills labels_[]. new_idx counts only real (non-meta) instructions.
200+ // Scans insns_[] for OP_LABEL entries and fills labels_[]. new_idx counts only real
201+ // (non-meta) instructions.
202202 constexpr void build_label_table () {
203203 std::uint64_t new_idx{};
204204 for (std::size_t i{}; i < insn_count_; ++i) {
@@ -208,8 +208,7 @@ namespace ngu::pvm {
208208 labels_[label_count_].target = &insns_[i + 1 ];
209209 labels_[label_count_].target_index = new_idx;
210210 ++label_count_;
211- }
212- else {
211+ } else {
213212 ++new_idx;
214213 }
215214 }
@@ -229,12 +228,13 @@ namespace ngu::pvm {
229228 return bytecode_decoder<DecodeTime, N>(code);
230229 }
231230
232- template <decode_time DecodeTime, std::size_t N> constexpr bytecode_decoder<DecodeTime, N>::bytecode_decoder(const bytecode<N> &code) : code_(code) {
231+ template <decode_time DecodeTime, std::size_t N>
232+ constexpr bytecode_decoder<DecodeTime, N>::bytecode_decoder(const bytecode<N>& code) : code_(code) {
233233 build_instruction_stream ();
234234 if constexpr (DecodeTime == COMPILE_TIME) {
235235 build_label_table ();
236236 }
237237 }
238- }
238+ } // namespace ngu::pvm
239239
240- #endif // NGU_PVM_BYTECODE_BYTECODE_DECODER_H
240+ #endif // NGU_PVM_BYTECODE_BYTECODE_DECODER_H
0 commit comments