Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1320671
  • 博文数量: 179
  • 博客积分: 4141
  • 博客等级: 中将
  • 技术积分: 2083
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-21 20:04
文章存档

2024年(1)

2019年(13)

2016年(1)

2014年(16)

2011年(8)

2010年(25)

2009年(115)

分类:

2009-03-22 12:23:22

/* outform.c    manages a list of output formats, and associates
 *         them with their relevant drivers. Also has a
 *         routine to find the correct driver given a name
 *         for it
 *
 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
 * Julian Hall. All rights reserved. The software is
 * redistributable under the licence given in the file "Licence"
 * distributed in the NASM archive.
 */


#include <stdio.h>
#include <string.h>

#define BUILD_DRIVERS_ARRAY
#include "outform.h"

static int ndrivers = 0;

/* 寻找是否有支持需要的格式 */
struct ofmt *ofmt_find(char *name)
{ /* find driver */
    int i;

    for (i = 0; i < ndrivers; i++)
        if (!strcmp(name, drivers[i]->shortname))
            return drivers[i];

    return NULL;
}

/* 寻找是否有支持需要的调试信息格式 */
struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
{ /* find driver */
    struct dfmt **dfmt = ofmt->debug_formats;
    while (*dfmt) {
        if (!strcmp(name, (*dfmt)->shortname))
            return (*dfmt);
        dfmt++;
    }
    return NULL;
}

/* 列出系统那个支持的输出文件格式,比如说bin,elf,etc */
void ofmt_list(struct ofmt *deffmt, FILE * fp)
{
    int i;
    for (i = 0; i < ndrivers; i++)
        fprintf(fp, " %c %-10s%s\n",
                drivers[i] == deffmt ? '*' : ' ',
                drivers[i]->shortname, drivers[i]->fullname);
}

/* 列出系统支持的调试文件格式信息 */
void dfmt_list(struct ofmt *ofmt, FILE * fp)
{
    struct dfmt **drivers = ofmt->debug_formats;
    while (*drivers) {
        fprintf(fp, " %c %-10s%s\n",
                drivers[0] == ofmt->current_dfmt ? '*' : ' ',
                drivers[0]->shortname, drivers[0]->fullname);
        drivers++;
    }
}

/* 判断nasm是否有支持输出文件格式,如果没有,出错 */
struct ofmt *ofmt_register(efunc error)
{
    for (ndrivers = 0; drivers[ndrivers] != NULL; ndrivers++) ;

    if (ndrivers == 0) {
        error(ERR_PANIC | ERR_NOFILE,
              "No output drivers given at compile time");
    }

    return (&OF_DEFAULT);
}

/* outform.h    header file for binding output format drivers to the
 * remainder of the code in the Netwide Assembler
 *
 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
 * Julian Hall. All rights reserved. The software is
 * redistributable under the licence given in the file "Licence"
 * distributed in the NASM archive.
 */


/*
 * This header file allows configuration of which output formats
 * get compiled into the NASM binary. You can configure by defining
 * various preprocessor symbols beginning with "OF_", either on the
 * compiler command line or at the top of this file.
 *
 * OF_ONLY -- only include specified object formats
 * OF_name -- ensure that output format 'name' is included
 * OF_NO_name -- remove output format 'name'
 * OF_DOS -- ensure that 'obj', 'bin' & 'win32' are included.
 * OF_UNIX -- ensure that 'aout', 'aoutb', 'coff', 'elf' are in.
 * OF_OTHERS -- ensure that 'bin', 'as86' & 'rdf' are in.
 * OF_ALL -- ensure that all formats are included.
 * note that this doesn't include 'dbg', which is
 * only really useful if you're doing development
 * work on NASM. Define OF_DBG if you want this.
 *
 * OF_DEFAULT=of_name -- ensure that 'name' is the default format.
 *
 * eg: -DOF_UNIX -DOF_ELF -DOF_DEFAULT=of_elf would be a suitable config
 * for an average linux system.
 *
 * Default config = -DOF_ALL -DOF_DEFAULT=of_bin
 *
 * You probably only want to set these options while compiling 'nasm.c'. */


#ifndef NASM_OUTFORM_H
#define NASM_OUTFORM_H

#include "nasm.h"

/* -------------- USER MODIFIABLE PART ---------------- */

/*
 * Insert #defines here in accordance with the configuration
 * instructions above.
 *
 * E.g.
 *
 * #define OF_ONLY
 * #define OF_OBJ
 * #define OF_BIN
 *
 * for a 16-bit DOS assembler with no extraneous formats.
 */


/* ------------ END USER MODIFIABLE PART -------------- */

/* ====configurable info begins here==== */
/* formats configurable:
 * bin,obj,elf,aout,aoutb,coff,win32,as86,rdf2 */


/* process options... */

#ifndef OF_ONLY
#ifndef OF_ALL
#define OF_ALL /* default is to have all formats */
#endif
#endif

#ifdef OF_ALL /* set all formats on... */
#ifndef OF_BIN
#define OF_BIN
#endif
#ifndef OF_OBJ
#define OF_OBJ
#endif
#ifndef OF_ELF
#define OF_ELF
#endif
#ifndef OF_COFF
#define OF_COFF
#endif
#ifndef OF_AOUT
#define OF_AOUT
#endif
#ifndef OF_AOUTB
#define OF_AOUTB
#endif
#ifndef OF_WIN32
#define OF_WIN32
#endif
#ifndef OF_AS86
#define OF_AS86
#endif
#ifndef OF_RDF2
#define OF_RDF2
#endif
#ifndef OF_IEEE
#define OF_IEEE
#endif
#endif /* OF_ALL */

/* turn on groups of formats specified.... */
#ifdef OF_DOS
#ifndef OF_OBJ
#define OF_OBJ
#endif
#ifndef OF_BIN
#define OF_BIN
#endif
#ifndef OF_WIN32
#define OF_WIN32
#endif
#endif

#ifdef OF_UNIX
#ifndef OF_AOUT
#define OF_AOUT
#endif
#ifndef OF_AOUTB
#define OF_AOUTB
#endif
#ifndef OF_COFF
#define OF_COFF
#endif
#ifndef OF_ELF
#define OF_ELF
#endif
#endif

#ifdef OF_OTHERS
#ifndef OF_BIN
#define OF_BIN
#endif
#ifndef OF_AS86
#define OF_AS86
#endif
#ifndef OF_RDF2
#define OF_RDF2
#endif
#ifndef OF_IEEE
#define OF_IEEE
#endif
#endif

/* finally... override any format specifically specified to be off */
#ifdef OF_NO_BIN
#undef OF_BIN
#endif
#ifdef OF_NO_OBJ
#undef OF_OBJ
#endif
#ifdef OF_NO_ELF
#undef OF_ELF
#endif
#ifdef OF_NO_AOUT
#undef OF_AOUT
#endif
#ifdef OF_NO_AOUTB
#undef OF_AOUTB
#endif
#ifdef OF_NO_COFF
#undef OF_COFF
#endif
#ifdef OF_NO_WIN32
#undef OF_WIN32
#endif
#ifdef OF_NO_AS86
#undef OF_AS86
#endif
#ifdef OF_NO_RDF2
#undef OF_RDF
#endif
#ifdef OF_NO_IEEE
#undef OF_IEEE
#endif

#ifndef OF_DEFAULT
#define OF_DEFAULT of_bin
#endif

#ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */

/* pull in the externs for the different formats, then make the *drivers
 * array based on the above defines */

/* 一下函数可以在output文件夹里面相应的文件找到,模块化做得so good!!!^-^ */
extern struct ofmt of_bin;
extern struct ofmt of_aout;
extern struct ofmt of_aoutb;
extern struct ofmt of_coff;
extern struct ofmt of_elf;
extern struct ofmt of_as86;
extern struct ofmt of_obj;
extern struct ofmt of_win32;
extern struct ofmt of_rdf2;
extern struct ofmt of_ieee;
extern struct ofmt of_dbg;

/* 目标可执行文件格式数组 */
struct ofmt *drivers[] = {
#ifdef OF_BIN
    &of_bin,
#endif
#ifdef OF_AOUT
    &of_aout,
#endif
#ifdef OF_AOUTB
    &of_aoutb,
#endif
#ifdef OF_COFF
    &of_coff,
#endif
#ifdef OF_ELF
    &of_elf,
#endif
#ifdef OF_AS86
    &of_as86,
#endif
#ifdef OF_OBJ
    &of_obj,
#endif
#ifdef OF_WIN32
    &of_win32,
#endif
#ifdef OF_RDF2
    &of_rdf2,
#endif
#ifdef OF_IEEE
    &of_ieee,
#endif
#ifdef OF_DBG
    &of_dbg,
#endif

    NULL
};

#endif /* BUILD_DRIVERS_ARRAY */

struct ofmt *ofmt_find(char *);
struct dfmt *dfmt_find(struct ofmt *, char *);
void ofmt_list(struct ofmt *, FILE *);
void dfmt_list(struct ofmt *ofmt, FILE * fp);
struct ofmt *ofmt_register(efunc error);

#endif /* NASM_OUTFORM_H */

阅读(2034) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~