version 1.1, 2001/02/27 21:17:11
|
version 1.2, 2001/02/28 22:31:43
|
Line 22
|
Line 22
|
#include "config.h" |
#include "config.h" |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
|
#include <assert.h> |
#include "forth.h" |
#include "forth.h" |
|
|
|
|
/* data structure: simple hash table with external chaining */ |
/* data structure: simple hash table with external chaining */ |
|
|
#define HASH_SIZE (1<<20) |
#define HASH_SIZE (1<<20) |
Line 65 block_count *block_insert(Xt *ip)
|
Line 67 block_count *block_insert(Xt *ip)
|
new->ip = ip; |
new->ip = ip; |
new->count = 0LL; |
new->count = 0LL; |
new->insts = malloc(0); |
new->insts = malloc(0); |
|
assert(new->insts != NULL); |
new->ninsts = 0; |
new->ninsts = 0; |
blocks[hash(ip)] = new; |
blocks[hash(ip)] = new; |
return new; |
return new; |
Line 72 block_count *block_insert(Xt *ip)
|
Line 75 block_count *block_insert(Xt *ip)
|
|
|
void add_inst(block_count *b, char *inst) |
void add_inst(block_count *b, char *inst) |
{ |
{ |
b->insts = realloc(b->insts, b->ninsts * sizeof(char *)); |
b->insts = realloc(b->insts, (b->ninsts+1) * sizeof(char *)); |
b->insts[b->ninsts++] = inst; |
b->insts[b->ninsts++] = inst; |
} |
} |
|
|
Line 81 void vm_count_block(Xt *ip)
|
Line 84 void vm_count_block(Xt *ip)
|
block_insert(ip)->count++; |
block_insert(ip)->count++; |
} |
} |
|
|
/* !! fix this */ |
#ifdef DIRECT_THREADED |
#define VM_INST(n) NULL |
#define VM_IS_INST(inst, n) ((inst) == vm_prims[(n)+DOESJUMP+1]) |
|
#else |
|
#define VM_IS_INST(inst, n) ((inst) == &(vm_prims[(n)+DOESJUMP+1])) |
|
#endif |
|
|
void postprocess_block(block_count *b) |
void postprocess_block(block_count *b) |
{ |
{ |
Line 123 void postprocess(void)
|
Line 129 void postprocess(void)
|
|
|
void print_block(FILE *file, block_count *b) |
void print_block(FILE *file, block_count *b) |
{ |
{ |
fprintf(file,"%12lld ip=%p\n",b->count,b->ip); |
size_t i; |
|
|
|
fprintf(file,"%14lld\t",b->count); |
|
for (i=0; i<b->ninsts; i++) |
|
fprintf(file, "%s ", b->insts[i]); |
|
putc('\n', file); |
} |
} |
|
|
void vm_print_profile(FILE *file) |
void vm_print_profile(FILE *file) |