ival.g 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /* CODE FOR THE INITIALISATION OF GLOBAL VARIABLES */
  7. {
  8. #include "lint.h"
  9. #ifndef LINT
  10. #include <em.h>
  11. #else
  12. #include "l_em.h"
  13. #include "l_lint.h"
  14. #endif /* LINT */
  15. #include "debug.h"
  16. #include <alloc.h>
  17. #include <assert.h>
  18. #include "nobitfield.h"
  19. #include <flt_arith.h>
  20. #include "arith.h"
  21. #include "label.h"
  22. #include "expr.h"
  23. #include "type.h"
  24. #include "proto.h"
  25. #include "struct.h"
  26. #include "field.h"
  27. #include "assert.h"
  28. #include "Lpars.h"
  29. #include "sizes.h"
  30. #include "align.h"
  31. #include "idf.h"
  32. #include "level.h"
  33. #include "def.h"
  34. #include "LLlex.h"
  35. #include "estack.h"
  36. #include "conversion.h"
  37. #include "cstopen.h"
  38. #define con_nullbyte() C_con_ucon("0", (arith)1)
  39. #define aggregate_type(tp) ((tp)->tp_fund == ARRAY || (tp)->tp_fund == STRUCT)
  40. char *long2str();
  41. char *strncpy();
  42. extern char options[];
  43. static int gen_error;
  44. static int pack_level;
  45. struct type **gen_tphead(), **gen_tpmiddle();
  46. struct sdef *gen_align_to_next();
  47. struct e_stack *p_stack;
  48. }
  49. /* initial_value recursively guides the initialisation expression.
  50. */
  51. /* 3.5 */
  52. initial_value(register struct type **tpp; register struct expr **expp;) :
  53. { if (tpp) gen_tpcheck(tpp); }
  54. [
  55. { if (pack_level == 0) gen_error = 0; }
  56. assignment_expression(expp)
  57. {
  58. #ifdef LINT
  59. lint_expr(*expp, USED);
  60. #endif /* LINT */
  61. if ((*expp)->ex_type->tp_fund == ARRAY)
  62. array2pointer(*expp);
  63. if (tpp) {
  64. if (level >= L_LOCAL
  65. || is_ld_cst(*expp)
  66. || is_fp_cst(*expp)
  67. || (*expp)->ex_class == String) {
  68. gen_simple_exp(tpp, expp);
  69. free_expression(*expp);
  70. *expp = 0;
  71. } else {
  72. expr_error(*expp,"illegal initialization");
  73. free_expression(*expp);
  74. *expp = 0;
  75. }
  76. }
  77. }
  78. |
  79. initial_value_pack(tpp, expp)
  80. ]
  81. ;
  82. initial_value_pack(struct type **tpp; struct expr **expp;)
  83. :
  84. '{'
  85. { if (pack_level == 0) gen_error = 0; pack_level++; }
  86. initial_value_list(tpp, expp)
  87. { pack_level--;
  88. if (!pack_level) {
  89. while (p_stack) {
  90. struct e_stack *p = p_stack->next;
  91. free_e_stack(p_stack);
  92. p_stack = p;
  93. }
  94. }
  95. if (pack_level < gen_error) gen_error = 0;
  96. }
  97. '}'
  98. ;
  99. initial_value_list(register struct type **tpp; struct expr **expp;)
  100. { struct expr *e1;
  101. register struct type **tpp2 = 0;
  102. int err_flag = gen_error;
  103. }
  104. :
  105. { if (tpp) tpp2 = gen_tphead(tpp, 0); }
  106. initial_value(tpp2, &e1)
  107. { if (!tpp) init_expression(&expp, e1); }
  108. [%while (AHEAD != '}') /* >>> conflict on ',' */
  109. ','
  110. { if (tpp) tpp2 = gen_tpmiddle(); }
  111. initial_value(tpp2, &e1)
  112. { if (!tpp) init_expression(&expp, e1); }
  113. ]*
  114. { if (tpp && ! err_flag) gen_tpend(); }
  115. ','? /* optional trailing comma */
  116. ;
  117. {
  118. gen_tpcheck(tpp)
  119. struct type **tpp;
  120. {
  121. register struct type *tp;
  122. if (gen_error) return;
  123. switch((tp = *tpp)->tp_fund) {
  124. case ARRAY:
  125. if (! valid_type(tp->tp_up, "array element"))
  126. gen_error = pack_level;
  127. break;
  128. case STRUCT:
  129. if (! valid_type(tp, "struct"))
  130. gen_error = pack_level;
  131. break;
  132. case UNION:
  133. if (! valid_type(tp, "union"))
  134. gen_error = pack_level;
  135. break;
  136. case ERRONEOUS:
  137. if (! gen_error) gen_error = pack_level;
  138. break;
  139. }
  140. }
  141. gen_simple_exp(tpp, expp)
  142. struct type **tpp;
  143. struct expr **expp;
  144. {
  145. register struct type *tp;
  146. if (gen_error) return;
  147. tp = *tpp;
  148. switch(tp->tp_fund) {
  149. case ARRAY:
  150. if ((*expp)->ex_class == String && tp->tp_up->tp_fund == CHAR) {
  151. ch_array(tpp,*expp);
  152. break;
  153. }
  154. /* Fall through */
  155. case UNION:
  156. case STRUCT:
  157. check_and_pad(expp, tpp);
  158. break;
  159. case ERRONEOUS:
  160. case FUNCTION:
  161. case VOID:
  162. gen_error = pack_level;
  163. break;
  164. default:
  165. check_ival(expp, tp);
  166. break;
  167. }
  168. }
  169. struct type **
  170. arr_elem(tpp, p)
  171. struct type **tpp;
  172. struct e_stack *p;
  173. {
  174. register struct type *tp = *tpp;
  175. if (tp->tp_up->tp_fund == CHAR && AHEAD == STRING && p->elem_count == 1) {
  176. p->nelem = 1;
  177. return tpp;
  178. }
  179. if (AHEAD == '{' || (! aggregate_type(tp->tp_up) && tp->tp_up->tp_fund != UNION))
  180. return &(tp->tp_up);
  181. return gen_tphead(&(tp->tp_up), 1);
  182. }
  183. struct sdef *
  184. next_field(sd, p)
  185. register struct sdef *sd;
  186. register struct e_stack *p;
  187. {
  188. if (sd->sd_sdef)
  189. p->bytes_upto_here += zero_bytes(sd);
  190. p->bytes_upto_here +=
  191. size_of_type(sd->sd_type, "selector");
  192. p->last_offset = sd->sd_offset;
  193. return sd->sd_sdef;
  194. }
  195. struct type **
  196. gen_tphead(tpp, nest)
  197. struct type **tpp;
  198. {
  199. register struct type *tp = *tpp;
  200. register struct e_stack *p;
  201. register struct sdef *sd;
  202. if (tpp && *tpp == error_type) {
  203. gen_error = pack_level;
  204. return 0;
  205. }
  206. if (gen_error) return tpp;
  207. if (tp->tp_fund == UNION) {
  208. /* Here, we saw a {, which could be the start of a union
  209. initializer. It could, however, also be the start of the
  210. initializer for the first union field ...
  211. */
  212. sd = tp->tp_sdef;
  213. if (AHEAD != '{' &&
  214. (aggregate_type(sd->sd_type) ||
  215. sd->sd_type->tp_fund == UNION)) {
  216. /* In this case, assume that it is the start of the
  217. initializer of the union field, so:
  218. */
  219. return gen_tphead(&(tp->tp_sdef->sd_type), nest);
  220. }
  221. }
  222. p = new_e_stack();
  223. p->next = p_stack;
  224. p_stack = p;
  225. p->s_nested = nest;
  226. p->s_tpp = tpp;
  227. switch(tp->tp_fund) {
  228. case UNION:
  229. p->s_def = sd = tp->tp_sdef;
  230. p->bytes_upto_here = 0;
  231. return &(sd->sd_type);
  232. case ARRAY:
  233. p->nelem = -1;
  234. p->elem_count = 1;
  235. if (tp->tp_size != (arith) -1) {
  236. p->nelem = (tp->tp_size / tp->tp_up->tp_size);
  237. }
  238. return arr_elem(tpp, p);
  239. case STRUCT:
  240. p->s_def = sd = tp->tp_sdef;
  241. p->bytes_upto_here = 0;
  242. p->last_offset = -1;
  243. #ifndef NOBITFIELD
  244. while (sd && is_anon_idf(sd->sd_idf)) {
  245. put_bf(sd->sd_type, (arith) 0);
  246. sd = next_field(sd, p);
  247. }
  248. #endif
  249. if (! sd) {
  250. /* something wrong with this struct */
  251. gen_error = pack_level;
  252. p_stack = p->next;
  253. free_e_stack(p);
  254. return 0;
  255. }
  256. p->s_def = sd;
  257. if (AHEAD != '{' && aggregate_type(sd->sd_type)) {
  258. return gen_tphead(&(sd->sd_type), 1);
  259. }
  260. return &(sd->sd_type);
  261. case ERRONEOUS:
  262. if (! gen_error) gen_error = pack_level;
  263. /* fall through */
  264. default:
  265. p->nelem = 1;
  266. p->elem_count = 1;
  267. return tpp;
  268. }
  269. }
  270. struct type **
  271. gen_tpmiddle()
  272. {
  273. register struct type *tp;
  274. register struct sdef *sd;
  275. register struct e_stack *p = p_stack;
  276. if (gen_error) {
  277. if (p) return p->s_tpp;
  278. return 0;
  279. }
  280. again:
  281. tp = *(p->s_tpp);
  282. switch(tp->tp_fund) {
  283. case ERRONEOUS:
  284. if (! gen_error) gen_error = pack_level;
  285. return p->s_tpp;
  286. case UNION:
  287. sd = p->s_def;
  288. p->bytes_upto_here +=
  289. size_of_type(sd->sd_type, "selector");
  290. return p->s_tpp;
  291. default:
  292. if (p->elem_count == p->nelem && p->s_nested) {
  293. p = p->next;
  294. free_e_stack(p_stack);
  295. p_stack = p;
  296. goto again;
  297. }
  298. p->elem_count++;
  299. if (p->nelem >= 0 && p->elem_count > p->nelem) {
  300. too_many_initialisers();
  301. return p->s_tpp;
  302. }
  303. if (tp->tp_fund == ARRAY) {
  304. return arr_elem(p->s_tpp, p);
  305. }
  306. return p->s_tpp;
  307. case STRUCT:
  308. sd = gen_align_to_next(p);
  309. if (! sd) {
  310. while (p->bytes_upto_here++ < tp->tp_size)
  311. con_nullbyte();
  312. if (p->s_nested) {
  313. p = p->next;
  314. free_e_stack(p_stack);
  315. p_stack = p;
  316. goto again;
  317. }
  318. too_many_initialisers();
  319. return p->s_tpp;
  320. }
  321. if (AHEAD != '{' && aggregate_type(sd->sd_type)) {
  322. return gen_tphead(&(sd->sd_type), 1);
  323. }
  324. return &(sd->sd_type);
  325. }
  326. }
  327. struct sdef *
  328. gen_align_to_next(p)
  329. register struct e_stack *p;
  330. {
  331. register struct sdef *sd = p->s_def;
  332. if (! sd) return sd;
  333. #ifndef NOBITFIELD
  334. do {
  335. if (is_anon_idf(sd->sd_idf)) put_bf(sd->sd_type, (arith) 0);
  336. #endif
  337. sd = next_field(sd, p);
  338. #ifndef NOBITFIELD
  339. } while (sd && is_anon_idf(sd->sd_idf));
  340. #endif
  341. p->s_def = sd;
  342. return sd;
  343. }
  344. gen_tpend()
  345. {
  346. register struct e_stack *p = p_stack;
  347. register struct type *tp;
  348. register struct sdef *sd;
  349. int getout = 0;
  350. while (!getout && p) {
  351. if (!gen_error) {
  352. tp = *(p->s_tpp);
  353. switch(tp->tp_fund) {
  354. case UNION:
  355. sd = p->s_def;
  356. p->bytes_upto_here +=
  357. size_of_type(sd->sd_type, "selector");
  358. while (p->bytes_upto_here++ < tp->tp_size)
  359. con_nullbyte();
  360. break;
  361. case ARRAY:
  362. if (tp->tp_size == -1) {
  363. *(p->s_tpp) = construct_type(ARRAY, tp->tp_up,
  364. 0, p->elem_count, NO_PROTO);
  365. }
  366. else {
  367. while (p->nelem-- > p->elem_count) {
  368. pad(tp->tp_up);
  369. }
  370. }
  371. break;
  372. case STRUCT:
  373. sd = gen_align_to_next(p);
  374. while (sd) {
  375. pad(sd->sd_type);
  376. if (sd->sd_sdef)
  377. p->bytes_upto_here += zero_bytes(sd);
  378. p->bytes_upto_here +=
  379. size_of_type(sd->sd_type, "selector");
  380. sd = sd->sd_sdef;
  381. }
  382. while (p->bytes_upto_here++ < tp->tp_size)
  383. con_nullbyte();
  384. break;
  385. }
  386. }
  387. if (! p->s_nested) getout = 1;
  388. p = p->next;
  389. free_e_stack(p_stack);
  390. p_stack = p;
  391. }
  392. }
  393. /* check_and_pad() is given a simple initialisation expression
  394. where the type can be either a simple or an aggregate type.
  395. In the latter case, only the first member is initialised and
  396. the rest is zeroed.
  397. */
  398. check_and_pad(expp, tpp)
  399. struct type **tpp;
  400. struct expr **expp;
  401. {
  402. register struct type *tp = *tpp;
  403. if (tp->tp_fund == ARRAY) {
  404. check_and_pad(expp, &(tp->tp_up)); /* first member */
  405. if (tp->tp_size == (arith)-1)
  406. /* no size specified upto here: just
  407. set it to the size of one member.
  408. */
  409. tp = *tpp = construct_type(ARRAY, tp->tp_up,
  410. 0, (arith)1, NO_PROTO);
  411. else {
  412. register int dim = tp->tp_size / tp->tp_up->tp_size;
  413. /* pad remaining members with zeroes */
  414. while (--dim > 0)
  415. pad(tp->tp_up);
  416. }
  417. }
  418. else
  419. if (tp->tp_fund == STRUCT) {
  420. register struct sdef *sd = tp->tp_sdef;
  421. check_and_pad(expp, &(sd->sd_type));
  422. /* next selector is aligned by adding extra zeroes */
  423. if (sd->sd_sdef)
  424. zero_bytes(sd);
  425. while (sd = sd->sd_sdef) { /* pad remaining selectors */
  426. pad(sd->sd_type);
  427. if (sd->sd_sdef)
  428. zero_bytes(sd);
  429. }
  430. }
  431. else if (tp->tp_fund == UNION) {
  432. /* only the first selector can be initialized */
  433. register struct sdef *sd = tp->tp_sdef;
  434. check_and_pad(expp, &(sd->sd_type));
  435. }
  436. else /* simple type */
  437. check_ival(expp, tp);
  438. }
  439. /* pad() fills an element of type tp with zeroes.
  440. If the element is an aggregate, pad() is called recursively.
  441. */
  442. pad(tpx)
  443. struct type *tpx;
  444. {
  445. register struct type *tp = tpx;
  446. register arith sz = tp->tp_size;
  447. gen_tpcheck(&tpx);
  448. if (gen_error) return;
  449. #ifndef NOBITFIELD
  450. if (tp->tp_fund == FIELD) {
  451. put_bf(tp, (arith)0);
  452. return;
  453. }
  454. #endif /* NOBITFIELD */
  455. if (tp->tp_align >= word_align) while (sz >= word_size) {
  456. C_con_cst((arith) 0);
  457. sz -= word_size;
  458. }
  459. while (sz) {
  460. C_con_icon("0", (arith) 1);
  461. sz--;
  462. }
  463. }
  464. /* check_ival() checks whether the initialisation of an element
  465. of a fundamental type is legal and, if so, performs the initialisation
  466. by directly generating the necessary code.
  467. No further comment is needed to explain the internal structure
  468. of this straightforward function.
  469. */
  470. check_ival(expp, tp)
  471. register struct type *tp;
  472. struct expr **expp;
  473. {
  474. /* The philosophy here is that ch3cast puts an explicit
  475. conversion node in front of the expression if the types
  476. are not compatible. In this case, the initialisation
  477. expression is no longer a constant.
  478. */
  479. register struct expr *expr = *expp;
  480. switch (tp->tp_fund) {
  481. case CHAR:
  482. case SHORT:
  483. case INT:
  484. case LONG:
  485. case ENUM:
  486. case POINTER:
  487. ch3cast(expp, '=', tp);
  488. expr = *expp;
  489. #ifdef DEBUG
  490. print_expr("init-expr after cast", expr);
  491. #endif /* DEBUG */
  492. if (!is_ld_cst(expr))
  493. illegal_init_cst(expr);
  494. else
  495. if (expr->VL_CLASS == Const)
  496. con_int(expr);
  497. else
  498. if (expr->VL_CLASS == Name) {
  499. register struct idf *idf = expr->VL_IDF;
  500. if (idf->id_def->df_level >= L_LOCAL
  501. && idf->id_def->df_sc != GLOBAL
  502. && idf->id_def->df_sc != EXTERN) {
  503. illegal_init_cst(expr);
  504. }
  505. else /* e.g., int f(); int p = f; */
  506. if (idf->id_def->df_type->tp_fund == FUNCTION)
  507. C_con_pnam(idf->id_text);
  508. else /* e.g., int a; int *p = &a; */
  509. C_con_dnam(idf->id_text, expr->VL_VALUE);
  510. }
  511. else {
  512. ASSERT(expr->VL_CLASS == Label);
  513. C_con_dlb(expr->VL_LBL, expr->VL_VALUE);
  514. }
  515. break;
  516. case FLOAT:
  517. case DOUBLE:
  518. case LNGDBL:
  519. ch3cast(expp, '=', tp);
  520. expr = *expp;
  521. #ifdef DEBUG
  522. print_expr("init-expr after cast", expr);
  523. #endif /* DEBUG */
  524. if (expr->ex_class == Float) {
  525. char buf[FLT_STRLEN];
  526. flt_flt2str(&(expr->FL_ARITH), buf, FLT_STRLEN);
  527. C_con_fcon(buf, expr->ex_type->tp_size);
  528. }
  529. #ifdef NOTDEF
  530. Coercion from int to float is now always done compile time.
  531. This, to accept declarations like
  532. double x = -(double)1;
  533. and also to prevent runtime coercions for compile-time constants.
  534. else
  535. if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) {
  536. /* float f = 1; */
  537. expr = expr->OP_RIGHT;
  538. if (is_cp_cst(expr))
  539. C_con_fcon(long2str((long)expr->VL_VALUE, 10),
  540. tp->tp_size);
  541. else
  542. illegal_init_cst(expr);
  543. }
  544. #endif /* NOTDEF */
  545. else
  546. illegal_init_cst(expr);
  547. break;
  548. #ifndef NOBITFIELD
  549. case FIELD:
  550. ch3cast(expp, '=', tp->tp_up);
  551. expr = *expp;
  552. #ifdef DEBUG
  553. print_expr("init-expr after cast", expr);
  554. #endif /* DEBUG */
  555. if (is_cp_cst(expr))
  556. put_bf(tp, expr->VL_VALUE);
  557. else
  558. illegal_init_cst(expr);
  559. break;
  560. #endif /* NOBITFIELD */
  561. case ERRONEOUS:
  562. if (! gen_error) gen_error = pack_level;
  563. /* fall through */
  564. case VOID:
  565. break;
  566. default:
  567. crash("check_ival");
  568. /*NOTREACHED*/
  569. }
  570. }
  571. /* ch_array() initialises an array of characters when given
  572. a string constant.
  573. Alignment is taken care of.
  574. */
  575. ch_array(tpp, ex)
  576. struct type **tpp; /* type tp = array of characters */
  577. struct expr *ex;
  578. {
  579. register struct type *tp = *tpp;
  580. register int length = ex->SG_LEN, i;
  581. register char *to, *from, *s;
  582. ASSERT(ex->ex_class == String);
  583. if (tp->tp_size == (arith)-1) {
  584. /* set the dimension */
  585. tp = *tpp = construct_type(ARRAY, tp->tp_up, 0, (arith)length, NO_PROTO);
  586. }
  587. else {
  588. arith dim = tp->tp_size / tp->tp_up->tp_size;
  589. #ifdef LINT
  590. if (length == dim + 1) {
  591. expr_warning(ex, "array is not null-terminated");
  592. } else
  593. #endif
  594. if (length > dim + 1) {
  595. expr_strict(ex, "too many initializers");
  596. }
  597. length = dim;
  598. }
  599. /* throw out the characters of the already prepared string */
  600. s = Malloc((unsigned) (length));
  601. clear(s, (unsigned)length);
  602. i = length <= ex->SG_LEN ? length : ex->SG_LEN;
  603. to = s; from = ex->SG_VALUE;
  604. while(--i >= 0) {
  605. *to++ = *from++;
  606. }
  607. free(ex->SG_VALUE);
  608. str_cst(s, length, 0); /* a string, but not in rom */
  609. free(s);
  610. }
  611. /* As long as some parts of the pipeline cannot handle very long string
  612. constants, string constants are written out in chunks
  613. */
  614. str_cst(str, len, inrom)
  615. register char *str;
  616. register int len;
  617. int inrom;
  618. {
  619. int chunksize = ((127 + (int) word_size) / (int) word_size) * (int) word_size;
  620. while (len > chunksize) {
  621. if (inrom)
  622. C_rom_scon(str, (arith) chunksize);
  623. else C_con_scon(str, (arith) chunksize);
  624. len -= chunksize;
  625. str += chunksize;
  626. }
  627. if (inrom)
  628. C_rom_scon(str, (arith) len);
  629. else C_con_scon(str, (arith) len);
  630. }
  631. #ifndef NOBITFIELD
  632. /* put_bf() takes care of the initialisation of (bit-)field
  633. selectors of a struct: each time such an initialisation takes place,
  634. put_bf() is called instead of the normal code generating routines.
  635. Put_bf() stores the given integral value into "field" and
  636. "throws" the result of "field" out if the current selector
  637. is the last of this number of fields stored at the same address.
  638. */
  639. put_bf(tp, val)
  640. struct type *tp;
  641. arith val;
  642. {
  643. static long field = (arith)0;
  644. static arith offset = (arith)-1;
  645. register struct field *fd = tp->tp_field;
  646. register struct sdef *sd = fd->fd_sdef;
  647. static struct expr exp;
  648. ASSERT(sd);
  649. if (offset == (arith)-1) {
  650. /* first bitfield in this field */
  651. offset = sd->sd_offset;
  652. exp.ex_type = tp->tp_up;
  653. exp.ex_class = Value;
  654. exp.VL_CLASS = Const;
  655. }
  656. if (val != 0) /* insert the value into "field" */
  657. field |= (val & fd->fd_mask) << fd->fd_shift;
  658. if (sd->sd_sdef == 0 || sd->sd_sdef->sd_offset != offset) {
  659. /* the selector was the last stored at this address */
  660. exp.VL_VALUE = field;
  661. con_int(&exp);
  662. field = (arith)0;
  663. offset = (arith)-1;
  664. }
  665. }
  666. #endif /* NOBITFIELD */
  667. int
  668. zero_bytes(sd)
  669. register struct sdef *sd;
  670. {
  671. /* fills the space between a selector of a struct
  672. and the next selector of that struct with zero-bytes.
  673. */
  674. register int n = sd->sd_sdef->sd_offset - sd->sd_offset -
  675. size_of_type(sd->sd_type, "struct member");
  676. int count = n;
  677. while (n-- > 0)
  678. con_nullbyte();
  679. return count;
  680. }
  681. int
  682. valid_type(tp, str)
  683. struct type *tp;
  684. char *str;
  685. {
  686. ASSERT(tp!=(struct type *)0);
  687. if (tp->tp_size < 0) {
  688. error("size of %s unknown", str);
  689. return 0;
  690. }
  691. return 1;
  692. }
  693. con_int(ex)
  694. register struct expr *ex;
  695. {
  696. register struct type *tp = ex->ex_type;
  697. ASSERT(is_cp_cst(ex));
  698. if (tp->tp_unsigned)
  699. C_con_ucon(long2str((long)ex->VL_VALUE, -10), tp->tp_size);
  700. else if (tp->tp_size == word_size)
  701. C_con_cst(ex->VL_VALUE);
  702. else
  703. C_con_icon(long2str((long)ex->VL_VALUE, 10), tp->tp_size);
  704. }
  705. illegal_init_cst(ex)
  706. struct expr *ex;
  707. {
  708. expr_error(ex, "illegal initialization constant");
  709. gen_error = pack_level;
  710. }
  711. too_many_initialisers()
  712. {
  713. error("too many initializers");
  714. gen_error = pack_level;
  715. }
  716. }