Added comments

This commit is contained in:
Dmitry Boulytchev 2021-09-28 09:58:10 +03:00
parent fa874b4a4c
commit e03e2dda25

View file

@ -9,28 +9,33 @@
void *__start_custom_data;
void *__stop_custom_data;
/* The unpacked representation of bytecode file */
typedef struct {
char *string_ptr;
int *public_ptr;
char *code_ptr;
int stringtab_size;
int global_area_size;
int public_symbols_number;
char buffer[0];
char *string_ptr; /* A pointer to the beginning of the string table */
int *public_ptr; /* A pointer to the beginning of publics table */
char *code_ptr; /* A pointer to the bytecode itself */
int stringtab_size; /* The size (in bytes) of the string table */
int global_area_size; /* The size (in words) of global area */
int public_symbols_number; /* The number of public symbols */
char buffer[0];
} bytefile;
/* Gets a string from a string table by an index */
char* get_string (bytefile *f, int pos) {
return &f->string_ptr[pos];
}
/* Gets a name for a public symbol */
char* get_public_name (bytefile *f, int i) {
return get_string (f, f->public_ptr[i*2]);
}
/* Gets an offset for a publie symbol */
int get_public_offset (bytefile *f, int i) {
return f->public_ptr[i*2+1];
}
/* Reads a binary bytecode file by name and unpacks it */
bytefile* read_file (char *fname) {
FILE *f = fopen (fname, "rb");
long size;
@ -65,6 +70,7 @@ bytefile* read_file (char *fname) {
return file;
}
/* Disassembles the bytecode pull */
void disassemble (FILE *f, bytefile *bf) {
# define INT (ip += sizeof (int), *(int*)(ip - sizeof (int)))
@ -235,9 +241,10 @@ void disassemble (FILE *f, bytefile *bf) {
fprintf (f, "\n");
}
while (1);
stop: {}
stop: fprintf (f, "<end>\n");
}
/* Dumps the contents of the file */
void dump_file (FILE *f, bytefile *bf) {
int i;