code.c 19 KB

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