vm: pack frame size into code block header bits
parent
c9cc98d124
commit
d6227c182b
|
@ -433,7 +433,7 @@ code_block *factor_vm::add_code_block(code_block_type type, cell code_, cell lab
|
||||||
if(to_boolean(labels.value()))
|
if(to_boolean(labels.value()))
|
||||||
fixup_labels(labels.as<array>().untagged(),compiled);
|
fixup_labels(labels.as<array>().untagged(),compiled);
|
||||||
|
|
||||||
compiled->stack_frame_size = frame_size_untagged;
|
compiled->set_stack_frame_size(frame_size_untagged);
|
||||||
|
|
||||||
/* Once we are ready, fill in literal and word references in this code
|
/* Once we are ready, fill in literal and word references in this code
|
||||||
block's instruction operands. In most cases this is done right after this
|
block's instruction operands. In most cases this is done right after this
|
||||||
|
|
|
@ -7,13 +7,15 @@ struct code_block
|
||||||
// header format (bits indexed with least significant as zero):
|
// header format (bits indexed with least significant as zero):
|
||||||
// bit 0 : free?
|
// bit 0 : free?
|
||||||
// bits 1-2: type (as a code_block_type)
|
// bits 1-2: type (as a code_block_type)
|
||||||
// bits 4- : code size / 16
|
// if not free:
|
||||||
|
// bits 3-23: code size / 8
|
||||||
|
// bits 24-31: stack frame size / 16
|
||||||
|
// if free:
|
||||||
|
// bits 3-end: code size / 8
|
||||||
cell header;
|
cell header;
|
||||||
cell owner; /* tagged pointer to word, quotation or f */
|
cell owner; /* tagged pointer to word, quotation or f */
|
||||||
cell parameters; /* tagged pointer to array or f */
|
cell parameters; /* tagged pointer to array or f */
|
||||||
cell relocation; /* tagged pointer to byte-array or f */
|
cell relocation; /* tagged pointer to byte-array or f */
|
||||||
cell stack_frame_size;
|
|
||||||
cell pad;
|
|
||||||
|
|
||||||
bool free_p() const
|
bool free_p() const
|
||||||
{
|
{
|
||||||
|
@ -42,11 +44,32 @@ struct code_block
|
||||||
|
|
||||||
cell size() const
|
cell size() const
|
||||||
{
|
{
|
||||||
cell size = header & ~7;
|
cell size;
|
||||||
|
if (free_p())
|
||||||
|
size = header & ~7;
|
||||||
|
else
|
||||||
|
size = header & 0xFFFFF8;
|
||||||
FACTOR_ASSERT(size > 0);
|
FACTOR_ASSERT(size > 0);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cell stack_frame_size() const
|
||||||
|
{
|
||||||
|
if (free_p())
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return (header >> 20) & 0xFF0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_stack_frame_size(cell frame_size)
|
||||||
|
{
|
||||||
|
FACTOR_ASSERT(size() < 0xFFFFFF);
|
||||||
|
FACTOR_ASSERT(!free_p());
|
||||||
|
FACTOR_ASSERT(frame_size % 16 == 0);
|
||||||
|
FACTOR_ASSERT(frame_size <= 0xFF0);
|
||||||
|
header = (header & 0xFFFFFF) | (frame_size << 20);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Fixup> cell size(Fixup fixup) const
|
template<typename Fixup> cell size(Fixup fixup) const
|
||||||
{
|
{
|
||||||
return size();
|
return size();
|
||||||
|
|
|
@ -418,7 +418,7 @@ struct code_block_printer {
|
||||||
std::cout << std::hex << (cell)scan << std::dec << " ";
|
std::cout << std::hex << (cell)scan << std::dec << " ";
|
||||||
std::cout << std::hex << size << std::dec << " ";
|
std::cout << std::hex << size << std::dec << " ";
|
||||||
std::cout << status << " ";
|
std::cout << status << " ";
|
||||||
std::cout << "stack frame " << scan->stack_frame_size;
|
std::cout << "stack frame " << scan->stack_frame_size();
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue