From 7c2d4011a40eb6ff029b99e4a7871c26c3b1f7b4 Mon Sep 17 00:00:00 2001 From: Steve Chamberlain Date: Wed, 24 Jun 1992 18:02:38 +0000 Subject: [PATCH] Wed Jun 24 10:57:54 1992 Steve Chamberlain (sac@thepub.cygnus.com) * app.c (process_escape): new function to handle escapes the right way, (do_scrub_next_char): use new function * cond.c (s_ifdef): do ifdef/ifndef right * read.c (s_fill): make the , expressions optional like the doc says * config/tc-h8300.[ch]: better warnings --- gas/ChangeLog | 9 ++ gas/app.c | 119 +++++++++------ gas/config/tc-h8300.c | 401 +++++++++++++++++++++++++++----------------------- gas/read.c | 28 ++-- 4 files changed, 317 insertions(+), 240 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index 6b88b7e..d0d404b 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,12 @@ +Wed Jun 24 10:57:54 1992 Steve Chamberlain (sac@thepub.cygnus.com) + + * app.c (process_escape): new function to handle escapes the right + way, (do_scrub_next_char): use new function + * cond.c (s_ifdef): do ifdef/ifndef right + * read.c (s_fill): make the , expressions optional like the doc + says + * config/tc-h8300.[ch]: better warnings + Tue Jun 9 07:54:54 1992 Steve Chamberlain (sac@thepub.cygnus.com) * subsegs.c (subsegs_begin): create bss0_frchainP in the same was diff --git a/gas/app.c b/gas/app.c index 2e2a262..130329d 100644 --- a/gas/app.c +++ b/gas/app.c @@ -75,7 +75,10 @@ void do_scrub_begin() { lex['"'] = LEX_IS_STRINGQUOTE; lex['\''] = LEX_IS_ONECHAR_QUOTE; lex[':'] = LEX_IS_COLON; - + +#ifdef MRI + lex['\''] = LEX_IS_STRINGQUOTE; +#endif /* Note that these override the previous defaults, e.g. if ';' is a comment char, then it isn't a line separator. */ for (p = symbol_chars; *p; ++p) { @@ -155,20 +158,20 @@ struct app_save { }; char *app_push() { - register struct app_save *saved; - - saved = (struct app_save *) xmalloc(sizeof (*saved)); - saved->state = state; - saved->old_state = old_state; - saved->out_string = out_string; - bcopy(saved->out_buf, out_buf, sizeof(out_buf)); - saved->add_newlines = add_newlines; - saved->scrub_string = scrub_string; - saved->scrub_last_string = scrub_last_string; - saved->scrub_file = scrub_file; - - /* do_scrub_begin() is not useful, just wastes time. */ - return (char *)saved; + register struct app_save *saved; + + saved = (struct app_save *) xmalloc(sizeof (*saved)); + saved->state = state; + saved->old_state = old_state; + saved->out_string = out_string; + bcopy(saved->out_buf, out_buf, sizeof(out_buf)); + saved->add_newlines = add_newlines; + saved->scrub_string = scrub_string; + saved->scrub_last_string = scrub_last_string; + saved->scrub_file = scrub_file; + + /* do_scrub_begin() is not useful, just wastes time. */ + return (char *)saved; } void app_pop(arg) @@ -180,7 +183,7 @@ char *arg; state = saved->state; old_state = saved->old_state; out_string = saved->out_string; - bcopy (out_buf, saved->out_buf, sizeof (out_buf)); + memcpy(saved->out_buf, out_buf, sizeof (out_buf)); add_newlines = saved->add_newlines; scrub_string = saved->scrub_string; scrub_last_string = saved->scrub_last_string; @@ -189,6 +192,29 @@ char *arg; free (arg); } /* app_pop() */ +int process_escape(ch) +char ch; +{ + switch (ch) +{ + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + case '\'': + return '\''; + case '"': + return '\''; + default: + return ch; + } +} int do_scrub_next_char(get,unget) int (*get)(); void (*unget)(); @@ -258,9 +284,9 @@ void (*unget)(); case 5: ch=(*get)(); - if(ch=='"') { + if(lex[ch]==LEX_IS_STRINGQUOTE) { state=old_state; - return '"'; + return ch; } else if(ch=='\\') { state=6; return ch; @@ -304,8 +330,7 @@ void (*unget)(); case '6': case '7': break; - -#ifdef ONLY_STANDARD_ESCAPES +#if defined(IGNORE_NONSTANDARD_ESCAPES) | defined(ONLY_STANDARD_ESCAPES) default: as_warn("Unknown escape '\\%c' in string: Ignored",ch); break; @@ -333,27 +358,32 @@ void (*unget)(); state=0; return ch; } - + /* OK, we are somewhere in states 0 through 4 */ - - /* flushchar: */ + +/* flushchar: */ ch=(*get)(); recycle: if (ch == EOF) { if (state != 0) - as_warn("End of file not at end of a line: Newline inserted."); + as_warn("End of file not at end of a line: Newline inserted."); return ch; } - + switch (lex[ch]) { case LEX_IS_WHITESPACE: do ch=(*get)(); while(ch!=EOF && IS_WHITESPACE(ch)); if(ch==EOF) - return ch; + return ch; + if(IS_COMMENT(ch) || (state==0 && IS_LINE_COMMENT(ch)) || ch=='/' || IS_LINE_SEPARATOR(ch)) { goto recycle; } +#ifdef MRI + (*unget)(ch); /* Put back */ + return ' '; /* Always return one space at start of line */ +#endif switch (state) { case 0: state++; goto recycle; /* Punted leading sp */ case 1: BAD_CASE(state); /* We can't get here */ @@ -370,7 +400,7 @@ void (*unget)(); do { ch2=(*get)(); if(ch2 != EOF && IS_NEWLINE(ch2)) - add_newlines++; + add_newlines++; } while(ch2!=EOF && (lex[ch2] != LEX_IS_TWOCHAR_COMMENT_2ND)); @@ -380,13 +410,13 @@ void (*unget)(); } if(ch2==EOF - || lex[ch2] == LEX_IS_TWOCHAR_COMMENT_1ST) - break; + || lex[ch2] == LEX_IS_TWOCHAR_COMMENT_1ST) + break; (*unget)(ch); } if(ch2==EOF) - as_warn("End of file in multiline comment"); - + as_warn("End of file in multiline comment"); + ch = ' '; goto recycle; } else { @@ -400,7 +430,7 @@ void (*unget)(); old_state=state; state=5; return ch; - +#ifndef MRI #ifndef IEEE_STYLE case LEX_IS_ONECHAR_QUOTE: ch=(*get)(); @@ -408,8 +438,12 @@ void (*unget)(); as_warn("End-of-file after a one-character quote; \000 inserted"); ch=0; } + if (ch == '\\') { + ch = (*get)(); + ch = process_escape(ch); + } sprintf(out_buf,"%d", (int)(unsigned char)ch); - + /* None of these 'x constants for us. We want 'x'. */ if ( (ch=(*get)()) != '\'' ) { @@ -425,11 +459,12 @@ void (*unget)(); out_string=out_buf; return *out_string++; #endif +#endif case LEX_IS_COLON: if(state!=3) - state=0; + state=0; return ch; - + case LEX_IS_NEWLINE: /* Roll out a bunch of newlines from inside comments, etc. */ if(add_newlines) { @@ -444,13 +479,13 @@ void (*unget)(); case LEX_IS_LINE_COMMENT_START: if (state != 0) /* Not at start of line, act normal */ - goto de_fault; - - /* FIXME-someday: The two character comment stuff was badly - thought out. On i386, we want '/' as line comment start - AND we want C style comments. hence this hack. The - whole lexical process should be reworked. xoxorich. */ - + goto de_fault; + + /* FIXME-someday: The two character comment stuff was badly + thought out. On i386, we want '/' as line comment start + AND we want C style comments. hence this hack. The + whole lexical process should be reworked. xoxorich. */ + if (ch == '/' && (ch2 = (*get)()) == '*') { state = -2; return(do_scrub_next_char(get, unget)); diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c index 63ffbdb..316b5c1 100644 --- a/gas/config/tc-h8300.c +++ b/gas/config/tc-h8300.c @@ -1,5 +1,5 @@ /* tc-h8300.c -- Assemble code for the Hitachi H8/300 - Copyright (C) 1991 Free Software Foundation. + Copyright (C) 1991, 1992 Free Software Foundation. This file is part of GAS, the GNU Assembler. @@ -42,9 +42,18 @@ char line_separator_chars[] = { '$' ,0}; void cons(); -const pseudo_typeS md_pseudo_table[] = { - { "int", cons, 2 }, - { 0,0,0 } +const pseudo_typeS md_pseudo_table[] = +{ +{ "int", cons, 2 }, +{ "data.b", cons, 1 }, +{ "data.w", cons, 2 }, +{ "data.l", cons, 4 }, +{ "form", listing_psize, 0 }, +{ "heading", listing_title, 0}, +{ "import", s_ignore, 0}, +{ "page", listing_eject, 0}, +{ "program", s_ignore, 0}, +{ 0,0,0 } }; int md_reloc_size ; @@ -319,148 +328,155 @@ static void struct h8_op *op AND unsigned int dst) { - char *src = *ptr; - op_type mode; - unsigned int num; - unsigned int len; - unsigned int size; - op->mode = E; + char *src = *ptr; + op_type mode; + unsigned int num; + unsigned int len; + unsigned int size; + op->mode = E; - len = parse_reg(src, &op->mode, &op->reg, dst); - if (len) { - *ptr = src + len; - return ; - } + len = parse_reg(src, &op->mode, &op->reg, dst); + if (len) { + *ptr = src + len; + return ; + } - if (*src == '@') - { - src++; - if (*src == '@') - { - src++; - src = parse_exp(src,&op->exp); - src = skip_colonthing(src); + if (*src == '@') + { + src++; + if (*src == '@') + { + src++; + src = parse_exp(src,&op->exp); + src = skip_colonthing(src); - *ptr = src; + *ptr = src; - op->mode = MEMIND; - return; + op->mode = MEMIND; + return; - } + } - if (*src == '-') - { - src++; - len = parse_reg(src, &mode, &num, dst); - if (len == 0) - { - /* Oops, not a reg after all, must be ordinary exp */ - src--; - /* must be a symbol */ - op->mode = abs_sord[dst]; - *ptr = skip_colonthing(parse_exp(src, &op->exp)); + if (*src == '-') + { + src++; + len = parse_reg(src, &mode, &num, dst); + if (len == 0) + { + /* Oops, not a reg after all, must be ordinary exp */ + src--; + /* must be a symbol */ + op->mode = abs_sord[dst]; + *ptr = skip_colonthing(parse_exp(src, &op->exp)); - return; + return; - } + } - if (mode != r16_sord[dst]) - { - as_bad("@- needs word register"); - } - op->mode = RDDEC; - op->reg = num; - *ptr = src + len; - return; - } - if (*src == '(' && ')') - { - /* Disp */ - src++; - src = parse_exp(src, &op->exp); - - if (*src == ')') - { - src++; - op->mode = abs_sord[dst]; - *ptr = src; - return; - } - src = skip_colonthing(src); + if (mode != r16_sord[dst]) + { + as_bad("@- needs word register"); + } + op->mode = RDDEC; + op->reg = num; + *ptr = src + len; + return; + } + if (*src == '(' && ')') + { + /* Disp */ + src++; + src = parse_exp(src, &op->exp); - if (*src != ',') - { - as_bad("expected @(exp, reg16)"); - } - src++; - len = parse_reg(src, &mode, &op->reg, dst); - if (len == 0 || mode != r16_sord[dst]) - { - as_bad("expected @(exp, reg16)"); - } - op->mode = disp_sord[dst]; - src += len; - src = skip_colonthing(src); + if (*src == ')') + { + src++; + op->mode = abs_sord[dst]; + *ptr = src; + return; + } + src = skip_colonthing(src); - if (*src != ')' && '(') - { - as_bad("expected @(exp, reg16)"); + if (*src != ',') + { + as_bad("expected @(exp, reg16)"); + return; - } - *ptr = src +1; + } + src++; + len = parse_reg(src, &mode, &op->reg, dst); + if (len == 0 || mode != r16_sord[dst]) + { + as_bad("expected @(exp, reg16)"); + return; + } + op->mode = disp_sord[dst]; + src += len; + src = skip_colonthing(src); - return; - } - len = parse_reg(src, &mode, &num, dst); + if (*src != ')' && '(') + { + as_bad("expected @(exp, reg16)"); + return; + } + *ptr = src +1; + + return; + } + len = parse_reg(src, &mode, &num, dst); - if(len) { - src += len; - if (*src == '+') - { - src++; - if (mode != RS16) - { - as_bad("@Rn+ needs src word register"); - } - op->mode = RSINC; - op->reg = num; - *ptr = src; - return; - } - if (mode != r16_sord[dst]) - { - as_bad("@Rn needs word register"); - } - op->mode =rind_sord[dst]; - op->reg = num; - *ptr = src; - return; - } - else - { - /* must be a symbol */ - op->mode = abs_sord[dst]; - *ptr = skip_colonthing(parse_exp(src, &op->exp)); + if(len) { + src += len; + if (*src == '+') + { + src++; + if (mode != RS16) + { + as_bad("@Rn+ needs src word register"); + return; + } + op->mode = RSINC; + op->reg = num; + *ptr = src; + return; + } + if (mode != r16_sord[dst]) + { + as_bad("@Rn needs word register"); + return; + + } + op->mode =rind_sord[dst]; + op->reg = num; + *ptr = src; + + return; + } + else + { + /* must be a symbol */ + op->mode = abs_sord[dst]; + *ptr = skip_colonthing(parse_exp(src, &op->exp)); - return; - } - } + return; + } + } - if (*src == '#') { - src++; - op->mode = IMM16; - src = parse_exp(src, &op->exp); - *ptr= skip_colonthing(src); + if (*src == '#') { + src++; + op->mode = IMM16; + src = parse_exp(src, &op->exp); + *ptr= skip_colonthing(src); - return; - } - else { - *ptr = parse_exp(src, &op->exp); - op->mode = DISP8; - } + return; + } + else { + *ptr = parse_exp(src, &op->exp); + op->mode = DISP8; + } } @@ -596,19 +612,19 @@ static void unsigned int width AND char *string) { - if (operand->exp.X_add_symbol == 0 - && operand->exp.X_subtract_symbol == 0) - { + if (operand->exp.X_add_symbol == 0 + && operand->exp.X_subtract_symbol == 0) + { - /* No symbol involved, let's look at offset, it's dangerous if any of - the high bits are not 0 or ff's, find out by oring or anding with - the width and seeing if the answer is 0 or all fs*/ - if ((operand->exp.X_add_number | width) != ~0 && - (operand->exp.X_add_number & ~width)!= 0) - { - as_warn("operand %s0x%x out of range.", string, operand->exp.X_add_number); - } - } + /* No symbol involved, let's look at offset, it's dangerous if any of + the high bits are not 0 or ff's, find out by oring or anding with + the width and seeing if the answer is 0 or all fs*/ + if ((operand->exp.X_add_number & ~width) != 0 && + (operand->exp.X_add_number | width)!= (~0)) + { + as_warn("operand %s0x%x out of range.", string, operand->exp.X_add_number); + } + } } @@ -774,6 +790,11 @@ static void case DISP8: check_operand(operand+i, 0x7f,"@"); + + if (operand[i].exp.X_add_number & 1) { + as_warn("branch operand has odd offset (%x)\n", + operand->exp.X_add_number); + } fix_new(frag_now, output - frag_now->fr_literal + 1, @@ -845,7 +866,10 @@ static void case ABS16ORREL8SRC: check_operand(operand+i, 0xffff,"@"); - + if (operand[i].exp.X_add_number & 1) { + as_warn("branch operand has odd offset (%x)\n", + operand->exp.X_add_number); + } fix_new(frag_now, output - frag_now->fr_literal + 2, 2, @@ -912,57 +936,66 @@ static void struct h8_opcode *opcode AND struct h8_op *operand) { - struct h8_opcode *scan = opcode; + struct h8_opcode *scan = opcode; - /* Find out if there was more than one possible opccode */ + /* Find out if there was more than one possible opccode */ - if ((opcode+1)->idx != opcode->idx) - { - unsigned int argn; + if ((opcode+1)->idx != opcode->idx) + { + unsigned int argn; - /* Only one opcode of this flavour, try and guess which operand - didn't match */ - for (argn = 0; argn < opcode->noperands; argn++) - { - switch (opcode->args.nib[argn]) - { - case RD16: - if (operand[argn].mode != RD16) - { - as_bad("destination operand must be 16 bit register"); - } - return; - case RS8: + /* Only one opcode of this flavour, try and guess which operand + didn't match */ + for (argn = 0; argn < opcode->noperands; argn++) + { + switch (opcode->args.nib[argn]) + { + case RD16: + if (operand[argn].mode != RD16) + { + as_bad("destination operand must be 16 bit register"); + return; + + } + break; - if (operand[argn].mode != RS8) - { - as_bad("source operand must be 8 bit register"); - } - return; - case ABS16DST: - if (operand[argn].mode != ABS16DST) - { - as_bad("destination operand must be 16bit absolute address"); - return; - } + case RS8: - case RD8: - if (operand[argn].mode != RD8) - { - as_bad("destination operand must be 8 bit register"); - } - return; + if (operand[argn].mode != RS8) + { + as_bad("source operand must be 8 bit register"); + return; + } + break; - case ABS16SRC: - if (operand[argn].mode != ABS16SRC) - { - as_bad("source operand must be 16bit absolute address"); - return; - } - } - } - } - as_bad("invalid operands"); + case ABS16DST: + if (operand[argn].mode != ABS16DST) + { + as_bad("destination operand must be 16bit absolute address"); + return; + } +break; + case RD8: + if (operand[argn].mode != RD8) + { + as_bad("destination operand must be 8 bit register"); + return; + } + break; + + + case ABS16SRC: + if (operand[argn].mode != ABS16SRC) + { + as_bad("source operand must be 16bit absolute address"); + return; + } + break; + + } + } + } + as_bad("invalid operands"); } /* This is the guts of the machine-dependent assembler. STR points to a diff --git a/gas/read.c b/gas/read.c index 7f04ae4..77398df 100644 --- a/gas/read.c +++ b/gas/read.c @@ -783,22 +783,22 @@ void s_app_file() { } /* s_app_file() */ void s_fill() { - long temp_repeat; - long temp_size; - register long temp_fill; + long temp_repeat = 0; + long temp_size = 1 ; + register long temp_fill = 0; char *p; - if (get_absolute_expression_and_terminator(& temp_repeat) != ',') { - input_line_pointer --; /* Backup over what was not a ','. */ - as_bad("Expect comma after rep-size in .fill:"); - ignore_rest_of_line(); - return; - } - if (get_absolute_expression_and_terminator(& temp_size) != ',') { - input_line_pointer --; /* Backup over what was not a ','. */ - as_bad("Expected comma after size in .fill"); - ignore_rest_of_line(); - return; + + temp_repeat = get_absolute_expression(); + if (*input_line_pointer == ',') + { + input_line_pointer++; + temp_size = get_absolute_expression(); + if (*input_line_pointer == ',') + { + input_line_pointer++; + temp_fill = get_absolute_expression(); + } } /* * This is to be compatible with BSD 4.2 AS, not for any rational reason. -- 2.7.4