Commit b9df3123 authored by jgruber's avatar jgruber Committed by Commit Bot

Refactor RelocIterator constructors

The (currently four, soon five) RelocIterator constructors contain
basically identical logic. Refactor that into a basic version that all
other constructors call.

Bug: v8:6666
Change-Id: Ice7b4891d5e539ff6fe63337fc52d480d85dc270
Reviewed-on: https://chromium-review.googlesource.com/1059109
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53189}
parent 41e7e173
...@@ -451,50 +451,39 @@ void RelocIterator::next() { ...@@ -451,50 +451,39 @@ void RelocIterator::next() {
} }
RelocIterator::RelocIterator(Code* code, int mode_mask) RelocIterator::RelocIterator(Code* code, int mode_mask)
: mode_mask_(mode_mask) { : RelocIterator(code, code->raw_instruction_start(), code->constant_pool(),
rinfo_.host_ = code; code->relocation_end(), code->relocation_start(),
rinfo_.pc_ = code->raw_instruction_start(); mode_mask) {}
rinfo_.data_ = 0;
rinfo_.constant_pool_ = code->constant_pool();
// Relocation info is read backwards.
pos_ = code->relocation_end();
end_ = code->relocation_start();
if (mode_mask_ == 0) pos_ = end_;
next();
}
RelocIterator::RelocIterator(const CodeReference code_reference, int mode_mask) RelocIterator::RelocIterator(const CodeReference code_reference, int mode_mask)
: mode_mask_(mode_mask) { : RelocIterator(nullptr, code_reference.instruction_start(),
rinfo_.pc_ = code_reference.instruction_start(); code_reference.constant_pool(),
rinfo_.data_ = 0; code_reference.relocation_end(),
rinfo_.constant_pool_ = code_reference.constant_pool(); code_reference.relocation_start(), mode_mask) {}
// Relocation info is read backwards.
pos_ = code_reference.relocation_end();
end_ = code_reference.relocation_start();
if (mode_mask_ == 0) pos_ = end_;
next();
}
RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask)
: mode_mask_(mode_mask) { : RelocIterator(nullptr, reinterpret_cast<Address>(desc.buffer), 0,
rinfo_.pc_ = reinterpret_cast<Address>(desc.buffer); desc.buffer + desc.buffer_size,
// Relocation info is read backwards. desc.buffer + desc.buffer_size - desc.reloc_size,
pos_ = desc.buffer + desc.buffer_size; mode_mask) {}
end_ = pos_ - desc.reloc_size;
if (mode_mask_ == 0) pos_ = end_;
next();
}
RelocIterator::RelocIterator(Vector<byte> instructions, RelocIterator::RelocIterator(Vector<byte> instructions,
Vector<const byte> reloc_info, Address const_pool, Vector<const byte> reloc_info, Address const_pool,
int mode_mask) int mode_mask)
: mode_mask_(mode_mask) { : RelocIterator(nullptr, reinterpret_cast<Address>(instructions.start()),
rinfo_.pc_ = reinterpret_cast<Address>(instructions.start()); const_pool, reloc_info.start() + reloc_info.size(),
rinfo_.constant_pool_ = const_pool; reloc_info.start(), mode_mask) {
rinfo_.flags_ = RelocInfo::kInNativeWasmCode; rinfo_.flags_ = RelocInfo::kInNativeWasmCode;
}
RelocIterator::RelocIterator(Code* host, Address pc, Address constant_pool,
const byte* pos, const byte* end, int mode_mask)
: pos_(pos), end_(end), mode_mask_(mode_mask) {
// Relocation info is read backwards. // Relocation info is read backwards.
pos_ = reloc_info.start() + reloc_info.size(); DCHECK_GE(pos_, end_);
end_ = reloc_info.start(); rinfo_.host_ = host;
rinfo_.pc_ = pc;
rinfo_.constant_pool_ = constant_pool;
if (mode_mask_ == 0) pos_ = end_; if (mode_mask_ == 0) pos_ = end_;
next(); next();
} }
......
...@@ -699,6 +699,9 @@ class RelocIterator: public Malloced { ...@@ -699,6 +699,9 @@ class RelocIterator: public Malloced {
} }
private: private:
RelocIterator(Code* host, Address pc, Address constant_pool, const byte* pos,
const byte* end, int mode_mask);
// Advance* moves the position before/after reading. // Advance* moves the position before/after reading.
// *Read* reads from current byte(s) into rinfo_. // *Read* reads from current byte(s) into rinfo_.
// *Get* just reads and returns info on current byte. // *Get* just reads and returns info on current byte.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment