Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: src/assembler-re2k.cc

Issue 9326: Assembler and .h file for macro assembler for regexp bytecodes. This compile... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/regexp2000/
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/assembler-re2k.h ('k') | src/bytecodes-re2k.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/assembler-re2k.cc
===================================================================
--- src/assembler-re2k.cc (revision 0)
+++ src/assembler-re2k.cc (revision 0)
@@ -0,0 +1,233 @@
+// Copyright 2008 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// A light-weight assembler for the Regexp2000 byte code.
+
+
+#include "v8.h"
+#include "ast.h"
+#include "bytecodes-re2k.h"
+#include "regexp-codegen.h"
+#include "assembler-re2k.h"
+
+
+namespace v8 { namespace internal {
+
+
+Re2kAssembler::Re2kAssembler(byte* buffer, int buffer_size)
+ : buffer_(buffer),
+ buffer_size_(buffer_size),
+ pc_(0),
+ own_buffer_(false) {
+}
+
+
+void Re2kAssembler::PushCurrentPosition(int cp_offset) {
+ ASSERT(cp_offset >= 0);
+ if (cp_offset < 256) {
+ Emit(BC_PUSH_CP);
+ Emit(cp_offset);
+ } else {
+ Emit(BC_PUSH_CP_WIDE);
+ Emit32(cp_offset);
+ }
+}
+
+
+void Re2kAssembler::PushBacktrack(Label* l) {
+ Emit(BC_PUSH_BT);
+ bind_or_link(l);
+}
+
+
+void Re2kAssembler::PushCapture(int index) {
+ ASSERT(index >= 0);
+ Emit(BC_PUSH_CAPTURE);
+ Emit(index);
+}
+
+
+void Re2kAssembler::SetCapture(int index, int cp_offset) {
+ ASSERT(cp_offset >= 0);
+ ASSERT(index >= 0);
+ if (cp_offset < 256) {
+ Emit(BC_SET_CAPTURE);
+ Emit(index);
+ Emit(cp_offset);
+ } else {
+ Emit(BC_SET_CAPTURE_WIDE);
+ Emit(index);
+ Emit32(cp_offset);
+ }
+}
+
+
+void Re2kAssembler::PopCurrentPosition() {
+ Emit(BC_POP_CP);
+}
+
+
+void Re2kAssembler::PopBacktrack() {
+ Emit(BC_POP_BT);
+}
+
+
+void Re2kAssembler::PopCapture(int index) {
+ Emit(BC_POP_CAPTURE);
+ Emit(index);
+}
+
+
+void Re2kAssembler::Fail() {
+ Emit(BC_FAIL);
+}
+
+
+void Re2kAssembler::Succeed() {
+ Emit(BC_SUCCEED);
+}
+
+
+void Re2kAssembler::Bind(Label* l) {
+ ASSERT(!l->is_bound());
+ l->bind_to(reinterpret_cast<int>(pc_));
+}
+
+
+void Re2kAssembler::AdvanceCP(int cp_offset) {
+ if (cp_offset < 256) {
+ Emit(BC_ADVANCE_CP);
+ Emit(cp_offset);
+ } else {
+ Emit(BC_ADVANCE_CP_WIDE);
+ Emit32(cp_offset);
+ }
+}
+
+
+void Re2kAssembler::GoTo(Label* l) {
+ Emit(BC_GOTO);
+ bind_or_link(l);
+}
+
+
+void Re2kAssembler::LoadCurrentChar(int cp_offset) {
+ if (cp_offset < 256) {
+ Emit(BC_LOAD_CURRENT_CHAR);
+ Emit(cp_offset);
+ } else {
+ Emit(BC_LOAD_CURRENT_CHAR_WIDE);
+ Emit32(cp_offset);
+ }
+}
+
+
+void Re2kAssembler::CheckChar(uc16 c, Label* on_mismatch) {
+ Emit(BC_CHECK_CHAR);
+ Emit16(c);
+ bind_or_link(on_mismatch);
+}
+
+
+void Re2kAssembler::CheckNotChar(uc16 c, Label* on_match) {
+ Emit(BC_CHECK_NOT_CHAR);
+ Emit16(c);
+ bind_or_link(on_match);
+}
+
+
+void Re2kAssembler::CheckRange(uc16 start, uc16 end, Label* on_mismatch) {
+ Emit(BC_CHECK_RANGE);
+ Emit16(start);
+ Emit16(end);
+ bind_or_link(on_mismatch);
+}
+
+
+void Re2kAssembler::CheckNotRange(uc16 start, uc16 end, Label* on_match) {
+ Emit(BC_CHECK_NOT_RANGE);
+ Emit16(start);
+ Emit16(end);
+ bind_or_link(on_match);
+}
+
+
+void Re2kAssembler::CheckBackref(int capture_index, Label* on_mismatch, int cp_offset) {
+ if (cp_offset < 256) {
+ Emit(BC_CHECK_BACKREF);
+ Emit(cp_offset);
+ } else {
+ Emit(BC_CHECK_BACKREF_WIDE);
+ Emit32(cp_offset);
+ }
+ Emit(capture_index);
+ bind_or_link(on_mismatch);
+}
+
+
+void Re2kAssembler::CheckNotBackref(int capture_index, Label* on_match, int cp_offset) {
+ if (cp_offset < 256) {
+ Emit(BC_CHECK_NOT_BACKREF);
+ Emit(cp_offset);
+ } else {
+ Emit(BC_CHECK_NOT_BACKREF_WIDE);
+ Emit32(cp_offset);
+ }
+ Emit(capture_index);
+ bind_or_link(on_match);
+}
+
+
+void Re2kAssembler::Emit(uint32_t byte) {
+ *pc_++ = byte;
+}
+
+
+void Re2kAssembler::Emit16(uint32_t word) {
+ union {
+ byte bytes[2];
+ uint16_t word;
+ } u;
+ u.word = static_cast<uint16_t>(word);
+ Emit(u.bytes[0]);
+ Emit(u.bytes[1]);
+}
+
+
+void Re2kAssembler::Emit32(uint32_t word) {
+ union {
+ byte bytes[4];
+ uint32_t word;
+ } u;
+ u.word = word;
+ Emit(u.bytes[0]);
+ Emit(u.bytes[1]);
+ Emit(u.bytes[2]);
+ Emit(u.bytes[3]);
+}
+
+} } // namespace v8::internal
« no previous file with comments | « src/assembler-re2k.h ('k') | src/bytecodes-re2k.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698