2010-11-23 11:46:36 +00:00
|
|
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-11-23 11:46:36 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "include/v8stdint.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/logging.h"
|
2014-07-10 10:28:05 +00:00
|
|
|
#include "src/compiler.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/globals.h"
|
|
|
|
#include "src/hashmap.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/preparse-data.h"
|
|
|
|
#include "src/preparse-data-format.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2010-11-23 11:46:36 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
CompleteParserRecorder::CompleteParserRecorder()
|
2014-05-05 14:55:13 +00:00
|
|
|
: function_store_(0) {
|
2010-11-23 11:46:36 +00:00
|
|
|
preamble_[PreparseDataConstants::kMagicOffset] =
|
|
|
|
PreparseDataConstants::kMagicNumber;
|
|
|
|
preamble_[PreparseDataConstants::kVersionOffset] =
|
|
|
|
PreparseDataConstants::kCurrentVersion;
|
|
|
|
preamble_[PreparseDataConstants::kHasErrorOffset] = false;
|
|
|
|
preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0;
|
|
|
|
preamble_[PreparseDataConstants::kSizeOffset] = 0;
|
2014-05-05 14:55:13 +00:00
|
|
|
ASSERT_EQ(5, PreparseDataConstants::kHeaderSize);
|
2010-11-23 11:46:36 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
prev_start_ = -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
void CompleteParserRecorder::LogMessage(int start_pos,
|
2014-04-01 14:17:43 +00:00
|
|
|
int end_pos,
|
|
|
|
const char* message,
|
|
|
|
const char* arg_opt,
|
|
|
|
bool is_reference_error) {
|
2014-07-10 10:28:05 +00:00
|
|
|
if (HasError()) return;
|
2010-11-23 11:46:36 +00:00
|
|
|
preamble_[PreparseDataConstants::kHasErrorOffset] = true;
|
|
|
|
function_store_.Reset();
|
|
|
|
STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0);
|
|
|
|
function_store_.Add(start_pos);
|
|
|
|
STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1);
|
|
|
|
function_store_.Add(end_pos);
|
|
|
|
STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2);
|
|
|
|
function_store_.Add((arg_opt == NULL) ? 0 : 1);
|
2014-04-01 14:17:43 +00:00
|
|
|
STATIC_ASSERT(PreparseDataConstants::kIsReferenceErrorPos == 3);
|
|
|
|
function_store_.Add(is_reference_error ? 1 : 0);
|
|
|
|
STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 4);
|
2010-11-23 11:46:36 +00:00
|
|
|
WriteString(CStrVector(message));
|
2011-05-19 09:01:46 +00:00
|
|
|
if (arg_opt != NULL) WriteString(CStrVector(arg_opt));
|
2010-11-23 11:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-13 11:56:13 +00:00
|
|
|
void CompleteParserRecorder::WriteString(Vector<const char> str) {
|
2010-11-23 11:46:36 +00:00
|
|
|
function_store_.Add(str.length());
|
|
|
|
for (int i = 0; i < str.length(); i++) {
|
|
|
|
function_store_.Add(str[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
ScriptData* CompleteParserRecorder::GetScriptData() {
|
2010-11-23 11:46:36 +00:00
|
|
|
int function_size = function_store_.size();
|
2014-05-05 14:55:13 +00:00
|
|
|
int total_size = PreparseDataConstants::kHeaderSize + function_size;
|
2014-07-10 10:28:05 +00:00
|
|
|
unsigned* data = NewArray<unsigned>(total_size);
|
2010-11-23 11:46:36 +00:00
|
|
|
preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size;
|
2014-07-10 10:28:05 +00:00
|
|
|
MemCopy(data, preamble_, sizeof(preamble_));
|
2010-11-23 11:46:36 +00:00
|
|
|
if (function_size > 0) {
|
2014-07-10 10:28:05 +00:00
|
|
|
function_store_.WriteTo(Vector<unsigned>(
|
|
|
|
data + PreparseDataConstants::kHeaderSize, function_size));
|
2010-11-23 11:46:36 +00:00
|
|
|
}
|
2014-07-10 10:28:05 +00:00
|
|
|
ASSERT(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment));
|
|
|
|
ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data),
|
|
|
|
total_size * sizeof(unsigned));
|
|
|
|
result->AcquireDataOwnership();
|
|
|
|
return result;
|
2010-11-23 11:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal.
|