ival.g 16 KB

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