Exemple #1
0
Node *push(Node *node)
{
  assert(node);
  assert(stackPointer < stack + 1023);
#ifdef DEBUG
  dumpStack();  fprintf(stderr, " PUSH ");  Node_print(node);  fprintf(stderr, "\n");
#endif
  return *++stackPointer= node;
}
Exemple #2
0
static void dumpStack(void)
{
  Node **p;
  for (p= stack + 1;  p <= stackPointer;  ++p)
    {
      fprintf(stderr, "### %ld\t", p - stack);
      Node_print(*p);
      fprintf(stderr, "\n");
    }
}
Exemple #3
0
struct node* Node_getchild(struct node* parent, unsigned char l) {

    assert(parent);

    if (!BITTEST(parent -> bitarray, l))		//child not present
        return NULL;

    int x = Bit_count_set_bits_up_to(parent -> bitarray, sizeof(parent -> bitarray), l);
    struct node* target = parent -> child[x];

    if (!target) {
        Node_print(parent);
        printf("Did not find label [%x]\n", l);
        assert(target);				//cause assert(NULL)
    }

    return target;
}
Exemple #4
0
void Node_printer(Node *self, void *stream) {
	Node_print(self, (FILE *)stream);
	fprintf((FILE *)stream, " ");
}
Exemple #5
0
int main(int argc, char *const argv[])
{
    long parsed;
    mozvm_loader_t L;
    moz_inst_t *head, *inst;

    const char *syntax_file = NULL;
    const char *input_file = NULL;
    unsigned tmp, loop = 1;
    unsigned print_stats = 0;
    unsigned quiet_mode = 0;
#ifdef MOZVM_ENABLE_NODE_DIGEST
    unsigned show_digest = 0;
    unsigned test_mode = 0;
#endif
    int opt;

    while ((opt = getopt(argc, argv,
#ifdef MOZVM_ENABLE_NODE_DIGEST
                    "d"
#ifdef MOZVM_ENABLE_NEZTEST
                    "t"
#endif
#endif
                    "qsn:p:i:h")) != -1) {
        switch (opt) {
        case 'n':
            tmp = atoi(optarg);
            loop = tmp > loop ? tmp : loop;
            break;
#ifdef MOZVM_ENABLE_NODE_DIGEST
        case 'd':
            show_digest = 1;
            break;
        case 't':
            test_mode = 1;
            break;
#endif
        case 'q':
            quiet_mode = 1;
            break;
        case 's':
            print_stats = 1;
            break;
        case 'p':
            syntax_file = optarg;
            break;
        case 'i':
            input_file = optarg;
            break;
        case 'h':
        default: /* '?' */
            usage(argv[0]);
            exit(EXIT_FAILURE);
        }
    }
    if (syntax_file == NULL) {
        fprintf(stderr, "error: please specify bytecode file\n");
        usage(argv[0]);
        exit(EXIT_FAILURE);
    }
    if (test_mode == 0 && input_file == NULL) {
        fprintf(stderr, "error: please specify input file\n");
        usage(argv[0]);
        exit(EXIT_FAILURE);
    }
    if (test_mode == 0 && !mozvm_loader_load_input_file(&L, input_file)) {
        fprintf(stderr, "error: failed to load input_file='%s'\n", input_file);
        usage(argv[0]);
        exit(EXIT_FAILURE);
    }
#if defined(MOZVM_PROFILE) && defined(MOZVM_MEMORY_PROFILE)
        mozvm_mm_snapshot(MOZVM_MM_PROF_EVENT_INPUT_LOAD);
#endif
    head = inst = mozvm_loader_load_file(&L, syntax_file, 1);
    assert(inst != NULL);

    if (test_mode) {
        mozvm_run_test(&L, input_file);
        goto L_exit;
    }

    NodeManager_init();
    while (loop-- > 0) {
        Node *node = NULL;
        reset_timer();
        inst = head;
        moz_runtime_set_source(L.R, L.input, L.input + L.input_size);
#if defined(MOZVM_PROFILE) && defined(MOZVM_MEMORY_PROFILE)
        mozvm_mm_snapshot(MOZVM_MM_PROF_EVENT_PARSE_START);
#endif
        inst = moz_runtime_parse_init(L.R, L.input, inst);
        parsed = moz_runtime_parse(L.R, L.input, inst);
        if (parsed != 0) {
            fprintf(stderr, "parse error\n");
            break;
        }
        node = ast_get_parsed_node(L.R->ast);
#if defined(MOZVM_PROFILE) && defined(MOZVM_MEMORY_PROFILE)
        mozvm_mm_snapshot(MOZVM_MM_PROF_EVENT_PARSE_END);
#endif
        if (node) {
            if (!quiet_mode) {
#ifdef NODE_USE_NODE_PRINT
                Node_print(node, L.R->C.tags);
#endif
            }
#ifdef MOZVM_ENABLE_NODE_DIGEST
            if (show_digest) {
                unsigned char buf[32] = {};
                Node_digest(node, L.R->C.tags, buf);
                fprintf(stderr, "%.*s\n", 32, buf);
            }
#endif
            NODE_GC_RELEASE(node);
        }
        if (print_stats) {
            _show_timer(input_file, L.input_size);
        }
#if defined(MOZVM_PROFILE) && defined(MOZVM_MEMORY_PROFILE)
        mozvm_mm_snapshot(MOZVM_MM_PROF_EVENT_GC_EXECUTED);
#endif
        moz_runtime_reset1(L.R);
        NodeManager_reset();
        moz_runtime_reset2(L.R);
    }
    if (print_stats) {
#if defined(MOZVM_PROFILE) && defined(MOZVM_MEMORY_PROFILE)
        mozvm_mm_print_stats();
#endif
        moz_loader_print_stats(&L);
        NodeManager_print_stats();
        memo_print_stats();
        symtable_print_stats();
        moz_runtime_print_stats(L.R);
    }
L_exit:
    moz_runtime_dispose(L.R);
    mozvm_loader_dispose(&L);
    NodeManager_dispose();
    return 0;
}