From e03e2dda251b3a704abc797b55952b8fdf84040f Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Tue, 28 Sep 2021 09:58:10 +0300 Subject: [PATCH] Added comments --- byterun/byterun.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/byterun/byterun.c b/byterun/byterun.c index 4d52b8c3f..0a0620152 100644 --- a/byterun/byterun.c +++ b/byterun/byterun.c @@ -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, "\n"); } +/* Dumps the contents of the file */ void dump_file (FILE *f, bytefile *bf) { int i;