code.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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. /* C O D E - G E N E R A T I N G R O U T I N E S */
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "lint.h"
  10. #include "debug.h"
  11. #include "dbsymtab.h"
  12. #ifndef LINT
  13. #include <em.h>
  14. #else
  15. #include "l_em.h"
  16. #include "l_lint.h"
  17. #endif /* LINT */
  18. #include "botch_free.h"
  19. #include <alloc.h>
  20. #include "dataflow.h"
  21. #include "use_tmp.h"
  22. #include <flt_arith.h>
  23. #include "arith.h"
  24. #include "type.h"
  25. #include "idf.h"
  26. #include "label.h"
  27. #include "code.h"
  28. #include "stmt.h"
  29. #include "def.h"
  30. #include "expr.h"
  31. #include "sizes.h"
  32. #include "stack.h"
  33. #include "level.h"
  34. #include "decspecs.h"
  35. #include "declar.h"
  36. #include "Lpars.h"
  37. #include "specials.h"
  38. #include "atw.h"
  39. #include "assert.h"
  40. #include "LLlex.h"
  41. #include "align.h"
  42. #include "blocks.h"
  43. #include "code_c.h"
  44. #include "conversion.h"
  45. #include <symbol2str.h>
  46. #ifdef LINT
  47. #include "l_lint.h"
  48. #endif /* LINT */
  49. #ifdef DBSYMTAB
  50. #include <stb.h>
  51. #endif /* DBSYMTAB */
  52. label lab_count = 1;
  53. label datlab_count = 1;
  54. int fp_used;
  55. /* global function info */
  56. char *func_name;
  57. struct type *func_type;
  58. #ifdef LINT
  59. int func_notypegiven;
  60. #endif
  61. #ifdef USE_TMP
  62. static int tmp_id;
  63. static int pro_id;
  64. #endif /* USE_TMP */
  65. extern char options[];
  66. extern char *source;
  67. static void def_strings(struct string_cst *sc);
  68. static void prc_entry(char *name);
  69. static void prc_exit();
  70. #ifndef LINT
  71. void init_code(char *dst_file)
  72. {
  73. /* init_code() initialises the output file on which the
  74. compact EM code is written
  75. */
  76. C_init(word_size, pointer_size); /* initialise EM module */
  77. if (C_open(dst_file) == 0)
  78. fatal("cannot write to %s\n", dst_file);
  79. C_magic();
  80. C_ms_emx(word_size, pointer_size);
  81. #ifdef DBSYMTAB
  82. if (options['g']) {
  83. C_ms_std(source, N_SO, 0);
  84. stb_typedef(int_type, "int");
  85. stb_typedef(schar_type, "char");
  86. stb_typedef(long_type, "long");
  87. stb_typedef(short_type, "short");
  88. stb_typedef(uchar_type, "unsigned char");
  89. stb_typedef(ushort_type, "unsigned short");
  90. stb_typedef(ulong_type, "unsigned long");
  91. stb_typedef(uint_type, "unsigned int");
  92. stb_typedef(float_type, "float");
  93. stb_typedef(double_type, "double");
  94. stb_typedef(lngdbl_type, "long double");
  95. stb_typedef(void_type, "void");
  96. }
  97. #endif /* DBSYMTAB */
  98. #ifdef USE_TMP
  99. #ifdef PREPEND_SCOPES
  100. C_insertpart(tmp_id = C_getid());
  101. #endif /* PREPEND_SCOPES */
  102. #endif /* USE_TMP */
  103. }
  104. #endif /* LINT */
  105. struct string_cst *str_list = 0;
  106. label code_string(char *val, int len)
  107. {
  108. register struct string_cst *sc = new_string_cst();
  109. label dlb = data_label();
  110. C_ina_dlb(dlb);
  111. sc->next = str_list;
  112. str_list = sc;
  113. sc->sc_value = val;
  114. sc->sc_len = len;
  115. sc->sc_dlb = dlb;
  116. return dlb;
  117. }
  118. static void def_strings(struct string_cst *sc)
  119. {
  120. while (sc) {
  121. struct string_cst *sc1 = sc;
  122. C_df_dlb(sc->sc_dlb);
  123. str_cst(sc->sc_value, sc->sc_len, 1); /* string in rom */
  124. sc = sc->next;
  125. free(sc1->sc_value);
  126. free_string_cst(sc1);
  127. }
  128. }
  129. /* flush_strings() is called from program.g after each external definition */
  130. void flush_strings()
  131. {
  132. if (str_list) {
  133. def_strings(str_list);
  134. str_list = 0;
  135. }
  136. }
  137. #ifndef LINT
  138. void end_code()
  139. {
  140. /* end_code() performs the actions to be taken when closing
  141. the output stream.
  142. */
  143. if (fp_used) {
  144. /* floating point used */
  145. C_ms_flt();
  146. }
  147. C_ms_src((int)(LineNumber - 2), source);
  148. C_close();
  149. }
  150. #endif /* LINT */
  151. #ifdef PREPEND_SCOPES
  152. void prepend_scopes()
  153. {
  154. /* prepend_scopes() runs down the list of global idf's
  155. and generates those exa's, exp's, ina's and inp's
  156. that superior hindsight has provided.
  157. */
  158. struct stack_entry *se = local_level->sl_entry;
  159. #ifdef USE_TMP
  160. C_beginpart(tmp_id);
  161. #endif /* USE_TMP */
  162. while (se != 0) {
  163. struct def *df = se->se_idf->id_def;
  164. if (df && (df->df_initialized || df->df_used || df->df_alloc)) {
  165. code_scope(se->se_idf->id_text, df);
  166. }
  167. se = se->next;
  168. }
  169. #ifdef USE_TMP
  170. C_endpart(tmp_id);
  171. #endif /* USE_TMP */
  172. }
  173. #endif /* PREPEND_SCOPES */
  174. void code_scope(char *text, struct def *def)
  175. {
  176. /* generates code for one name, text, of the storage class
  177. as given by def, if meaningful.
  178. */
  179. int fund = def->df_type->tp_fund;
  180. switch (def->df_sc) {
  181. case EXTERN:
  182. case GLOBAL:
  183. if (fund == FUNCTION)
  184. C_exp(text);
  185. else
  186. C_exa_dnam(text);
  187. break;
  188. case STATIC:
  189. if (fund == FUNCTION)
  190. C_inp(text);
  191. else
  192. C_ina_dnam(text);
  193. break;
  194. }
  195. }
  196. static label return_label, return2_label;
  197. static char return_expr_occurred;
  198. static arith func_size;
  199. static int struct_return;
  200. static char *last_fn_given = (char *)0;
  201. static label file_name_label;
  202. /* to be called when entering a procedure */
  203. void begin_proc(struct decspecs *ds, struct idf *idf)
  204. {
  205. /* begin_proc() is called at the entrance of a new function
  206. and performs the necessary code generation:
  207. - a scope indicator (if needed) exp/inp
  208. - the procedure entry pro $name
  209. - reserves some space if the result of the function
  210. does not fit in the return area
  211. - a fil pseudo instruction
  212. */
  213. char *name = idf->id_text;
  214. struct def *def = idf->id_def;
  215. /* idf->id_def does not indicate the right def structure
  216. * when the function being defined has a parameter of the
  217. * same name in an old-style function definition.
  218. */
  219. while (def->df_level != L_GLOBAL) def = def->next;
  220. /* When we have a new-style function definition, the parameters
  221. * are defined first, which means that it may look as if they have
  222. * the greatest scope. Correct this.
  223. */
  224. if (idf->id_def == def && def->next && def->next->df_level == L_PROTO) {
  225. struct def *tmpdef = def->next;
  226. def->next = tmpdef->next;
  227. tmpdef->next = def;
  228. idf->id_def = tmpdef;
  229. }
  230. #ifndef PREPEND_SCOPES
  231. code_scope(name, def);
  232. #endif /* PREPEND_SCOPES */
  233. #ifdef DATAFLOW
  234. if (options['d'])
  235. DfaStartFunction(name);
  236. #endif /* DATAFLOW */
  237. /* set global function info */
  238. func_name = name;
  239. if (def->df_type->tp_fund != FUNCTION) {
  240. error("making function body for non-function");
  241. def->df_type = error_type;
  242. }
  243. func_type = def->df_type->tp_up;
  244. #ifdef LINT
  245. func_notypegiven = ds->ds_notypegiven;
  246. #endif
  247. func_size = ATW(func_type->tp_size);
  248. sp_occurred[SP_SETJMP] = 0;
  249. #ifndef USE_TMP
  250. C_pro_narg(name);
  251. #else
  252. C_insertpart(pro_id = C_getid());
  253. #endif
  254. if (is_struct_or_union(func_type->tp_fund)) {
  255. if (func_size <= 0) {
  256. error("unknown return type for function %s", name);
  257. } else {
  258. struct_return = 1;
  259. }
  260. }
  261. else
  262. struct_return = 0;
  263. /* Special arrangements if the function result doesn't fit in
  264. the function return area of the EM machine. The size of
  265. the function return area is implementation dependent.
  266. */
  267. lab_count = (label) 1;
  268. return_label = text_label();
  269. return2_label = text_label();
  270. return_expr_occurred = 0;
  271. LocalInit();
  272. prc_entry(name);
  273. if (! options['L']) { /* profiling */
  274. if (!last_fn_given || strcmp(last_fn_given, FileName) != 0) {
  275. /* previous function came from other file */
  276. C_df_dlb(file_name_label = data_label());
  277. C_con_scon(last_fn_given = FileName,
  278. (arith)(strlen(FileName) + 1));
  279. }
  280. /* enable debug trace of EM source */
  281. C_fil_dlb(file_name_label, (arith)0);
  282. C_lin((arith)LineNumber);
  283. }
  284. #ifdef DBSYMTAB
  285. if (options['g']) {
  286. stb_string(def, FUNCTION, name);
  287. if (! strcmp(name, "main")) {
  288. C_ms_stb_cst(name, N_MAIN, 0, (arith) 0);
  289. }
  290. }
  291. #endif
  292. }
  293. void end_proc(arith fbytes)
  294. {
  295. /* end_proc() deals with the code to be generated at the end of
  296. a function, as there is:
  297. - the EM ret instruction: "ret 0"
  298. - loading of the function result in the function
  299. result area if there has been a return <expr>
  300. in the function body (see do_return_expr())
  301. - indication of the use of floating points
  302. - indication of the number of bytes used for
  303. formal parameters
  304. - use of special identifiers such as "__setjmp"
  305. - "end" + number of bytes used for local variables
  306. */
  307. arith nbytes;
  308. char optionsn = options['n'];
  309. #ifdef DATAFLOW
  310. if (options['d'])
  311. DfaEndFunction();
  312. #endif /* DATAFLOW */
  313. C_df_ilb(return2_label);
  314. if (return_expr_occurred && struct_return == 0) {
  315. C_asp(-func_size);
  316. }
  317. C_df_ilb(return_label);
  318. prc_exit();
  319. if (return_expr_occurred) {
  320. if (struct_return != 0) {
  321. LoadLocal((arith) 0, pointer_size);
  322. C_ret(pointer_size);
  323. }
  324. else
  325. C_ret(func_size);
  326. }
  327. else C_ret((arith) 0);
  328. /* getting the number of "local" bytes is posponed until here,
  329. because copying the function result may need temporaries!
  330. However, local_level is now L_FORMAL2, because
  331. L_LOCAL is already unstacked. Therefore, "unstack_level" must
  332. also pass "sl_max_block" to the level above L_LOCAL.
  333. */
  334. nbytes = ATW(- local_level->sl_max_block);
  335. #ifdef USE_TMP
  336. C_beginpart(pro_id);
  337. C_pro(func_name, nbytes);
  338. #endif
  339. if (fbytes > max_int) {
  340. error("%s has more than %ld parameter bytes",
  341. func_name, (long) max_int);
  342. }
  343. C_ms_par(fbytes); /* # bytes for formals */
  344. if (sp_occurred[SP_SETJMP]) { /* indicate use of "__setjmp" */
  345. options['n'] = 1;
  346. C_ms_gto();
  347. sp_occurred[SP_SETJMP] = 0;
  348. }
  349. #ifdef USE_TMP
  350. C_endpart(pro_id);
  351. #endif
  352. LocalFinish();
  353. C_end(nbytes);
  354. if (nbytes > max_int) {
  355. error("%s has more than %ld bytes of local variables",
  356. func_name, (long) max_int);
  357. }
  358. options['n'] = optionsn;
  359. }
  360. void do_return()
  361. {
  362. /* do_return handles the case of a return without expression.
  363. This version branches to the return label, which is
  364. probably smarter than generating a direct return.
  365. Return sequences may be expensive.
  366. */
  367. #ifdef DBSYMTAB
  368. if (options['g']) db_line(dot.tk_file, dot.tk_line);
  369. #endif /* DBSYMTAB */
  370. C_bra(return2_label);
  371. }
  372. void do_return_expr(struct expr *expr)
  373. {
  374. /* do_return_expr() generates the expression and the jump for
  375. a return statement with an expression.
  376. */
  377. ch3cast(&expr, RETURN, func_type);
  378. code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
  379. if (struct_return != 0) {
  380. LoadLocal((arith) 0, pointer_size);
  381. store_block(func_type->tp_size, func_type->tp_align);
  382. }
  383. C_bra(return_label);
  384. return_expr_occurred = 1;
  385. }
  386. /* struct idf *idf idf to be declared
  387. * struct expr *expr initialisation; NULL if absent
  388. * int lvl declaration level
  389. * int sc storage class, as in the declaration
  390. */
  391. void code_declaration(struct idf *idf, struct expr *expr, int lvl, int sc)
  392. {
  393. /* code_declaration() does the actual declaration of the
  394. variable indicated by "idf" on declaration level "lvl".
  395. If the variable is initialised, the expression is given
  396. in "expr", but for global and static initialisations it
  397. is just non-zero, as the expression is not parsed yet.
  398. There are some cases to be considered:
  399. - filter out typedefs, they don't correspond to code;
  400. - global variables, coded only if initialized;
  401. - local static variables;
  402. - local automatic variables;
  403. Since the expression may be modified in the process,
  404. code_declaration() frees it after use, as the caller can
  405. no longer do so.
  406. If there is a storage class indication (EXTERN/STATIC),
  407. code_declaration() will generate an exa or ina.
  408. The sc is the actual storage class, as given in the
  409. declaration.
  410. */
  411. struct def *def = idf->id_def;
  412. arith size = def->df_type->tp_size;
  413. int fund = def->df_type->tp_fund;
  414. int def_sc = def->df_sc;
  415. if (def_sc == TYPEDEF) { /* no code for typedefs */
  416. #ifdef DBSYMTAB
  417. if (options['g']) {
  418. stb_typedef(def->df_type, idf->id_text);
  419. }
  420. #endif /* DBSYMTAB */
  421. return;
  422. }
  423. if (lvl == L_GLOBAL) { /* global variable */
  424. /* is this an allocating declaration? */
  425. if ( (sc == 0 || sc == STATIC)
  426. && fund != FUNCTION
  427. )
  428. def->df_alloc = ALLOC_SEEN;
  429. if (expr && def_sc == STATIC && sc == EXTERN) {
  430. warning("%s has internal linkage", idf->id_text);
  431. }
  432. if (expr) { /* code only if initialized */
  433. #ifndef PREPEND_SCOPES
  434. code_scope(idf->id_text, def);
  435. #endif /* PREPEND_SCOPES */
  436. def->df_alloc = ALLOC_DONE;
  437. C_df_dnam(idf->id_text);
  438. }
  439. }
  440. else
  441. if (lvl >= L_LOCAL) { /* local variable */
  442. /* STATIC, EXTERN, GLOBAL, AUTO or REGISTER */
  443. switch (def_sc) {
  444. case STATIC:
  445. if (fund == FUNCTION) {
  446. /* should produce "inp $function" ??? */
  447. break;
  448. }
  449. /* they are handled on the spot and get an
  450. integer label in EM.
  451. */
  452. #ifdef DBSYMTAB
  453. if (options['g'] && ! expr) {
  454. stb_string(def, sc, idf->id_text);
  455. }
  456. #endif /* DBSYMTAB */
  457. C_df_dlb((label)def->df_address);
  458. if (expr) { /* there is an initialisation */
  459. }
  460. else { /* produce blank space */
  461. if (size <= 0) {
  462. error("size of %s unknown", idf->id_text);
  463. size = (arith)0;
  464. }
  465. C_bss_cst(ATW(size), (arith)0, 1);
  466. }
  467. break;
  468. case EXTERN:
  469. if (expr && !is_anon_idf(idf) && level != L_GLOBAL)
  470. error("cannot initialize extern %s in block"
  471. , idf->id_text);
  472. case GLOBAL:
  473. /* we are sure there is no expression */
  474. break;
  475. case AUTO:
  476. case REGISTER:
  477. #ifdef DBSYMTAB
  478. if (options['g']) {
  479. stb_string(def, sc, idf->id_text);
  480. }
  481. #endif /* DBSYMTAB */
  482. if (expr)
  483. loc_init(expr, idf);
  484. else if ((fund == ARRAY)
  485. && (def->df_type->tp_size == (arith)-1)) {
  486. error("size for local %s unknown"
  487. , idf->id_text);
  488. }
  489. break;
  490. default:
  491. crash("bad local storage class");
  492. /*NOTREACHED*/
  493. }
  494. }
  495. }
  496. void loc_init(struct expr *expr, struct idf *id)
  497. {
  498. /* loc_init() generates code for the assignment of
  499. expression expr to the local variable described by id.
  500. It frees the expression afterwards.
  501. */
  502. struct expr *e = expr;
  503. struct def *df = id->id_def;
  504. struct type *tp = df->df_type;
  505. static arith tmpoffset = 0;
  506. static arith unknownsize = 0;
  507. ASSERT(df->df_sc != STATIC);
  508. switch (tp->tp_fund) {
  509. case ARRAY:
  510. if (tp->tp_size == (arith) -1)
  511. unknownsize = 1;
  512. case STRUCT:
  513. case UNION:
  514. if (e != (struct expr *) 0) {
  515. break; /* switch */
  516. } else if (!tmpoffset) {/* first time for this variable */
  517. tmpoffset = df->df_address;
  518. if (unknownsize) tmpoffset = -1;
  519. df->df_address = data_label();
  520. C_df_dlb((label)df->df_address);
  521. } else {
  522. C_lae_dlb((label)df->df_address, (arith)0);
  523. load_block(tp->tp_size, word_align);
  524. if (unknownsize) {
  525. /* tmpoffset += tp->tp_size; */
  526. unknownsize = 0;
  527. tmpoffset = NewLocal(tp->tp_size
  528. , tp->tp_align
  529. , regtype(tp)
  530. , df->df_sc);
  531. }
  532. C_lal(tmpoffset);
  533. store_block(tp->tp_size, tmpoffset % word_align ? 1 : word_align);
  534. df->df_address = tmpoffset;
  535. tmpoffset = 0;
  536. }
  537. #ifdef DBSYMTAB
  538. if (options['g']) {
  539. stb_string(df, AUTO, id->id_text);
  540. }
  541. #endif /* DBSYMTAB */
  542. return;
  543. }
  544. if (ISCOMMA(e)) { /* embraced: int i = {12}; */
  545. while (e) {
  546. loc_init(e->OP_LEFT, id);
  547. e = e->OP_RIGHT;
  548. }
  549. }
  550. else { /* not embraced */
  551. ch3cast(&expr, '=', tp); /* may modify expr */
  552. #ifndef LINT
  553. {
  554. struct value vl;
  555. EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
  556. vl.vl_class = Name;
  557. vl.vl_data.vl_idf = id;
  558. vl.vl_value = (arith)0;
  559. store_val(&vl, tp);
  560. }
  561. #else /* LINT */
  562. id->id_def->df_set = 1;
  563. #endif /* LINT */
  564. free_expression(expr);
  565. }
  566. }
  567. void bss(struct idf *idf)
  568. {
  569. /* bss() allocates bss space for the global idf.
  570. */
  571. struct def *df = idf->id_def;
  572. #ifndef PREPEND_SCOPES
  573. code_scope(idf->id_text, df);
  574. #endif /* PREPEND_SCOPES */
  575. #ifdef DBSYMTAB
  576. if (options['g']) {
  577. stb_string(df, df->df_sc, idf->id_text);
  578. }
  579. #endif /* DBSYMTAB */
  580. if (df->df_type->tp_size <= 0) {
  581. if (df->df_sc != STATIC &&
  582. df->df_type->tp_fund == ARRAY &&
  583. df->df_type->tp_up &&
  584. df->df_type->tp_up->tp_size >= 0) {
  585. C_df_dnam(idf->id_text);
  586. C_bss_cst(ATW(df->df_type->tp_up->tp_size), (arith)0, 1);
  587. }
  588. else error("size of %s unknown (\"%s\", line %d)"
  589. , idf->id_text, df->df_file, df->df_line);
  590. } else {
  591. C_df_dnam(idf->id_text);
  592. C_bss_cst(ATW(df->df_type->tp_size), (arith)0, 1);
  593. }
  594. }
  595. void formal_cvt(int hasproto, struct def *df)
  596. {
  597. /* formal_cvt() converts a formal parameter of type char or
  598. short from int to that type. It also converts a formal
  599. parameter of type float from a double to a float.
  600. */
  601. struct type *tp = df->df_type;
  602. if (tp->tp_size != int_size &&
  603. (tp->tp_fund == CHAR || tp->tp_fund == SHORT)
  604. ) {
  605. LoadLocal(df->df_address, int_size);
  606. /* conversion(int_type, df->df_type); ???
  607. No, you can't do this on the stack! (CJ)
  608. */
  609. StoreLocal(df->df_address, tp->tp_size);
  610. } else if (tp->tp_size != double_size
  611. && tp->tp_fund == FLOAT
  612. && !hasproto) {
  613. LoadLocal(df->df_address, double_size);
  614. #ifndef LINT
  615. conversion(double_type, float_type);
  616. #endif /* LINT */
  617. StoreLocal(df->df_address, tp->tp_size);
  618. }
  619. }
  620. #ifdef LINT
  621. /*ARGSUSED*/
  622. #endif /* LINT */
  623. void code_expr(struct expr *expr, int val, int code, label tlbl, label flbl)
  624. {
  625. /* code_expr() is the parser's interface to the expression code
  626. generator. If line number trace is wanted, it generates a
  627. lin instruction. EVAL() is called directly.
  628. */
  629. #ifndef LINT
  630. if (! options['L']) /* profiling */
  631. C_lin((arith)(expr->ex_line));
  632. #ifdef DBSYMTAB
  633. if (options['g']) db_line(expr->ex_file, (unsigned int)expr->ex_line);
  634. #endif
  635. EVAL(expr, val, code, tlbl, flbl);
  636. #else /* LINT */
  637. lint_expr(expr, code ? USED : IGNORED);
  638. #endif /* LINT */
  639. }
  640. /* The FOR/WHILE/DO/SWITCH stacking mechanism:
  641. stack_stmt() has to be called at the entrance of a
  642. for, while, do or switch statement to indicate the
  643. EM labels where a subsequent break or continue causes
  644. the program to jump to.
  645. */
  646. static struct stmt_block *stmt_stack; /* top of statement stack */
  647. /* code_break() generates EM code needed at the occurrence of "break":
  648. it generates a branch instruction to the break label of the
  649. innermost statement in which break has a meaning.
  650. As "break" is legal in any of 'while', 'do', 'for' or 'switch',
  651. which are the only ones that are stacked, only the top of
  652. the stack is interesting.
  653. */
  654. void code_break()
  655. {
  656. struct stmt_block *stmt_block = stmt_stack;
  657. #ifdef DBSYMTAB
  658. if (options['g']) db_line(dot.tk_file, dot.tk_line);
  659. #endif /* DBSYMTAB */
  660. if (stmt_block)
  661. C_bra(stmt_block->st_break);
  662. else
  663. error("break not inside for, while, do or switch");
  664. }
  665. /* code_continue() generates EM code needed at the occurrence of
  666. "continue":
  667. it generates a branch instruction to the continue label of the
  668. innermost statement in which continue has a meaning.
  669. */
  670. void code_continue()
  671. {
  672. struct stmt_block *stmt_block = stmt_stack;
  673. while (stmt_block) {
  674. if (stmt_block->st_continue) {
  675. #ifdef DBSYMTAB
  676. if (options['g']) db_line(dot.tk_file, dot.tk_line);
  677. #endif /* DBSYMTAB */
  678. C_bra(stmt_block->st_continue);
  679. return;
  680. }
  681. stmt_block = stmt_block->next;
  682. }
  683. error("continue not inside for, while or do");
  684. }
  685. void stack_stmt(label break_label, label cont_label)
  686. {
  687. struct stmt_block *stmt_block = new_stmt_block();
  688. stmt_block->next = stmt_stack;
  689. stmt_block->st_break = break_label;
  690. stmt_block->st_continue = cont_label;
  691. stmt_stack = stmt_block;
  692. }
  693. void unstack_stmt()
  694. {
  695. /* unstack_stmt() unstacks the data of a statement
  696. which may contain break or continue
  697. */
  698. register struct stmt_block *sbp = stmt_stack;
  699. stmt_stack = sbp->next;
  700. free_stmt_block(sbp);
  701. }
  702. static label prc_name;
  703. static void prc_entry(char *name)
  704. {
  705. if (options['p']) {
  706. C_df_dlb(prc_name = data_label());
  707. C_rom_scon(name, (arith) (strlen(name) + 1));
  708. C_lae_dlb(prc_name, (arith) 0);
  709. C_cal("procentry");
  710. C_asp(pointer_size);
  711. }
  712. }
  713. static void prc_exit()
  714. {
  715. if (options['p']) {
  716. C_lae_dlb(prc_name, (arith) 0);
  717. C_cal("procexit");
  718. C_asp(pointer_size);
  719. }
  720. }
  721. #ifdef DBSYMTAB
  722. void db_line(char *file, unsigned int line)
  723. {
  724. static unsigned oldline;
  725. static char *oldfile;
  726. if (file != oldfile || line != oldline) {
  727. C_ms_std((char *) 0, N_SLINE, (int) line);
  728. oldline = line;
  729. oldfile = file;
  730. }
  731. }
  732. #endif /* DBSYMTAB */