Преглед на файлове

generate a con instruction for each character in a string constant

erikb преди 38 години
родител
ревизия
196cc676d9
променени са 2 файла, в които са добавени 13 реда и са изтрити 5 реда
  1. 1 1
      lang/cem/cemcom/code.c
  2. 12 4
      lang/cem/cemcom/ival.c

+ 1 - 1
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);
 	}
 }

+ 12 - 4
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,