code.c 19 KB

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