version 1.1, 2001/02/27 21:17:11
|
version 1.3, 2001/03/01 14:27:22
|
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 121 void postprocess(void)
|
Line 127 void postprocess(void)
|
} |
} |
} |
} |
|
|
|
#if 0 |
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); |
|
} |
|
#endif |
|
|
|
void print_block(FILE *file, block_count *b) |
|
{ |
|
size_t i,j,k; |
|
|
|
for (i=2; i<12; i++) |
|
for (j=0; i+j<b->ninsts; j++) { |
|
fprintf(file,"%14lld\t",b->count); |
|
for (k=j; k<i+j; k++) |
|
fprintf(file, "%s ", b->insts[k]); |
|
putc('\n', file); |
|
} |
} |
} |
|
|
void vm_print_profile(FILE *file) |
void vm_print_profile(FILE *file) |