Commit c6ffff9d authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[parser] Minor cleanup PreParsedScopeDataBuilder

- Mark Serialize method as non-virtual
- Use simple scheme to mask out bytes when de-/serializing Uint32

- Improve ByteArray::ByteArrayPrint method

Drive-by-fix: 
Change-Id: I9a6779587c0a031bcf23e4f431d17026b83a808d
Reviewed-on: https://chromium-review.googlesource.com/c/1387493Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58428}
parent 6679fd2e
......@@ -444,8 +444,10 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
}
void ByteArray::ByteArrayPrint(std::ostream& os) { // NOLINT
os << "byte array, data starts at "
<< static_cast<void*>(GetDataStartAddress());
PrintHeader(os, "ByteArray");
os << "\n - length: " << length()
<< "\n - data-start: " << static_cast<void*>(GetDataStartAddress())
<< "\n";
}
void BytecodeArray::BytecodeArrayPrint(std::ostream& os) { // NOLINT
......
......@@ -105,11 +105,10 @@ class BaseConsumedPreParsedScopeData : public ConsumedPreParsedScopeData {
DCHECK_GE(RemainingBytes(), kUint32Size);
// Check that there indeed is an integer following.
DCHECK_EQ(data_.get(index_++), kUint32Size);
int32_t result = 0;
byte* p = reinterpret_cast<byte*>(&result);
for (int i = 0; i < 4; ++i) {
*p++ = data_.get(index_++);
}
int32_t result = data_.get(index_) + (data_.get(index_ + 1) << 8) +
(data_.get(index_ + 2) << 16) +
(data_.get(index_ + 3) << 24);
index_ += 4;
stored_quarters_ = 0;
return result;
}
......@@ -216,8 +215,7 @@ class ZoneVectorWrapper {
class ZonePreParsedScopeData : public ZoneObject {
public:
ZonePreParsedScopeData(Zone* zone,
ZoneChunkList<uint8_t>::iterator byte_data_begin,
ZoneChunkList<uint8_t>::iterator byte_data_end,
PreParsedScopeDataBuilder::ByteData* byte_data,
int child_length);
Handle<PreParsedScopeData> Serialize(Isolate* isolate);
......
......@@ -83,10 +83,10 @@ void PreParsedScopeDataBuilder::ByteData::WriteUint32(uint32_t data) {
// Save expected item size in debug mode.
backing_store_.push_back(kUint32Size);
#endif
const uint8_t* d = reinterpret_cast<uint8_t*>(&data);
for (int i = 0; i < 4; ++i) {
backing_store_.push_back(*d++);
}
backing_store_.push_back(data & 0xFF);
backing_store_.push_back((data >> 8) & 0xFF);
backing_store_.push_back((data >> 16) & 0xFF);
backing_store_.push_back((data >> 24) & 0xFF);
free_quarters_in_last_byte_ = 0;
}
......@@ -97,10 +97,10 @@ void PreParsedScopeDataBuilder::ByteData::OverwriteFirstUint32(uint32_t data) {
DCHECK_GE(backing_store_.size(), kUint32Size);
DCHECK_EQ(*it, kUint32Size);
++it;
const uint8_t* d = reinterpret_cast<uint8_t*>(&data);
for (size_t i = 0; i < 4; ++i) {
*it++ = *d++;
}
*it++ = data & 0xFF;
*it++ = (data >> 8) & 0xFF;
*it++ = (data >> 16) & 0xFF;
*it++ = (data >> 24) & 0xFF;
}
#endif
......@@ -209,14 +209,12 @@ void PreParsedScopeDataBuilder::SaveScopeAllocationData(
if (bailed_out_) return;
uint32_t scope_data_start = static_cast<uint32_t>(byte_data_->size());
// If there are no skippable inner functions, we don't need to save anything.
if (scope_data_start == ByteData::kPlaceholderSize) {
return;
}
if (!ContainsInnerFunctions()) return;
#ifdef DEBUG
uint32_t scope_data_start = static_cast<uint32_t>(byte_data_->size());
byte_data_->OverwriteFirstUint32(scope_data_start);
// For a data integrity check, write a value between data about skipped inner
......@@ -239,7 +237,7 @@ MaybeHandle<PreParsedScopeData> PreParsedScopeDataBuilder::Serialize(
DCHECK(!ThisOrParentBailedOut());
if (byte_data_->size() <= ByteData::kPlaceholderSize) {
if (!ContainsInnerFunctions()) {
// The data contains only the placeholder.
return MaybeHandle<PreParsedScopeData>();
}
......@@ -270,14 +268,11 @@ ZonePreParsedScopeData* PreParsedScopeDataBuilder::Serialize(Zone* zone) {
DCHECK(!ThisOrParentBailedOut());
if (byte_data_->size() <= ByteData::kPlaceholderSize) {
// The data contains only the placeholder.
return nullptr;
}
if (!ContainsInnerFunctions()) return nullptr;
int child_length = static_cast<int>(data_for_inner_functions_.size());
ZonePreParsedScopeData* result = new (zone) ZonePreParsedScopeData(
zone, byte_data_->begin(), byte_data_->end(), child_length);
ZonePreParsedScopeData* result =
new (zone) ZonePreParsedScopeData(zone, byte_data_, child_length);
int i = 0;
for (const auto& item : data_for_inner_functions_) {
......@@ -628,9 +623,9 @@ OnHeapConsumedPreParsedScopeData::OnHeapConsumedPreParsedScopeData(
}
ZonePreParsedScopeData::ZonePreParsedScopeData(
Zone* zone, ZoneChunkList<uint8_t>::iterator byte_data_begin,
ZoneChunkList<uint8_t>::iterator byte_data_end, int child_length)
: byte_data_(byte_data_begin, byte_data_end, zone),
Zone* zone, PreParsedScopeDataBuilder::ByteData* byte_data,
int child_length)
: byte_data_(byte_data->begin(), byte_data->end(), zone),
children_(child_length, zone) {}
Handle<PreParsedScopeData> ZonePreParsedScopeData::Serialize(Isolate* isolate) {
......
......@@ -126,8 +126,8 @@ class PreParsedScopeDataBuilder : public ZoneObject {
private:
friend class BuilderProducedPreParsedScopeData;
virtual MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
virtual ZonePreParsedScopeData* Serialize(Zone* zone);
MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
ZonePreParsedScopeData* Serialize(Zone* zone);
void SaveDataForScope(Scope* scope);
void SaveDataForVariable(Variable* var);
......
......@@ -840,8 +840,7 @@ TEST(ProducingAndConsumingByteData) {
{
// Serialize as a ZoneConsumedPreParsedScopeData, and read back data.
i::ZonePreParsedScopeData zone_serialized(&zone, bytes.begin(), bytes.end(),
0);
i::ZonePreParsedScopeData zone_serialized(&zone, &bytes, 0);
i::ZoneConsumedPreParsedScopeData::ByteData bytes_for_reading;
i::ZoneVectorWrapper wrapper(zone_serialized.byte_data());
i::ZoneConsumedPreParsedScopeData::ByteData::ReadingScope reading_scope(
......
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