2009-06-29 08:13:04 +08:00
|
|
|
/* ----------------------------------------------------------------------- *
|
2009-07-13 03:04:56 +08:00
|
|
|
*
|
2018-02-08 06:14:36 +08:00
|
|
|
* Copyright 1996-2018 The NASM Authors - All Rights Reserved
|
2009-06-29 08:13:04 +08:00
|
|
|
* See the file AUTHORS included with the NASM distribution for
|
|
|
|
* the specific copyright holders.
|
2002-05-01 04:51:32 +08:00
|
|
|
*
|
2009-06-29 08:13:04 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * 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.
|
2009-07-13 03:04:56 +08:00
|
|
|
*
|
2009-06-29 08:13:04 +08:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
* 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 COPYRIGHT OWNER OR
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
|
2009-07-13 03:04:56 +08:00
|
|
|
/*
|
2009-06-29 08:13:04 +08:00
|
|
|
* The Netwide Assembler main program module
|
2002-05-01 04:51:32 +08:00
|
|
|
*/
|
|
|
|
|
2007-10-03 12:53:51 +08:00
|
|
|
#include "compiler.h"
|
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
#include "nasm.h"
|
|
|
|
#include "nasmlib.h"
|
2018-11-29 06:55:58 +08:00
|
|
|
#include "nctype.h"
|
2017-03-08 11:23:03 +08:00
|
|
|
#include "error.h"
|
2008-06-10 08:32:43 +08:00
|
|
|
#include "saa.h"
|
2008-06-10 08:40:16 +08:00
|
|
|
#include "raa.h"
|
2007-10-17 05:40:27 +08:00
|
|
|
#include "float.h"
|
2007-08-31 06:35:34 +08:00
|
|
|
#include "stdscan.h"
|
2002-05-01 04:59:21 +08:00
|
|
|
#include "insns.h"
|
2002-05-01 04:52:08 +08:00
|
|
|
#include "preproc.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
#include "parser.h"
|
2002-05-01 04:52:49 +08:00
|
|
|
#include "eval.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
#include "assemble.h"
|
|
|
|
#include "labels.h"
|
2016-05-26 03:06:29 +08:00
|
|
|
#include "outform.h"
|
2002-05-01 04:52:26 +08:00
|
|
|
#include "listing.h"
|
2013-11-10 02:16:11 +08:00
|
|
|
#include "iflag.h"
|
2016-03-08 18:17:36 +08:00
|
|
|
#include "ver.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2010-07-16 09:28:52 +08:00
|
|
|
/*
|
|
|
|
* This is the maximum number of optimization passes to do. If we ever
|
|
|
|
* find a case where the optimizer doesn't naturally converge, we might
|
|
|
|
* have to drop this value so the assembler doesn't appear to just hang.
|
|
|
|
*/
|
|
|
|
#define MAX_OPTIMIZE (INT_MAX >> 1)
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
struct forwrefinfo { /* info held on forward refs. */
|
2002-05-01 04:53:55 +08:00
|
|
|
int lineno;
|
|
|
|
int operand;
|
|
|
|
};
|
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
const char *_progname;
|
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
static void parse_cmdline(int, char **, int);
|
2018-11-12 02:33:52 +08:00
|
|
|
static void assemble_file(const char *, struct strlist *);
|
2018-12-14 11:39:41 +08:00
|
|
|
static bool skip_this_pass(errflags severity);
|
|
|
|
static void nasm_verror_asm(errflags severity, const char *fmt, va_list args);
|
2002-05-01 04:51:32 +08:00
|
|
|
static void usage(void);
|
2019-08-10 16:38:06 +08:00
|
|
|
static void help(FILE *);
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2018-12-11 14:29:49 +08:00
|
|
|
struct error_format {
|
|
|
|
const char *beforeline; /* Before line number, if present */
|
|
|
|
const char *afterline; /* After line number, if present */
|
|
|
|
const char *beforemsg; /* Before actual message */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct error_format errfmt_gnu = { ":", "", ": " };
|
|
|
|
static const struct error_format errfmt_msvc = { "(", ")", " : " };
|
|
|
|
static const struct error_format *errfmt = &errfmt_gnu;
|
2018-12-14 16:17:13 +08:00
|
|
|
static struct strlist *warn_list;
|
2018-12-11 14:29:49 +08:00
|
|
|
|
2019-08-09 19:28:55 +08:00
|
|
|
unsigned int debug_nasm; /* Debugging messages? */
|
|
|
|
|
2016-03-08 15:18:30 +08:00
|
|
|
static bool using_debug_info, opt_verbose_info;
|
|
|
|
static const char *debug_format;
|
|
|
|
|
2018-02-08 06:14:36 +08:00
|
|
|
#ifndef ABORT_ON_PANIC
|
|
|
|
# define ABORT_ON_PANIC 0
|
|
|
|
#endif
|
|
|
|
static bool abort_on_panic = ABORT_ON_PANIC;
|
2018-06-15 08:04:32 +08:00
|
|
|
static bool keep_all;
|
2018-02-08 06:14:36 +08:00
|
|
|
|
2007-10-11 05:58:45 +08:00
|
|
|
bool tasm_compatible_mode = false;
|
2018-12-19 03:12:46 +08:00
|
|
|
enum pass_type _pass_type;
|
|
|
|
const char * const _pass_types[] =
|
|
|
|
{
|
|
|
|
"init", "first", "optimize", "stabilize", "final"
|
|
|
|
};
|
|
|
|
int64_t _passn;
|
2007-08-29 07:06:00 +08:00
|
|
|
int globalrel = 0;
|
2013-12-05 12:05:55 +08:00
|
|
|
int globalbnd = 0;
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2017-08-03 09:37:54 +08:00
|
|
|
struct compile_time official_compile_time;
|
2008-02-17 06:54:10 +08:00
|
|
|
|
2017-12-21 05:33:49 +08:00
|
|
|
const char *inname;
|
|
|
|
const char *outname;
|
|
|
|
static const char *listname;
|
|
|
|
static const char *errname;
|
|
|
|
|
2018-06-16 08:51:39 +08:00
|
|
|
static int64_t globallineno; /* for forward-reference tracking */
|
2018-05-02 23:07:53 +08:00
|
|
|
|
2016-02-18 12:59:22 +08:00
|
|
|
const struct ofmt *ofmt = &OF_DEFAULT;
|
|
|
|
const struct ofmt_alias *ofmt_alias = NULL;
|
2009-07-19 09:07:17 +08:00
|
|
|
const struct dfmt *dfmt;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2018-12-14 05:55:25 +08:00
|
|
|
FILE *error_file; /* Where to write error messages */
|
2002-05-01 04:57:38 +08:00
|
|
|
|
2009-07-19 09:07:17 +08:00
|
|
|
FILE *ofile = NULL;
|
2018-08-16 04:22:21 +08:00
|
|
|
struct optimization optimizing =
|
|
|
|
{ MAX_OPTIMIZE, OPTIM_ALL_ENABLED }; /* number of optimization passes to take */
|
2016-11-16 23:48:13 +08:00
|
|
|
static int cmd_sb = 16; /* by default */
|
2013-11-10 02:16:11 +08:00
|
|
|
|
2017-03-08 11:23:03 +08:00
|
|
|
iflag_t cpu;
|
2013-11-10 02:16:11 +08:00
|
|
|
static iflag_t cmd_cpu;
|
|
|
|
|
2016-02-18 17:25:46 +08:00
|
|
|
struct location location;
|
2017-03-08 11:23:03 +08:00
|
|
|
bool in_absolute; /* Flag we are in ABSOLUTE seg */
|
|
|
|
struct location absolute; /* Segment/offset inside ABSOLUTE */
|
2002-05-01 04:52:26 +08:00
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
static struct RAA *offsets;
|
2002-05-01 04:51:53 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
static struct SAA *forwrefs; /* keep track of forward references */
|
2007-10-05 04:42:56 +08:00
|
|
|
static const struct forwrefinfo *forwref;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2016-02-18 18:20:59 +08:00
|
|
|
static const struct preproc_ops *preproc;
|
2018-11-12 02:33:52 +08:00
|
|
|
static struct strlist *include_path;
|
2018-12-15 04:22:11 +08:00
|
|
|
bool pp_noline; /* Ignore %line directives */
|
2011-07-01 14:38:25 +08:00
|
|
|
|
2018-11-29 04:36:53 +08:00
|
|
|
#define OP_NORMAL (1U << 0)
|
|
|
|
#define OP_PREPROCESS (1U << 1)
|
|
|
|
#define OP_DEPEND (1U << 2)
|
2014-06-23 06:22:02 +08:00
|
|
|
|
|
|
|
static unsigned int operating_mode;
|
2014-06-23 00:53:12 +08:00
|
|
|
|
2008-05-30 10:09:11 +08:00
|
|
|
/* Dependency flags */
|
2008-05-30 12:38:00 +08:00
|
|
|
static bool depend_emit_phony = false;
|
2008-05-30 10:09:11 +08:00
|
|
|
static bool depend_missing_ok = false;
|
|
|
|
static const char *depend_target = NULL;
|
|
|
|
static const char *depend_file = NULL;
|
2018-11-12 02:33:52 +08:00
|
|
|
struct strlist *depend_list;
|
2002-05-01 04:52:08 +08:00
|
|
|
|
2009-06-28 06:34:32 +08:00
|
|
|
static bool want_usage;
|
|
|
|
static bool terminate_after_phase;
|
2016-02-18 12:27:41 +08:00
|
|
|
bool user_nolist = false;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2017-08-17 12:14:33 +08:00
|
|
|
static char *quote_for_pmake(const char *str);
|
|
|
|
static char *quote_for_wmake(const char *str);
|
|
|
|
static char *(*quote_for_make)(const char *) = quote_for_pmake;
|
2012-09-10 08:09:00 +08:00
|
|
|
|
2018-06-13 04:50:37 +08:00
|
|
|
/*
|
|
|
|
* Execution limits that can be set via a command-line option or %pragma
|
|
|
|
*/
|
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
/*
|
|
|
|
* This is really unlimited; it would take far longer than the
|
|
|
|
* current age of the universe for this limit to be reached even on
|
|
|
|
* much faster CPUs than currently exist.
|
|
|
|
*/
|
|
|
|
#define LIMIT_MAX_VAL (INT64_MAX >> 1)
|
2018-06-13 04:50:37 +08:00
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
int64_t nasm_limit[LIMIT_MAX+1];
|
2018-06-13 04:50:37 +08:00
|
|
|
|
|
|
|
struct limit_info {
|
|
|
|
const char *name;
|
|
|
|
const char *help;
|
2019-08-10 16:38:06 +08:00
|
|
|
int64_t default_val;
|
2018-06-13 04:50:37 +08:00
|
|
|
};
|
2019-08-10 16:38:06 +08:00
|
|
|
/* The order here must match enum nasm_limit in nasm.h */
|
2018-06-13 04:50:37 +08:00
|
|
|
static const struct limit_info limit_info[LIMIT_MAX+1] = {
|
2019-08-10 16:38:06 +08:00
|
|
|
{ "passes", "total number of passes", LIMIT_MAX_VAL },
|
|
|
|
{ "stalled-passes", "number of passes without forward progress", 1000 },
|
|
|
|
{ "macro-levels", "levels of macro expansion", 10000 },
|
2019-08-16 10:26:52 +08:00
|
|
|
{ "macro-tokens", "tokens processed during single-lime macro expansion", 10000000 },
|
|
|
|
{ "mmacros", "multi-line macros before final return", 100000 },
|
2019-08-10 16:38:06 +08:00
|
|
|
{ "rep", "%rep count", 1000000 },
|
|
|
|
{ "eval", "expression evaluation descent", 1000000},
|
|
|
|
{ "lines", "total source lines processed", 2000000000 }
|
2018-06-13 04:50:37 +08:00
|
|
|
};
|
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
static void set_default_limits(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i <= LIMIT_MAX; i++)
|
|
|
|
nasm_limit[i] = limit_info[i].default_val;
|
|
|
|
}
|
|
|
|
|
2018-06-13 05:23:05 +08:00
|
|
|
enum directive_result
|
|
|
|
nasm_set_limit(const char *limit, const char *valstr)
|
2018-06-13 04:50:37 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int64_t val;
|
|
|
|
bool rn_error;
|
2018-06-13 05:23:05 +08:00
|
|
|
int errlevel;
|
2018-06-13 04:50:37 +08:00
|
|
|
|
2019-08-16 16:12:54 +08:00
|
|
|
if (!limit)
|
|
|
|
limit = "";
|
|
|
|
if (!valstr)
|
|
|
|
valstr = "";
|
|
|
|
|
2018-06-13 04:50:37 +08:00
|
|
|
for (i = 0; i <= LIMIT_MAX; i++) {
|
|
|
|
if (!nasm_stricmp(limit, limit_info[i].name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i > LIMIT_MAX) {
|
2018-12-19 03:12:46 +08:00
|
|
|
if (not_started())
|
2018-12-15 05:44:35 +08:00
|
|
|
errlevel = ERR_WARNING|WARN_OTHER|ERR_USAGE;
|
2018-06-13 05:23:05 +08:00
|
|
|
else
|
2019-06-07 11:53:17 +08:00
|
|
|
errlevel = ERR_WARNING|WARN_PRAGMA_UNKNOWN;
|
2018-06-13 05:23:05 +08:00
|
|
|
nasm_error(errlevel, "unknown limit: `%s'", limit);
|
2018-06-13 04:50:37 +08:00
|
|
|
return DIRR_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nasm_stricmp(valstr, "unlimited")) {
|
|
|
|
val = LIMIT_MAX_VAL;
|
|
|
|
} else {
|
|
|
|
val = readnum(valstr, &rn_error);
|
|
|
|
if (rn_error || val < 0) {
|
2018-12-19 03:12:46 +08:00
|
|
|
if (not_started())
|
2018-12-15 05:44:35 +08:00
|
|
|
errlevel = ERR_WARNING|WARN_OTHER|ERR_USAGE;
|
2018-06-13 05:23:05 +08:00
|
|
|
else
|
2019-06-07 11:53:17 +08:00
|
|
|
errlevel = ERR_WARNING|WARN_PRAGMA_BAD;
|
2019-08-16 16:12:54 +08:00
|
|
|
nasm_error(errlevel, "invalid limit value: `%s'", valstr);
|
2018-06-13 04:50:37 +08:00
|
|
|
return DIRR_ERROR;
|
|
|
|
}
|
2018-06-13 05:23:05 +08:00
|
|
|
if (val > LIMIT_MAX_VAL)
|
|
|
|
val = LIMIT_MAX_VAL;
|
2018-06-13 04:50:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
nasm_limit[i] = val;
|
|
|
|
return DIRR_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-31 05:43:46 +08:00
|
|
|
int64_t switch_segment(int32_t segment)
|
2013-02-15 16:35:04 +08:00
|
|
|
{
|
2018-05-31 05:43:46 +08:00
|
|
|
location.segment = segment;
|
|
|
|
if (segment == NO_SEG) {
|
|
|
|
location.offset = absolute.offset;
|
|
|
|
in_absolute = true;
|
|
|
|
} else {
|
|
|
|
location.offset = raa_read(offsets, segment);
|
|
|
|
in_absolute = false;
|
|
|
|
}
|
|
|
|
return location.offset;
|
2013-02-15 16:35:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_curr_offs(int64_t l_off)
|
|
|
|
{
|
2017-03-08 11:23:03 +08:00
|
|
|
if (in_absolute)
|
|
|
|
absolute.offset = l_off;
|
2013-02-15 16:35:04 +08:00
|
|
|
else
|
|
|
|
offsets = raa_write(offsets, location.segment, l_off);
|
|
|
|
}
|
|
|
|
|
2018-05-31 05:43:46 +08:00
|
|
|
static void increment_offset(int64_t delta)
|
|
|
|
{
|
|
|
|
if (unlikely(delta == 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
location.offset += delta;
|
|
|
|
set_curr_offs(location.offset);
|
|
|
|
}
|
|
|
|
|
2007-04-14 00:47:53 +08:00
|
|
|
static void nasm_fputs(const char *line, FILE * outfile)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2002-05-15 06:38:55 +08:00
|
|
|
if (outfile) {
|
2005-01-16 06:15:51 +08:00
|
|
|
fputs(line, outfile);
|
2007-11-14 01:37:59 +08:00
|
|
|
putc('\n', outfile);
|
2002-05-01 04:53:55 +08:00
|
|
|
} else
|
2005-01-16 06:15:51 +08:00
|
|
|
puts(line);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
|
2018-11-12 05:25:16 +08:00
|
|
|
/*
|
|
|
|
* Define system-defined macros that are not part of
|
|
|
|
* macros/standard.mac.
|
|
|
|
*/
|
|
|
|
static void define_macros(void)
|
2008-02-17 06:54:10 +08:00
|
|
|
{
|
2017-08-03 09:37:54 +08:00
|
|
|
const struct compile_time * const oct = &official_compile_time;
|
2008-02-17 06:54:10 +08:00
|
|
|
char temp[128];
|
2013-02-15 06:16:58 +08:00
|
|
|
|
2017-08-03 09:37:54 +08:00
|
|
|
if (oct->have_local) {
|
|
|
|
strftime(temp, sizeof temp, "__DATE__=\"%Y-%m-%d\"", &oct->local);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2017-08-03 09:37:54 +08:00
|
|
|
strftime(temp, sizeof temp, "__DATE_NUM__=%Y%m%d", &oct->local);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2017-08-03 09:37:54 +08:00
|
|
|
strftime(temp, sizeof temp, "__TIME__=\"%H:%M:%S\"", &oct->local);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2017-08-03 09:37:54 +08:00
|
|
|
strftime(temp, sizeof temp, "__TIME_NUM__=%H%M%S", &oct->local);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2008-02-17 06:54:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 09:37:54 +08:00
|
|
|
if (oct->have_gm) {
|
|
|
|
strftime(temp, sizeof temp, "__UTC_DATE__=\"%Y-%m-%d\"", &oct->gm);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2017-08-03 09:37:54 +08:00
|
|
|
strftime(temp, sizeof temp, "__UTC_DATE_NUM__=%Y%m%d", &oct->gm);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2017-08-03 09:37:54 +08:00
|
|
|
strftime(temp, sizeof temp, "__UTC_TIME__=\"%H:%M:%S\"", &oct->gm);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2017-08-03 09:37:54 +08:00
|
|
|
strftime(temp, sizeof temp, "__UTC_TIME_NUM__=%H%M%S", &oct->gm);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2008-02-17 06:54:10 +08:00
|
|
|
}
|
2008-05-05 08:53:31 +08:00
|
|
|
|
2017-08-03 09:37:54 +08:00
|
|
|
if (oct->have_posix) {
|
|
|
|
snprintf(temp, sizeof temp, "__POSIX_TIME__=%"PRId64, oct->posix);
|
2013-02-15 06:16:58 +08:00
|
|
|
preproc->pre_define(temp);
|
2008-02-17 06:54:10 +08:00
|
|
|
}
|
|
|
|
|
2011-04-06 22:32:15 +08:00
|
|
|
/*
|
|
|
|
* In case if output format is defined by alias
|
|
|
|
* we have to put shortname of the alias itself here
|
|
|
|
* otherwise ABI backward compatibility gets broken.
|
|
|
|
*/
|
2010-07-12 19:19:17 +08:00
|
|
|
snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s",
|
2011-04-06 22:32:15 +08:00
|
|
|
ofmt_alias ? ofmt_alias->shortname : ofmt->shortname);
|
2012-05-07 05:57:55 +08:00
|
|
|
preproc->pre_define(temp);
|
2018-11-12 05:25:16 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Output-format specific macros.
|
|
|
|
*/
|
|
|
|
if (ofmt->stdmac)
|
|
|
|
preproc->extra_stdmac(ofmt->stdmac);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debug format, if any
|
|
|
|
*/
|
|
|
|
if (dfmt != &null_debug_form) {
|
|
|
|
snprintf(temp, sizeof(temp), "__DEBUG_FORMAT__=%s", dfmt->shortname);
|
|
|
|
preproc->pre_define(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the preprocessor, set up the include path, and define
|
|
|
|
* the system-included macros. This is called between passes 1 and 2
|
|
|
|
* of parsing the command options; ofmt and dfmt are defined at this
|
|
|
|
* point.
|
|
|
|
*
|
|
|
|
* Command-line specified preprocessor directives (-p, -d, -u,
|
|
|
|
* --pragma, --before) are processed after this function.
|
|
|
|
*/
|
2018-11-24 19:33:48 +08:00
|
|
|
static void preproc_init(struct strlist *ipath)
|
2018-11-12 05:25:16 +08:00
|
|
|
{
|
|
|
|
preproc->init();
|
|
|
|
define_macros();
|
2018-11-24 19:33:48 +08:00
|
|
|
preproc->include_path(ipath);
|
2008-02-17 06:54:10 +08:00
|
|
|
}
|
|
|
|
|
2018-11-12 02:33:52 +08:00
|
|
|
static void emit_dependencies(struct strlist *list)
|
2008-05-30 12:38:00 +08:00
|
|
|
{
|
|
|
|
FILE *deps;
|
|
|
|
int linepos, len;
|
2017-08-17 13:08:36 +08:00
|
|
|
bool wmake = (quote_for_make == quote_for_wmake);
|
|
|
|
const char *wrapstr, *nulltarget;
|
2018-12-12 05:06:14 +08:00
|
|
|
const struct strlist_entry *l;
|
2018-10-26 03:33:58 +08:00
|
|
|
|
|
|
|
if (!list)
|
|
|
|
return;
|
2017-08-17 12:14:33 +08:00
|
|
|
|
2017-08-17 13:08:36 +08:00
|
|
|
wrapstr = wmake ? " &\n " : " \\\n ";
|
|
|
|
nulltarget = wmake ? "\t%null\n" : "";
|
2008-05-30 12:38:00 +08:00
|
|
|
|
|
|
|
if (depend_file && strcmp(depend_file, "-")) {
|
2016-05-25 19:28:46 +08:00
|
|
|
deps = nasm_open_write(depend_file, NF_TEXT);
|
2013-02-15 16:25:04 +08:00
|
|
|
if (!deps) {
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatal("unable to write dependency file `%s'", depend_file);
|
2013-02-15 16:25:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-05-30 12:38:00 +08:00
|
|
|
} else {
|
2013-02-15 16:25:04 +08:00
|
|
|
deps = stdout;
|
2008-05-30 12:38:00 +08:00
|
|
|
}
|
2009-07-13 03:04:56 +08:00
|
|
|
|
2017-08-17 12:14:33 +08:00
|
|
|
linepos = fprintf(deps, "%s :", depend_target);
|
2018-12-12 05:06:14 +08:00
|
|
|
strlist_for_each(l, list) {
|
2012-09-10 08:09:00 +08:00
|
|
|
char *file = quote_for_make(l->str);
|
2013-02-15 16:25:04 +08:00
|
|
|
len = strlen(file);
|
|
|
|
if (linepos + len > 62 && linepos > 1) {
|
2017-08-17 13:08:36 +08:00
|
|
|
fputs(wrapstr, deps);
|
2013-02-15 16:25:04 +08:00
|
|
|
linepos = 1;
|
|
|
|
}
|
|
|
|
fprintf(deps, " %s", file);
|
|
|
|
linepos += len+1;
|
2012-09-10 08:09:00 +08:00
|
|
|
nasm_free(file);
|
2008-05-30 12:38:00 +08:00
|
|
|
}
|
2019-08-10 16:38:06 +08:00
|
|
|
fputs("\n\n", deps);
|
2009-07-13 03:04:56 +08:00
|
|
|
|
2018-12-12 05:06:14 +08:00
|
|
|
strlist_for_each(l, list) {
|
2017-08-17 12:14:33 +08:00
|
|
|
if (depend_emit_phony) {
|
|
|
|
char *file = quote_for_make(l->str);
|
2017-08-17 13:08:36 +08:00
|
|
|
fprintf(deps, "%s :\n%s\n", file, nulltarget);
|
2017-08-17 12:14:33 +08:00
|
|
|
nasm_free(file);
|
|
|
|
}
|
2008-05-30 12:38:00 +08:00
|
|
|
}
|
|
|
|
|
2018-12-14 16:17:13 +08:00
|
|
|
strlist_free(&list);
|
2018-10-26 03:33:58 +08:00
|
|
|
|
2008-05-30 12:38:00 +08:00
|
|
|
if (deps != stdout)
|
2013-02-15 16:25:04 +08:00
|
|
|
fclose(deps);
|
2008-05-30 12:38:00 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 09:37:54 +08:00
|
|
|
/* Convert a struct tm to a POSIX-style time constant */
|
|
|
|
static int64_t make_posix_time(const struct tm *tm)
|
|
|
|
{
|
|
|
|
int64_t t;
|
|
|
|
int64_t y = tm->tm_year;
|
|
|
|
|
|
|
|
/* See IEEE 1003.1:2004, section 4.14 */
|
|
|
|
|
|
|
|
t = (y-70)*365 + (y-69)/4 - (y-1)/100 + (y+299)/400;
|
|
|
|
t += tm->tm_yday;
|
|
|
|
t *= 24;
|
|
|
|
t += tm->tm_hour;
|
|
|
|
t *= 60;
|
|
|
|
t += tm->tm_min;
|
|
|
|
t *= 60;
|
|
|
|
t += tm->tm_sec;
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void timestamp(void)
|
|
|
|
{
|
|
|
|
struct compile_time * const oct = &official_compile_time;
|
|
|
|
const struct tm *tp, *best_gm;
|
|
|
|
|
|
|
|
time(&oct->t);
|
|
|
|
|
|
|
|
best_gm = NULL;
|
|
|
|
|
|
|
|
tp = localtime(&oct->t);
|
|
|
|
if (tp) {
|
|
|
|
oct->local = *tp;
|
|
|
|
best_gm = &oct->local;
|
|
|
|
oct->have_local = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
tp = gmtime(&oct->t);
|
|
|
|
if (tp) {
|
|
|
|
oct->gm = *tp;
|
|
|
|
best_gm = &oct->gm;
|
|
|
|
oct->have_gm = true;
|
|
|
|
if (!oct->have_local)
|
|
|
|
oct->local = oct->gm;
|
|
|
|
} else {
|
|
|
|
oct->gm = oct->local;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_gm) {
|
|
|
|
oct->posix = make_posix_time(best_gm);
|
|
|
|
oct->have_posix = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-13 00:54:50 +08:00
|
|
|
int main(int argc, char **argv)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2019-08-10 16:38:06 +08:00
|
|
|
_progname = argv[0];
|
|
|
|
if (!_progname || !_progname[0])
|
|
|
|
_progname = "nasm";
|
|
|
|
|
2017-08-03 09:37:54 +08:00
|
|
|
timestamp();
|
2008-02-17 06:54:10 +08:00
|
|
|
|
2018-12-14 05:55:25 +08:00
|
|
|
error_file = stderr;
|
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
iflag_set_default_cpu(&cpu);
|
|
|
|
iflag_set_default_cpu(&cmd_cpu);
|
2013-11-10 02:16:11 +08:00
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
set_default_limits();
|
|
|
|
|
2018-12-14 14:48:14 +08:00
|
|
|
include_path = strlist_alloc(true);
|
2018-11-13 06:09:27 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
_pass_type = PASS_INIT;
|
|
|
|
_passn = 0;
|
|
|
|
|
2007-10-11 05:58:45 +08:00
|
|
|
want_usage = terminate_after_phase = false;
|
2018-12-11 14:29:49 +08:00
|
|
|
nasm_set_verror(nasm_verror_asm);
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2018-11-29 06:55:58 +08:00
|
|
|
nasm_ctype_init();
|
2016-05-10 17:56:29 +08:00
|
|
|
src_init();
|
2008-06-12 06:49:41 +08:00
|
|
|
|
2018-06-26 03:58:49 +08:00
|
|
|
/*
|
|
|
|
* We must call init_labels() before the command line parsing,
|
|
|
|
* because we may be setting prefixes/suffixes from the command
|
|
|
|
* line.
|
|
|
|
*/
|
|
|
|
init_labels();
|
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
offsets = raa_init();
|
2007-04-12 10:40:54 +08:00
|
|
|
forwrefs = saa_init((int32_t)sizeof(struct forwrefinfo));
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2002-05-01 04:52:08 +08:00
|
|
|
preproc = &nasmpp;
|
2014-06-23 00:53:12 +08:00
|
|
|
operating_mode = OP_NORMAL;
|
2002-05-01 05:01:08 +08:00
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
parse_cmdline(argc, argv, 1);
|
|
|
|
if (terminate_after_phase) {
|
|
|
|
if (want_usage)
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-11-12 05:25:16 +08:00
|
|
|
/* At this point we have ofmt and the name of the desired debug format */
|
2016-03-08 15:18:30 +08:00
|
|
|
if (!using_debug_info) {
|
|
|
|
/* No debug info, redirect to the null backend (empty stubs) */
|
2016-02-18 12:55:08 +08:00
|
|
|
dfmt = &null_debug_form;
|
2016-03-08 15:18:30 +08:00
|
|
|
} else if (!debug_format) {
|
|
|
|
/* Default debug format for this backend */
|
2018-12-16 04:44:46 +08:00
|
|
|
dfmt = ofmt->default_dfmt;
|
2016-03-08 15:18:30 +08:00
|
|
|
} else {
|
|
|
|
dfmt = dfmt_find(ofmt, debug_format);
|
|
|
|
if (!dfmt) {
|
2018-12-11 14:29:49 +08:00
|
|
|
nasm_fatalf(ERR_USAGE, "unrecognized debug format `%s' for output format `%s'",
|
2016-03-08 15:18:30 +08:00
|
|
|
debug_format, ofmt->shortname);
|
|
|
|
}
|
|
|
|
}
|
2003-09-11 07:34:23 +08:00
|
|
|
|
2018-11-24 19:33:48 +08:00
|
|
|
preproc_init(include_path);
|
2018-11-12 05:25:16 +08:00
|
|
|
|
|
|
|
parse_cmdline(argc, argv, 2);
|
|
|
|
if (terminate_after_phase) {
|
|
|
|
if (want_usage)
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save away the default state of warnings */
|
2019-01-12 05:13:03 +08:00
|
|
|
init_warnings();
|
2002-05-01 04:52:49 +08:00
|
|
|
|
2018-11-29 04:36:53 +08:00
|
|
|
/* Dependency filename if we are also doing other things */
|
|
|
|
if (!depend_file && (operating_mode & ~OP_DEPEND)) {
|
|
|
|
if (outname)
|
|
|
|
depend_file = nasm_strcat(outname, ".d");
|
|
|
|
else
|
|
|
|
depend_file = filename_set_extension(inname, ".d");
|
|
|
|
}
|
|
|
|
|
2018-09-22 18:46:45 +08:00
|
|
|
/*
|
|
|
|
* If no output file name provided and this
|
2018-11-29 04:36:53 +08:00
|
|
|
* is preprocess mode, we're perfectly
|
2018-09-22 19:10:36 +08:00
|
|
|
* fine to output into stdout.
|
2018-09-22 18:46:45 +08:00
|
|
|
*/
|
2018-11-21 02:56:57 +08:00
|
|
|
if (!outname && !(operating_mode & OP_PREPROCESS)) {
|
|
|
|
outname = filename_set_extension(inname, ofmt->extension);
|
|
|
|
if (!strcmp(outname, inname)) {
|
|
|
|
outname = "nasm.out";
|
2018-12-15 05:33:24 +08:00
|
|
|
nasm_warn(WARN_OTHER, "default output file same as input, using `%s' for output\n", outname);
|
2018-11-21 02:56:57 +08:00
|
|
|
}
|
2018-09-22 18:46:45 +08:00
|
|
|
}
|
2017-12-21 05:33:49 +08:00
|
|
|
|
2018-12-14 14:48:14 +08:00
|
|
|
depend_list = (operating_mode & OP_DEPEND) ? strlist_alloc(true) : NULL;
|
2017-08-17 12:14:33 +08:00
|
|
|
|
2008-05-30 10:09:11 +08:00
|
|
|
if (!depend_target)
|
2013-02-15 16:24:11 +08:00
|
|
|
depend_target = quote_for_make(outname);
|
2008-05-30 10:09:11 +08:00
|
|
|
|
2018-11-29 04:36:53 +08:00
|
|
|
if (!(operating_mode & (OP_PREPROCESS|OP_NORMAL))) {
|
2007-04-14 00:47:53 +08:00
|
|
|
char *line;
|
2008-05-30 10:09:11 +08:00
|
|
|
|
2013-02-15 16:24:11 +08:00
|
|
|
if (depend_missing_ok)
|
|
|
|
preproc->include_path(NULL); /* "assume generated" */
|
2008-05-30 10:09:11 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
preproc->reset(inname, PP_DEPS, depend_list);
|
2005-01-16 06:15:51 +08:00
|
|
|
ofile = NULL;
|
|
|
|
while ((line = preproc->getline()))
|
|
|
|
nasm_free(line);
|
2018-12-19 03:12:46 +08:00
|
|
|
preproc->cleanup_pass();
|
2019-01-12 05:13:03 +08:00
|
|
|
reset_warnings();
|
2014-06-23 06:22:02 +08:00
|
|
|
} else if (operating_mode & OP_PREPROCESS) {
|
2007-04-14 00:47:53 +08:00
|
|
|
char *line;
|
2016-05-10 17:56:29 +08:00
|
|
|
const char *file_name = NULL;
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t prior_linnum = 0;
|
2005-01-16 06:15:51 +08:00
|
|
|
int lineinc = 0;
|
|
|
|
|
2017-12-21 05:33:49 +08:00
|
|
|
if (outname) {
|
2016-05-25 19:28:46 +08:00
|
|
|
ofile = nasm_open_write(outname, NF_TEXT);
|
2005-01-16 06:15:51 +08:00
|
|
|
if (!ofile)
|
2018-12-11 14:29:49 +08:00
|
|
|
nasm_fatal("unable to open output file `%s'", outname);
|
2005-01-16 06:15:51 +08:00
|
|
|
} else
|
|
|
|
ofile = NULL;
|
|
|
|
|
2007-10-11 05:58:45 +08:00
|
|
|
location.known = false;
|
2002-05-01 05:01:08 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
_pass_type = PASS_FIRST; /* We emulate this assembly pass */
|
|
|
|
preproc->reset(inname, PP_PREPROC, depend_list);
|
2017-03-08 17:26:40 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
while ((line = preproc->getline())) {
|
|
|
|
/*
|
|
|
|
* We generate %line directives if needed for later programs
|
|
|
|
*/
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t linnum = prior_linnum += lineinc;
|
2005-01-16 06:15:51 +08:00
|
|
|
int altline = src_get(&linnum, &file_name);
|
|
|
|
if (altline) {
|
|
|
|
if (altline == 1 && lineinc == 1)
|
|
|
|
nasm_fputs("", ofile);
|
|
|
|
else {
|
|
|
|
lineinc = (altline != -1 || lineinc != 1);
|
|
|
|
fprintf(ofile ? ofile : stdout,
|
2007-04-14 08:10:59 +08:00
|
|
|
"%%line %"PRId32"+%d %s\n", linnum, lineinc,
|
2005-01-16 06:15:51 +08:00
|
|
|
file_name);
|
|
|
|
}
|
|
|
|
prior_linnum = linnum;
|
|
|
|
}
|
|
|
|
nasm_fputs(line, ofile);
|
|
|
|
nasm_free(line);
|
|
|
|
}
|
2018-12-19 03:12:46 +08:00
|
|
|
preproc->cleanup_pass();
|
2019-01-12 05:13:03 +08:00
|
|
|
reset_warnings();
|
2005-01-16 06:15:51 +08:00
|
|
|
if (ofile)
|
|
|
|
fclose(ofile);
|
2018-06-15 08:04:32 +08:00
|
|
|
if (ofile && terminate_after_phase && !keep_all)
|
2005-01-16 06:15:51 +08:00
|
|
|
remove(outname);
|
2013-02-15 16:24:11 +08:00
|
|
|
ofile = NULL;
|
2014-06-24 04:55:17 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2014-06-24 04:55:17 +08:00
|
|
|
if (operating_mode & OP_NORMAL) {
|
2016-05-25 19:28:46 +08:00
|
|
|
ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
|
2014-06-24 04:55:17 +08:00
|
|
|
if (!ofile)
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_fatal("unable to open output file `%s'", outname);
|
2014-06-24 04:55:17 +08:00
|
|
|
|
|
|
|
ofmt->init();
|
|
|
|
dfmt->init();
|
|
|
|
|
2018-10-26 03:33:58 +08:00
|
|
|
assemble_file(inname, depend_list);
|
2014-06-24 04:55:17 +08:00
|
|
|
|
|
|
|
if (!terminate_after_phase) {
|
2016-03-08 14:53:06 +08:00
|
|
|
ofmt->cleanup();
|
2014-06-24 04:55:17 +08:00
|
|
|
cleanup_labels();
|
|
|
|
fflush(ofile);
|
2018-12-11 14:06:15 +08:00
|
|
|
if (ferror(ofile))
|
|
|
|
nasm_nonfatal("write error on output file `%s'", outname);
|
2014-06-24 04:55:17 +08:00
|
|
|
}
|
2013-02-15 16:24:11 +08:00
|
|
|
|
2014-06-24 04:55:17 +08:00
|
|
|
if (ofile) {
|
|
|
|
fclose(ofile);
|
2018-06-15 08:04:32 +08:00
|
|
|
if (terminate_after_phase && !keep_all)
|
2014-06-24 04:55:17 +08:00
|
|
|
remove(outname);
|
|
|
|
ofile = NULL;
|
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
2002-05-01 05:01:08 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
preproc->cleanup_session();
|
|
|
|
|
2009-06-28 06:34:32 +08:00
|
|
|
if (depend_list && !terminate_after_phase)
|
2013-02-15 16:24:11 +08:00
|
|
|
emit_dependencies(depend_list);
|
2008-05-30 10:09:11 +08:00
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
if (want_usage)
|
2005-01-16 06:15:51 +08:00
|
|
|
usage();
|
2002-05-01 05:01:08 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
raa_free(offsets);
|
|
|
|
saa_free(forwrefs);
|
|
|
|
eval_cleanup();
|
2007-08-31 06:35:34 +08:00
|
|
|
stdscan_cleanup();
|
2016-05-10 17:56:29 +08:00
|
|
|
src_free();
|
2018-12-14 16:17:13 +08:00
|
|
|
strlist_free(&include_path);
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2009-06-28 06:34:32 +08:00
|
|
|
return terminate_after_phase;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
/*
|
|
|
|
* Get a parameter for a command line option.
|
|
|
|
* First arg must be in the form of e.g. -f...
|
|
|
|
*/
|
2007-11-16 09:12:29 +08:00
|
|
|
static char *get_param(char *p, char *q, bool *advance)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2007-11-16 09:12:29 +08:00
|
|
|
*advance = false;
|
2009-10-13 23:38:52 +08:00
|
|
|
if (p[2]) /* the parameter's in the option */
|
|
|
|
return nasm_skip_spaces(p + 2);
|
2005-01-16 06:15:51 +08:00
|
|
|
if (q && q[0]) {
|
2007-11-16 09:12:29 +08:00
|
|
|
*advance = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
return q;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatalf(ERR_USAGE, "option `-%c' requires an argument", p[1]);
|
2002-05-01 04:53:55 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-19 03:55:10 +08:00
|
|
|
/*
|
|
|
|
* Copy a filename
|
|
|
|
*/
|
2017-12-21 05:33:49 +08:00
|
|
|
static void copy_filename(const char **dst, const char *src, const char *what)
|
2007-11-19 03:55:10 +08:00
|
|
|
{
|
2017-12-21 05:33:49 +08:00
|
|
|
if (*dst)
|
2018-06-16 09:20:17 +08:00
|
|
|
nasm_fatal("more than one %s file specified: %s\n", what, src);
|
2007-11-19 03:55:10 +08:00
|
|
|
|
2017-12-21 05:33:49 +08:00
|
|
|
*dst = nasm_strdup(src);
|
2007-11-19 03:55:10 +08:00
|
|
|
}
|
|
|
|
|
2008-05-30 10:09:11 +08:00
|
|
|
/*
|
2017-08-17 12:14:33 +08:00
|
|
|
* Convert a string to a POSIX make-safe form
|
2008-05-30 10:09:11 +08:00
|
|
|
*/
|
2017-08-17 12:14:33 +08:00
|
|
|
static char *quote_for_pmake(const char *str)
|
2008-05-30 10:09:11 +08:00
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
char *os, *q;
|
|
|
|
|
2013-02-15 16:22:27 +08:00
|
|
|
size_t n = 1; /* Terminating zero */
|
2008-05-30 10:09:11 +08:00
|
|
|
size_t nbs = 0;
|
|
|
|
|
|
|
|
if (!str)
|
2013-02-15 16:22:27 +08:00
|
|
|
return NULL;
|
2008-05-30 10:09:11 +08:00
|
|
|
|
|
|
|
for (p = str; *p; p++) {
|
2013-02-15 16:22:27 +08:00
|
|
|
switch (*p) {
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
/* Convert N backslashes + ws -> 2N+1 backslashes + ws */
|
|
|
|
n += nbs + 2;
|
|
|
|
nbs = 0;
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
case '#':
|
|
|
|
nbs = 0;
|
|
|
|
n += 2;
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
nbs++;
|
|
|
|
n++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nbs = 0;
|
|
|
|
n++;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-30 10:09:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert N backslashes at the end of filename to 2N backslashes */
|
|
|
|
if (nbs)
|
2013-02-15 16:22:27 +08:00
|
|
|
n += nbs;
|
2008-05-30 10:09:11 +08:00
|
|
|
|
|
|
|
os = q = nasm_malloc(n);
|
|
|
|
|
|
|
|
nbs = 0;
|
|
|
|
for (p = str; *p; p++) {
|
2013-02-15 16:22:27 +08:00
|
|
|
switch (*p) {
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
while (nbs--)
|
|
|
|
*q++ = '\\';
|
|
|
|
*q++ = '\\';
|
|
|
|
*q++ = *p;
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
*q++ = *p;
|
|
|
|
*q++ = *p;
|
|
|
|
nbs = 0;
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
*q++ = '\\';
|
|
|
|
*q++ = *p;
|
|
|
|
nbs = 0;
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
*q++ = *p;
|
|
|
|
nbs++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*q++ = *p;
|
|
|
|
nbs = 0;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-30 10:09:11 +08:00
|
|
|
}
|
|
|
|
while (nbs--)
|
2013-02-15 16:22:27 +08:00
|
|
|
*q++ = '\\';
|
2008-05-30 10:09:11 +08:00
|
|
|
|
|
|
|
*q = '\0';
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2017-08-17 12:14:33 +08:00
|
|
|
/*
|
|
|
|
* Convert a string to a Watcom make-safe form
|
|
|
|
*/
|
|
|
|
static char *quote_for_wmake(const char *str)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
char *os, *q;
|
2017-08-17 13:15:39 +08:00
|
|
|
bool quote = false;
|
2017-08-17 12:14:33 +08:00
|
|
|
|
|
|
|
size_t n = 1; /* Terminating zero */
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (p = str; *p; p++) {
|
|
|
|
switch (*p) {
|
2017-08-17 13:15:39 +08:00
|
|
|
case ' ':
|
|
|
|
case '\t':
|
2017-08-17 13:20:36 +08:00
|
|
|
case '&':
|
2017-08-17 13:15:39 +08:00
|
|
|
quote = true;
|
|
|
|
n++;
|
|
|
|
break;
|
|
|
|
case '\"':
|
|
|
|
quote = true;
|
|
|
|
n += 2;
|
|
|
|
break;
|
2017-08-17 12:14:33 +08:00
|
|
|
case '$':
|
|
|
|
case '#':
|
|
|
|
n += 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
n++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 13:15:39 +08:00
|
|
|
if (quote)
|
|
|
|
n += 2;
|
|
|
|
|
2017-08-17 12:14:33 +08:00
|
|
|
os = q = nasm_malloc(n);
|
|
|
|
|
2017-08-17 13:15:39 +08:00
|
|
|
if (quote)
|
|
|
|
*q++ = '\"';
|
|
|
|
|
2017-08-17 12:14:33 +08:00
|
|
|
for (p = str; *p; p++) {
|
|
|
|
switch (*p) {
|
|
|
|
case '$':
|
|
|
|
case '#':
|
|
|
|
*q++ = '$';
|
|
|
|
*q++ = *p;
|
|
|
|
break;
|
2017-08-17 13:15:39 +08:00
|
|
|
case '\"':
|
|
|
|
*q++ = *p;
|
|
|
|
*q++ = *p;
|
|
|
|
break;
|
2017-08-17 12:14:33 +08:00
|
|
|
default:
|
|
|
|
*q++ = *p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 13:15:39 +08:00
|
|
|
if (quote)
|
|
|
|
*q++ = '\"';
|
|
|
|
|
2017-08-17 12:14:33 +08:00
|
|
|
*q = '\0';
|
|
|
|
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2015-11-11 05:07:20 +08:00
|
|
|
enum text_options {
|
2018-02-08 06:14:36 +08:00
|
|
|
OPT_BOGUS,
|
|
|
|
OPT_VERSION,
|
2018-06-13 04:50:37 +08:00
|
|
|
OPT_HELP,
|
2018-02-08 06:14:36 +08:00
|
|
|
OPT_ABORT_ON_PANIC,
|
2018-06-12 04:32:42 +08:00
|
|
|
OPT_MANGLE,
|
|
|
|
OPT_INCLUDE,
|
|
|
|
OPT_PRAGMA,
|
2018-06-13 04:50:37 +08:00
|
|
|
OPT_BEFORE,
|
2018-06-15 08:04:32 +08:00
|
|
|
OPT_LIMIT,
|
2018-12-15 04:22:11 +08:00
|
|
|
OPT_KEEP_ALL,
|
2019-08-09 19:28:55 +08:00
|
|
|
OPT_NO_LINE,
|
|
|
|
OPT_DEBUG
|
2015-11-11 05:07:20 +08:00
|
|
|
};
|
2019-08-10 07:10:17 +08:00
|
|
|
enum need_arg {
|
|
|
|
ARG_NO,
|
|
|
|
ARG_YES,
|
|
|
|
ARG_MAYBE
|
|
|
|
};
|
|
|
|
|
2018-02-08 06:14:36 +08:00
|
|
|
struct textargs {
|
|
|
|
const char *label;
|
|
|
|
enum text_options opt;
|
2019-08-10 07:10:17 +08:00
|
|
|
enum need_arg need_arg;
|
2018-06-02 09:02:54 +08:00
|
|
|
int pvt;
|
2018-02-08 06:14:36 +08:00
|
|
|
};
|
2016-02-18 18:28:15 +08:00
|
|
|
static const struct textargs textopts[] = {
|
2019-08-10 07:10:17 +08:00
|
|
|
{"v", OPT_VERSION, ARG_NO, 0},
|
|
|
|
{"version", OPT_VERSION, ARG_NO, 0},
|
|
|
|
{"help", OPT_HELP, ARG_NO, 0},
|
|
|
|
{"abort-on-panic", OPT_ABORT_ON_PANIC, ARG_NO, 0},
|
|
|
|
{"prefix", OPT_MANGLE, ARG_YES, LM_GPREFIX},
|
|
|
|
{"postfix", OPT_MANGLE, ARG_YES, LM_GSUFFIX},
|
|
|
|
{"gprefix", OPT_MANGLE, ARG_YES, LM_GPREFIX},
|
|
|
|
{"gpostfix", OPT_MANGLE, ARG_YES, LM_GSUFFIX},
|
|
|
|
{"lprefix", OPT_MANGLE, ARG_YES, LM_LPREFIX},
|
|
|
|
{"lpostfix", OPT_MANGLE, ARG_YES, LM_LSUFFIX},
|
|
|
|
{"include", OPT_INCLUDE, ARG_YES, 0},
|
|
|
|
{"pragma", OPT_PRAGMA, ARG_YES, 0},
|
|
|
|
{"before", OPT_BEFORE, ARG_YES, 0},
|
|
|
|
{"limit-", OPT_LIMIT, ARG_YES, 0},
|
|
|
|
{"keep-all", OPT_KEEP_ALL, ARG_NO, 0},
|
|
|
|
{"no-line", OPT_NO_LINE, ARG_NO, 0},
|
|
|
|
{"debug", OPT_DEBUG, ARG_MAYBE, 0},
|
|
|
|
{NULL, OPT_BOGUS, ARG_NO, 0}
|
2002-05-01 05:00:33 +08:00
|
|
|
};
|
|
|
|
|
2014-05-10 02:34:34 +08:00
|
|
|
static void show_version(void)
|
|
|
|
{
|
|
|
|
printf("NASM version %s compiled on %s%s\n",
|
|
|
|
nasm_version, nasm_date, nasm_compile_options);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2007-11-16 09:12:29 +08:00
|
|
|
static bool stopoptions = false;
|
2016-10-04 10:46:49 +08:00
|
|
|
static bool process_arg(char *p, char *q, int pass)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2007-04-14 00:47:53 +08:00
|
|
|
char *param;
|
2007-11-16 09:12:29 +08:00
|
|
|
bool advance = false;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2002-05-01 04:52:26 +08:00
|
|
|
if (!p || !p[0])
|
2007-11-16 09:12:29 +08:00
|
|
|
return false;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
if (p[0] == '-' && !stopoptions) {
|
2019-08-09 23:06:39 +08:00
|
|
|
if (strchr("oOfpPdDiIlLFXuUZwW", p[1])) {
|
2013-02-15 16:20:58 +08:00
|
|
|
/* These parameters take values */
|
|
|
|
if (!(param = get_param(p, q, &advance)))
|
|
|
|
return advance;
|
|
|
|
}
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
switch (p[1]) {
|
|
|
|
case 's':
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 1)
|
|
|
|
error_file = stdout;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'o': /* output file */
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 2)
|
2017-12-21 05:33:49 +08:00
|
|
|
copy_filename(&outname, param, "output");
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'f': /* output format */
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 1) {
|
|
|
|
ofmt = ofmt_find(param, &ofmt_alias);
|
|
|
|
if (!ofmt) {
|
2018-12-11 14:29:49 +08:00
|
|
|
nasm_fatalf(ERR_USAGE, "unrecognised output format `%s' - use -hf for a list", param);
|
2016-10-04 10:46:49 +08:00
|
|
|
}
|
2013-02-15 16:20:58 +08:00
|
|
|
}
|
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'O': /* Optimization level */
|
2018-11-12 05:25:16 +08:00
|
|
|
if (pass == 1) {
|
2016-10-04 10:46:49 +08:00
|
|
|
int opt;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
if (!*param) {
|
|
|
|
/* Naked -O == -Ox */
|
2018-08-16 04:22:21 +08:00
|
|
|
optimizing.level = MAX_OPTIMIZE;
|
2016-10-04 10:46:49 +08:00
|
|
|
} else {
|
|
|
|
while (*param) {
|
|
|
|
switch (*param) {
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
opt = strtoul(param, ¶m, 10);
|
|
|
|
|
2018-08-16 04:22:21 +08:00
|
|
|
/* -O0 -> optimizing.level == -1, 0.98 behaviour */
|
|
|
|
/* -O1 -> optimizing.level == 0, 0.98.09 behaviour */
|
2016-10-04 10:46:49 +08:00
|
|
|
if (opt < 2)
|
2018-08-16 04:22:21 +08:00
|
|
|
optimizing.level = opt - 1;
|
2016-10-04 10:46:49 +08:00
|
|
|
else
|
2018-08-16 04:22:21 +08:00
|
|
|
optimizing.level = opt;
|
2016-10-04 10:46:49 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
case 'v':
|
|
|
|
case '+':
|
2013-02-15 16:20:58 +08:00
|
|
|
param++;
|
|
|
|
opt_verbose_info = true;
|
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
case 'x':
|
|
|
|
param++;
|
2018-08-16 04:22:21 +08:00
|
|
|
optimizing.level = MAX_OPTIMIZE;
|
2016-10-04 10:46:49 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
default:
|
2018-06-16 09:20:17 +08:00
|
|
|
nasm_fatal("unknown optimization option -O%c\n",
|
2016-10-04 10:46:49 +08:00
|
|
|
*param);
|
|
|
|
break;
|
|
|
|
}
|
2013-02-15 16:20:58 +08:00
|
|
|
}
|
2018-08-16 04:22:21 +08:00
|
|
|
if (optimizing.level > MAX_OPTIMIZE)
|
|
|
|
optimizing.level = MAX_OPTIMIZE;
|
2013-02-15 16:20:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'p': /* pre-include */
|
|
|
|
case 'P':
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 2)
|
|
|
|
preproc->pre_include(param);
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'd': /* pre-define */
|
|
|
|
case 'D':
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 2)
|
|
|
|
preproc->pre_define(param);
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'u': /* un-define */
|
|
|
|
case 'U':
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 2)
|
|
|
|
preproc->pre_undefine(param);
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': /* include search path */
|
|
|
|
case 'I':
|
2018-11-12 05:25:16 +08:00
|
|
|
if (pass == 1)
|
2018-11-12 02:33:52 +08:00
|
|
|
strlist_add(include_path, param);
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': /* listing file */
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 2)
|
2017-12-21 05:33:49 +08:00
|
|
|
copy_filename(&listname, param, "listing");
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
|
|
|
|
2019-08-09 23:06:39 +08:00
|
|
|
case 'L': /* listing options */
|
|
|
|
if (pass == 2) {
|
2019-08-11 09:04:04 +08:00
|
|
|
while (*param)
|
|
|
|
list_options |= list_option_mask(*param++);
|
2019-08-09 23:06:39 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'Z': /* error messages file */
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 1)
|
2017-12-21 05:33:49 +08:00
|
|
|
copy_filename(&errname, param, "error");
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F': /* specify debug format */
|
2018-11-12 05:25:16 +08:00
|
|
|
if (pass == 1) {
|
2016-10-04 10:46:49 +08:00
|
|
|
using_debug_info = true;
|
|
|
|
debug_format = param;
|
|
|
|
}
|
2013-02-15 16:20:58 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'X': /* specify error reporting format */
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 1) {
|
2018-12-11 14:29:49 +08:00
|
|
|
if (!nasm_stricmp("vc", param) || !nasm_stricmp("msvc", param) || !nasm_stricmp("ms", param))
|
|
|
|
errfmt = &errfmt_msvc;
|
|
|
|
else if (!nasm_stricmp("gnu", param) || !nasm_stricmp("gcc", param))
|
|
|
|
errfmt = &errfmt_gnu;
|
2016-10-04 10:46:49 +08:00
|
|
|
else
|
2018-12-11 14:29:49 +08:00
|
|
|
nasm_fatalf(ERR_USAGE, "unrecognized error reporting format `%s'", param);
|
2016-10-04 10:46:49 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
case 'g':
|
2018-11-12 05:25:16 +08:00
|
|
|
if (pass == 1) {
|
2016-10-04 10:46:49 +08:00
|
|
|
using_debug_info = true;
|
|
|
|
if (p[2])
|
|
|
|
debug_format = nasm_skip_spaces(p + 2);
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
case 'h':
|
2019-08-10 16:38:06 +08:00
|
|
|
help(stdout);
|
2013-02-15 16:20:58 +08:00
|
|
|
exit(0); /* never need usage message here */
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
case 'y':
|
2019-08-10 16:38:06 +08:00
|
|
|
/* legacy option */
|
|
|
|
dfmt_list(stdout);
|
2005-01-16 06:15:51 +08:00
|
|
|
exit(0);
|
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
case 't':
|
2018-11-29 06:55:58 +08:00
|
|
|
if (pass == 2) {
|
2016-10-04 10:46:49 +08:00
|
|
|
tasm_compatible_mode = true;
|
2018-11-29 06:55:58 +08:00
|
|
|
nasm_ctype_tasm_mode();
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
case 'v':
|
2014-05-10 02:34:34 +08:00
|
|
|
show_version();
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'e': /* preprocess only */
|
|
|
|
case 'E':
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 1)
|
|
|
|
operating_mode = OP_PREPROCESS;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2013-02-15 16:20:58 +08:00
|
|
|
case 'a': /* assemble only - don't preprocess */
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass == 1)
|
|
|
|
preproc = &preproc_nop;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
case 'w':
|
2017-03-08 17:26:40 +08:00
|
|
|
case 'W':
|
2018-12-14 13:53:31 +08:00
|
|
|
if (pass == 2)
|
|
|
|
set_warning_status(param);
|
2017-03-08 17:26:40 +08:00
|
|
|
break;
|
2007-11-16 09:12:29 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
case 'M':
|
2017-08-17 12:14:33 +08:00
|
|
|
if (pass == 1) {
|
|
|
|
switch (p[2]) {
|
|
|
|
case 'W':
|
|
|
|
quote_for_make = quote_for_wmake;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
case 'F':
|
|
|
|
case 'T':
|
|
|
|
case 'Q':
|
|
|
|
advance = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-04 10:46:49 +08:00
|
|
|
switch (p[2]) {
|
|
|
|
case 0:
|
|
|
|
operating_mode = OP_DEPEND;
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
operating_mode = OP_DEPEND;
|
|
|
|
depend_missing_ok = true;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
depend_emit_phony = true;
|
|
|
|
break;
|
|
|
|
case 'D':
|
2018-11-29 04:36:53 +08:00
|
|
|
operating_mode |= OP_DEPEND;
|
|
|
|
if (q && (q[0] != '-' || q[1] == '\0')) {
|
|
|
|
depend_file = q;
|
|
|
|
advance = true;
|
|
|
|
}
|
2016-10-04 10:46:49 +08:00
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
depend_file = q;
|
|
|
|
advance = true;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
depend_target = q;
|
|
|
|
advance = true;
|
|
|
|
break;
|
|
|
|
case 'Q':
|
|
|
|
depend_target = quote_for_make(q);
|
|
|
|
advance = true;
|
|
|
|
break;
|
2017-08-17 12:14:33 +08:00
|
|
|
case 'W':
|
|
|
|
/* handled in pass 1 */
|
|
|
|
break;
|
2016-10-04 10:46:49 +08:00
|
|
|
default:
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatalf(ERR_USAGE, "unknown dependency option `-M%c'", p[2]);
|
2016-10-04 10:46:49 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-08-17 12:14:33 +08:00
|
|
|
}
|
|
|
|
if (advance && (!q || !q[0])) {
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatalf(ERR_USAGE, "option `-M%c' requires a parameter", p[2]);
|
2017-08-17 12:14:33 +08:00
|
|
|
break;
|
2013-02-15 16:20:58 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
|
|
|
{
|
2018-02-08 06:14:36 +08:00
|
|
|
const struct textargs *tx;
|
2018-06-13 04:50:37 +08:00
|
|
|
size_t olen, plen;
|
2018-06-13 05:23:05 +08:00
|
|
|
char *eqsave;
|
2019-08-10 07:10:17 +08:00
|
|
|
enum text_options opt;
|
2018-06-13 04:50:37 +08:00
|
|
|
|
|
|
|
p += 2;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2018-06-13 04:50:37 +08:00
|
|
|
if (!*p) { /* -- => stop processing options */
|
2018-02-08 06:14:36 +08:00
|
|
|
stopoptions = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-05-10 02:34:34 +08:00
|
|
|
|
2018-12-15 05:02:39 +08:00
|
|
|
olen = 0; /* Placate gcc at lower optimization levels */
|
2018-06-13 04:50:37 +08:00
|
|
|
plen = strlen(p);
|
2018-02-08 06:14:36 +08:00
|
|
|
for (tx = textopts; tx->label; tx++) {
|
2018-06-13 04:50:37 +08:00
|
|
|
olen = strlen(tx->label);
|
|
|
|
|
|
|
|
if (olen > plen)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nasm_memicmp(p, tx->label, olen))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tx->label[olen-1] == '-')
|
|
|
|
break; /* Incomplete option */
|
|
|
|
|
|
|
|
if (!p[olen] || p[olen] == '=')
|
|
|
|
break; /* Complete option */
|
2018-02-08 06:14:36 +08:00
|
|
|
}
|
2016-09-13 05:02:21 +08:00
|
|
|
|
2018-06-13 04:50:37 +08:00
|
|
|
if (!tx->label) {
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatalf(ERR_USAGE, "unrecognized option `--%s'", p);
|
2018-06-13 04:50:37 +08:00
|
|
|
}
|
|
|
|
|
2019-08-10 07:10:17 +08:00
|
|
|
opt = tx->opt;
|
|
|
|
|
2018-06-13 05:23:05 +08:00
|
|
|
eqsave = param = strchr(p+olen, '=');
|
2018-06-13 04:50:37 +08:00
|
|
|
if (param)
|
|
|
|
*param++ = '\0';
|
|
|
|
|
2019-08-10 07:10:17 +08:00
|
|
|
switch (tx->need_arg) {
|
|
|
|
case ARG_YES: /* Argument required, and may be standalone */
|
2018-06-13 04:50:37 +08:00
|
|
|
if (!param) {
|
|
|
|
param = q;
|
|
|
|
advance = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: a null string is a valid parameter */
|
|
|
|
if (!param) {
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatalf(ERR_USAGE, "option `--%s' requires an argument", p);
|
2019-08-10 07:10:17 +08:00
|
|
|
opt = OPT_BOGUS;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2019-08-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_NO: /* Argument prohibited */
|
2018-06-13 04:50:37 +08:00
|
|
|
if (param) {
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatalf(ERR_USAGE, "option `--%s' does not take an argument", p);
|
2019-08-10 07:10:17 +08:00
|
|
|
opt = OPT_BOGUS;
|
2018-06-13 04:50:37 +08:00
|
|
|
}
|
2019-08-10 07:10:17 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_MAYBE: /* Argument permitted, but must be attached with = */
|
|
|
|
break;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
|
2019-08-10 07:10:17 +08:00
|
|
|
switch (opt) {
|
|
|
|
case OPT_BOGUS:
|
|
|
|
break; /* We have already errored out */
|
2018-02-08 06:14:36 +08:00
|
|
|
case OPT_VERSION:
|
|
|
|
show_version();
|
|
|
|
break;
|
|
|
|
case OPT_ABORT_ON_PANIC:
|
|
|
|
abort_on_panic = true;
|
|
|
|
break;
|
2018-06-02 09:02:54 +08:00
|
|
|
case OPT_MANGLE:
|
2018-02-08 06:14:36 +08:00
|
|
|
if (pass == 2)
|
2018-06-13 04:50:37 +08:00
|
|
|
set_label_mangle(tx->pvt, param);
|
2018-02-08 06:14:36 +08:00
|
|
|
break;
|
2018-06-12 04:32:42 +08:00
|
|
|
case OPT_INCLUDE:
|
|
|
|
if (pass == 2)
|
|
|
|
preproc->pre_include(q);
|
|
|
|
break;
|
|
|
|
case OPT_PRAGMA:
|
|
|
|
if (pass == 2)
|
2018-06-13 04:50:37 +08:00
|
|
|
preproc->pre_command("pragma", param);
|
2018-06-12 04:32:42 +08:00
|
|
|
break;
|
|
|
|
case OPT_BEFORE:
|
|
|
|
if (pass == 2)
|
2018-06-13 04:50:37 +08:00
|
|
|
preproc->pre_command(NULL, param);
|
2018-06-12 04:32:42 +08:00
|
|
|
break;
|
2018-06-13 04:50:37 +08:00
|
|
|
case OPT_LIMIT:
|
2018-11-12 05:25:16 +08:00
|
|
|
if (pass == 1)
|
2018-06-13 04:50:37 +08:00
|
|
|
nasm_set_limit(p+olen, param);
|
2018-02-08 06:14:36 +08:00
|
|
|
break;
|
2018-06-15 08:04:32 +08:00
|
|
|
case OPT_KEEP_ALL:
|
|
|
|
keep_all = true;
|
|
|
|
break;
|
2018-12-15 04:22:11 +08:00
|
|
|
case OPT_NO_LINE:
|
|
|
|
pp_noline = true;
|
|
|
|
break;
|
2019-08-09 19:28:55 +08:00
|
|
|
case OPT_DEBUG:
|
2019-08-10 07:10:17 +08:00
|
|
|
debug_nasm = param ? strtoul(param, NULL, 10) : debug_nasm+1;
|
2019-08-09 19:28:55 +08:00
|
|
|
break;
|
2018-06-13 04:50:37 +08:00
|
|
|
case OPT_HELP:
|
2019-08-10 16:38:06 +08:00
|
|
|
help(stdout);
|
2018-06-13 04:50:37 +08:00
|
|
|
exit(0);
|
2005-01-16 06:15:51 +08:00
|
|
|
default:
|
2018-02-08 06:14:36 +08:00
|
|
|
panic();
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2018-06-13 05:23:05 +08:00
|
|
|
|
|
|
|
if (eqsave)
|
|
|
|
*eqsave = '='; /* Restore = argument separator */
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2018-12-11 14:06:15 +08:00
|
|
|
nasm_nonfatalf(ERR_USAGE, "unrecognised option `-%c'", p[1]);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-10-04 10:46:49 +08:00
|
|
|
} else if (pass == 2) {
|
2017-12-21 05:33:49 +08:00
|
|
|
/* In theory we could allow multiple input files... */
|
|
|
|
copy_filename(&inname, p, "input");
|
2002-05-01 04:52:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return advance;
|
|
|
|
}
|
|
|
|
|
2002-05-01 04:53:55 +08:00
|
|
|
#define ARG_BUF_DELTA 128
|
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
static void process_respfile(FILE * rfile, int pass)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2007-04-14 00:47:53 +08:00
|
|
|
char *buffer, *p, *q, *prevarg;
|
2002-05-01 04:53:55 +08:00
|
|
|
int bufsize, prevargsize;
|
|
|
|
|
|
|
|
bufsize = prevargsize = ARG_BUF_DELTA;
|
|
|
|
buffer = nasm_malloc(ARG_BUF_DELTA);
|
|
|
|
prevarg = nasm_malloc(ARG_BUF_DELTA);
|
|
|
|
prevarg[0] = '\0';
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
while (1) { /* Loop to handle all lines in file */
|
|
|
|
p = buffer;
|
|
|
|
while (1) { /* Loop to handle long lines */
|
|
|
|
q = fgets(p, bufsize - (p - buffer), rfile);
|
|
|
|
if (!q)
|
|
|
|
break;
|
|
|
|
p += strlen(p);
|
|
|
|
if (p > buffer && p[-1] == '\n')
|
|
|
|
break;
|
|
|
|
if (p - buffer > bufsize - 10) {
|
|
|
|
int offset;
|
|
|
|
offset = p - buffer;
|
|
|
|
bufsize += ARG_BUF_DELTA;
|
|
|
|
buffer = nasm_realloc(buffer, bufsize);
|
|
|
|
p = buffer + offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!q && p == buffer) {
|
|
|
|
if (prevarg[0])
|
2016-10-04 10:46:49 +08:00
|
|
|
process_arg(prevarg, NULL, pass);
|
2005-01-16 06:15:51 +08:00
|
|
|
nasm_free(buffer);
|
|
|
|
nasm_free(prevarg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Play safe: remove CRs, LFs and any spurious ^Zs, if any of
|
|
|
|
* them are present at the end of the line.
|
|
|
|
*/
|
|
|
|
*(p = &buffer[strcspn(buffer, "\r\n\032")]) = '\0';
|
|
|
|
|
2008-06-22 01:23:17 +08:00
|
|
|
while (p > buffer && nasm_isspace(p[-1]))
|
2005-01-16 06:15:51 +08:00
|
|
|
*--p = '\0';
|
|
|
|
|
2009-10-13 23:38:52 +08:00
|
|
|
p = nasm_skip_spaces(buffer);
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
if (process_arg(prevarg, p, pass))
|
2005-01-16 06:15:51 +08:00
|
|
|
*p = '\0';
|
|
|
|
|
2007-10-19 10:02:42 +08:00
|
|
|
if ((int) strlen(p) > prevargsize - 10) {
|
2005-01-16 06:15:51 +08:00
|
|
|
prevargsize += ARG_BUF_DELTA;
|
|
|
|
prevarg = nasm_realloc(prevarg, prevargsize);
|
|
|
|
}
|
2007-11-19 03:55:10 +08:00
|
|
|
strncpy(prevarg, p, prevargsize);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-01 05:00:33 +08:00
|
|
|
/* Function to process args from a string of args, rather than the
|
|
|
|
* argv array. Used by the environment variable and response file
|
|
|
|
* processing.
|
|
|
|
*/
|
2016-10-04 10:46:49 +08:00
|
|
|
static void process_args(char *args, int pass)
|
2005-01-16 06:15:51 +08:00
|
|
|
{
|
2007-04-14 00:47:53 +08:00
|
|
|
char *p, *q, *arg, *prevarg;
|
|
|
|
char separator = ' ';
|
2002-05-01 05:00:33 +08:00
|
|
|
|
|
|
|
p = args;
|
|
|
|
if (*p && *p != '-')
|
2005-01-16 06:15:51 +08:00
|
|
|
separator = *p++;
|
2002-05-01 05:00:33 +08:00
|
|
|
arg = NULL;
|
|
|
|
while (*p) {
|
2005-01-16 06:15:51 +08:00
|
|
|
q = p;
|
|
|
|
while (*p && *p != separator)
|
|
|
|
p++;
|
|
|
|
while (*p == separator)
|
|
|
|
*p++ = '\0';
|
|
|
|
prevarg = arg;
|
|
|
|
arg = q;
|
2016-10-04 10:46:49 +08:00
|
|
|
if (process_arg(prevarg, arg, pass))
|
2005-01-16 06:15:51 +08:00
|
|
|
arg = NULL;
|
2002-05-01 05:00:33 +08:00
|
|
|
}
|
|
|
|
if (arg)
|
2016-10-04 10:46:49 +08:00
|
|
|
process_arg(arg, NULL, pass);
|
2002-05-01 05:00:33 +08:00
|
|
|
}
|
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
static void process_response_file(const char *file, int pass)
|
2008-01-22 08:23:59 +08:00
|
|
|
{
|
|
|
|
char str[2048];
|
2016-05-25 19:28:46 +08:00
|
|
|
FILE *f = nasm_open_read(file, NF_TEXT);
|
2008-01-22 08:23:59 +08:00
|
|
|
if (!f) {
|
2013-02-15 16:14:06 +08:00
|
|
|
perror(file);
|
|
|
|
exit(-1);
|
2008-01-22 08:23:59 +08:00
|
|
|
}
|
|
|
|
while (fgets(str, sizeof str, f)) {
|
2016-10-04 10:46:49 +08:00
|
|
|
process_args(str, pass);
|
2008-01-22 08:23:59 +08:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2016-10-04 10:46:49 +08:00
|
|
|
static void parse_cmdline(int argc, char **argv, int pass)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
|
|
|
FILE *rfile;
|
2011-07-17 17:55:25 +08:00
|
|
|
char *envreal, *envcopy = NULL, *p;
|
2002-05-01 04:52:26 +08:00
|
|
|
|
2018-12-13 07:58:32 +08:00
|
|
|
/*
|
|
|
|
* Initialize all the warnings to their default state, including
|
|
|
|
* warning index 0 used for "always on".
|
|
|
|
*/
|
2019-01-12 05:13:03 +08:00
|
|
|
memcpy(warning_state, warning_default, sizeof warning_state);
|
2002-05-01 04:52:26 +08:00
|
|
|
|
|
|
|
/*
|
2002-05-07 03:41:57 +08:00
|
|
|
* First, process the NASMENV environment variable.
|
2002-05-01 04:52:26 +08:00
|
|
|
*/
|
2002-05-07 03:41:57 +08:00
|
|
|
envreal = getenv("NASMENV");
|
2002-05-01 04:52:26 +08:00
|
|
|
if (envreal) {
|
2005-01-16 06:15:51 +08:00
|
|
|
envcopy = nasm_strdup(envreal);
|
2016-10-04 10:46:49 +08:00
|
|
|
process_args(envcopy, pass);
|
2005-01-16 06:15:51 +08:00
|
|
|
nasm_free(envcopy);
|
2002-05-01 04:52:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now process the actual command line.
|
|
|
|
*/
|
2005-01-16 06:15:51 +08:00
|
|
|
while (--argc) {
|
2011-12-05 05:44:43 +08:00
|
|
|
bool advance;
|
2005-01-16 06:15:51 +08:00
|
|
|
argv++;
|
|
|
|
if (argv[0][0] == '@') {
|
2011-12-05 05:44:43 +08:00
|
|
|
/*
|
|
|
|
* We have a response file, so process this as a set of
|
2005-01-16 06:15:51 +08:00
|
|
|
* arguments like the environment variable. This allows us
|
|
|
|
* to have multiple arguments on a single line, which is
|
|
|
|
* different to the -@resp file processing below for regular
|
|
|
|
* NASM.
|
|
|
|
*/
|
2016-10-04 10:46:49 +08:00
|
|
|
process_response_file(argv[0]+1, pass);
|
2005-01-16 06:15:51 +08:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
if (!stopoptions && argv[0][0] == '-' && argv[0][1] == '@') {
|
2011-12-05 05:44:43 +08:00
|
|
|
p = get_param(argv[0], argc > 1 ? argv[1] : NULL, &advance);
|
2007-04-14 00:47:53 +08:00
|
|
|
if (p) {
|
2016-05-25 19:28:46 +08:00
|
|
|
rfile = nasm_open_read(p, NF_TEXT);
|
2007-04-14 00:47:53 +08:00
|
|
|
if (rfile) {
|
2016-10-04 10:46:49 +08:00
|
|
|
process_respfile(rfile, pass);
|
2005-01-16 06:15:51 +08:00
|
|
|
fclose(rfile);
|
2018-12-11 14:06:15 +08:00
|
|
|
} else {
|
|
|
|
nasm_nonfatalf(ERR_USAGE, "unable to open response file `%s'", p);
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
} else
|
2016-10-04 10:46:49 +08:00
|
|
|
advance = process_arg(argv[0], argc > 1 ? argv[1] : NULL, pass);
|
2007-11-16 09:12:29 +08:00
|
|
|
argv += advance, argc -= advance;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
2002-05-01 04:52:26 +08:00
|
|
|
|
2011-12-05 05:44:43 +08:00
|
|
|
/*
|
|
|
|
* Look for basic command line typos. This definitely doesn't
|
|
|
|
* catch all errors, but it might help cases of fumbled fingers.
|
|
|
|
*/
|
2016-10-04 10:46:49 +08:00
|
|
|
if (pass != 2)
|
|
|
|
return;
|
|
|
|
|
2017-12-21 05:33:49 +08:00
|
|
|
if (!inname)
|
2018-12-11 14:29:49 +08:00
|
|
|
nasm_fatalf(ERR_USAGE, "no input file specified");
|
2017-12-21 05:33:49 +08:00
|
|
|
else if ((errname && !strcmp(inname, errname)) ||
|
|
|
|
(outname && !strcmp(inname, outname)) ||
|
|
|
|
(listname && !strcmp(inname, listname)) ||
|
2011-12-05 05:44:43 +08:00
|
|
|
(depend_file && !strcmp(inname, depend_file)))
|
2018-11-25 03:17:47 +08:00
|
|
|
nasm_fatalf(ERR_USAGE, "will not overwrite input file");
|
2007-10-02 02:26:31 +08:00
|
|
|
|
2017-12-21 05:33:49 +08:00
|
|
|
if (errname) {
|
2016-05-25 19:28:46 +08:00
|
|
|
error_file = nasm_open_write(errname, NF_TEXT);
|
2011-12-05 05:44:43 +08:00
|
|
|
if (!error_file) {
|
|
|
|
error_file = stderr; /* Revert to default! */
|
2018-12-11 14:29:49 +08:00
|
|
|
nasm_fatalf(ERR_USAGE, "cannot open file `%s' for error messages", errname);
|
2011-12-05 05:44:43 +08:00
|
|
|
}
|
2007-10-01 13:15:36 +08:00
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2018-12-19 11:14:40 +08:00
|
|
|
static void forward_refs(insn *instruction)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct forwrefinfo *fwinf;
|
|
|
|
|
|
|
|
instruction->forw_ref = false;
|
|
|
|
|
|
|
|
if (!optimizing.level)
|
|
|
|
return; /* For -O0 don't bother */
|
|
|
|
|
|
|
|
if (!forwref)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (forwref->lineno != globallineno)
|
|
|
|
return;
|
|
|
|
|
|
|
|
instruction->forw_ref = true;
|
|
|
|
do {
|
|
|
|
instruction->oprs[forwref->operand].opflags |= OPFLAG_FORWARD;
|
|
|
|
forwref = saa_rstruct(forwrefs);
|
|
|
|
} while (forwref && forwref->lineno == globallineno);
|
|
|
|
|
|
|
|
if (!pass_first())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < instruction->operands; i++) {
|
|
|
|
if (instruction->oprs[i].opflags & OPFLAG_FORWARD) {
|
|
|
|
fwinf = saa_wstruct(forwrefs);
|
|
|
|
fwinf->lineno = globallineno;
|
|
|
|
fwinf->operand = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void process_insn(insn *instruction)
|
|
|
|
{
|
|
|
|
int32_t n;
|
|
|
|
int64_t l;
|
|
|
|
|
|
|
|
if (!instruction->times)
|
|
|
|
return; /* Nothing to do... */
|
|
|
|
|
|
|
|
nasm_assert(instruction->times > 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: insn_size() can change instruction->times
|
|
|
|
* (usually to 1) when called.
|
|
|
|
*/
|
|
|
|
if (!pass_final()) {
|
2019-08-10 17:45:41 +08:00
|
|
|
int64_t start = location.offset;
|
2018-12-19 11:14:40 +08:00
|
|
|
for (n = 1; n <= instruction->times; n++) {
|
|
|
|
l = insn_size(location.segment, location.offset,
|
|
|
|
globalbits, instruction);
|
2019-08-10 16:38:06 +08:00
|
|
|
/* l == -1 -> invalid instruction */
|
|
|
|
if (l != -1)
|
2018-12-19 11:14:40 +08:00
|
|
|
increment_offset(l);
|
|
|
|
}
|
2019-08-10 17:45:41 +08:00
|
|
|
if (list_option('p')) {
|
|
|
|
struct out_data dummy;
|
|
|
|
memset(&dummy, 0, sizeof dummy);
|
|
|
|
dummy.type = OUT_RAWDATA; /* Handled specially with .data NULL */
|
|
|
|
dummy.offset = start;
|
|
|
|
dummy.size = location.offset - start;
|
|
|
|
lfmt->output(&dummy);
|
|
|
|
}
|
2018-12-19 11:14:40 +08:00
|
|
|
} else {
|
|
|
|
l = assemble(location.segment, location.offset,
|
|
|
|
globalbits, instruction);
|
|
|
|
/* We can't get an invalid instruction here */
|
|
|
|
increment_offset(l);
|
|
|
|
|
|
|
|
if (instruction->times > 1) {
|
2019-08-07 15:46:27 +08:00
|
|
|
lfmt->uplevel(LIST_TIMES, instruction->times);
|
2018-12-19 11:14:40 +08:00
|
|
|
for (n = 2; n <= instruction->times; n++) {
|
|
|
|
l = assemble(location.segment, location.offset,
|
|
|
|
globalbits, instruction);
|
|
|
|
increment_offset(l);
|
|
|
|
}
|
|
|
|
lfmt->downlevel(LIST_TIMES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 02:33:52 +08:00
|
|
|
static void assemble_file(const char *fname, struct strlist *depend_list)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2017-03-08 09:45:01 +08:00
|
|
|
char *line;
|
2005-01-16 06:15:51 +08:00
|
|
|
insn output_ins;
|
2017-03-08 11:44:21 +08:00
|
|
|
uint64_t prev_offset_changed;
|
2018-06-16 08:51:39 +08:00
|
|
|
int64_t stall_count = 0; /* Make sure we make forward progress... */
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
switch (cmd_sb) {
|
|
|
|
case 16:
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
if (!iflag_cpu_level_ok(&cmd_cpu, IF_386))
|
2018-06-16 09:20:17 +08:00
|
|
|
nasm_fatal("command line: 32-bit segment size requires a higher cpu");
|
2018-02-07 06:43:07 +08:00
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
if (!iflag_cpu_level_ok(&cmd_cpu, IF_X86_64))
|
2018-06-16 09:20:17 +08:00
|
|
|
nasm_fatal("command line: 64-bit segment size requires a higher cpu");
|
2018-02-07 06:43:07 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic();
|
|
|
|
break;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
prev_offset_changed = INT64_MAX;
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
if (listname && !keep_all) {
|
|
|
|
/* Remove the list file in case we die before the output pass */
|
|
|
|
remove(listname);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!terminate_after_phase && !pass_final()) {
|
|
|
|
_passn++;
|
|
|
|
if (pass_type() != PASS_OPT || !global_offset_changed)
|
|
|
|
_pass_type++;
|
|
|
|
global_offset_changed = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a warning buffer list unless we are in
|
|
|
|
* pass 2 (everything will be emitted immediately in pass 2.)
|
|
|
|
*/
|
|
|
|
if (warn_list) {
|
|
|
|
if (warn_list->nstr || pass_final())
|
2018-12-14 16:17:13 +08:00
|
|
|
strlist_free(&warn_list);
|
2018-12-16 04:44:46 +08:00
|
|
|
}
|
2018-12-14 16:17:13 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
if (!pass_final() && !warn_list)
|
2018-12-16 04:44:46 +08:00
|
|
|
warn_list = strlist_alloc(false);
|
2018-12-14 16:17:13 +08:00
|
|
|
|
2017-03-29 07:12:30 +08:00
|
|
|
globalbits = cmd_sb; /* set 'bits' to command line default */
|
2005-01-16 06:15:51 +08:00
|
|
|
cpu = cmd_cpu;
|
2019-08-10 21:45:12 +08:00
|
|
|
if (listname) {
|
|
|
|
if (pass_final() || list_on_every_pass()) {
|
|
|
|
active_list_options = list_options;
|
|
|
|
lfmt->init(listname);
|
|
|
|
} else if (active_list_options) {
|
|
|
|
/*
|
|
|
|
* Looks like we used the list engine on a previous pass,
|
|
|
|
* but now it is turned off, presumably via %pragma -p
|
|
|
|
*/
|
|
|
|
lfmt->cleanup();
|
|
|
|
if (!keep_all)
|
|
|
|
remove(listname);
|
|
|
|
active_list_options = 0;
|
|
|
|
}
|
2019-08-09 23:06:39 +08:00
|
|
|
}
|
2018-12-19 03:12:46 +08:00
|
|
|
|
2017-03-08 11:23:03 +08:00
|
|
|
in_absolute = false;
|
2018-12-19 03:12:46 +08:00
|
|
|
if (!pass_first()) {
|
2005-01-16 06:15:51 +08:00
|
|
|
saa_rewind(forwrefs);
|
|
|
|
forwref = saa_rstruct(forwrefs);
|
|
|
|
raa_free(offsets);
|
|
|
|
offsets = raa_init();
|
|
|
|
}
|
2018-05-31 05:43:46 +08:00
|
|
|
location.segment = NO_SEG;
|
|
|
|
location.offset = 0;
|
2018-12-19 03:12:46 +08:00
|
|
|
if (pass_first())
|
2018-05-31 05:43:46 +08:00
|
|
|
location.known = true;
|
|
|
|
ofmt->reset();
|
2018-12-19 03:12:46 +08:00
|
|
|
switch_segment(ofmt->section(NULL, &globalbits));
|
|
|
|
preproc->reset(fname, PP_NORMAL, pass_final() ? depend_list : NULL);
|
2017-03-08 17:26:40 +08:00
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
globallineno = 0;
|
|
|
|
|
|
|
|
while ((line = preproc->getline())) {
|
2018-06-16 08:51:39 +08:00
|
|
|
if (++globallineno > nasm_limit[LIMIT_LINES])
|
2018-06-16 09:20:17 +08:00
|
|
|
nasm_fatal("overall line count exceeds the maximum %"PRId64"\n",
|
2018-12-16 04:44:46 +08:00
|
|
|
nasm_limit[LIMIT_LINES]);
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2009-06-28 07:30:00 +08:00
|
|
|
/*
|
2013-02-15 16:13:09 +08:00
|
|
|
* Here we parse our directives; this is not handled by the
|
2017-03-08 09:45:01 +08:00
|
|
|
* main parser.
|
2013-02-15 16:13:09 +08:00
|
|
|
*/
|
2017-03-08 13:32:37 +08:00
|
|
|
if (process_directives(line))
|
2017-03-08 09:45:01 +08:00
|
|
|
goto end_of_line; /* Just do final cleanup */
|
|
|
|
|
|
|
|
/* Not a directive, or even something that starts with [ */
|
2018-12-19 03:12:46 +08:00
|
|
|
parse_line(line, &output_ins);
|
2018-12-19 11:14:40 +08:00
|
|
|
forward_refs(&output_ins);
|
|
|
|
process_insn(&output_ins);
|
2017-03-08 09:45:01 +08:00
|
|
|
cleanup_insn(&output_ins);
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2017-03-08 09:45:01 +08:00
|
|
|
end_of_line:
|
2005-01-16 06:15:51 +08:00
|
|
|
nasm_free(line);
|
|
|
|
} /* end while (line = preproc->getline... */
|
2009-06-28 07:30:00 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
preproc->cleanup_pass();
|
|
|
|
|
|
|
|
if (global_offset_changed) {
|
|
|
|
switch (pass_type()) {
|
|
|
|
case PASS_OPT:
|
|
|
|
/*
|
|
|
|
* This is the only pass type that can be executed more
|
|
|
|
* than once, and therefore has the ability to stall.
|
|
|
|
*/
|
|
|
|
if (global_offset_changed < prev_offset_changed) {
|
|
|
|
prev_offset_changed = global_offset_changed;
|
|
|
|
stall_count = 0;
|
|
|
|
} else {
|
|
|
|
stall_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stall_count > nasm_limit[LIMIT_STALLED] ||
|
|
|
|
pass_count() >= nasm_limit[LIMIT_PASSES]) {
|
|
|
|
/* No convergence, almost certainly dead */
|
2019-01-12 05:13:03 +08:00
|
|
|
nasm_nonfatalf(ERR_UNDEAD,
|
|
|
|
"unable to find valid values for all labels "
|
|
|
|
"after %"PRId64" passes; "
|
|
|
|
"stalled for %"PRId64", giving up.",
|
|
|
|
pass_count(), stall_count);
|
2019-08-09 19:28:55 +08:00
|
|
|
nasm_nonfatalf(ERR_UNDEAD,
|
2019-01-12 05:13:03 +08:00
|
|
|
"Possible causes: recursive EQUs, macro abuse.");
|
2018-12-19 03:12:46 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PASS_STAB:
|
2018-12-14 13:53:31 +08:00
|
|
|
/*!
|
|
|
|
*!phase [off] phase error during stabilization
|
|
|
|
*! warns about symbols having changed values during
|
|
|
|
*! the second-to-last assembly pass. This is not
|
|
|
|
*! inherently fatal, but may be a source of bugs.
|
|
|
|
*/
|
2019-01-12 05:13:03 +08:00
|
|
|
nasm_warn(WARN_PHASE|ERR_UNDEAD,
|
|
|
|
"phase error during stabilization "
|
2018-12-19 03:12:46 +08:00
|
|
|
"pass, hoping for the best");
|
2018-06-28 12:03:38 +08:00
|
|
|
break;
|
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
case PASS_FINAL:
|
2019-01-12 05:13:03 +08:00
|
|
|
nasm_nonfatalf(ERR_UNDEAD,
|
|
|
|
"phase error during code generation pass");
|
2018-06-28 12:03:38 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* This is normal, we'll keep going... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-01-12 05:13:03 +08:00
|
|
|
|
|
|
|
reset_warnings();
|
2018-12-19 03:12:46 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2018-12-19 03:12:46 +08:00
|
|
|
if (opt_verbose_info && pass_final()) {
|
|
|
|
/* -On and -Ov switches */
|
2019-08-09 19:28:55 +08:00
|
|
|
nasm_info("assembly required 1+%"PRId64"+2 passes\n", pass_count()-3);
|
2008-01-09 15:03:57 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
|
2016-02-18 17:16:18 +08:00
|
|
|
lfmt->cleanup();
|
2019-08-10 21:45:12 +08:00
|
|
|
strlist_free(&warn_list);
|
2009-06-28 06:34:32 +08:00
|
|
|
}
|
2002-05-01 04:53:55 +08:00
|
|
|
|
2018-12-13 07:58:32 +08:00
|
|
|
/**
|
|
|
|
* get warning index; 0 if this is non-suppressible.
|
2017-03-08 11:23:03 +08:00
|
|
|
*/
|
2018-12-14 11:39:41 +08:00
|
|
|
static size_t warn_index(errflags severity)
|
2017-03-08 11:23:03 +08:00
|
|
|
{
|
2018-12-13 07:58:32 +08:00
|
|
|
size_t index;
|
2017-03-08 11:23:03 +08:00
|
|
|
|
2018-12-13 07:58:32 +08:00
|
|
|
if ((severity & ERR_MASK) >= ERR_FATAL)
|
|
|
|
return 0; /* Fatal errors are never suppressible */
|
2017-03-08 11:23:03 +08:00
|
|
|
|
2018-12-15 05:44:35 +08:00
|
|
|
/* Warnings MUST HAVE a warning category specifier! */
|
|
|
|
nasm_assert((severity & (ERR_MASK|WARN_MASK)) != ERR_WARNING);
|
2017-03-08 17:26:40 +08:00
|
|
|
|
2018-12-13 07:58:32 +08:00
|
|
|
index = WARN_IDX(severity);
|
2018-12-14 13:53:31 +08:00
|
|
|
nasm_assert(index < WARN_IDX_ALL);
|
2018-12-13 07:58:32 +08:00
|
|
|
|
|
|
|
return index;
|
2002-06-10 04:56:40 +08:00
|
|
|
}
|
|
|
|
|
2018-12-14 11:39:41 +08:00
|
|
|
static bool skip_this_pass(errflags severity)
|
2016-02-18 12:47:01 +08:00
|
|
|
{
|
2019-08-09 19:28:55 +08:00
|
|
|
errflags type = severity & ERR_MASK;
|
|
|
|
|
2017-04-03 10:02:29 +08:00
|
|
|
/*
|
|
|
|
* See if it's a pass-specific error or warning which should be skipped.
|
2018-12-13 07:58:32 +08:00
|
|
|
* We can never skip fatal errors as by definition they cannot be
|
|
|
|
* resumed from.
|
2017-04-03 10:02:29 +08:00
|
|
|
*/
|
2019-08-09 19:28:55 +08:00
|
|
|
if (type >= ERR_FATAL)
|
2018-12-16 04:44:46 +08:00
|
|
|
return false;
|
2016-02-18 12:47:01 +08:00
|
|
|
|
2019-08-09 19:28:55 +08:00
|
|
|
/*
|
|
|
|
* ERR_LISTMSG messages are always skipped; the list file
|
|
|
|
* receives them anyway as this function is not consulted
|
|
|
|
* for sending to the list file.
|
|
|
|
*/
|
|
|
|
if (type == ERR_LISTMSG)
|
|
|
|
return true;
|
|
|
|
|
2018-12-19 04:25:11 +08:00
|
|
|
/* This message not applicable unless pass_final */
|
|
|
|
return (severity & ERR_PASS2) && !pass_final();
|
2016-02-18 12:47:01 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 07:58:32 +08:00
|
|
|
/**
|
|
|
|
* check for suppressed message (usually warnings or notes)
|
|
|
|
*
|
|
|
|
* @param severity the severity of the warning or error
|
|
|
|
* @return true if we should abort error/warning printing
|
|
|
|
*/
|
2018-12-14 11:39:41 +08:00
|
|
|
static bool is_suppressed(errflags severity)
|
2018-12-13 07:58:32 +08:00
|
|
|
{
|
2018-12-28 03:24:17 +08:00
|
|
|
/* Fatal errors must never be suppressed */
|
2018-12-11 16:06:29 +08:00
|
|
|
if ((severity & ERR_MASK) >= ERR_FATAL)
|
2018-12-28 03:24:17 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* This error/warning is pointless if we are dead anyway */
|
|
|
|
if ((severity & ERR_UNDEAD) && terminate_after_phase)
|
|
|
|
return true;
|
2018-12-11 16:06:29 +08:00
|
|
|
|
2018-12-13 07:58:32 +08:00
|
|
|
return !(warning_state[warn_index(severity)] & WARN_ST_ENABLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-11 16:06:29 +08:00
|
|
|
* Return the true error type (the ERR_MASK part) of the given
|
|
|
|
* severity, accounting for warnings that may need to be promoted to
|
|
|
|
* error.
|
2018-12-13 07:58:32 +08:00
|
|
|
*
|
|
|
|
* @param severity the severity of the warning or error
|
2018-12-11 16:06:29 +08:00
|
|
|
* @return true if we should error out
|
2018-12-13 07:58:32 +08:00
|
|
|
*/
|
2018-12-14 11:39:41 +08:00
|
|
|
static errflags true_error_type(errflags severity)
|
2018-12-13 07:58:32 +08:00
|
|
|
{
|
2018-12-11 16:06:29 +08:00
|
|
|
const uint8_t warn_is_err = WARN_ST_ENABLED|WARN_ST_ERROR;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
type = severity & ERR_MASK;
|
|
|
|
|
|
|
|
/* Promote warning to error? */
|
|
|
|
if (type == ERR_WARNING) {
|
|
|
|
uint8_t state = warning_state[warn_index(severity)];
|
|
|
|
if ((state & warn_is_err) == warn_is_err)
|
|
|
|
type = ERR_NONFATAL;
|
|
|
|
}
|
2018-12-13 07:58:32 +08:00
|
|
|
|
2018-12-11 16:06:29 +08:00
|
|
|
return type;
|
2018-12-13 07:58:32 +08:00
|
|
|
}
|
|
|
|
|
2002-06-10 04:56:40 +08:00
|
|
|
/**
|
|
|
|
* common error reporting
|
|
|
|
* This is the common back end of the error reporting schemes currently
|
2007-10-20 05:42:29 +08:00
|
|
|
* implemented. It prints the nature of the warning and then the
|
2002-06-10 04:56:40 +08:00
|
|
|
* specific error message to error_file and may or may not return. It
|
|
|
|
* doesn't return if the error severity is a "panic" or "debug" type.
|
2007-10-20 05:42:29 +08:00
|
|
|
*
|
|
|
|
* @param severity the severity of the warning or error
|
2002-06-10 04:56:40 +08:00
|
|
|
* @param fmt the printf style format string
|
|
|
|
*/
|
2018-12-14 11:39:41 +08:00
|
|
|
static void nasm_verror_asm(errflags severity, const char *fmt, va_list args)
|
2002-06-10 04:56:40 +08:00
|
|
|
{
|
2009-07-08 03:04:12 +08:00
|
|
|
char msg[1024];
|
2018-12-11 16:06:29 +08:00
|
|
|
char warnsuf[64];
|
|
|
|
char linestr[64];
|
2009-07-08 03:04:12 +08:00
|
|
|
const char *pfx;
|
2018-12-14 11:39:41 +08:00
|
|
|
errflags true_type = true_error_type(severity);
|
2018-12-11 14:29:49 +08:00
|
|
|
const char *currentfile = NULL;
|
|
|
|
int32_t lineno = 0;
|
2018-12-11 16:06:29 +08:00
|
|
|
static const char * const pfx_table[ERR_MASK+1] = {
|
2019-08-09 19:28:55 +08:00
|
|
|
";;; ", "debug: ", "info: ", "warning: ",
|
|
|
|
"error: ", "", "fatal: ", "panic: "
|
2018-12-11 16:06:29 +08:00
|
|
|
};
|
2018-12-11 14:29:49 +08:00
|
|
|
|
2018-12-13 07:58:32 +08:00
|
|
|
if (is_suppressed(severity))
|
2018-12-11 14:29:49 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(severity & ERR_NOFILE)) {
|
2018-12-16 04:44:46 +08:00
|
|
|
src_get(&lineno, ¤tfile);
|
2018-12-11 14:29:49 +08:00
|
|
|
if (!currentfile) {
|
|
|
|
currentfile = currentfile ? currentfile :
|
|
|
|
inname && inname[0] ? inname :
|
|
|
|
outname && outname[0] ? outname :
|
|
|
|
NULL;
|
|
|
|
lineno = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-07-13 03:04:56 +08:00
|
|
|
|
2018-12-11 16:06:29 +08:00
|
|
|
if (severity & ERR_NO_SEVERITY)
|
2013-02-15 06:20:26 +08:00
|
|
|
pfx = "";
|
2018-12-11 16:06:29 +08:00
|
|
|
else
|
|
|
|
pfx = pfx_table[true_type];
|
2018-12-11 16:06:29 +08:00
|
|
|
|
|
|
|
vsnprintf(msg, sizeof msg, fmt, args);
|
|
|
|
*warnsuf = 0;
|
2019-08-09 19:28:55 +08:00
|
|
|
if ((severity & (ERR_MASK|ERR_HERE|ERR_PP_LISTMACRO)) == ERR_WARNING) {
|
|
|
|
/*
|
|
|
|
* It's a warning without ERR_HERE defined, and we are not already
|
|
|
|
* unwinding the macros that led us here.
|
|
|
|
*/
|
2018-12-16 04:44:46 +08:00
|
|
|
snprintf(warnsuf, sizeof warnsuf, " [-w+%s%s]",
|
2018-12-14 13:53:31 +08:00
|
|
|
(true_type >= ERR_NONFATAL) ? "error=" : "",
|
|
|
|
warning_name[warn_index(severity)]);
|
2016-05-10 03:00:19 +08:00
|
|
|
}
|
2009-07-08 03:04:12 +08:00
|
|
|
|
2018-12-11 16:06:29 +08:00
|
|
|
*linestr = 0;
|
|
|
|
if (lineno) {
|
|
|
|
snprintf(linestr, sizeof linestr, "%s%"PRId32"%s",
|
|
|
|
errfmt->beforeline, lineno, errfmt->afterline);
|
|
|
|
}
|
|
|
|
|
2018-12-11 14:29:49 +08:00
|
|
|
if (!skip_this_pass(severity)) {
|
2018-12-16 04:44:46 +08:00
|
|
|
const char *file = currentfile ? currentfile : "nasm";
|
2019-08-09 19:28:55 +08:00
|
|
|
const char *here = "";
|
|
|
|
|
|
|
|
if (severity & ERR_HERE)
|
|
|
|
here = currentfile ? " here" : " in an unknown location";
|
2018-12-16 04:44:46 +08:00
|
|
|
|
2018-12-19 04:25:11 +08:00
|
|
|
if (warn_list && true_type < ERR_NONFATAL &&
|
|
|
|
!(pass_first() && (severity & ERR_PASS1)))
|
|
|
|
{
|
2018-12-16 04:44:46 +08:00
|
|
|
/*
|
|
|
|
* Buffer up warnings until we either get an error
|
|
|
|
* or we are on the code-generation pass.
|
|
|
|
*/
|
|
|
|
strlist_printf(warn_list, "%s%s%s%s%s%s%s",
|
|
|
|
file, linestr, errfmt->beforemsg,
|
|
|
|
pfx, msg, here, warnsuf);
|
|
|
|
} else {
|
2018-12-19 04:25:11 +08:00
|
|
|
/*
|
|
|
|
* If we have buffered warnings, and this is a non-warning,
|
|
|
|
* output them now.
|
|
|
|
*/
|
|
|
|
if (true_type >= ERR_NONFATAL && warn_list) {
|
2018-12-16 04:44:46 +08:00
|
|
|
strlist_write(warn_list, "\n", error_file);
|
|
|
|
strlist_free(&warn_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(error_file, "%s%s%s%s%s%s%s\n",
|
|
|
|
file, linestr, errfmt->beforemsg,
|
|
|
|
pfx, msg, here, warnsuf);
|
|
|
|
|
|
|
|
}
|
2018-12-11 14:29:49 +08:00
|
|
|
}
|
2009-07-08 03:04:12 +08:00
|
|
|
|
2016-05-10 04:59:44 +08:00
|
|
|
/* Are we recursing from error_list_macros? */
|
|
|
|
if (severity & ERR_PP_LISTMACRO)
|
2018-12-16 04:44:46 +08:00
|
|
|
return;
|
2016-05-10 04:59:44 +08:00
|
|
|
|
2016-02-18 12:47:01 +08:00
|
|
|
/*
|
|
|
|
* Don't suppress this with skip_this_pass(), or we don't get
|
2016-05-10 03:00:19 +08:00
|
|
|
* pass1 or preprocessor warnings in the list file
|
2016-02-18 12:47:01 +08:00
|
|
|
*/
|
2018-12-11 16:06:29 +08:00
|
|
|
if (severity & ERR_HERE) {
|
|
|
|
if (lineno)
|
|
|
|
lfmt->error(severity, "%s%s at %s:%"PRId32"%s",
|
|
|
|
pfx, msg, currentfile, lineno, warnsuf);
|
|
|
|
else if (currentfile)
|
|
|
|
lfmt->error(severity, "%s%s in file %s%s",
|
|
|
|
pfx, msg, currentfile, warnsuf);
|
|
|
|
else
|
2019-08-09 19:28:55 +08:00
|
|
|
lfmt->error(severity, "%s%s in an unknown location%s",
|
2018-12-11 16:06:29 +08:00
|
|
|
pfx, msg, warnsuf);
|
|
|
|
} else {
|
|
|
|
lfmt->error(severity, "%s%s%s", pfx, msg, warnsuf);
|
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2017-04-03 10:02:29 +08:00
|
|
|
if (skip_this_pass(severity))
|
|
|
|
return;
|
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
if (severity & ERR_USAGE)
|
2007-10-11 05:58:45 +08:00
|
|
|
want_usage = true;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2019-08-09 19:28:55 +08:00
|
|
|
/* error_list_macros can for obvious reasons not work with ERR_HERE */
|
|
|
|
if (!(severity & ERR_HERE))
|
|
|
|
preproc->error_list_macros(severity);
|
2016-05-10 04:59:44 +08:00
|
|
|
|
2018-12-11 16:06:29 +08:00
|
|
|
switch (true_type) {
|
2019-08-09 19:28:55 +08:00
|
|
|
case ERR_LISTMSG:
|
2005-01-16 06:15:51 +08:00
|
|
|
case ERR_DEBUG:
|
2019-08-09 19:28:55 +08:00
|
|
|
case ERR_INFO:
|
2007-11-14 03:31:15 +08:00
|
|
|
case ERR_WARNING:
|
2018-12-11 16:06:29 +08:00
|
|
|
/* no further action, by definition */
|
2013-02-15 06:20:26 +08:00
|
|
|
break;
|
2005-01-16 06:15:51 +08:00
|
|
|
case ERR_NONFATAL:
|
2007-10-11 05:58:45 +08:00
|
|
|
terminate_after_phase = true;
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case ERR_FATAL:
|
|
|
|
if (ofile) {
|
|
|
|
fclose(ofile);
|
2018-06-15 08:04:32 +08:00
|
|
|
if (!keep_all)
|
|
|
|
remove(outname);
|
2013-02-15 06:20:26 +08:00
|
|
|
ofile = NULL;
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
|
|
|
if (want_usage)
|
|
|
|
usage();
|
|
|
|
exit(1); /* instantly die */
|
|
|
|
break; /* placate silly compilers */
|
|
|
|
case ERR_PANIC:
|
|
|
|
fflush(NULL);
|
2018-02-08 06:14:36 +08:00
|
|
|
|
|
|
|
if (abort_on_panic)
|
2018-12-16 04:44:46 +08:00
|
|
|
abort(); /* halt, catch fire, dump core/stop debugger */
|
2018-02-08 06:14:36 +08:00
|
|
|
|
2016-02-18 12:47:01 +08:00
|
|
|
if (ofile) {
|
|
|
|
fclose(ofile);
|
2018-06-15 08:04:32 +08:00
|
|
|
if (!keep_all)
|
|
|
|
remove(outname);
|
2016-02-18 12:47:01 +08:00
|
|
|
ofile = NULL;
|
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
exit(3);
|
|
|
|
break;
|
2018-12-11 13:14:57 +08:00
|
|
|
default:
|
|
|
|
break; /* ??? */
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-01 05:01:08 +08:00
|
|
|
static void usage(void)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2019-08-10 16:55:00 +08:00
|
|
|
fprintf(error_file, "Type %s -h for help.\n", _progname);
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
2018-06-13 04:50:37 +08:00
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
static void help(FILE *out)
|
2018-06-13 04:50:37 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
fprintf(out,
|
2019-08-10 16:55:00 +08:00
|
|
|
"Usage: %s [-@ response_file] [options...] [--] filename\n"
|
|
|
|
" %s -v (or --v)\n",
|
2019-08-10 16:38:06 +08:00
|
|
|
_progname, _progname);
|
|
|
|
fputs(
|
|
|
|
"\n"
|
2019-08-10 16:55:00 +08:00
|
|
|
"Options (values in brackets indicate defaults):\n"
|
2019-08-10 16:38:06 +08:00
|
|
|
"\n"
|
|
|
|
" -h show this text and exit (also --help)\n"
|
2019-08-10 16:55:00 +08:00
|
|
|
" -v (or --v) print the NASM version number and exit\n"
|
|
|
|
" -@ file response file; one command line option per line\n"
|
2019-08-10 16:38:06 +08:00
|
|
|
"\n"
|
|
|
|
" -o outfile write output to outfile\n"
|
|
|
|
" --keep-all output files will not be removed even if an error happens\n"
|
|
|
|
"\n"
|
|
|
|
" -Xformat specifiy error reporting format (gnu or vc)\n"
|
|
|
|
" -s redirect error messages to stdout\n"
|
|
|
|
" -Zfile redirect error messages to file\n"
|
|
|
|
"\n"
|
|
|
|
" -M generate Makefile dependencies on stdout\n"
|
|
|
|
" -MG d:o, missing files assumed generated\n"
|
|
|
|
" -MF file set Makefile dependency file\n"
|
|
|
|
" -MD file assemble and generate dependencies\n"
|
|
|
|
" -MT file dependency target name\n"
|
|
|
|
" -MQ file dependency target name (quoted)\n"
|
|
|
|
" -MP emit phony targets\n"
|
|
|
|
"\n"
|
|
|
|
" -f format select output file format\n"
|
|
|
|
, out);
|
|
|
|
ofmt_list(ofmt, out);
|
|
|
|
fputs(
|
|
|
|
"\n"
|
|
|
|
" -g generate debugging information\n"
|
|
|
|
" -F format select a debugging format (output format dependent)\n"
|
|
|
|
" -gformat same as -g -F format\n"
|
|
|
|
, out);
|
|
|
|
dfmt_list(out);
|
|
|
|
fputs(
|
|
|
|
"\n"
|
|
|
|
" -l listfile write listing to a list file\n"
|
|
|
|
" -Lflags... add optional information to the list file\n"
|
2019-08-10 20:33:14 +08:00
|
|
|
" -Lb show builtin macro packages (standard and %use)\n"
|
2019-08-10 16:38:06 +08:00
|
|
|
" -Ld show byte and repeat counts in decimal, not hex\n"
|
|
|
|
" -Le show the preprocessed output\n"
|
2019-08-10 20:33:14 +08:00
|
|
|
" -Lf ignore .nolist (force output)\n"
|
2019-08-21 07:00:57 +08:00
|
|
|
" -Lm show multi-line macro calls with expanded parmeters\n"
|
2019-08-10 16:38:06 +08:00
|
|
|
" -Lp output a list file every pass, in case of errors\n"
|
2019-08-21 07:00:57 +08:00
|
|
|
" -Ls show all single-line macro definitions\n"
|
2019-08-20 04:09:46 +08:00
|
|
|
" -L+ enable all listing options (very verbose!)\n"
|
2019-08-10 16:38:06 +08:00
|
|
|
"\n"
|
|
|
|
" -Oflags... optimize opcodes, immediates and branch offsets\n"
|
|
|
|
" -O0 no optimization\n"
|
|
|
|
" -O1 minimal optimization\n"
|
|
|
|
" -Ox multipass optimization (default)\n"
|
|
|
|
" -Ov display the number of passes executed at the end\n"
|
|
|
|
" -t assemble in limited SciTech TASM compatible mode\n"
|
|
|
|
"\n"
|
|
|
|
" -E (or -e) preprocess only (writes output to stdout by default)\n"
|
|
|
|
" -a don't preprocess (assemble only)\n"
|
|
|
|
" -Ipath add a pathname to the include file path\n"
|
|
|
|
" -Pfile pre-include a file (also --include)\n"
|
|
|
|
" -Dmacro[=str] pre-define a macro\n"
|
|
|
|
" -Umacro undefine a macro\n"
|
|
|
|
" --pragma str pre-executes a specific %%pragma\n"
|
|
|
|
" --before str add line (usually a preprocessor statement) before the input\n"
|
|
|
|
" --no-line ignore %line directives in input\n"
|
|
|
|
"\n"
|
|
|
|
" --prefix str prepend the given string to the names of all extern,\n"
|
|
|
|
" common and global symbols (also --gprefix)\n"
|
|
|
|
" --suffix str append the given string to the names of all extern,\n"
|
|
|
|
" common and global symbols (also --gprefix)\n"
|
|
|
|
" --lprefix str prepend the given string to local symbols\n"
|
|
|
|
" --lpostfix str append the given string to local symbols\n"
|
|
|
|
"\n"
|
|
|
|
" -w+x enable warning x (also -Wx)\n"
|
|
|
|
" -w-x disable warning x (also -Wno-x)\n"
|
|
|
|
" -w[+-]error promote all warnings to errors (also -Werror)\n"
|
|
|
|
" -w[+-]error=x promote warning x to errors (also -Werror=x)\n"
|
|
|
|
, out);
|
|
|
|
|
|
|
|
fprintf(out, " %-20s %s\n",
|
|
|
|
warning_name[WARN_IDX_ALL], warning_help[WARN_IDX_ALL]);
|
|
|
|
|
|
|
|
for (i = 1; i < WARN_IDX_ALL; i++) {
|
|
|
|
const char *me = warning_name[i];
|
|
|
|
const char *prev = warning_name[i-1];
|
|
|
|
const char *next = warning_name[i+1];
|
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
int prev_len = strlen(prev);
|
|
|
|
const char *dash = me;
|
|
|
|
|
|
|
|
while ((dash = strchr(dash+1, '-'))) {
|
|
|
|
int prefix_len = dash - me; /* Not including final dash */
|
|
|
|
if (strncmp(next, me, prefix_len+1)) {
|
|
|
|
/* Only one or last option with this prefix */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (prefix_len >= prev_len ||
|
|
|
|
strncmp(prev, me, prefix_len) ||
|
|
|
|
(prev[prefix_len] != '-' && prev[prefix_len] != '\0')) {
|
|
|
|
/* This prefix is different from the previous option */
|
|
|
|
fprintf(out, " %-20.*s all warnings prefixed with \"%.*s\"\n",
|
|
|
|
prefix_len, me, prefix_len+1, me);
|
|
|
|
}
|
|
|
|
}
|
2018-06-13 04:50:37 +08:00
|
|
|
}
|
2019-08-10 16:38:06 +08:00
|
|
|
|
|
|
|
fprintf(out, " %-20s %s%s\n",
|
|
|
|
warning_name[i], warning_help[i],
|
|
|
|
(warning_default[i] & WARN_ST_ERROR) ? " [error]" :
|
|
|
|
(warning_default[i] & WARN_ST_ENABLED) ? " [on]" : " [off]");
|
2018-06-13 04:50:37 +08:00
|
|
|
}
|
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
fputs(
|
|
|
|
"\n"
|
|
|
|
" --limit-X val set execution limit X\n"
|
|
|
|
, out);
|
2018-06-13 04:50:37 +08:00
|
|
|
|
|
|
|
|
2019-08-10 16:38:06 +08:00
|
|
|
for (i = 0; i <= LIMIT_MAX; i++) {
|
|
|
|
fprintf(out, " %-20s %s [",
|
|
|
|
limit_info[i].name, limit_info[i].help);
|
|
|
|
if (nasm_limit[i] < LIMIT_MAX_VAL) {
|
|
|
|
fprintf(out, "%"PRId64"]\n", nasm_limit[i]);
|
|
|
|
} else {
|
|
|
|
fputs("unlimited]\n", out);
|
|
|
|
}
|
2018-06-13 04:50:37 +08:00
|
|
|
}
|
|
|
|
}
|