Resetting the builder arena. May be a bug or two here still.
This commit is contained in:
parent
63f11732a5
commit
cd9172ed62
|
@ -35,6 +35,14 @@ void Arena::Reset() {
|
|||
}
|
||||
}
|
||||
|
||||
void Arena::DebugFill() {
|
||||
auto chunk = head_chunk_;
|
||||
while (chunk) {
|
||||
memset(chunk->buffer, 0xCD, chunk->capacity);
|
||||
chunk = chunk->next;
|
||||
}
|
||||
}
|
||||
|
||||
void* Arena::Alloc(size_t size) {
|
||||
if (active_chunk_) {
|
||||
if (active_chunk_->capacity - active_chunk_->offset < size) {
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
~Arena();
|
||||
|
||||
void Reset();
|
||||
void DebugFill();
|
||||
|
||||
void* Alloc(size_t size);
|
||||
template<typename T> T* Alloc() {
|
||||
|
|
|
@ -69,9 +69,12 @@ int IVMAssembler::Assemble(
|
|||
ctx.scratch_arena = &scratch_arena_;
|
||||
ctx.label_ref_head = NULL;
|
||||
|
||||
// Reset label tags as we use them.
|
||||
builder->ResetLabelTags();
|
||||
|
||||
// Function prologue.
|
||||
|
||||
Block* block = builder->first_block();
|
||||
auto block = builder->first_block();
|
||||
while (block) {
|
||||
Label* label = block->label_head;
|
||||
while (label) {
|
||||
|
|
|
@ -42,6 +42,10 @@ void HIRBuilder::Reset() {
|
|||
next_value_ordinal_ = 0;
|
||||
block_head_ = block_tail_ = NULL;
|
||||
current_block_ = NULL;
|
||||
#if XE_DEBUG
|
||||
arena_->DebugFill();
|
||||
#endif
|
||||
arena_->Reset();
|
||||
}
|
||||
|
||||
int HIRBuilder::Finalize() {
|
||||
|
@ -319,6 +323,19 @@ void HIRBuilder::InsertLabel(Label* label, Instr* prev_instr) {
|
|||
}
|
||||
}
|
||||
|
||||
void HIRBuilder::ResetLabelTags() {
|
||||
// TODO(benvanik): make this faster?
|
||||
auto block = block_head_;
|
||||
while (block) {
|
||||
auto label = block->label_head;
|
||||
while (label) {
|
||||
label->tag = 0;
|
||||
label = label->next;
|
||||
}
|
||||
block = block->next;
|
||||
}
|
||||
}
|
||||
|
||||
Block* HIRBuilder::AppendBlock() {
|
||||
Block* block = arena_->Alloc<Block>();
|
||||
block->arena = arena_;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <alloy/core.h>
|
||||
#include <alloy/hir/block.h>
|
||||
#include <alloy/hir/instr.h>
|
||||
#include <alloy/hir/label.h>
|
||||
#include <alloy/hir/opcodes.h>
|
||||
#include <alloy/hir/value.h>
|
||||
|
||||
|
@ -47,6 +48,7 @@ public:
|
|||
Label* NewLabel();
|
||||
void MarkLabel(Label* label, Block* block = 0);
|
||||
void InsertLabel(Label* label, Instr* prev_instr);
|
||||
void ResetLabelTags();
|
||||
|
||||
// static allocations:
|
||||
// Value* AllocStatic(size_t length);
|
||||
|
|
Loading…
Reference in New Issue