Exemplo n.º 1
0
/* machine printing, (write) */
void sexp_pprint(secd_t* secd, cell_t *port, const cell_t *cell) {
    switch (cell_type(cell)) {
      case CELL_UNDEF:  secd_pprintf(secd, port, "#?"); break;
      case CELL_INT:    secd_pprintf(secd, port, "%d", cell->as.num); break;
      case CELL_CHAR:
        if (isprint(cell->as.num))
            secd_pprintf(secd, port, "#\\%c", (char)cell->as.num);
        else
            secd_pprintf(secd, port, "#\\x%x", numval(cell));
        break;
      case CELL_OP:     sexp_print_opcode(secd, port, cell->as.op); break;
      case CELL_FUNC:   secd_pprintf(secd, port, "##func*%p", cell->as.ptr); break;
      case CELL_FRAME:  secd_pprintf(secd, port,
                                "##frame@%ld ", cell_index(secd, cell)); break;
      case CELL_KONT:   secd_pprintf(secd, port,
                                "##kont@%ld ", cell_index(secd, cell)); break;
      case CELL_CONS:   sexp_print_list(secd, port, cell); break;
      case CELL_ARRAY:  sexp_print_array(secd, port, cell); break;
      case CELL_STR:    secd_pprintf(secd, port, "\"%s\"", strval(cell) + cell->as.str.offset); break;
      case CELL_SYM:    secd_pprintf(secd, port, "%s", symname(cell)); break;
      case CELL_BYTES:  sexp_print_bytes(secd, port, strval(cell), mem_size(cell)); break;
      case CELL_ERROR:  secd_pprintf(secd, port, "#!\"%s\"", errmsg(cell)); break;
      case CELL_PORT:   sexp_pprint_port(secd, port, cell); break;
      case CELL_REF:    sexp_pprint(secd, port, cell->as.ref);  break;
      default: errorf("sexp_print: unknown cell type %d", (int)cell_type(cell));
    }
}
Exemplo n.º 2
0
size_t mem_alignedsize(void* ptr)
{
    uptr_t aligned_addr = (uptr_t)ptr;
    uint8 adjust = *((uint8*)(aligned_addr - sizeof(uint8)));
    uptr_t raw_addr = aligned_addr - adjust;
    return mem_size((void*)raw_addr);
}
Exemplo n.º 3
0
static void mem_dump_each_leak(void* that, mapll_t m, int64_t k) {
    char* st = (char*)ll2p(mapll_remove(leaks, k));
    void* p = ll2p(k);
    size_t bytes = mem_size(p);
    trace("leak %p allocated %d at: %s", p, bytes, st != null ? st : "???");
    free(st); /* IMPORTANT: not mem_free see: mem_alloc code */
}
Exemplo n.º 4
0
void* mem_alloc_(size_t size) {
    mutex_lock(&mutex);
    void* a = malloc(size);
    if (a == null && reserved != null) {
        trace("MEMORY LOW: allocations=%lld allocated %lld", total_allocations, total_allocated);
        memory_low = true;
        free(reserved);
        reserved = null;
        a = malloc(size);
    }
    if (a != null) {
        int allocated = mem_size(a);
        const char* st = null;
        if (trace_allocs)  {
            st = stacktrace_(false, null, null, 3);
            trace("%p allocated=%d size=%d total: allocations=%lld allocated %lld %s",
                   a, allocated, size, total_allocations, total_allocated, st);
        }
        total_allocations++;
        total_allocated += allocated;
        if (leaks != null) { /* IMPORTANT: intentionally not mem_strdup */
            st = st != null ? st : stacktrace_(false, null, null, 3);
            mapll_put(leaks, p2ll((void*)a), p2ll((void*)strdup(st)));
        }
    }
    mutex_unlock(&mutex);
    return a;
}
Exemplo n.º 5
0
Arquivo: mu0.c Projeto: tessereth/mu0
/* one instruction per line, nothing else in file, addresses as hex */
memory_t *read_machine_code(FILE *fin, int verbose)
{
    memory_t *mem;
    int i;
    mem = malloc(sizeof(memory_t));
    if (mem == NULL)
    {
        fprintf(stderr, "Memory allocation error\n");
        exit(1);
    }
    mem->size = mem_size(fin);
    mem->data = malloc(mem->size * sizeof(int));
    if (mem->data == NULL)
    {
        fprintf(stderr, "Memory allocation error\n");
        exit(1);
    }
    for (i = 0; i < mem->size; i++)
    {
        fscanf(fin, "%x", mem->data + i);
    }
    if (verbose)
    {
        fprintf(stderr, "Read in %d lines\n", mem->size);
    }
    return mem;
}
Exemplo n.º 6
0
int main() {
  double size;
  void *ptr;

  size = mem_size() / (1024 * 1024);
  printf("Initial memory use = %.2f MB\n", size);

  ptr = safe_malloc(4096 * 1024); // 4 MB?
  size = mem_size() / (1024 * 1024);
  printf("Memory use after malloc = %.2f MB\n", size);

  safe_free(ptr);
  size = mem_size() / (1024 * 1024);
  printf("Memory use after free = %.2f MB\n", size);

  return 0;
}
Exemplo n.º 7
0
void* webserver_realloc(void* ptr, size_t s)
{
	void* tmp = ALLOC(s, MID_NET);
	if (tmp == NULL)
		return NULL;
	memcpy(tmp, ptr, mem_size(ptr));
	FREE(ptr);
	return tmp;
}
Exemplo n.º 8
0
char *get_string(int smo)
{
    //get_string: gets a string from a Shared Memory Object
    int size = mem_size(smo);

    char *tmp = (char *)malloc(size);

    if(read_mem(smo, 0, size, tmp))
    {
        return NULL;
    }

    return tmp;
}
Exemplo n.º 9
0
void
list_remove (LIST *list, void *data, size_t size)
{
    LIST
        *node;

    ASSERT (!list_empty (list));

    node = list-> next;
    ASSERT (mem_size (node) - sizeof (LIST) == size);

    memcpy ((char *) data, (char *) node + sizeof (LIST), size);
    list_unlink (node);
    mem_free (node);
}
Exemplo n.º 10
0
void mem_free_(const void* a) {
    if (a != null) {
        size_t allocated = mem_size(a);
        if (trace_allocs) {
            trace("%p allocated=%d total: allocations=%lld allocated %lld", a, allocated, total_allocations, total_allocated);
        }
        mutex_lock(&mutex);
        total_allocations--;
        total_allocated -= allocated;
        if (leaks != null) {
            mapll_remove(leaks, p2ll((void*)a));
        }
        mutex_unlock(&mutex);
        free((void*)a);
    }
}
Exemplo n.º 11
0
void CServer::server_stat_request()
{
	send_string("FSearch server build on " __DATE__ " " __TIME__);
	send_string("FSearch server version " VERSION);
	send_string_fmt("Active clients: %u", m_clients.size());
	send_string_fmt("Debug level: %d", logger->get_level());
	send_string_fmt("Allocated in swap: %u Mb", swapAllocator->allocated()/(1024*1024));
	send_string_fmt("Total swap space used: %u Mb", swapAllocator->memUsed()/(1024*1024));
	send_string_fmt("Total hosts: %u", m_host_set.host_count());
	send_string_fmt("Total files: %u", m_host_set.file_count());
	send_string_fmt("Total files size: %d Gb", m_host_set.total_size()/(1024*1024*1024));
	if (m_host_set.host_count() > 0) {
		send_string_fmt("Average files per host: %d", m_host_set.file_count()/m_host_set.host_count());
	}
	if (m_host_set.file_count() > 0) {
		send_string_fmt("Average file size: %d", m_host_set.total_size()/m_host_set.file_count());
	}
	send_string_fmt("Total server memory usage: %u Mb", mem_size()/(1024*1024));
	send_string_fmt("Number of swap pages: %u Mb", page_max*page_size/(1024*1024));
	send_string_fmt("Present swap pages: %u Mb", page_present*page_size/(1024*1024));
	send_string_fmt("Locked swap pages: %u Mb", page_locked*page_size/(1024*1024));
	send_string_fmt("Number of page loads: %lu", page_read_count);
	send_string_fmt("Number of page swaps: %lu", page_swap_count);
	send_string_fmt("Total queries: %u", m_cache.total());
	send_string_fmt("Total uncached queries: %u", m_cache.query_made());
	send_string_fmt("Average query time: %.3lf sec", m_cache.avg_search_time());
	send_string_fmt("Maximal query time: %.3lf sec", m_cache.max_search_time());
	send_string_fmt("Queries in cache: %u", m_cache.count());
	send_string_fmt("Query cache size: %u Kb", m_cache.mem_size()/1024);
	send_string_fmt("Query cache hits: %u", m_cache.hits());
	if (m_cache.total() > 0) {
		send_string_fmt("Query cache hit ratio: %5.2lf%%", 100.0*m_cache.hits()/m_cache.total());
		send_string_fmt("Average query matches: %d", m_cache.total_matched()/m_cache.total());
	}
	send_string_fmt("Word hash size: %u", wordhash.size());
	send_string_fmt("Dictionary index size: %u Kb", wordhash.get_dictindex().mem_size()/1024);
	send_string_fmt("Max collisions: %u", wordhash.max_collisions());
	send_string_fmt("Total words: %u", wordhash.total_words());
	send_string_fmt("Common words: %u", wordhash.common_count());
	send_string("END");
}
Exemplo n.º 12
0
static void output(ErlDrvData handle, char *buf, int len) {
  bloom_drv_t *driver = (bloom_drv_t *)handle;
  char command = buf[0];
  
  switch (command) {
    case SETUP:
    setup(driver, &buf[1], len-1);
    break;
    case PUT:
    put(driver, &buf[1], len-1);
    break;
    case HAS:
    has(driver, &buf[1], len-1);
    break;
    case MEM_SIZE:
    mem_size(driver);
    break;
    case KEY_SIZE:
    key_size(driver);
    break;
  }
}
Exemplo n.º 13
0
static void print_results(smt_core_t *core, double construction_time, double search_time) {
  dpll_stats_t *stat;
  double mem_used, simplified_percent;

  stat = &core->stats;
  show_stats(stat);
  printf("Search time             : %.4f s\n", search_time);
  mem_used = mem_size() / (1024 * 1024);
  if (mem_used > 0) {
    printf("Memory used             : %.2f MB\n", mem_used);
  }
  printf("\n\n");

  // Print status again, in format used by Leonardo's scripts
  print_status(stdout, smt_status(core));
  printf("\n");
  validate_assignment(core);
  printf("\n");

  simplified_percent = 0.0;
  if (stat->literals_before_simpl > 0) {
    simplified_percent = (100.0 * stat->subsumed_literals) / stat->literals_before_simpl;
  }
  printf("STAT %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu32" %"PRIu64" %"PRIu64" %.2f %.2f %.2f\n",
	 stat->decisions,
	 stat->conflicts,
	 stat->propagations,
	 stat->restarts,
	 stat->literals_before_simpl,
	 stat->learned_literals,
	 mem_used,
	 (search_time + construction_time),
	 simplified_percent);

  fflush(stdout);
}
Exemplo n.º 14
0
int main(int argc, char *argv[]) {
  uint32_t i, j, n;
  double runtime, memused;
  int32_t x, *val;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s filename\n", argv[0]);
    fprintf(stderr, "  filename must contain a set of strings, one per line, less than 100 char long\n");
    fflush(stderr);
    exit(1);
  }
  words_from_file(argv[1]);

  init_stbl(&sym_table, 0);

  val = (int32_t *) malloc(n_words * sizeof(int32_t));
  if (val == NULL) {
    fprintf(stderr, "Failed to allocate array val\n");
    exit(1);
  }

  for (i=0; i<n_words; i++) {
    x = stbl_find(&sym_table, words[i]);
    if (x < 0) {
      stbl_add(&sym_table, words[i], i);
      val[i] = i;
    } else {
      val[i] = x;
    }
  }

  printf("\n--- checking ---\n");
  for (i=0; i<n_words; i++) {
    x = stbl_find(&sym_table, words[i]);
    if (x != val[i]) {
      printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[i], x, val[i]);
      fflush(stdout);
      exit(1);
    }
  }

  printf("\n*** Added %"PRIu32" words from %s ***\n", n_words, argv[1]);

  // repeated additions of the same symbols with multiple lookups
  // warning: this code does not work (may give a false alarm)
  // if the input file contains duplicates.
  n = (n_words < 200) ?  n_words : 200;
  printf("\n*** Repeated symbol addition ***\n");
  runtime = get_cpu_time();
  for (i=0; i<10000; i++) {
    for (j=0; j<n; j++) {
      stbl_add(&sym_table, words[j], new_val(i, j));
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n_words; j++) {
      x = stbl_find(&sym_table, words[j]);
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n_words; j++) {
      x = stbl_find(&sym_table, words[j]);
    }
  }


  runtime = get_cpu_time() - runtime;
  memused = mem_size() / (1024 * 1024);
  printf("Adding 10000 times the same %"PRIu32" words + repeated lookups\n", n);
  printf("Runtime: %.4f s\n", runtime);
  printf("Table size: %"PRIu32" (nelems = %"PRIu32", ndeleted = %"PRIu32")\n",
	sym_table.size, sym_table.nelems, sym_table.ndeleted);
  if (memused > 0) {
    printf("Memory used: %.2f MB\n", memused);
  }

  clear_words();
  free(val);
  delete_stbl(&sym_table);

  return 0;
}
Exemplo n.º 15
0
void cmd_create_task(struct pm_msg_create_task *msg, struct pm_task *ctask) 
{
	struct pm_task *tsk = NULL;
	UINT16 new_task_id = msg->new_task_id;
	UINT16 flags = msg->flags;
	UINT16 type = (flags & SERVER_TASK) / SERVER_TASK;
	UINT32 psize, ret;
	char *path = NULL;

	if(pman_stage == PMAN_STAGE_INITIALIZING)
	{
		cmd_inform_result(msg, ctask->id, PM_IS_INITIALIZING, 0, 0);
		return;
	}

	if(new_task_id != 0xFFFF) 
	{
		if (tsk_lower_bound[type] <=  new_task_id && new_task_id <=  tsk_upper_bound[type]) 
		{
			tsk = tsk_get(new_task_id);

			if(tsk != NULL) 
			{
				/* new_task_id is not free to be used */
				cmd_inform_result(msg, ctask->id, PM_TASK_ID_TAKEN, 0, 0);
				return;
			}
	    } 
		else 
		{
			/* new_task_id is out of range */
			cmd_inform_result(msg, ctask->id, PM_TASK_ID_INVALID, 0, 0);
			return;
		}
	}
	else 
	{
		/* search for a free task id */
		new_task_id = tsk_get_id(tsk_lower_bound[type], tsk_upper_bound[type]);
    
		if(new_task_id == 0xFFFF) 
		{
			cmd_inform_result(msg, ctask->id, PM_NO_FREE_ID, 0, 0);
			return;
        }
	}
  
	tsk = tsk_create(new_task_id);
    if(tsk == NULL)
    {
        cmd_inform_result(msg, ctask->id, PM_NOT_ENOUGH_MEM, 0, 0);
        return;
    }
	path = NULL;
	psize = mem_size(msg->path_smo_id);

	if(psize < 1)
	{
        tsk_destroy(tsk);
		cmd_inform_result(msg, ctask->id, PM_BAD_SMO, 0, 0);
		return;
	}

	path = kmalloc(psize);

	if(path == NULL)
	{
        tsk_destroy(tsk);
		cmd_inform_result(msg, ctask->id, PM_NOT_ENOUGH_MEM, 0, 0);
		return;
	}
	
	/* Read Path */
	if(read_mem(msg->path_smo_id, 0, psize, path) != SUCCESS) 
	{
        tsk_destroy(tsk);
		cmd_inform_result(msg, ctask->id, PM_BAD_SMO, 0, 0);
		return;
	}

	tsk->flags = (flags & SERVER_TASK)? TSK_FLAG_SERVICE : 0;

	if(path[psize-1] == '\0') psize--;
    
    tsk->creator_task = ctask->id;
	tsk->creator_task_port = msg->response_port;
	tsk->command_inf.command_req_id = msg->req_id;

	tsk->command_inf.command_ret_port = -1;
	tsk->command_inf.command_sender_id = -1;

	ret = loader_create_task(tsk, path, psize, msg->param, type, LOADER_CTASK_TYPE_PRG);

	if(ret != PM_OK)
	{
        tsk_destroy(tsk);
		kfree(path);
		cmd_inform_result(msg, ctask->id, ret, 0, 0);
	}
}
Exemplo n.º 16
0
void cmd_load_library(struct pm_msg_loadlib *msg, UINT16 loader_task) 
{
	struct pm_task *tsk;
	UINT32 psize;
	char *path = NULL;

	if(pman_stage == PMAN_STAGE_INITIALIZING)
	{
        pman_print_dbg("PM LOAD LIB ERR1\n");
		cmd_inform_result(msg, loader_task, PM_IS_INITIALIZING, 0, 0);
		return;
	}

    if(msg->vlow < PMAN_MAPPING_BASE || msg->vhigh < msg->vlow)
	{
        pman_print_dbg("PM LOAD LIB ERR2\n");
		cmd_inform_result(msg, loader_task, PM_INVALID_BOUNDARIES, 0, 0);
		return;
	}

    tsk = tsk_get(loader_task);

    if(tsk->flags & TSK_LOADING_LIB)
	{
		cmd_inform_result(msg, loader_task, PM_TASK_RETRY_LATER, 0, 0);
		return;
	}

    if(!(tsk->flags & TSK_DYNAMIC))
	{
		cmd_inform_result(msg, loader_task, PM_ERROR, 0, 0);
		return;
	}
    path = NULL;
	psize = mem_size(msg->path_smo_id);

    pman_print_dbg("LOADING LIB path size %i\n", psize);
	if(psize < 1)
	{
		cmd_inform_result(msg, loader_task, PM_BAD_SMO, 0, 0);
		return;
	}

	path = kmalloc(psize);

	if(path == NULL)
	{
		cmd_inform_result(msg, loader_task, PM_NOT_ENOUGH_MEM, 0, 0);
		return;
	}
	
	/* Read Path */
	if(read_mem(msg->path_smo_id, 0, psize, path) != SUCCESS) 
	{
        kfree(path);
		cmd_inform_result(msg, loader_task, PM_BAD_SMO, 0, 0);
		return;
	}
    pman_print_dbg("LOADING LIB path %s\n", path);

    tsk->command_inf.callback = cmd_finished__callback;
	tsk->command_inf.command_ret_port = msg->response_port;
	tsk->command_inf.command_req_id = msg->req_id;
	tsk->command_inf.command_sender_id = loader_task;
    tsk->flags |= TSK_LOADING_LIB;

    // load the library
    int ret = vmm_lib_load(tsk, path, psize, msg->vlow, msg->vhigh);
    if(!ret)
    {
        kfree(path);
        cmd_inform_result(msg, loader_task, PM_ERROR, 0, 0);
    }   
    else if(ret == 2)
    {
        kfree(path);
        cmd_inform_result(msg, loader_task, PM_OK, 0, 0);
        return;
    }
}
Exemplo n.º 17
0
int main(int argc, char *argv[]) {
  char *filename;
  int32_t code;
  FILE *dump;
  double time, mem_used;

  if (argc > 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(YICES_EXIT_USAGE);
  }

  if (argc == 2) {
    // read from file
    filename = argv[1];
    if (init_smt_file_lexer(&lexer, filename) < 0) {
      perror(filename);
      exit(YICES_EXIT_FILE_NOT_FOUND);
    }
  } else {
    // read from stdin
    init_smt_stdin_lexer(&lexer);
  }

  yices_init();

  init_smt_tstack(&stack);

  init_parser(&parser, &lexer, &stack);
  init_benchmark(&bench);
  code = parse_smt_benchmark(&parser, &bench);
  if (code == 0) {
    printf("No syntax error found\n");
  }

  if (benchmark_reduced_to_false(&bench)) {
    printf("Reduced to false\n\nunsat\n");
    fflush(stdout);
  }
  printf("\n");

  time = get_cpu_time();
  mem_used = mem_size() / (1024 * 1024);
  printf("Construction time: %.4f s\n", time);
  printf("Memory used: %.2f MB\n\n", mem_used);
  fflush(stdout);

  dump = fopen("yices2new.dmp", "w");
  if (dump == NULL) {
    perror("yices2new.dmp");
  } else {
    dump_benchmark(dump, &bench);
    fclose(dump);
  }

  delete_benchmark(&bench);
  delete_parser(&parser);
  close_lexer(&lexer);
  delete_tstack(&stack);
  yices_exit();

  return YICES_EXIT_SUCCESS;
}
Exemplo n.º 18
0
int main(int argc, char *argv[]) {
  char *filename;
  int32_t code;
  double time, mem_used;

  if (argc > 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(YICES_EXIT_USAGE);
  }

  if (argc == 2) {
    // read from file
    interactive = false;
    filename = argv[1];
    if (init_smt2_file_lexer(&lexer, filename) < 0) {
      perror(filename);
      exit(YICES_EXIT_FILE_NOT_FOUND);
    }
  } else {
    // read from stdin
    interactive = true;
    init_smt2_stdin_lexer(&lexer);
  }

  yices_init();
  init_smt2(true, 0, interactive);
  init_smt2_tstack(&stack);
  init_parser(&parser, &lexer, &stack);

  // disable SMT2_CHECK_SAT/PUSH/POP/GET_VALUE
  tstack_add_op(&stack, SMT2_CHECK_SAT, false, eval_smt2_skip, check_smt2_skip);
  tstack_add_op(&stack, SMT2_PUSH, false, eval_smt2_skip, check_smt2_skip);
  tstack_add_op(&stack, SMT2_POP, false, eval_smt2_skip, check_smt2_skip);
  tstack_add_op(&stack, SMT2_GET_VALUE, false, eval_smt2_skip, check_smt2_skip);

  //  smt2_set_verbosity(100);

  while (smt2_active()) {
    if (interactive) {
      fputs("smt2> ", stdout);
      fflush(stdout);
    }
    code = parse_smt2_command(&parser);
    if (code < 0) {
      // syntax error
      if (interactive) {
	flush_lexer(&lexer);
      } else {
	break; // exit
      }
    }
    fflush(stdout);
  }

  // statistics
  time = get_cpu_time();
  mem_used = mem_size() / (1024 * 1024);
  printf("\nRun time: %.4f s\n", time);
  printf("Memory used: %.2f MB\n\n", mem_used);
  fflush(stdout);

  delete_parser(&parser);
  close_lexer(&lexer);
  delete_tstack(&stack);
  delete_smt2();
  yices_exit();

  return YICES_EXIT_SUCCESS;
}
Exemplo n.º 19
0
static void *fb(void)              { return malloc(mem_size()); }
Exemplo n.º 20
0
int main(int argc, char *argv[]) {
  bool interactive;
  int32_t code;
  FILE *dump;
  double memused;

  process_command_line(argc, argv);

  yices_init();
  init_tstack(&stack, NUM_BASE_OPCODES);
  interactive = false;

  if (input_filename == NULL) {
    init_yices_stdin_lexer(&lexer);
    interactive = true;
  } else {
    if (init_yices_file_lexer(&lexer, input_filename) < 0) {
      perror(input_filename);
      exit(YICES_EXIT_FILE_NOT_FOUND);
    }
  }

  init_parser(&parser, &lexer, &stack);
  while (current_token(&lexer) != TK_EOS) {
    if (interactive) {
      printf("yices> ");
      fflush(stdout);
    }
    code = parse_yices_command(&parser, stderr);
    if (code < 0) {
      flush_lexer(&lexer);
    }
  }

  delete_parser(&parser);
  close_lexer(&lexer);
  delete_tstack(&stack);

  memused = mem_size() / (1024 * 1024);
  if (memused > 0) {
    fprintf(stderr, "Memory used: %.2f MB\n", memused);
  }

  if (dump_requested) {
    if (dump_filename == NULL) {
      dump = stdout;
    } else {
      dump = fopen(dump_filename, "w");
      if (dump == NULL) {
	perror(dump_filename);
	exit(YICES_EXIT_FILE_NOT_FOUND);
      }
    }

    fprintf(dump, "\n==== ALL TYPES ====\n");
    print_type_table(dump, __yices_globals.types);
    fflush(dump);
    fprintf(dump, "\n==== ALL TERMS ====\n");
    print_term_table(dump, __yices_globals.terms);
    fflush(dump);

    if (dump_filename != NULL) {
      if (fclose(dump) != 0) {
	fprintf(stderr, "Error while closing dump file: ");
	perror(dump_filename);
      }
    }
  }

  yices_exit();

  return 0;
}