OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * Defines an instruction (decoder) iterator that processes code segments. | 8 * Defines an instruction (decoder) iterator that processes code segments. |
9 */ | 9 */ |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 NaClInstIter* NaClInstIterCreate(NaClSegment* segment) { | 68 NaClInstIter* NaClInstIterCreate(NaClSegment* segment) { |
69 return NaClInstIterCreateWithLookback(segment, 0); | 69 return NaClInstIterCreateWithLookback(segment, 0); |
70 } | 70 } |
71 | 71 |
72 void NaClInstIterDestroy(NaClInstIter* iter) { | 72 void NaClInstIterDestroy(NaClInstIter* iter) { |
73 free(iter->buffer); | 73 free(iter->buffer); |
74 free(iter); | 74 free(iter); |
75 } | 75 } |
76 | 76 |
| 77 NaClInstState* NaClInstIterGetUndecodedState(NaClInstIter* iter) { |
| 78 return &iter->buffer[iter->buffer_index]; |
| 79 } |
| 80 |
77 NaClInstState* NaClInstIterGetState(NaClInstIter* iter) { | 81 NaClInstState* NaClInstIterGetState(NaClInstIter* iter) { |
78 NaClInstState* state = &iter->buffer[iter->buffer_index]; | 82 NaClInstState* state = NaClInstIterGetUndecodedState(iter); |
79 if (NULL == state->inst) { | 83 if (NULL == state->inst) { |
80 NaClDecodeInst(iter, state); | 84 NaClDecodeInst(iter, state); |
81 } | 85 } |
82 return state; | 86 return state; |
83 } | 87 } |
84 | 88 |
85 Bool NaClInstIterHasLookbackState(NaClInstIter* iter, size_t distance) { | 89 Bool NaClInstIterHasLookbackState(NaClInstIter* iter, size_t distance) { |
86 return distance < iter->buffer_size && distance <= iter->inst_count; | 90 return distance < iter->buffer_size && distance <= iter->inst_count; |
87 } | 91 } |
88 | 92 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 iter->index, iter->buffer_index)); | 125 iter->index, iter->buffer_index)); |
122 iter->buffer[iter->buffer_index].inst = NULL; | 126 iter->buffer[iter->buffer_index].inst = NULL; |
123 } | 127 } |
124 | 128 |
125 uint8_t* NaClInstIterGetInstMemory(NaClInstIter* iter) { | 129 uint8_t* NaClInstIterGetInstMemory(NaClInstIter* iter) { |
126 if (iter->index >= iter->segment->size) { | 130 if (iter->index >= iter->segment->size) { |
127 NaClInstIterFatal("NaClInstIterGetInstMemory with no next element."); | 131 NaClInstIterFatal("NaClInstIterGetInstMemory with no next element."); |
128 } | 132 } |
129 return iter->segment->mbase + iter->index; | 133 return iter->segment->mbase + iter->index; |
130 } | 134 } |
OLD | NEW |