summaryrefslogtreecommitdiff
path: root/src/arch/storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/storage.c')
-rw-r--r--src/arch/storage.c76
1 files changed, 70 insertions, 6 deletions
diff --git a/src/arch/storage.c b/src/arch/storage.c
index ac1c878..217d327 100644
--- a/src/arch/storage.c
+++ b/src/arch/storage.c
@@ -131,11 +131,13 @@ struct _GAsmStorage
char *idx_filename; /* Fichier pour l'indexage */
char *ins_filename; /* Fichier pour instructions */
char *op_filename; /* Fichier pour les opérandes */
+ char *reg_filename; /* Fichier pour les registres */
char *tp_filename; /* Fichier pour les types */
int idx_fd; /* Flux pour l'indexage */
int ins_fd; /* Flux pour les instructions */
int op_fd; /* Flux pour les opérandes */
+ int reg_fd; /* Flux pour les registres */
int tp_fd; /* Flux pour les types */
/**
@@ -602,11 +604,13 @@ static void g_asm_storage_init(GAsmStorage *storage)
storage->idx_filename = NULL;
storage->ins_filename = NULL;
storage->op_filename = NULL;
+ storage->reg_filename = NULL;
storage->tp_filename = NULL;
storage->idx_fd = -1;
storage->ins_fd = -1;
storage->op_fd = -1;
+ storage->reg_fd = -1;
storage->tp_fd = -1;
storage->gtypes = NULL;
@@ -693,6 +697,7 @@ static void g_asm_storage_finalize(GAsmStorage *storage)
finalize_storage_file(storage->idx_filename);
finalize_storage_file(storage->ins_filename);
finalize_storage_file(storage->op_filename);
+ finalize_storage_file(storage->reg_filename);
finalize_storage_file(storage->tp_filename);
if (storage->idx_fd != -1)
@@ -704,6 +709,9 @@ static void g_asm_storage_finalize(GAsmStorage *storage)
if (storage->op_fd != -1)
close(storage->op_fd);
+ if (storage->reg_fd != -1)
+ close(storage->reg_fd);
+
if (storage->gtypes != NULL)
free(storage->gtypes);
@@ -757,6 +765,7 @@ GAsmStorage *g_asm_storage_new_compressed(GArchProcessor *proc, const gchar *id)
asprintf(&result->idx_filename, "%s.%s-%s", basedir, id, "index.bin");
asprintf(&result->ins_filename, "%s.%s-%s", basedir, id, "instructions.bin");
asprintf(&result->op_filename, "%s.%s-%s", basedir, id, "operands.bin");
+ asprintf(&result->reg_filename, "%s.%s-%s", basedir, id, "registers.bin");
asprintf(&result->tp_filename, "%s.%s-%s", basedir, id, "types.bin");
free(basedir);
@@ -891,6 +900,11 @@ static bool g_asm_storage_decompress(const GAsmStorage *storage)
if (!dump_archive_entry_into_file(in, entry, storage->op_filename))
goto gasd_exit;
}
+ else if (strcmp(path, "registers.bin") == 0)
+ {
+ if (!dump_archive_entry_into_file(in, entry, storage->reg_filename))
+ goto gasd_exit;
+ }
else if (strcmp(path, "types.bin") == 0)
{
if (!dump_archive_entry_into_file(in, entry, storage->tp_filename))
@@ -958,6 +972,9 @@ static bool g_asm_storage_compress(const GAsmStorage *storage)
status = add_file_into_archive(out, storage->op_filename, "operands.bin");
if (status != CPE_NO_ERROR) goto gasc_exit;
+ status = add_file_into_archive(out, storage->reg_filename, "registers.bin");
+ if (status != CPE_NO_ERROR) goto gasc_exit;
+
status = add_file_into_archive(out, storage->tp_filename, "types.bin");
if (status != CPE_NO_ERROR) goto gasc_exit;
@@ -1212,7 +1229,7 @@ static bool g_asm_storage_write_types(GAsmStorage *storage)
/******************************************************************************
* *
* Paramètres : storage = gestionnaire à manipuler. *
-* ins = true si les données viennent d'une instruction. *
+* type = type du fichier de destination. *
* pbuf = zone tampon à remplir. *
* pos = tête de lecture avant écriture. *
* *
@@ -1224,13 +1241,33 @@ static bool g_asm_storage_write_types(GAsmStorage *storage)
* *
******************************************************************************/
-bool _g_asm_storage_load_data(const GAsmStorage *storage, bool ins, packed_buffer *pbuf, off64_t pos)
+bool _g_asm_storage_load_data(const GAsmStorage *storage, StorageFileType type, packed_buffer *pbuf, off64_t pos)
{
bool result; /* Bilan à retourner */
int fd; /* Flux ciblé */
off64_t new; /* Nouvelle position de lecture*/
- fd = ins ? storage->ins_fd : storage->op_fd;
+ switch (type)
+ {
+ case SFT_INSTRUCTION:
+ fd = storage->ins_fd;
+ break;
+ case SFT_OPERAND:
+ fd = storage->op_fd;
+ break;
+ case SFT_REGISTER:
+ fd = storage->reg_fd;
+ break;
+ default:
+ fd = -1;
+ break;
+ }
+
+ if (fd == -1)
+ {
+ result = false;
+ goto type_error;
+ }
new = lseek64(fd, pos, SEEK_SET);
@@ -1243,6 +1280,8 @@ bool _g_asm_storage_load_data(const GAsmStorage *storage, bool ins, packed_buffe
result = read_packed_buffer(pbuf, fd);
}
+ type_error:
+
return result;
}
@@ -1251,7 +1290,7 @@ bool _g_asm_storage_load_data(const GAsmStorage *storage, bool ins, packed_buffe
/******************************************************************************
* *
* Paramètres : storage = gestionnaire à manipuler. *
-* ins = true si les données viennent d'une instruction. *
+* type = type du fichier de destination. *
* pbuf = zone tampon à lire. *
* pos = tête de lecture avant écriture. [OUT] *
* *
@@ -1263,12 +1302,32 @@ bool _g_asm_storage_load_data(const GAsmStorage *storage, bool ins, packed_buffe
* *
******************************************************************************/
-bool _g_asm_storage_store_data(const GAsmStorage *storage, bool ins, packed_buffer *pbuf, off64_t *pos)
+bool _g_asm_storage_store_data(const GAsmStorage *storage, StorageFileType type, packed_buffer *pbuf, off64_t *pos)
{
bool result; /* Bilan à retourner */
int fd; /* Flux ciblé */
- fd = ins ? storage->ins_fd : storage->op_fd;
+ switch (type)
+ {
+ case SFT_INSTRUCTION:
+ fd = storage->ins_fd;
+ break;
+ case SFT_OPERAND:
+ fd = storage->op_fd;
+ break;
+ case SFT_REGISTER:
+ fd = storage->reg_fd;
+ break;
+ default:
+ fd = -1;
+ break;
+ }
+
+ if (fd == -1)
+ {
+ result = false;
+ goto type_error;
+ }
*pos = lseek64(fd, 0, SEEK_CUR);
@@ -1281,6 +1340,8 @@ bool _g_asm_storage_store_data(const GAsmStorage *storage, bool ins, packed_buff
reset_packed_buffer(pbuf);
}
+ type_error:
+
return result;
}
@@ -1326,6 +1387,9 @@ static bool g_asm_storage_open_files(GAsmStorage *storage, int flags)
result = open_file(storage->op_filename, storage->op_fd);
if (result)
+ result = open_file(storage->reg_filename, storage->reg_fd);
+
+ if (result)
result = open_file(storage->tp_filename, storage->tp_fd);
return result;