ival.g 17 KB

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