mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-01-18 16:25:05 +08:00
strlist: Rework to drop type
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
8e0acaad66
commit
b7bb5acdaf
20
asm/nasm.c
20
asm/nasm.c
@ -75,7 +75,7 @@ struct forwrefinfo { /* info held on forward refs. */
|
||||
};
|
||||
|
||||
static void parse_cmdline(int, char **, int);
|
||||
static void assemble_file(const char *, StrList *);
|
||||
static void assemble_file(const char *, struct strlist *);
|
||||
static bool is_suppressed_warning(int severity);
|
||||
static bool skip_this_pass(int severity);
|
||||
static void nasm_verror_gnu(int severity, const char *fmt, va_list args);
|
||||
@ -134,7 +134,7 @@ static struct SAA *forwrefs; /* keep track of forward references */
|
||||
static const struct forwrefinfo *forwref;
|
||||
|
||||
static const struct preproc_ops *preproc;
|
||||
static StrList *include_path;
|
||||
static struct strlist *include_path;
|
||||
|
||||
#define OP_NORMAL (1u << 0)
|
||||
#define OP_PREPROCESS (1u << 1)
|
||||
@ -147,7 +147,7 @@ static bool depend_emit_phony = false;
|
||||
static bool depend_missing_ok = false;
|
||||
static const char *depend_target = NULL;
|
||||
static const char *depend_file = NULL;
|
||||
StrList *depend_list;
|
||||
struct strlist *depend_list;
|
||||
|
||||
static bool want_usage;
|
||||
static bool terminate_after_phase;
|
||||
@ -328,7 +328,7 @@ static void define_macros(void)
|
||||
* Command-line specified preprocessor directives (-p, -d, -u,
|
||||
* --pragma, --before) are processed after this function.
|
||||
*/
|
||||
static void preproc_init(StrList **ipath)
|
||||
static void preproc_init(struct strlist **ipath)
|
||||
{
|
||||
struct strlist_entry *l;
|
||||
|
||||
@ -339,10 +339,10 @@ static void preproc_init(StrList **ipath)
|
||||
preproc->include_path(l->str);
|
||||
|
||||
strlist_free(*ipath);
|
||||
*ipath = strlist_allocate();
|
||||
*ipath = strlist_alloc();
|
||||
}
|
||||
|
||||
static void emit_dependencies(StrList *list)
|
||||
static void emit_dependencies(struct strlist *list)
|
||||
{
|
||||
FILE *deps;
|
||||
int linepos, len;
|
||||
@ -455,7 +455,7 @@ int main(int argc, char **argv)
|
||||
iflag_set_default_cpu(&cpu);
|
||||
iflag_set_default_cpu(&cmd_cpu);
|
||||
|
||||
include_path = strlist_allocate();
|
||||
include_path = strlist_alloc();
|
||||
|
||||
pass0 = 0;
|
||||
want_usage = terminate_after_phase = false;
|
||||
@ -531,7 +531,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (depend_file || (operating_mode & OP_DEPEND))
|
||||
depend_list = strlist_allocate();
|
||||
depend_list = strlist_alloc();
|
||||
|
||||
if (!depend_target)
|
||||
depend_target = quote_for_make(outname);
|
||||
@ -972,7 +972,7 @@ static bool process_arg(char *p, char *q, int pass)
|
||||
case 'i': /* include search path */
|
||||
case 'I':
|
||||
if (pass == 1)
|
||||
strlist_add_string(include_path, param);
|
||||
strlist_add(include_path, param);
|
||||
break;
|
||||
|
||||
case 'l': /* listing file */
|
||||
@ -1417,7 +1417,7 @@ static void parse_cmdline(int argc, char **argv, int pass)
|
||||
}
|
||||
}
|
||||
|
||||
static void assemble_file(const char *fname, StrList *depend_list)
|
||||
static void assemble_file(const char *fname, struct strlist *depend_list)
|
||||
{
|
||||
char *line;
|
||||
insn output_ins;
|
||||
|
@ -63,7 +63,7 @@ static void nop_init(void)
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
static void nop_reset(const char *file, int pass, StrList *deplist)
|
||||
static void nop_reset(const char *file, int pass, struct strlist *deplist)
|
||||
{
|
||||
src_set(0, file);
|
||||
nop_lineinc = 1;
|
||||
@ -73,7 +73,7 @@ static void nop_reset(const char *file, int pass, StrList *deplist)
|
||||
nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
|
||||
(void)pass; /* placate compilers */
|
||||
|
||||
strlist_add_string(deplist, file);
|
||||
strlist_add(deplist, file);
|
||||
}
|
||||
|
||||
static char *nop_getline(void)
|
||||
|
@ -386,10 +386,10 @@ static int LocalOffset = 0;
|
||||
|
||||
static Context *cstk;
|
||||
static Include *istk;
|
||||
static StrList *ipath;
|
||||
static struct strlist *ipath;
|
||||
|
||||
static int pass; /* HACK: pass 0 = generate dependencies only */
|
||||
static StrList *deplist;
|
||||
static struct strlist *deplist;
|
||||
|
||||
static uint64_t unique; /* unique identifier numbers */
|
||||
|
||||
@ -1538,7 +1538,7 @@ static FILE *inc_fopen_search(const char *file, char **slpath,
|
||||
* considering the include path.
|
||||
*/
|
||||
static FILE *inc_fopen(const char *file,
|
||||
StrList *dhead,
|
||||
struct strlist *dhead,
|
||||
const char **found_path,
|
||||
enum incopen_mode omode,
|
||||
enum file_flags fmode)
|
||||
@ -1552,7 +1552,7 @@ static FILE *inc_fopen(const char *file,
|
||||
if (hp) {
|
||||
path = *hp;
|
||||
if (path || omode != INC_NEEDED) {
|
||||
strlist_add_string(dhead, path ? path : file);
|
||||
strlist_add(dhead, path ? path : file);
|
||||
}
|
||||
} else {
|
||||
/* Need to do the actual path search */
|
||||
@ -1565,7 +1565,7 @@ static FILE *inc_fopen(const char *file,
|
||||
* Add file to dependency path.
|
||||
*/
|
||||
if (path || omode != INC_NEEDED)
|
||||
strlist_add_string(dhead, file);
|
||||
strlist_add(dhead, file);
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
@ -2558,7 +2558,7 @@ static int do_directive(Token *tline, char **output)
|
||||
p = t->text;
|
||||
if (t->type != TOK_INTERNAL_STRING)
|
||||
nasm_unquote_cstr(p, i);
|
||||
strlist_add_string(deplist, p);
|
||||
strlist_add(deplist, p);
|
||||
free_tlist(origline);
|
||||
return DIRECTIVE_FOUND;
|
||||
|
||||
@ -4932,7 +4932,7 @@ static void pp_verror(int severity, const char *fmt, va_list arg)
|
||||
}
|
||||
|
||||
static void
|
||||
pp_reset(const char *file, int apass, StrList *dep_list)
|
||||
pp_reset(const char *file, int apass, struct strlist *dep_list)
|
||||
{
|
||||
Token *t;
|
||||
|
||||
@ -4976,7 +4976,7 @@ pp_reset(const char *file, int apass, StrList *dep_list)
|
||||
*/
|
||||
pass = apass > 2 ? 2 : apass;
|
||||
|
||||
strlist_add_string(deplist, file);
|
||||
strlist_add(deplist, file);
|
||||
|
||||
/*
|
||||
* Define the __PASS__ macro. This is defined here unlike
|
||||
@ -4993,7 +4993,7 @@ pp_reset(const char *file, int apass, StrList *dep_list)
|
||||
static void pp_init(void)
|
||||
{
|
||||
hash_init(&FileHash, HASH_MEDIUM);
|
||||
ipath = strlist_allocate();
|
||||
ipath = strlist_alloc();
|
||||
}
|
||||
|
||||
static char *pp_getline(void)
|
||||
@ -5270,7 +5270,7 @@ static void pp_include_path(const char *path)
|
||||
if (!path)
|
||||
path = "";
|
||||
|
||||
strlist_add_string(ipath, path);
|
||||
strlist_add(ipath, path);
|
||||
}
|
||||
|
||||
static void pp_pre_include(char *fname)
|
||||
|
@ -336,7 +336,7 @@ struct preproc_ops {
|
||||
* of the pass, an error reporting function, an evaluator
|
||||
* function, and a listing generator to talk to.
|
||||
*/
|
||||
void (*reset)(const char *file, int pass, StrList *deplist);
|
||||
void (*reset)(const char *file, int pass, struct strlist *deplist);
|
||||
|
||||
/*
|
||||
* Called to fetch a line of preprocessed source. The line
|
||||
@ -372,7 +372,7 @@ extern const struct preproc_ops nasmpp;
|
||||
extern const struct preproc_ops preproc_nop;
|
||||
|
||||
/* List of dependency files */
|
||||
extern StrList *depend_list;
|
||||
extern struct strlist *depend_list;
|
||||
|
||||
/*
|
||||
* Some lexical properties of the NASM source language, included
|
||||
|
@ -43,18 +43,19 @@
|
||||
#include "hashtbl.h"
|
||||
|
||||
struct strlist_entry {
|
||||
struct strlist_entry *next;
|
||||
size_t len;
|
||||
char str[1];
|
||||
struct strlist_entry *next;
|
||||
size_t len;
|
||||
char str[1];
|
||||
};
|
||||
|
||||
typedef struct string_list {
|
||||
struct hash_table hash;
|
||||
struct strlist_entry *head, **tailp;
|
||||
} StrList;
|
||||
struct strlist {
|
||||
struct hash_table hash;
|
||||
struct strlist_entry *head;
|
||||
struct strlist_entry **tailp;
|
||||
};
|
||||
|
||||
StrList safe_alloc *strlist_allocate(void);
|
||||
bool strlist_add_string(StrList *list, const char *str);
|
||||
void strlist_free(StrList *list);
|
||||
struct strlist safe_alloc *strlist_alloc(void);
|
||||
void strlist_free(struct strlist *list);
|
||||
bool strlist_add(struct strlist *list, const char *str);
|
||||
|
||||
#endif /* NASM_STRLIST_H */
|
||||
|
@ -40,54 +40,51 @@
|
||||
/*
|
||||
* Create a string list
|
||||
*/
|
||||
StrList *strlist_allocate(void)
|
||||
struct strlist *strlist_alloc(void)
|
||||
{
|
||||
StrList *list;
|
||||
|
||||
nasm_new(list);
|
||||
hash_init(&list->hash, HASH_MEDIUM);
|
||||
list->tailp = &list->head;
|
||||
|
||||
return list;
|
||||
struct strlist *list = nasm_zalloc(sizeof(*list));
|
||||
hash_init(&list->hash, HASH_MEDIUM);
|
||||
list->tailp = &list->head;
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append a string to a string list if and only if it isn't
|
||||
* already there. Return true if it was added.
|
||||
*/
|
||||
bool strlist_add_string(StrList *list, const char *str)
|
||||
bool strlist_add(struct strlist *list, const char *str)
|
||||
{
|
||||
struct hash_insert hi;
|
||||
struct strlist_entry *sl;
|
||||
size_t l;
|
||||
struct strlist_entry *e;
|
||||
struct hash_insert hi;
|
||||
size_t len;
|
||||
|
||||
if (!list)
|
||||
return false;
|
||||
if (!list)
|
||||
return false;
|
||||
|
||||
if (hash_find(&list->hash, str, &hi))
|
||||
return false; /* Already present */
|
||||
if (hash_find(&list->hash, str, &hi))
|
||||
return false;
|
||||
|
||||
l = strlen(str);
|
||||
len = strlen(str);
|
||||
|
||||
sl = nasm_malloc(sizeof(struct strlist_entry) + l);
|
||||
sl->len = l;
|
||||
memcpy(sl->str, str, l+1);
|
||||
sl->next = NULL;
|
||||
*list->tailp = sl;
|
||||
list->tailp = &sl->next;
|
||||
/* Structure already has char[1] as EOS */
|
||||
e = nasm_zalloc(sizeof(*e) + len);
|
||||
e->len = len;
|
||||
memcpy(e->str, str, len + 1);
|
||||
|
||||
hash_add(&hi, sl->str, (void *)sl);
|
||||
return true;
|
||||
*list->tailp = e;
|
||||
list->tailp = &e->next;
|
||||
|
||||
hash_add(&hi, e->str, (void *)e);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a string list
|
||||
*/
|
||||
void strlist_free(StrList *list)
|
||||
void strlist_free(struct strlist *list)
|
||||
{
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
hash_free_all(&list->hash, false);
|
||||
nasm_free(list);
|
||||
if (list) {
|
||||
hash_free_all(&list->hash, false);
|
||||
nasm_free(list);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user