The htab_structure has been modified in two ways, which should not break compatability with any of its uses. It includes a void pointer, which is in this commit used to point to a string for defines, and will in the future be used to point to the address space for words, bytes, and double words. It now includes a function htab_add_str specifically for storing strings. It calls htab_add so as not to be redundant, but makes the node's value their index for the lexer to fetch using htab_find, and assigns their void pointer. The lexer will now use htab_find on all tokens to see if they are a define string, and if so, substitute them with the appropriate token. The defines htab is destroyed after lexing, because that memory is done.
37 lines
657 B
C
37 lines
657 B
C
#ifndef TVM_PROGRAM_H_
|
|
#define TVM_PROGRAM_H_
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "tvm_htab.h"
|
|
#include "tvm_memory.h"
|
|
|
|
typedef struct tvm_program_s
|
|
{
|
|
int start;
|
|
|
|
int num_instructions;
|
|
int *instr;
|
|
|
|
int ***args;
|
|
|
|
int **values;
|
|
int num_values;
|
|
|
|
tvm_htab_t *defines;
|
|
|
|
tvm_htab_t *label_htab;
|
|
|
|
} tvm_program_t;
|
|
|
|
/* Create and initialize an empty program object */
|
|
tvm_program_t *program_create();
|
|
|
|
/* Interpret a source file into bytecode, and store it in a program object */
|
|
int program_interpret(tvm_program_t *p, char *filename, tvm_memory_t *pMemory);
|
|
|
|
void program_destroy(tvm_program_t *p);
|
|
|
|
#endif
|