Compare commits
4 commits
master
...
scan-build
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cec815530 | ||
|
|
523a88ad3a | ||
|
|
110a02f9b5 | ||
|
|
75f2a1e43e |
4 changed files with 44 additions and 19 deletions
|
|
@ -4,21 +4,8 @@
|
|||
#define TOK_INCLUDE "%include"
|
||||
#define TOK_DEFINE "%define"
|
||||
|
||||
static const char *tvm_opcode_map[] = {
|
||||
"nop", "int", "mov",
|
||||
"push", "pop", "pushf", "popf",
|
||||
"inc", "dec", "add", "sub", "mul", "div", "mod", "rem",
|
||||
"not", "xor", "or", "and", "shl", "shr",
|
||||
"cmp", "jmp", "call", "ret",
|
||||
"je", "jne", "jg", "jge", "jl", "jle",
|
||||
"prn", 0
|
||||
};
|
||||
extern const char *tvm_opcode_map[];
|
||||
|
||||
static const char *tvm_register_map[] = {
|
||||
"eax", "ebx", "ecx", "edx",
|
||||
"esi", "edi", "esp", "ebp",
|
||||
"eip",
|
||||
"r08", "r09", "r10", "r11",
|
||||
"r12", "r13", "r14", "r15", 0};
|
||||
extern const char *tvm_register_map[];
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -110,7 +110,6 @@ static struct tvm_htab_node *htab_add_core(
|
|||
node = node->next;
|
||||
|
||||
prev = node;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
/* Allocate space, and copy the key/value pair. */
|
||||
|
|
|
|||
|
|
@ -3,6 +3,24 @@
|
|||
#include <tvm/tvm_lexer.h>
|
||||
#include <tvm/tvm_tokens.h>
|
||||
|
||||
const char *tvm_opcode_map[] = {
|
||||
"nop", "int", "mov",
|
||||
"push", "pop", "pushf", "popf",
|
||||
"inc", "dec", "add", "sub", "mul", "div", "mod", "rem",
|
||||
"not", "xor", "or", "and", "shl", "shr",
|
||||
"cmp", "jmp", "call", "ret",
|
||||
"je", "jne", "jg", "jge", "jl", "jle",
|
||||
"prn", 0
|
||||
};
|
||||
|
||||
const char *tvm_register_map[] = {
|
||||
"eax", "ebx", "ecx", "edx",
|
||||
"esi", "edi", "esp", "ebp",
|
||||
"eip",
|
||||
"r08", "r09", "r10", "r11",
|
||||
"r12", "r13", "r14", "r15", 0};
|
||||
|
||||
|
||||
static int *token_to_register(const char *token, struct tvm_mem *mem);
|
||||
static int instr_to_opcode(const char *instr);
|
||||
|
||||
|
|
@ -119,6 +137,19 @@ static int **tvm_parse_args(
|
|||
return args;
|
||||
}
|
||||
|
||||
/* This function frees the memory allocated by tvm_parse_args().
|
||||
*/
|
||||
static void tvm_free_args(int **args) {
|
||||
if(args) {
|
||||
for (int i = 0; args[i]; i++) {
|
||||
free(args[i]);
|
||||
}
|
||||
|
||||
}
|
||||
free(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* This is a helper function that converts one instruction,
|
||||
|
|
@ -158,10 +189,13 @@ int tvm_parse_program(
|
|||
int opcode = tvm_parse_instr(
|
||||
vm, tokens[line_idx], &instr_place);
|
||||
|
||||
if (opcode == -1)
|
||||
continue;
|
||||
|
||||
int **args = tvm_parse_args(
|
||||
vm, tokens[line_idx], &instr_place);
|
||||
|
||||
if (opcode == -1 || !args)
|
||||
if (!args)
|
||||
continue;
|
||||
|
||||
void *newptr;
|
||||
|
|
@ -172,8 +206,10 @@ int tvm_parse_program(
|
|||
if (newptr != NULL) {
|
||||
vm->prog->instr = newptr;
|
||||
vm->prog->instr[vm->prog->num_instr - 1] = opcode;
|
||||
} else
|
||||
} else {
|
||||
tvm_free_args(args);
|
||||
return -1;
|
||||
}
|
||||
|
||||
newptr = realloc(
|
||||
vm->prog->args,
|
||||
|
|
@ -181,8 +217,10 @@ int tvm_parse_program(
|
|||
|
||||
if (newptr != NULL)
|
||||
vm->prog->args = (int ***)newptr;
|
||||
else
|
||||
else {
|
||||
tvm_free_args(args);
|
||||
return -1;
|
||||
}
|
||||
|
||||
vm->prog->args[vm->prog->num_instr - 1] = args;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ static int process_includes(
|
|||
|
||||
if (!filp) {
|
||||
printf("Unable to open file \"%s\"\n", filename);
|
||||
free(temp_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue