nasm.c: Tabs to spaces in assemble_file

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2013-02-15 12:13:09 +04:00
parent 04dba65098
commit 1476319ced

370
nasm.c
View File

@ -1188,7 +1188,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
int pass1, pass2; int pass1, pass2;
ldfunc def_label; ldfunc def_label;
pass1 = pass0 == 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */ pass1 = pass0 == 2 ? 2 : 1; /* 1, 1, 1, ..., 1, 2 */
pass2 = passn > 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */ pass2 = passn > 1 ? 2 : 1; /* 1, 2, 2, ..., 2, 2 */
/* pass0 0, 0, 0, ..., 1, 2 */ /* pass0 0, 0, 0, ..., 1, 2 */
@ -1211,7 +1211,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
offsets = raa_init(); offsets = raa_init();
} }
preproc->reset(fname, pass1, &nasmlist, preproc->reset(fname, pass1, &nasmlist,
pass1 == 2 ? depend_ptr : NULL); pass1 == 2 ? depend_ptr : NULL);
memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool)); memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool));
globallineno = 0; globallineno = 0;
@ -1220,21 +1220,21 @@ static void assemble_file(char *fname, StrList **depend_ptr)
location.offset = offs = GET_CURR_OFFS; location.offset = offs = GET_CURR_OFFS;
while ((line = preproc->getline())) { while ((line = preproc->getline())) {
enum directives d; enum directives d;
globallineno++; globallineno++;
/* /*
* Here we parse our directives; this is not handled by the * Here we parse our directives; this is not handled by the
* 'real' parser. This really should be a separate function. * 'real' parser. This really should be a separate function.
*/ */
directive = line; directive = line;
d = getkw(&directive, &value); d = getkw(&directive, &value);
if (d) { if (d) {
int err = 0; int err = 0;
switch (d) { switch (d) {
case D_SEGMENT: /* [SEGMENT n] */ case D_SEGMENT: /* [SEGMENT n] */
case D_SECTION: case D_SECTION:
seg = ofmt->section(value, pass2, &sb); seg = ofmt->section(value, pass2, &sb);
if (seg == NO_SEG) { if (seg == NO_SEG) {
nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
@ -1245,7 +1245,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
location.segment = seg; location.segment = seg;
} }
break; break;
case D_SECTALIGN: /* [SECTALIGN n] */ case D_SECTALIGN: /* [SECTALIGN n] */
if (*value) { if (*value) {
stdscan_reset(); stdscan_reset();
stdscan_set(value); stdscan_set(value);
@ -1271,7 +1271,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
} }
} }
break; break;
case D_EXTERN: /* [EXTERN label:special] */ case D_EXTERN: /* [EXTERN label:special] */
if (*value == '$') if (*value == '$')
value++; /* skip initial $ if present */ value++; /* skip initial $ if present */
if (pass0 == 2) { if (pass0 == 2) {
@ -1312,10 +1312,10 @@ static void assemble_file(char *fname, StrList **depend_ptr)
} }
} /* else pass0 == 1 */ } /* else pass0 == 1 */
break; break;
case D_BITS: /* [BITS bits] */ case D_BITS: /* [BITS bits] */
globalbits = sb = get_bits(value); globalbits = sb = get_bits(value);
break; break;
case D_GLOBAL: /* [GLOBAL symbol:special] */ case D_GLOBAL: /* [GLOBAL symbol:special] */
if (*value == '$') if (*value == '$')
value++; /* skip initial $ if present */ value++; /* skip initial $ if present */
if (pass0 == 2) { /* pass 2 */ if (pass0 == 2) { /* pass 2 */
@ -1349,60 +1349,60 @@ static void assemble_file(char *fname, StrList **depend_ptr)
declare_as_global(value, special); declare_as_global(value, special);
} /* pass == 1 */ } /* pass == 1 */
break; break;
case D_COMMON: /* [COMMON symbol size:special] */ case D_COMMON: /* [COMMON symbol size:special] */
{ {
int64_t size; int64_t size;
if (*value == '$') if (*value == '$')
value++; /* skip initial $ if present */ value++; /* skip initial $ if present */
p = value; p = value;
validid = true; validid = true;
if (!isidstart(*p)) if (!isidstart(*p))
validid = false; validid = false;
while (*p && !nasm_isspace(*p)) { while (*p && !nasm_isspace(*p)) {
if (!isidchar(*p)) if (!isidchar(*p))
validid = false; validid = false;
p++; p++;
} }
if (!validid) { if (!validid) {
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"identifier expected after COMMON"); "identifier expected after COMMON");
break; break;
} }
if (*p) { if (*p) {
p = nasm_zap_spaces_fwd(p); p = nasm_zap_spaces_fwd(p);
q = p; q = p;
while (*q && *q != ':') while (*q && *q != ':')
q++; q++;
if (*q == ':') { if (*q == ':') {
*q++ = '\0'; *q++ = '\0';
special = q; special = q;
} else { } else {
special = NULL; special = NULL;
} }
size = readnum(p, &rn_error); size = readnum(p, &rn_error);
if (rn_error) { if (rn_error) {
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"invalid size specified" "invalid size specified"
" in COMMON declaration"); " in COMMON declaration");
break; break;
} }
} else { } else {
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"no size specified in" "no size specified in"
" COMMON declaration"); " COMMON declaration");
break; break;
} }
if (pass0 < 2) { if (pass0 < 2) {
define_common(value, seg_alloc(), size, special); define_common(value, seg_alloc(), size, special);
} else if (pass0 == 2) { } else if (pass0 == 2) {
if (special) if (special)
ofmt->symdef(value, 0L, 0L, 3, special); ofmt->symdef(value, 0L, 0L, 3, special);
} }
break; break;
} }
case D_ABSOLUTE: /* [ABSOLUTE address] */ case D_ABSOLUTE: /* [ABSOLUTE address] */
stdscan_reset(); stdscan_reset();
stdscan_set(value); stdscan_set(value);
tokval.t_type = TOKEN_INVALID; tokval.t_type = TOKEN_INVALID;
@ -1426,76 +1426,75 @@ static void assemble_file(char *fname, StrList **depend_ptr)
in_abs_seg = true; in_abs_seg = true;
location.segment = NO_SEG; location.segment = NO_SEG;
break; break;
case D_DEBUG: /* [DEBUG] */ case D_DEBUG: /* [DEBUG] */
{ {
char debugid[128]; char debugid[128];
bool badid, overlong; bool badid, overlong;
p = value; p = value;
q = debugid; q = debugid;
badid = overlong = false; badid = overlong = false;
if (!isidstart(*p)) { if (!isidstart(*p)) {
badid = true; badid = true;
} else { } else {
while (*p && !nasm_isspace(*p)) { while (*p && !nasm_isspace(*p)) {
if (q >= debugid + sizeof debugid - 1) { if (q >= debugid + sizeof debugid - 1) {
overlong = true; overlong = true;
break; break;
} }
if (!isidchar(*p)) if (!isidchar(*p))
badid = true; badid = true;
*q++ = *p++; *q++ = *p++;
} }
*q = 0; *q = 0;
} }
if (badid) { if (badid) {
nasm_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC, nasm_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC,
"identifier expected after DEBUG"); "identifier expected after DEBUG");
break; break;
} }
if (overlong) { if (overlong) {
nasm_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC, nasm_error(passn == 1 ? ERR_NONFATAL : ERR_PANIC,
"DEBUG identifier too long"); "DEBUG identifier too long");
break; break;
} }
p = nasm_skip_spaces(p); p = nasm_skip_spaces(p);
if (pass0 == 2) if (pass0 == 2)
dfmt->debug_directive(debugid, p); dfmt->debug_directive(debugid, p);
break; break;
} }
case D_WARNING: /* [WARNING {+|-|*}warn-name] */ case D_WARNING: /* [WARNING {+|-|*}warn-name] */
value = nasm_skip_spaces(value); value = nasm_skip_spaces(value);
switch(*value) { switch(*value) {
case '-': validid = 0; value++; break; case '-': validid = 0; value++; break;
case '+': validid = 1; value++; break; case '+': validid = 1; value++; break;
case '*': validid = 2; value++; break; case '*': validid = 2; value++; break;
default: validid = 1; break; default: validid = 1; break;
} }
for (i = 1; i <= ERR_WARN_MAX; i++) for (i = 1; i <= ERR_WARN_MAX; i++)
if (!nasm_stricmp(value, warnings[i].name)) if (!nasm_stricmp(value, warnings[i].name))
break; break;
if (i <= ERR_WARN_MAX) { if (i <= ERR_WARN_MAX) {
switch(validid) { switch(validid) {
case 0: case 0:
warning_on[i] = false; warning_on[i] = false;
break; break;
case 1: case 1:
warning_on[i] = true; warning_on[i] = true;
break; break;
case 2: case 2:
warning_on[i] = warning_on_global[i]; warning_on[i] = warning_on_global[i];
break; break;
} }
} } else
else nasm_error(ERR_NONFATAL,
nasm_error(ERR_NONFATAL, "invalid warning id in WARNING directive");
"invalid warning id in WARNING directive");
break; break;
case D_CPU: /* [CPU] */ case D_CPU: /* [CPU] */
cpu = get_cpu(value); cpu = get_cpu(value);
break; break;
case D_LIST: /* [LIST {+|-}] */ case D_LIST: /* [LIST {+|-}] */
value = nasm_skip_spaces(value); value = nasm_skip_spaces(value);
if (*value == '+') { if (*value == '+') {
user_nolist = 0; user_nolist = 0;
@ -1503,52 +1502,52 @@ static void assemble_file(char *fname, StrList **depend_ptr)
if (*value == '-') { if (*value == '-') {
user_nolist = 1; user_nolist = 1;
} else { } else {
err = 1; err = 1;
} }
} }
break; break;
case D_DEFAULT: /* [DEFAULT] */ case D_DEFAULT: /* [DEFAULT] */
stdscan_reset(); stdscan_reset();
stdscan_set(value); stdscan_set(value);
tokval.t_type = TOKEN_INVALID; tokval.t_type = TOKEN_INVALID;
if (stdscan(NULL, &tokval) == TOKEN_SPECIAL) { if (stdscan(NULL, &tokval) == TOKEN_SPECIAL) {
switch ((int)tokval.t_integer) { switch ((int)tokval.t_integer) {
case S_REL: case S_REL:
globalrel = 1; globalrel = 1;
break; break;
case S_ABS: case S_ABS:
globalrel = 0; globalrel = 0;
break; break;
default: default:
err = 1; err = 1;
break; break;
} }
} else { } else {
err = 1; err = 1;
} }
break; break;
case D_FLOAT: case D_FLOAT:
if (float_option(value)) { if (float_option(value)) {
nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
"unknown 'float' directive: %s", "unknown 'float' directive: %s",
value); value);
} }
break; break;
default: default:
if (ofmt->directive(d, value, pass2)) if (ofmt->directive(d, value, pass2))
break; break;
/* else fall through */ /* else fall through */
case D_unknown: case D_unknown:
nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC, nasm_error(pass1 == 1 ? ERR_NONFATAL : ERR_PANIC,
"unrecognised directive [%s]", "unrecognised directive [%s]",
directive); directive);
break; break;
}
if (err) {
nasm_error(ERR_NONFATAL,
"invalid parameter to [%s] directive",
directive);
} }
if (err) {
nasm_error(ERR_NONFATAL,
"invalid parameter to [%s] directive",
directive);
}
} else { /* it isn't a directive */ } else { /* it isn't a directive */
parse_line(pass1, line, &output_ins, def_label); parse_line(pass1, line, &output_ins, def_label);
@ -1563,18 +1562,16 @@ static void assemble_file(char *fname, StrList **depend_ptr)
} else } else
output_ins.forw_ref = false; output_ins.forw_ref = false;
if (output_ins.forw_ref) { if (output_ins.forw_ref) {
if (passn == 1) { if (passn == 1) {
for (i = 0; i < output_ins.operands; i++) { for (i = 0; i < output_ins.operands; i++) {
if (output_ins.oprs[i].opflags & OPFLAG_FORWARD) { if (output_ins.oprs[i].opflags & OPFLAG_FORWARD) {
struct forwrefinfo *fwinf = struct forwrefinfo *fwinf = (struct forwrefinfo *)saa_wstruct(forwrefs);
(struct forwrefinfo *) fwinf->lineno = globallineno;
saa_wstruct(forwrefs); fwinf->operand = i;
fwinf->lineno = globallineno; }
fwinf->operand = i; }
} }
}
}
} }
} }
@ -1596,8 +1593,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
if (output_ins.operands == 1 && if (output_ins.operands == 1 &&
(output_ins.oprs[0].type & IMMEDIATE) && (output_ins.oprs[0].type & IMMEDIATE) &&
output_ins.oprs[0].wrt == NO_SEG) { output_ins.oprs[0].wrt == NO_SEG) {
bool isext = !!(output_ins.oprs[0].opflags bool isext = !!(output_ins.oprs[0].opflags & OPFLAG_EXTERN);
& OPFLAG_EXTERN);
def_label(output_ins.label, def_label(output_ins.label,
output_ins.oprs[0].segment, output_ins.oprs[0].segment,
output_ins.oprs[0].offset, NULL, output_ins.oprs[0].offset, NULL,
@ -1613,7 +1609,7 @@ static void assemble_file(char *fname, StrList **depend_ptr)
def_label(output_ins.label, def_label(output_ins.label,
output_ins.oprs[0].offset | SEG_ABS, output_ins.oprs[0].offset | SEG_ABS,
output_ins.oprs[1].offset, output_ins.oprs[1].offset,
NULL, false, false); NULL, false, false);
} else } else
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"bad syntax for EQU"); "bad syntax for EQU");
@ -1707,12 +1703,12 @@ static void assemble_file(char *fname, StrList **depend_ptr)
case I_DT: case I_DT:
typeinfo |= TY_TBYTE; typeinfo |= TY_TBYTE;
break; break;
case I_DO: case I_DO:
typeinfo |= TY_OWORD; typeinfo |= TY_OWORD;
break; break;
case I_DY: case I_DY:
typeinfo |= TY_YWORD; typeinfo |= TY_YWORD;
break; break;
default: default:
typeinfo = TY_LABEL; typeinfo = TY_LABEL;
@ -1745,23 +1741,23 @@ static void assemble_file(char *fname, StrList **depend_ptr)
if (pass0 == 2 && global_offset_changed && !terminate_after_phase) if (pass0 == 2 && global_offset_changed && !terminate_after_phase)
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"phase error detected at end of assembly."); "phase error detected at end of assembly.");
if (pass1 == 1) if (pass1 == 1)
preproc->cleanup(1); preproc->cleanup(1);
if ((passn > 1 && !global_offset_changed) || pass0 == 2) { if ((passn > 1 && !global_offset_changed) || pass0 == 2) {
pass0++; pass0++;
} else if (global_offset_changed && } else if (global_offset_changed &&
global_offset_changed < prev_offset_changed) { global_offset_changed < prev_offset_changed) {
prev_offset_changed = global_offset_changed; prev_offset_changed = global_offset_changed;
stall_count = 0; stall_count = 0;
} else { } else {
stall_count++; stall_count++;
} }
if (terminate_after_phase) if (terminate_after_phase)
break; break;
if ((stall_count > 997) || (passn >= pass_max)) { if ((stall_count > 997) || (passn >= pass_max)) {
/* We get here if the labels don't converge /* We get here if the labels don't converge
@ -1770,16 +1766,16 @@ static void assemble_file(char *fname, StrList **depend_ptr)
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"Can't find valid values for all labels " "Can't find valid values for all labels "
"after %d passes, giving up.", passn); "after %d passes, giving up.", passn);
nasm_error(ERR_NONFATAL, nasm_error(ERR_NONFATAL,
"Possible causes: recursive EQUs, macro abuse."); "Possible causes: recursive EQUs, macro abuse.");
break; break;
} }
} }
preproc->cleanup(0); preproc->cleanup(0);
nasmlist.cleanup(); nasmlist.cleanup();
if (!terminate_after_phase && opt_verbose_info) { if (!terminate_after_phase && opt_verbose_info) {
/* -On and -Ov switches */ /* -On and -Ov switches */
fprintf(stdout, "info: assembly required 1+%d+1 passes\n", passn-3); fprintf(stdout, "info: assembly required 1+%d+1 passes\n", passn-3);
} }
} }