Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/tls-maxphys]: src/sys/external/bsd/sljit/dist Initial import of sljit @ ...



details:   https://anonhg.NetBSD.org/src/rev/0cff14f68203
branches:  tls-maxphys
changeset: 852921:0cff14f68203
user:      alnsn <alnsn%NetBSD.org@localhost>
date:      Sat Oct 06 18:24:19 2012 +0000

description:
Initial import of sljit @ r175.

svn co https://sljit.svn.sourceforge.net/svnroot/sljit@r175 dist

diffstat:

 sys/external/bsd/sljit/dist/regex_src/regexJIT.c           |  2591 ++++++++++++
 sys/external/bsd/sljit/dist/regex_src/regexJIT.h           |    98 +
 sys/external/bsd/sljit/dist/regex_src/regexMain.c          |   293 +
 sys/external/bsd/sljit/dist/sljit_src/sljitExecAllocator.c |   277 +
 4 files changed, 3259 insertions(+), 0 deletions(-)

diffs (truncated from 3275 to 300 lines):

diff -r a03f9b86b101 -r 0cff14f68203 sys/external/bsd/sljit/dist/regex_src/regexJIT.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/sljit/dist/regex_src/regexJIT.c  Sat Oct 06 18:24:19 2012 +0000
@@ -0,0 +1,2591 @@
+/*
+ *    Stack-less Just-In-Time compiler
+ *
+ *    Copyright 2009-2010 Zoltan Herczeg (hzmester%freemail.hu@localhost). All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright notice, this list of
+ *      conditions and the following disclaimer.
+ *
+ *   2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) 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 HOLDER(S) 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.
+ */
+
+#include "sljitLir.h"
+#include "regexJIT.h"
+
+#ifdef REGEX_MATCH_VERBOSE
+#include <stdio.h>
+#endif
+
+/* Extra, hidden flags:
+   {id!} where id > 0 found in the code. */
+#define REGEX_ID_CHECK         0x100
+/* When REGEX_NEWLINE && REGEX_MATCH_BEGIN defined, the pattern turn to a normal search,
+   which starts with [\r\n] character range. */
+#define REGEX_FAKE_MATCH_BEGIN 0x200
+/* When REGEX_NEWLINE && REGEX_MATCH_END defined, the pattern turn to a normal search,
+   which ends with [\r\n] character range. */
+#define REGEX_FAKE_MATCH_END   0x400
+
+/* Check match completition after every (FINISH_TEST + 1) steps. */
+#define FINISH_TEST    0x7
+
+/* --------------------------------------------------------------------- */
+/*  Structures for JIT-ed pattern matching                               */
+/* --------------------------------------------------------------------- */
+
+struct regex_machine
+{
+       /* flags. */
+       int flags;
+       /* Number of state descriptors for one term. */
+       sljit_w no_states;
+       /* Total size. */
+       sljit_w size;
+
+       union {
+               void *init_match;
+               sljit_w (SLJIT_CALL *call_init)(void *next, void* match);
+       } u;
+#if (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
+       struct sljit_function_context context;
+#endif
+
+       void *continue_match;
+
+       /* Variable sized array to contain the handler addresses. */
+       sljit_uw entry_addrs[1];
+};
+
+struct regex_match
+{
+       /* Current and next state array. */
+       sljit_w *current;
+       sljit_w *next;
+       /* Starting. */
+       sljit_w head;
+       /* String character index (ever increasing). */
+       sljit_w index;
+       /* Best match found so far (members in priority order). */
+       sljit_w best_begin;
+       sljit_w best_end;
+       sljit_w best_id;
+       /* Bool flags (encoded as word). */
+       sljit_w fast_quit;
+       sljit_w fast_forward;
+       /* Machine. */
+       struct regex_machine *machine;
+
+       union {
+               void *continue_match;
+               void (SLJIT_CALL *call_continue)(struct regex_match *match, const regex_char_t *input_string, int length);
+       } u;
+
+       /* Variable sized array to contain the state arrays. */
+       sljit_w states[1];
+};
+
+/* State vector
+    ITEM[0] - pointer to the address inside the machine code
+    ITEM[1] - next pointer
+    ITEM[2] - string started from (optional)
+    ITEM[3] - max ID (optional) */
+
+/* Register allocation. */
+/* Current state array (loaded & stored: regex_match->current). */
+#define R_CURR_STATE   SLJIT_SAVED_REG1
+/* Next state array (loaded & stored: regex_match->next). */
+#define R_NEXT_STATE   SLJIT_SAVED_REG2
+/* Head (loaded & stored: regex_match->head). */
+#define R_NEXT_HEAD    SLJIT_SAVED_REG3
+/* String fragment pointer. */
+#define R_STRING       SLJIT_SAVED_EREG1
+/* String fragment length. */
+#define R_LENGTH       SLJIT_SAVED_EREG2
+/* 'struct regex_match*' */
+#define R_REGEX_MATCH  SLJIT_TEMPORARY_REG1
+/* Current character. */
+#define R_CURR_CHAR    SLJIT_TEMPORARY_REG2
+/* Temporary register. */
+#define R_TEMP         SLJIT_TEMPORARY_REG3
+/* Caches the regex_match->best_begin. */
+#define R_BEST_BEGIN   SLJIT_TEMPORARY_EREG1
+/* Current character index. */
+#define R_CURR_INDEX   SLJIT_TEMPORARY_EREG2
+
+/* --------------------------------------------------------------------- */
+/*  Stack management                                                     */
+/* --------------------------------------------------------------------- */
+
+/* Try to allocate 2^n blocks. */
+#define STACK_FRAGMENT_SIZE (((64 * sizeof(struct stack_item)) - (sizeof(struct stack_fragment_data))) / (sizeof(struct stack_item)))
+
+struct stack_item {
+       int type;
+       int value;
+};
+
+struct stack_fragment_data {
+       struct stack_fragment *next;
+       struct stack_fragment *prev;
+};
+
+struct stack_fragment {
+       struct stack_fragment_data data;
+       struct stack_item items[STACK_FRAGMENT_SIZE];
+};
+
+struct stack {
+       struct stack_fragment *first;
+       struct stack_fragment *last;
+       int index;
+       int count;
+};
+
+#if (defined SLJIT_DEBUG && SLJIT_DEBUG)
+
+static void stack_check(struct stack *stack)
+{
+       struct stack_fragment *curr;
+       int found;
+
+       if (!stack)
+               return;
+
+       SLJIT_ASSERT(stack->index >= 0 && stack->index < STACK_FRAGMENT_SIZE);
+
+       if (stack->first == NULL) {
+               SLJIT_ASSERT(stack->first == NULL && stack->last == NULL);
+               SLJIT_ASSERT(stack->index == STACK_FRAGMENT_SIZE - 1 && stack->count == 0);
+               return;
+       }
+
+       found = 0;
+       if (stack->last == NULL) {
+               SLJIT_ASSERT(stack->index == STACK_FRAGMENT_SIZE - 1 && stack->count == 0);
+               found = 1;
+       }
+       else
+               SLJIT_ASSERT(stack->index >= 0 && stack->count >= 0);
+
+       SLJIT_ASSERT(stack->first->data.prev == NULL);
+       curr = stack->first;
+       while (curr) {
+               if (curr == stack->last)
+                       found = 1;
+               if (curr->data.next)
+                       SLJIT_ASSERT(curr->data.next->data.prev == curr);
+               curr = curr->data.next;
+       }
+       SLJIT_ASSERT(found);
+}
+
+#endif
+
+static void stack_init(struct stack *stack)
+{
+       stack->first = NULL;
+       stack->last = NULL;
+       stack->index = STACK_FRAGMENT_SIZE - 1;
+       stack->count = 0;
+}
+
+static void stack_destroy(struct stack *stack)
+{
+       struct stack_fragment *curr = stack->first;
+       struct stack_fragment *prev;
+
+#if (defined SLJIT_DEBUG && SLJIT_DEBUG)
+       stack_check(stack);
+#endif
+
+       while (curr) {
+               prev = curr;
+               curr = curr->data.next;
+               SLJIT_FREE(prev);
+       }
+}
+
+static SLJIT_INLINE struct stack_item* stack_top(struct stack *stack)
+{
+       SLJIT_ASSERT(stack->last);
+       return stack->last->items + stack->index;
+}
+
+static int stack_push(struct stack *stack, int type, int value)
+{
+       if (stack->last) {
+               stack->index++;
+               if (stack->index >= STACK_FRAGMENT_SIZE) {
+                       stack->index = 0;
+                       if (!stack->last->data.next) {
+                               stack->last->data.next = (struct stack_fragment*)SLJIT_MALLOC(sizeof(struct stack_fragment));
+                               if (!stack->last->data.next)
+                                       return 1;
+                               stack->last->data.next->data.next = NULL;
+                               stack->last->data.next->data.prev = stack->last;
+                       }
+                       stack->last = stack->last->data.next;
+               }
+       }
+       else if (!stack->first) {
+               stack->last = (struct stack_fragment*)SLJIT_MALLOC(sizeof(struct stack_fragment));
+               if (!stack->last)
+                       return 1;
+               stack->last->data.prev = NULL;
+               stack->last->data.next = NULL;
+               stack->first = stack->last;
+               stack->index = 0;
+       }
+       else {
+               stack->last = stack->first;
+               stack->index = 0;
+       }
+       stack->last->items[stack->index].type = type;
+       stack->last->items[stack->index].value = value;
+       stack->count++;
+#if (defined SLJIT_DEBUG && SLJIT_DEBUG)
+       stack_check(stack);
+#endif
+       return 0;
+}
+
+static struct stack_item* stack_pop(struct stack *stack)
+{
+       struct stack_item *ret = stack_top(stack);
+
+       if (stack->index > 0)
+               stack->index--;
+       else {
+               stack->last = stack->last->data.prev;
+               stack->index = STACK_FRAGMENT_SIZE - 1;
+       }
+
+       stack->count--;
+#if (defined SLJIT_DEBUG && SLJIT_DEBUG)
+       stack_check(stack);
+#endif
+       return ret;
+}
+
+static SLJIT_INLINE void stack_clone(struct stack *src, struct stack *dst)
+{
+       *dst = *src;
+}
+
+static int stack_push_copy(struct stack *stack, int items, int length)
+{
+       struct stack_fragment *frag1;
+       int ind1;
+       struct stack_fragment *frag2;
+       int ind2;
+       int counter;



Home | Main Index | Thread Index | Old Index