Add image saver (Not working)
This commit is contained in:
parent
a5abfb0d39
commit
5ca8292ca1
1 changed files with 19 additions and 11 deletions
30
main.c
30
main.c
|
@ -252,32 +252,40 @@ void print_target_code(__uint32_t *target_code)
|
|||
}
|
||||
}
|
||||
|
||||
int save_img(char *out_path, __uint32_t *target_code){
|
||||
//get count of instructions
|
||||
unsigned int count = 0;
|
||||
while(target_code[count]!=0)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
FILE *out_file = fopen(out_path, "w");
|
||||
if(out_file == NULL) return -1;
|
||||
|
||||
fwrite(target_code, sizeof(__uint32_t), count, out_file);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
printf("-----------------\nEIPA Assembler\nVersion: %d.%d.%d\n-----------------\n", VER_MAJOR, VER_MINOR, VER_PATCH);
|
||||
|
||||
char assembly_path[] = "test.eipa";
|
||||
char assembly_path[] = "test/test.eipa";
|
||||
char image_path[] = "a.eipaimg";
|
||||
FILE *output_file = fopen(image_path, "w");
|
||||
FILE *assembly_file = fopen(assembly_path, "r");
|
||||
if (assembly_file == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (output_file == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (assembly_file == NULL) return 0;
|
||||
|
||||
char(*tokens)[MAX_TOKEN_SIZE] = malloc(sizeof(*tokens) * MAX_MEMORY);
|
||||
lexer(assembly_file, tokens);
|
||||
fclose(assembly_file);
|
||||
|
||||
print_tokens(tokens);
|
||||
|
||||
__uint32_t *target_code = malloc(MAX_MEMORY * sizeof(target_code));
|
||||
gen_target_code(tokens, target_code);
|
||||
print_target_code(target_code);
|
||||
save_img(image_path, target_code);
|
||||
|
||||
fclose(assembly_file);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue