RPA Toolkit
Reworked the build system for linux.
authorMartin Stoilov <martin@sigmadrone.org>
Mon, 10 Feb 2020 02:04:32 +0000 (18:04 -0800)
committerMartin Stoilov <martin@sigmadrone.org>
Mon, 10 Feb 2020 02:04:32 +0000 (18:04 -0800)
build/unix/build.mk
rex/build/unix/x86_64/Makefile
rjs/build/unix/rjs.mk
rjs/rjsexec.c [deleted file]
rjs/unix/rjsrules.c
tests/testmisc/test-asm.sh

index 2a1fa1f..97fafec 100644 (file)
@@ -12,6 +12,7 @@ all:
        +make -C $(ROOT_DIR)/rjs/build/unix/$(ARCHDIR) all
 ifeq ($(OS), linux)
        +make -C $(ROOT_DIR)/tests/testrjs/build/unix/$(ARCHDIR) all
+       +make -C $(ROOT_DIR)/tests2 all
 endif
 
 distclean: clean
@@ -28,6 +29,7 @@ distclean: clean
        +make -C $(ROOT_DIR)/rexgrep/build/unix/$(ARCHDIR) distclean
        +make -C $(ROOT_DIR)/rexcc/build/unix/$(ARCHDIR) distclean
        +make -C $(ROOT_DIR)/rjs/build/unix/$(ARCHDIR) distclean
+       +make -C $(ROOT_DIR)/tests2 distclean
 
 clean:
        +make -C $(ROOT_DIR)/rlib/build/unix/$(ARCHDIR) clean
@@ -42,6 +44,7 @@ clean:
        +make -C $(ROOT_DIR)/rexgrep/build/unix/$(ARCHDIR) clean
        +make -C $(ROOT_DIR)/rexcc/build/unix/$(ARCHDIR) clean
        +make -C $(ROOT_DIR)/rjs/build/unix/$(ARCHDIR) clean
+       +make -C $(ROOT_DIR)/tests2 clean
 
 $(RPATK_BIN_INSTALL) :
        mkdir -p $(RPATK_BIN_INSTALL)
index ff7204a..f4a2bdf 100644 (file)
@@ -1,5 +1,4 @@
-ROOT_DIR = ../../../..
-include $(ROOT_DIR)/build/unix/config.mk
+include $(ROOT_DIR)/unix/config.mk
 
 INCLUDE = -I$(ROOT_DIR)/arch/unix/$(ARCHDIR)
 OUTDIR = out
index f3ab9fd..aa78bc3 100644 (file)
@@ -85,6 +85,10 @@ endif
 $(OUTDIR)/%.o: $(RJS_SRCDIR)/unix/%.c
        $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $(RJS_SRCDIR)/unix/$*.c
 
+$(OUTDIR)/%.o: $(RJS_SRCDIR)/exec/%.c
+       $(CC) $(CFLAGS) -o $(OUTDIR)/$*.o -c $<
+
+
 $(RJS_LIB): $(RJS_OBJECTS)
        $(AR) -cr $@ $^
 
diff --git a/rjs/rjsexec.c b/rjs/rjsexec.c
deleted file mode 100644 (file)
index d4a43e4..0000000
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- *  Regular Pattern Analyzer Toolkit (RPA/Tk)
- *  Copyright (c) 2009-2012 Martin Stoilov
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- *  Martin Stoilov <martin@rpasearch.com>
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "rlib/rmem.h"
-#include "rjs/rjs.h"
-#include "rjs/rjsfile.h"
-#include "rpa/rparecord.h"
-
-
-static int debuginfo = 0;
-static int parseinfo = 0;
-static int compileonly = 0;
-static int debugcompileonly = 0;
-static int statinfo = 0;
-
-
-static char *errormsg[] = {
-       "OK",
-       "Undefined identifier",
-       "Syntax error",
-       "Not a function",
-       "Not a function call",
-       "Not a loop",
-       "Not a if statement",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-       "Unknown",
-};
-
-
-static void rjs_exec_ltrim(rvmcpu_t *cpu, rvm_asmins_t *ins)
-{
-       const char *ptr, *list;
-       unsigned long size;
-       rvmreg_t *r = NULL, *l = NULL;
-       rstring_t *src, *dest;
-
-       if (RJS_SWI_PARAMS(cpu) == 0)
-               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       r = (rvmreg_t *) RJS_SWI_PARAM(cpu, 1);
-       if (RJS_SWI_PARAMS(cpu) > 1) {
-               l = (rvmreg_t *) RJS_SWI_PARAM(cpu, 2);
-               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING)
-                       RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       }
-       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING)
-               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       if (l)
-               list = ((rstring_t *)RVM_REG_GETP(l))->s.str;
-       else
-               list = " \t\n\r\0";
-       src = (rstring_t *)RVM_REG_GETP(r);
-       ptr = src->s.str;
-       size = src->s.size;
-       while (size > 0) {
-               if (!r_strchr(list, *ptr))
-                       break;
-               size--;
-               ptr++;
-       }
-       dest = r_string_create_strsize(ptr, size);
-       r_gc_add(cpu->gc, (robject_t*)dest);
-       rvm_reg_setstring(RVM_CPUREG_PTR(cpu, R0), dest);
-}
-
-
-static void rjs_exec_rtrim(rvmcpu_t *cpu, rvm_asmins_t *ins)
-{
-       const char *ptr, *list;
-       unsigned long size;
-       rvmreg_t *r = NULL, *l = NULL;
-       rstring_t *src, *dest;
-
-       if (RJS_SWI_PARAMS(cpu) == 0)
-               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       r = (rvmreg_t *) RJS_SWI_PARAM(cpu, 1);
-       if (RJS_SWI_PARAMS(cpu) > 1) {
-               l = (rvmreg_t *) RJS_SWI_PARAM(cpu, 2);
-               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING)
-                       RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       }
-       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING)
-               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       if (l)
-               list = ((rstring_t *)RVM_REG_GETP(l))->s.str;
-       else
-               list = " \t\n\r\0";
-       src = (rstring_t *)RVM_REG_GETP(r);
-       size = src->s.size;
-       ptr = src->s.str + size - 1;
-       while (size > 0) {
-               if (!r_strchr(list, *ptr))
-                       break;
-               size--;
-               ptr--;
-       }
-       dest = r_string_create_strsize(src->s.str, size);
-       r_gc_add(cpu->gc, (robject_t*)dest);
-       rvm_reg_setstring(RVM_CPUREG_PTR(cpu, R0), dest);
-}
-
-
-static void rjs_exec_trim(rvmcpu_t *cpu, rvm_asmins_t *ins)
-{
-       const char *start, *ptr, *list;
-       unsigned long size;
-       rvmreg_t *r = NULL, *l = NULL;
-       rstring_t *src, *dest;
-
-       if (RJS_SWI_PARAMS(cpu) == 0)
-               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-
-       r = (rvmreg_t *) RJS_SWI_PARAM(cpu, 1);
-       if (RJS_SWI_PARAMS(cpu) > 1) {
-               l = (rvmreg_t *) RJS_SWI_PARAM(cpu, 2);
-               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING)
-                       RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       }
-       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING)
-               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
-       if (l)
-               list = ((rstring_t *)RVM_REG_GETP(l))->s.str;
-       else
-               list = " \t\n\r\0";
-       src = (rstring_t *)RVM_REG_GETP(r);
-       ptr = src->s.str;
-       size = src->s.size;
-       while (size > 0) {
-               if (!r_strchr(list, *ptr))
-                       break;
-               size--;
-               ptr++;
-       }
-       start = ptr;
-       ptr = start + size - 1;
-       while (size > 0) {
-               if (!r_strchr(list, *ptr))
-                       break;
-               size--;
-               ptr--;
-       }
-       dest = r_string_create_strsize(start, size);
-       r_gc_add(cpu->gc, (robject_t*)dest);
-       rvm_reg_setstring(RVM_CPUREG_PTR(cpu, R0), dest);
-}
-
-
-static rvm_switable_t swistring[] = {
-               {"ltrim", rjs_exec_ltrim},
-               {"rtrim", rjs_exec_rtrim},
-               {"trim", rjs_exec_trim},
-               {NULL, NULL},
-};
-
-
-int rjs_exec_script(rjs_engine_t *jse, rstr_t  *script)
-{
-       if (!script)
-               return -1;
-       if (parseinfo) {
-               rjs_engine_dumpast(jse, script->str, script->size);
-       } else if (debugcompileonly) {
-               int res = 0;
-               jse->debugcompile = 1;
-               res = rjs_engine_compile(jse, script->str, script->size);
-               jse->debugcompile = 0;
-               if (res < 0)
-                       return -1;
-       } else if (compileonly) {
-               if (rjs_engine_compile(jse, script->str, script->size) < 0)
-                       return -1;
-       } else {
-               if (rjs_engine_compile(jse, script->str, script->size) < 0)
-                       return -1;
-               if (rjs_engine_run(jse) < 0)
-                       return -1;
-       }
-
-       return 0;
-}
-
-
-long jrs_offset2line(const char *script, long offset)
-{
-       long line = 0;
-       const char *ptr;
-
-       for (line = 1, ptr = script + offset; ptr >= script; --ptr) {
-               if (*ptr == '\n')
-                       line += 1;
-       }
-
-       return line;
-}
-
-
-void rjs_display_errors(rjs_engine_t *jse, rstr_t *script)
-{
-       unsigned long i;
-       rjs_error_t *err;
-
-       for (i = 0; i < r_array_length(jse->errors); i++) {
-               err = (rjs_error_t *)r_array_slot(jse->errors, i);
-               fprintf(stdout, "Line: %ld (%ld, %ld), Error Code: %ld, ", (long)err->line, err->offset, err->lineoffset, err->error);
-               fprintf(stdout, "%s: ", errormsg[err->error]);
-               if (err->size) {
-                       fwrite(script->str + err->offset, sizeof(char), err->size, stdout);
-               } else {
-                       fwrite(script->str + err->lineoffset, sizeof(char), err->offset - err->lineoffset, stdout);
-               }
-               fprintf(stdout, "\n");
-       }
-}
-
-
-int usage(int argc, char *argv[])
-{
-           fprintf(stderr, "RJS with RPA Engine: %s \n", rpa_dbex_version());
-               fprintf(stderr, "Copyright (C) 2010 Martin Stoilov\n\n");
-
-               fprintf(stderr, "\t-e <script_expression>   Run the script supplied on the command line. Example: -e \"print('hello');\"\n");
-               fprintf(stderr, "\t-f <script_file>         Run the script file.\n");
-               fprintf(stderr, "\t-p                       Display rules parsing records.\n");
-               fprintf(stderr, "\t-d                       Execute in debug mode.\n");
-               fprintf(stderr, "\t-c                       Compile the script, without running it.\n");
-               fprintf(stderr, "\t-C                       Compile the script, showing the compile info, without running it.\n");
-               fprintf(stderr, "\t-h, --help               Display this help.\n");
-               return 0;
-}
-
-
-int main(int argc, char *argv[])
-{
-       int i;
-       rstr_t *script = NULL, *unmapscript = NULL;
-       rstr_t line;
-       rjs_engine_t *jse;
-
-       if (argc == 1) {
-               usage(argc, argv);
-               return 1;
-       }
-
-       for (i = 1; i < argc; i++) {
-               if (r_strcmp(argv[i], "--help") == 0 || r_strcmp(argv[i], "-help") == 0 || r_strcmp(argv[i], "/?") == 0 || r_strcmp(argv[i], "-h") == 0) {
-                       usage(argc, argv);
-                       return 1;
-               }
-       }
-
-       jse = rjs_engine_create();
-       if (!jse)
-               return 1;
-       if (rjs_engine_addswitable(jse, "string", swistring) < 0) {
-               return 2;
-       }
-       for (i = 1; i < argc; i++) {
-               if (r_strcmp(argv[i], "-L") == 0) {
-
-               } else if (r_strcmp(argv[i], "-d") == 0) {
-                       debuginfo = 1;
-                       jse->debugexec = 1;
-               } else if (r_strcmp(argv[i], "-p") == 0) {
-                       parseinfo = 1;
-               } else if (r_strcmp(argv[i], "-C") == 0) {
-                       debugcompileonly = 1;
-               } else if (r_strcmp(argv[i], "-c") == 0) {
-                       compileonly = 1;
-               } else if (r_strcmp(argv[i], "-t") == 0) {
-                       statinfo = 1;
-               }
-       }
-
-       for (i = 1; i < argc; i++) {
-               if (r_strcmp(argv[i], "-e") == 0) {
-                       if (++i < argc) {
-                               line.str = argv[i];
-                               line.size = r_strlen(argv[i]);
-                               script = &line;
-                       }
-                       if (rjs_exec_script(jse, script) < 0)
-                               goto end;
-               }
-       }
-
-       for (i = 1; i < argc; i++) {
-               if (r_strcmp(argv[i], "-f") == 0) {
-                       if (++i < argc) {
-                               script = rjs_file_map(argv[i]);
-                               if (script) {
-                                       unmapscript = script;
-                               }
-                       }
-                       if (rjs_exec_script(jse, script) < 0)
-                               goto end;
-               }
-       }
-
-end:
-       if (jse && r_array_length(jse->errors))
-               rjs_display_errors(jse, script);
-       rjs_engine_destroy(jse);
-       if (unmapscript)
-               rjs_file_unmap(unmapscript);
-       if (statinfo)
-               fprintf(stdout, "\nRJS Version: %s, memory: %ld Bytes (leaked %ld Bytes)\n", rjs_version(), (long)r_debug_get_maxmem(), (long)r_debug_get_allocmem());
-       return 0;
-}
index d0bcb98..0f81500 100644 (file)
@@ -1,20 +1,20 @@
 #include "rjs/rjsrules.h"
 
 
-extern char _binary_____________rjs_ecma262_rpa_start[];
-extern char _binary_____________rjs_ecma262_rpa_end[];
-extern unsigned long *_binary_____________rjs_ecma262_rpa_size;
+extern char _binary____ecma262_rpa_start[];
+extern char _binary____ecma262_rpa_end[];
+extern unsigned long *_binary____ecma262_rpa_size;
 
 
 const char *rjs_rules_get()
 {
-       const char *rules = _binary_____________rjs_ecma262_rpa_start;
+       const char *rules = _binary____ecma262_rpa_start;
        return rules;
 }
 
 
 unsigned long rjs_rules_size()
 {
-       unsigned long size = _binary_____________rjs_ecma262_rpa_end - _binary_____________rjs_ecma262_rpa_start;
+       unsigned long size = _binary____ecma262_rpa_end - _binary____ecma262_rpa_start;
        return size;
 }
index 28eea25..451a24e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-F=`find build/ -name "asm*"`; 
+F=`find unix/ -name "asm*"`; 
 for f in $F; 
 do 
     echo "Running: $f"