generate a con instruction for each character in a string constant

This commit is contained in:
erikb 1986-08-25 08:47:07 +00:00
parent fc9f365b47
commit 901d1b3af8
2 changed files with 13 additions and 5 deletions

View file

@ -81,7 +81,7 @@ def_strings(sc)
if (sc) { if (sc) {
def_strings(sc->next); def_strings(sc->next);
C_df_dlb(sc->sc_dlb); C_df_dlb(sc->sc_dlb);
C_con_scon(sc->sc_value, sc->sc_len); str_cst(sc->sc_value, sc->sc_len);
free_string_cst(sc); free_string_cst(sc);
} }
} }

View file

@ -67,7 +67,7 @@ IVAL(tpp, ex)
return do_array(ex, tpp); return do_array(ex, tpp);
/* catch initialisations like char s[] = "I am a string" */ /* catch initialisations like char s[] = "I am a string" */
if (tp->tp_up->tp_fund == CHAR && ex->ex_class == String) if (tp->tp_up->tp_fund == CHAR && ex->ex_class == String)
init_string(tpp, ex); ch_array(tpp, ex);
else /* " int i[24] = 12;" */ else /* " int i[24] = 12;" */
check_and_pad(ex, tpp); check_and_pad(ex, tpp);
break; break;
@ -140,7 +140,7 @@ do_array(ex, tpp)
f = f->OP_LEFT; f = f->OP_LEFT;
} }
if (f->ex_class == String) { /* hallelujah, it's a string! */ if (f->ex_class == String) { /* hallelujah, it's a string! */
init_string(tpp, f); ch_array(tpp, f);
return g ? g->OP_RIGHT : ex->OP_RIGHT; return g ? g->OP_RIGHT : ex->OP_RIGHT;
} }
/* else: just go on with the next part of this function */ /* else: just go on with the next part of this function */
@ -492,11 +492,11 @@ check_ival(ex, tp)
} }
} }
/* init_string() initialises an array of characters by specifying /* ch_array() initialises an array of characters when given
a string constant. a string constant.
Alignment is taken care of. Alignment is taken care of.
*/ */
init_string(tpp, ex) ch_array(tpp, ex)
struct type **tpp; /* type tp = array of characters */ struct type **tpp; /* type tp = array of characters */
struct expr *ex; struct expr *ex;
{ {
@ -536,6 +536,14 @@ init_string(tpp, ex)
con_nullbyte(); con_nullbyte();
} }
str_cst(str, len)
register char *str;
register int len;
{
while (len-- > 0)
C_con_ucon(long2str((long)*str++ & 0xFF, 10), (arith)1);
}
#ifndef NOBITFIELD #ifndef NOBITFIELD
/* put_bf() takes care of the initialisation of (bit-)field /* put_bf() takes care of the initialisation of (bit-)field
selectors of a struct: each time such an initialisation takes place, selectors of a struct: each time such an initialisation takes place,