From 901d1b3af8dd41a228155945caf7014d5e3fea90 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 25 Aug 1986 08:47:07 +0000 Subject: [PATCH] generate a con instruction for each character in a string constant --- lang/cem/cemcom/code.c | 2 +- lang/cem/cemcom/ival.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index b9ba88f87..b56e16e32 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -81,7 +81,7 @@ def_strings(sc) if (sc) { def_strings(sc->next); 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); } } diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index b47cd0ad4..95e8d3fac 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -67,7 +67,7 @@ IVAL(tpp, ex) return do_array(ex, tpp); /* catch initialisations like char s[] = "I am a 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;" */ check_and_pad(ex, tpp); break; @@ -140,7 +140,7 @@ do_array(ex, tpp) f = f->OP_LEFT; } 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; } /* 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. Alignment is taken care of. */ -init_string(tpp, ex) +ch_array(tpp, ex) struct type **tpp; /* type tp = array of characters */ struct expr *ex; { @@ -536,6 +536,14 @@ init_string(tpp, ex) 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 /* put_bf() takes care of the initialisation of (bit-)field selectors of a struct: each time such an initialisation takes place, -- 2.34.1