47 lines
930 B
C
47 lines
930 B
C
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <mips.h>
|
|
#include <merror.h>
|
|
#include <mlimits.h>
|
|
|
|
#include "parse.h"
|
|
|
|
#define RELTBL_INIT_LEN 8
|
|
|
|
int reftbl_init(struct reference_table *ref_tbl)
|
|
{
|
|
ref_tbl->len = RELTBL_INIT_LEN;
|
|
ref_tbl->count = 0;
|
|
ref_tbl->references = malloc(sizeof(struct reference) *
|
|
RELTBL_INIT_LEN);
|
|
|
|
if (ref_tbl->references == NULL) {
|
|
ERROR("cannot alloc");
|
|
return M_ERROR;
|
|
}
|
|
|
|
return M_SUCCESS;
|
|
}
|
|
|
|
void reftbl_free(struct reference_table *ref_tbl)
|
|
{
|
|
free(ref_tbl->references);
|
|
}
|
|
|
|
int reftbl_push(struct reference_table *ref_tbl, struct reference reference)
|
|
{
|
|
if (ref_tbl->count >= ref_tbl->len) {
|
|
ref_tbl->len *= 2;
|
|
ref_tbl->references = realloc(ref_tbl->references,
|
|
sizeof(struct reference) * ref_tbl->len);
|
|
|
|
if (ref_tbl->references == NULL) {
|
|
ERROR("cannot realloc");
|
|
return M_ERROR;
|
|
}
|
|
}
|
|
|
|
ref_tbl->references[ref_tbl->count++] = reference;
|
|
|
|
return M_SUCCESS;
|
|
}
|