Refactor list_objfmts() and list_parsers() into module.c.

svn path=/trunk/yasm/; revision=839
0.3
Peter Johnson 22 years ago
parent a2e07e1e10
commit 288401feff
  1. 2
      frontends/yasm/Makefile.inc
  2. 52
      frontends/yasm/yasm-module.c
  3. 10
      frontends/yasm/yasm-module.h
  4. 2
      libyasm/Makefile.inc
  5. 9
      libyasm/objfmt.h
  6. 9
      libyasm/parser.h
  7. 2
      modules/Makefile.inc
  8. 2
      src/Makefile.inc
  9. 52
      src/module.c
  10. 10
      src/module.h
  11. 60
      src/objfmt.c
  12. 9
      src/objfmt.h
  13. 58
      src/parser.c
  14. 9
      src/parser.h

@ -42,8 +42,6 @@ yasm_SOURCES += \
src/main.c \
src/options.c \
src/options.h \
src/objfmt.c \
src/parser.c \
src/module.h \
src/module.c \
src/errwarn.c \

@ -30,6 +30,8 @@
#include "ltdl.h"
#include "module.h"
#include "objfmt.h"
#include "parser.h"
typedef struct module {
@ -40,6 +42,28 @@ typedef struct module {
SLIST_HEAD(modulehead, module) modules = SLIST_HEAD_INITIALIZER(modules);
/* NULL-terminated list of all possibly available object format keywords.
* Could improve this a little by generating automatically at build-time.
*/
/*@-nullassign@*/
const char *objfmts[] = {
"dbg",
"bin",
"coff",
NULL
};
/*@=nullassign@*/
/* NULL-terminated list of all possibly available parser keywords.
* Could improve this a little by generating automatically at build-time.
*/
/*@-nullassign@*/
const char *parsers[] = {
"nasm",
NULL
};
/*@=nullassign@*/
static /*@dependent@*/ /*@null@*/ module *
load_module(const char *keyword)
@ -100,3 +124,31 @@ get_module_data(const char *keyword, const char *symbol)
/* Find and return data pointer: NULL if it doesn't exist */
return lt_dlsym(m->handle, symbol);
}
void
list_objfmts(void (*printfunc) (const char *name, const char *keyword))
{
int i;
yasm_objfmt *of;
/* Go through available list, and try to load each one */
for (i = 0; objfmts[i]; i++) {
of = load_objfmt(objfmts[i]);
if (of)
printfunc(of->name, of->keyword);
}
}
void
list_parsers(void (*printfunc) (const char *name, const char *keyword))
{
int i;
yasm_parser *p;
/* Go through available list, and try to load each one */
for (i = 0; parsers[i]; i++) {
p = load_parser(parsers[i]);
if (p)
printfunc(p->name, p->keyword);
}
}

@ -38,4 +38,14 @@ void unload_modules(void);
#define load_parser(keyword) get_module_data(keyword, "parser")
#define load_preproc(keyword) get_module_data(keyword, "preproc")
/* Lists all available object formats. Calls printfunc with the name and
* keyword of each available format.
*/
void list_objfmts(void (*printfunc) (const char *name, const char *keyword));
/* Lists all available parsers. Calls printfunc with the name and keyword
* of each available parser.
*/
void list_parsers(void (*printfunc) (const char *name, const char *keyword));
#endif

@ -42,8 +42,6 @@ yasm_SOURCES += \
src/main.c \
src/options.c \
src/options.h \
src/objfmt.c \
src/parser.c \
src/module.h \
src/module.c \
src/errwarn.c \

@ -123,13 +123,4 @@ struct yasm_objfmt {
void (*bc_objfmt_data_print)(FILE *f, int indent_level, unsigned int type,
const void *data);
};
/* Generic functions for all object formats - implemented in src/objfmt.c */
/* Lists all available object formats. Calls printfunc with the name and
* keyword of each available format.
*/
void yasm_list_objfmts(void (*printfunc) (const char *name,
const char *keyword));
#endif

@ -62,13 +62,4 @@ struct yasm_parser {
(yasm_preproc *pp, yasm_arch *a, yasm_objfmt *of, yasm_linemgr *lm,
yasm_errwarn *we, FILE *f, const char *in_filename, int save_input);
};
/* Generic functions for all parsers - implemented in src/parser.c */
/* Lists all available parsers. Calls printfunc with the name and keyword
* of each available parser.
*/
void yasm_list_parsers(void (*printfunc) (const char *name,
const char *keyword));
#endif

@ -42,8 +42,6 @@ yasm_SOURCES += \
src/main.c \
src/options.c \
src/options.h \
src/objfmt.c \
src/parser.c \
src/module.h \
src/module.c \
src/errwarn.c \

@ -42,8 +42,6 @@ yasm_SOURCES += \
src/main.c \
src/options.c \
src/options.h \
src/objfmt.c \
src/parser.c \
src/module.h \
src/module.c \
src/errwarn.c \

@ -30,6 +30,8 @@
#include "ltdl.h"
#include "module.h"
#include "objfmt.h"
#include "parser.h"
typedef struct module {
@ -40,6 +42,28 @@ typedef struct module {
SLIST_HEAD(modulehead, module) modules = SLIST_HEAD_INITIALIZER(modules);
/* NULL-terminated list of all possibly available object format keywords.
* Could improve this a little by generating automatically at build-time.
*/
/*@-nullassign@*/
const char *objfmts[] = {
"dbg",
"bin",
"coff",
NULL
};
/*@=nullassign@*/
/* NULL-terminated list of all possibly available parser keywords.
* Could improve this a little by generating automatically at build-time.
*/
/*@-nullassign@*/
const char *parsers[] = {
"nasm",
NULL
};
/*@=nullassign@*/
static /*@dependent@*/ /*@null@*/ module *
load_module(const char *keyword)
@ -100,3 +124,31 @@ get_module_data(const char *keyword, const char *symbol)
/* Find and return data pointer: NULL if it doesn't exist */
return lt_dlsym(m->handle, symbol);
}
void
list_objfmts(void (*printfunc) (const char *name, const char *keyword))
{
int i;
yasm_objfmt *of;
/* Go through available list, and try to load each one */
for (i = 0; objfmts[i]; i++) {
of = load_objfmt(objfmts[i]);
if (of)
printfunc(of->name, of->keyword);
}
}
void
list_parsers(void (*printfunc) (const char *name, const char *keyword))
{
int i;
yasm_parser *p;
/* Go through available list, and try to load each one */
for (i = 0; parsers[i]; i++) {
p = load_parser(parsers[i]);
if (p)
printfunc(p->name, p->keyword);
}
}

@ -38,4 +38,14 @@ void unload_modules(void);
#define load_parser(keyword) get_module_data(keyword, "parser")
#define load_preproc(keyword) get_module_data(keyword, "preproc")
/* Lists all available object formats. Calls printfunc with the name and
* keyword of each available format.
*/
void list_objfmts(void (*printfunc) (const char *name, const char *keyword));
/* Lists all available parsers. Calls printfunc with the name and keyword
* of each available parser.
*/
void list_parsers(void (*printfunc) (const char *name, const char *keyword));
#endif

@ -1,60 +0,0 @@
/*
* YASM generic functions for all object formats
*
* Copyright (C) 2001 Peter Johnson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "util.h"
/*@unused@*/ RCSID("$IdPath$");
#include "module.h"
#include "objfmt.h"
/* NULL-terminated list of all possibly available object format keywords.
* Could improve this a little by generating automatically at build-time.
*/
/*@-nullassign@*/
const char *objfmts[] = {
"dbg",
"bin",
"coff",
NULL
};
/*@=nullassign@*/
void
yasm_list_objfmts(void (*printfunc) (const char *name, const char *keyword))
{
int i;
yasm_objfmt *of;
/* Go through available list, and try to load each one */
for (i = 0; objfmts[i]; i++) {
of = load_objfmt(objfmts[i]);
if (of)
printfunc(of->name, of->keyword);
}
}

@ -123,13 +123,4 @@ struct yasm_objfmt {
void (*bc_objfmt_data_print)(FILE *f, int indent_level, unsigned int type,
const void *data);
};
/* Generic functions for all object formats - implemented in src/objfmt.c */
/* Lists all available object formats. Calls printfunc with the name and
* keyword of each available format.
*/
void yasm_list_objfmts(void (*printfunc) (const char *name,
const char *keyword));
#endif

@ -1,58 +0,0 @@
/*
* YASM generic functions for all parsers
*
* Copyright (C) 2001 Peter Johnson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "util.h"
/*@unused@*/ RCSID("$IdPath$");
#include "module.h"
#include "parser.h"
/* NULL-terminated list of all possibly available parser keywords.
* Could improve this a little by generating automatically at build-time.
*/
/*@-nullassign@*/
const char *parsers[] = {
"nasm",
NULL
};
/*@=nullassign@*/
void
yasm_list_parsers(void (*printfunc) (const char *name, const char *keyword))
{
int i;
yasm_parser *p;
/* Go through available list, and try to load each one */
for (i = 0; parsers[i]; i++) {
p = load_parser(parsers[i]);
if (p)
printfunc(p->name, p->keyword);
}
}

@ -62,13 +62,4 @@ struct yasm_parser {
(yasm_preproc *pp, yasm_arch *a, yasm_objfmt *of, yasm_linemgr *lm,
yasm_errwarn *we, FILE *f, const char *in_filename, int save_input);
};
/* Generic functions for all parsers - implemented in src/parser.c */
/* Lists all available parsers. Calls printfunc with the name and keyword
* of each available parser.
*/
void yasm_list_parsers(void (*printfunc) (const char *name,
const char *keyword));
#endif

Loading…
Cancel
Save