1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "src/base/logging.h"
6 #include "src/compiler.h"
7 #include "src/globals.h"
8 #include "src/hashmap.h"
9 #include "src/preparse-data.h"
10 #include "src/preparse-data-format.h"
16 CompleteParserRecorder::CompleteParserRecorder() {
17 preamble_[PreparseDataConstants::kMagicOffset] =
18 PreparseDataConstants::kMagicNumber;
19 preamble_[PreparseDataConstants::kVersionOffset] =
20 PreparseDataConstants::kCurrentVersion;
21 preamble_[PreparseDataConstants::kHasErrorOffset] = false;
22 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0;
23 preamble_[PreparseDataConstants::kSizeOffset] = 0;
24 DCHECK_EQ(5, PreparseDataConstants::kHeaderSize);
31 void CompleteParserRecorder::LogMessage(int start_pos,
35 bool is_reference_error) {
36 if (HasError()) return;
37 preamble_[PreparseDataConstants::kHasErrorOffset] = true;
38 function_store_.Reset();
39 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0);
40 function_store_.Add(start_pos);
41 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1);
42 function_store_.Add(end_pos);
43 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2);
44 function_store_.Add((arg_opt == NULL) ? 0 : 1);
45 STATIC_ASSERT(PreparseDataConstants::kIsReferenceErrorPos == 3);
46 function_store_.Add(is_reference_error ? 1 : 0);
47 STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 4);
48 WriteString(CStrVector(message));
49 if (arg_opt != NULL) WriteString(CStrVector(arg_opt));
53 void CompleteParserRecorder::WriteString(Vector<const char> str) {
54 function_store_.Add(str.length());
55 for (int i = 0; i < str.length(); i++) {
56 function_store_.Add(str[i]);
61 ScriptData* CompleteParserRecorder::GetScriptData() {
62 int function_size = function_store_.size();
63 int total_size = PreparseDataConstants::kHeaderSize + function_size;
64 unsigned* data = NewArray<unsigned>(total_size);
65 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size;
66 MemCopy(data, preamble_, sizeof(preamble_));
67 if (function_size > 0) {
68 function_store_.WriteTo(Vector<unsigned>(
69 data + PreparseDataConstants::kHeaderSize, function_size));
71 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment));
72 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data),
73 total_size * sizeof(unsigned));
74 result->AcquireDataOwnership();
79 } } // namespace v8::internal.