Files
sdk/runtime/vm/code_descriptors.cc
T
asiva@google.com e360e4d1c9 Second set of changes for implementation of stack map support.
- Added functionality to be able to build stack maps in the compiler and register them into the Code object during Code finalization.
- Merged code_generator_ia32_test.cc and code_generator_x64_test.cc into code_generator_test.cc as the two files were identical.
Review URL: https://chromiumcodereview.appspot.com//9721006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@5764 260f80e4-7a28-3924-810f-c04153c831b5
2012-03-23 01:27:35 +00:00

85 lines
2.3 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/code_descriptors.h"
namespace dart {
void DescriptorList::AddDescriptor(PcDescriptors::Kind kind,
intptr_t pc_offset,
intptr_t node_id,
intptr_t token_index,
intptr_t try_index) {
struct PcDesc data;
data.pc_offset = pc_offset;
data.kind = kind;
data.node_id = node_id;
data.token_index = token_index;
data.try_index = try_index;
list_.Add(data);
}
RawPcDescriptors* DescriptorList::FinalizePcDescriptors(uword entry_point) {
intptr_t num_descriptors = Length();
const PcDescriptors& descriptors =
PcDescriptors::Handle(PcDescriptors::New(num_descriptors));
for (intptr_t i = 0; i < num_descriptors; i++) {
descriptors.AddDescriptor(i,
(entry_point + PcOffset(i)),
Kind(i),
NodeId(i),
TokenIndex(i),
TryIndex(i));
}
return descriptors.raw();
}
void StackmapBuilder::AddEntry(intptr_t pc_offset) {
stack_map_ = Stackmap::New(pc_offset, code_, builder_);
list_.Add(stack_map_);
}
bool StackmapBuilder::Verify() {
intptr_t num_entries = Length();
Stackmap& map1 = Stackmap::Handle();
Stackmap& map2 = Stackmap::Handle();
for (intptr_t i = 1; i < num_entries; i++) {
map1 = Map(i - 1);
map2 = Map(i);
// Ensure there are no duplicates and the entries are sorted.
if (map1.PC() >= map2.PC()) {
return false;
}
}
return true;
}
RawArray* StackmapBuilder::FinalizeStackmaps(const Code& code) {
ASSERT(Verify());
intptr_t num_entries = Length();
uword entry_point = code.EntryPoint();
if (num_entries == 0) {
return Array::Empty();
}
for (intptr_t i = 0; i < num_entries; i++) {
stack_map_ = Map(i);
stack_map_.SetPC(entry_point + stack_map_.PC());
stack_map_.SetCode(code);
}
return Array::MakeArray(list_);
}
RawStackmap* StackmapBuilder::Map(int index) const {
Stackmap& map = Stackmap::Handle();
map ^= list_.At(index);
return map.raw();
}
} // namespace dart