code.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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 "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. label
  100. code_string(val, len)
  101. char *val;
  102. int len;
  103. {
  104. register struct string_cst *sc = new_string_cst();
  105. label dlb = data_label();
  106. C_ina_dlb(dlb);
  107. sc->next = str_list;
  108. str_list = sc;
  109. sc->sc_value = val;
  110. sc->sc_len = len;
  111. sc->sc_dlb = dlb;
  112. return dlb;
  113. }
  114. def_strings(sc)
  115. register struct string_cst *sc;
  116. {
  117. while (sc) {
  118. struct string_cst *sc1 = sc;
  119. C_df_dlb(sc->sc_dlb);
  120. str_cst(sc->sc_value, sc->sc_len, 1); /* string in rom */
  121. sc = sc->next;
  122. free(sc1->sc_value);
  123. free_string_cst(sc1);
  124. }
  125. }
  126. /* flush_strings() is called from program.g after each external definition */
  127. flush_strings() {
  128. if (str_list) {
  129. def_strings(str_list);
  130. str_list = 0;
  131. }
  132. }
  133. #ifndef LINT
  134. end_code()
  135. {
  136. /* end_code() performs the actions to be taken when closing
  137. the output stream.
  138. */
  139. if (fp_used) {
  140. /* floating point used */
  141. C_ms_flt();
  142. }
  143. C_ms_src((int)(LineNumber - 2), FileName);
  144. C_close();
  145. }
  146. #endif /* LINT */
  147. #ifdef PREPEND_SCOPES
  148. prepend_scopes()
  149. {
  150. /* prepend_scopes() runs down the list of global idf's
  151. and generates those exa's, exp's, ina's and inp's
  152. that superior hindsight has provided.
  153. */
  154. register struct stack_entry *se = local_level->sl_entry;
  155. #ifdef USE_TMP
  156. C_beginpart(tmp_id);
  157. #endif /* USE_TMP */
  158. while (se != 0) {
  159. register struct def *df = se->se_idf->id_def;
  160. if (df && (df->df_initialized || df->df_used || df->df_alloc)) {
  161. code_scope(se->se_idf->id_text, df);
  162. }
  163. se = se->next;
  164. }
  165. #ifdef USE_TMP
  166. C_endpart(tmp_id);
  167. #endif /* USE_TMP */
  168. }
  169. #endif /* PREPEND_SCOPES */
  170. code_scope(text, def)
  171. char *text;
  172. register struct def *def;
  173. {
  174. /* generates code for one name, text, of the storage class
  175. as given by def, if meaningful.
  176. */
  177. int fund = def->df_type->tp_fund;
  178. switch (def->df_sc) {
  179. case EXTERN:
  180. case GLOBAL:
  181. if (fund == FUNCTION)
  182. C_exp(text);
  183. else
  184. C_exa_dnam(text);
  185. break;
  186. case STATIC:
  187. if (fund == FUNCTION)
  188. C_inp(text);
  189. else
  190. C_ina_dnam(text);
  191. break;
  192. }
  193. }
  194. static label return_label, return2_label;
  195. static char return_expr_occurred;
  196. static arith func_size;
  197. static int struct_return;
  198. static char *last_fn_given = (char *)0;
  199. static label file_name_label;
  200. begin_proc(ds, idf) /* to be called when entering a procedure */
  201. struct decspecs *ds;
  202. struct idf *idf;
  203. {
  204. /* begin_proc() is called at the entrance of a new function
  205. and performs the necessary code generation:
  206. - a scope indicator (if needed) exp/inp
  207. - the procedure entry pro $name
  208. - reserves some space if the result of the function
  209. does not fit in the return area
  210. - a fil pseudo instruction
  211. */
  212. register char *name = idf->id_text;
  213. register struct def *def = idf->id_def;
  214. /* idf->id_def does not indicate the right def structure
  215. * when the function being defined has a parameter of the
  216. * same name in an old-style function definition.
  217. */
  218. while (def->df_level != L_GLOBAL) def = def->next;
  219. /* When we have a new-style function definition, the parameters
  220. * are defined first, which means that it may look as if they have
  221. * the greatest scope. Correct this.
  222. */
  223. if (idf->id_def == def && def->next && def->next->df_level == L_PROTO) {
  224. struct def *tmpdef = def->next;
  225. def->next = tmpdef->next;
  226. tmpdef->next = def;
  227. idf->id_def = tmpdef;
  228. }
  229. #ifndef PREPEND_SCOPES
  230. code_scope(name, def);
  231. #endif /* PREPEND_SCOPES */
  232. #ifdef DATAFLOW
  233. if (options['d'])
  234. DfaStartFunction(name);
  235. #endif /* DATAFLOW */
  236. /* set global function info */
  237. func_name = name;
  238. if (def->df_type->tp_fund != FUNCTION) {
  239. error("making function body for non-function");
  240. def->df_type = error_type;
  241. }
  242. func_type = def->df_type->tp_up;
  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. struct_return = 1;
  258. }
  259. }
  260. else
  261. struct_return = 0;
  262. /* Special arrangements if the function result doesn't fit in
  263. the function return area of the EM machine. The size of
  264. the function return area is implementation dependent.
  265. */
  266. lab_count = (label) 1;
  267. return_label = text_label();
  268. return2_label = text_label();
  269. return_expr_occurred = 0;
  270. LocalInit();
  271. prc_entry(name);
  272. if (! options['L']) { /* profiling */
  273. if (!last_fn_given || strcmp(last_fn_given, FileName) != 0) {
  274. /* previous function came from other file */
  275. C_df_dlb(file_name_label = data_label());
  276. C_con_scon(last_fn_given = FileName,
  277. (arith)(strlen(FileName) + 1));
  278. }
  279. /* enable debug trace of EM source */
  280. C_fil_dlb(file_name_label, (arith)0);
  281. C_lin((arith)LineNumber);
  282. }
  283. #ifdef DBSYMTAB
  284. if (options['g']) {
  285. stb_string(def, FUNCTION, name);
  286. if (! strcmp(name, "main")) {
  287. C_ms_stb_cst(name, N_MAIN, 0, (arith) 0);
  288. }
  289. }
  290. #endif
  291. }
  292. end_proc(fbytes)
  293. 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. 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. do_return_expr(expr)
  373. struct expr *expr;
  374. {
  375. /* do_return_expr() generates the expression and the jump for
  376. a return statement with an expression.
  377. */
  378. ch3cast(&expr, RETURN, func_type);
  379. code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
  380. if (struct_return != 0) {
  381. LoadLocal((arith) 0, pointer_size);
  382. store_block(func_size, func_type->tp_align);
  383. }
  384. C_bra(return_label);
  385. return_expr_occurred = 1;
  386. }
  387. code_declaration(idf, expr, lvl, sc)
  388. register struct idf *idf; /* idf to be declared */
  389. struct expr *expr; /* initialisation; NULL if absent */
  390. int lvl; /* declaration level */
  391. int sc; /* storage class, as in the declaration */
  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. register struct def *def = idf->id_def;
  412. register 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. loc_init(expr, id)
  497. struct expr *expr;
  498. struct idf *id;
  499. {
  500. /* loc_init() generates code for the assignment of
  501. expression expr to the local variable described by id.
  502. It frees the expression afterwards.
  503. */
  504. register struct expr *e = expr;
  505. register struct def *df = id->id_def;
  506. register struct type *tp = df->df_type;
  507. static arith tmpoffset = 0;
  508. static arith unknownsize = 0;
  509. ASSERT(df->df_sc != STATIC);
  510. switch (tp->tp_fund) {
  511. case ARRAY:
  512. if (tp->tp_size == (arith) -1)
  513. unknownsize = 1;
  514. case STRUCT:
  515. case UNION:
  516. if (e != (struct expr *) 0) {
  517. break; /* switch */
  518. } else if (!tmpoffset) {/* first time for this variable */
  519. tmpoffset = df->df_address;
  520. df->df_address = data_label();
  521. C_df_dlb((label)df->df_address);
  522. } else {
  523. C_lae_dlb((label)df->df_address, (arith)0);
  524. load_block(tp->tp_size, 1);
  525. if (unknownsize) {
  526. /* tmpoffset += tp->tp_size; */
  527. unknownsize = 0;
  528. tmpoffset = NewLocal(tp->tp_size
  529. , tp->tp_align
  530. , regtype(tp)
  531. , df->df_sc);
  532. }
  533. C_lal(tmpoffset);
  534. store_block(tp->tp_size, 1);
  535. df->df_address = tmpoffset;
  536. tmpoffset = 0;
  537. }
  538. #ifdef DBSYMTAB
  539. if (options['g']) {
  540. stb_string(df, AUTO, id->id_text);
  541. }
  542. #endif /* DBSYMTAB */
  543. return;
  544. }
  545. if (ISCOMMA(e)) { /* embraced: int i = {12}; */
  546. while (e) {
  547. loc_init(e->OP_LEFT, id);
  548. e = e->OP_RIGHT;
  549. }
  550. }
  551. else { /* not embraced */
  552. ch3cast(&expr, '=', tp); /* may modify expr */
  553. #ifndef LINT
  554. {
  555. struct value vl;
  556. EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
  557. vl.vl_class = Name;
  558. vl.vl_data.vl_idf = id;
  559. vl.vl_value = (arith)0;
  560. store_val(&vl, tp);
  561. }
  562. #else /* LINT */
  563. id->id_def->df_set = 1;
  564. #endif /* LINT */
  565. free_expression(expr);
  566. }
  567. }
  568. bss(idf)
  569. register struct idf *idf;
  570. {
  571. /* bss() allocates bss space for the global idf.
  572. */
  573. register struct def *df = idf->id_def;
  574. #ifndef PREPEND_SCOPES
  575. code_scope(idf->id_text, df);
  576. #endif /* PREPEND_SCOPES */
  577. #ifdef DBSYMTAB
  578. if (options['g']) {
  579. stb_string(df, df->df_sc, idf->id_text);
  580. }
  581. #endif /* DBSYMTAB */
  582. if (df->df_type->tp_size <= 0) {
  583. if (df->df_sc != STATIC &&
  584. df->df_type->tp_fund == ARRAY &&
  585. df->df_type->tp_up &&
  586. df->df_type->tp_up->tp_size >= 0) {
  587. C_df_dnam(idf->id_text);
  588. C_bss_cst(ATW(df->df_type->tp_up->tp_size), (arith)0, 1);
  589. }
  590. else error("size of %s unknown (\"%s\", line %d)"
  591. , idf->id_text, df->df_file, df->df_line);
  592. } else {
  593. C_df_dnam(idf->id_text);
  594. C_bss_cst(ATW(df->df_type->tp_size), (arith)0, 1);
  595. }
  596. }
  597. formal_cvt(hasproto,df)
  598. int hasproto;
  599. register struct def *df;
  600. {
  601. /* formal_cvt() converts a formal parameter of type char or
  602. short from int to that type. It also converts a formal
  603. parameter of type float from a double to a float.
  604. */
  605. register struct type *tp = df->df_type;
  606. if (tp->tp_size != int_size &&
  607. (tp->tp_fund == CHAR || tp->tp_fund == SHORT)
  608. ) {
  609. LoadLocal(df->df_address, int_size);
  610. /* conversion(int_type, df->df_type); ???
  611. No, you can't do this on the stack! (CJ)
  612. */
  613. StoreLocal(df->df_address, tp->tp_size);
  614. } else if (tp->tp_size != double_size
  615. && tp->tp_fund == FLOAT
  616. && !hasproto) {
  617. LoadLocal(df->df_address, double_size);
  618. #ifndef LINT
  619. conversion(double_type, float_type);
  620. #endif /* LINT */
  621. StoreLocal(df->df_address, tp->tp_size);
  622. }
  623. }
  624. #ifdef LINT
  625. /*ARGSUSED*/
  626. #endif /* LINT */
  627. code_expr(expr, val, code, tlbl, flbl)
  628. struct expr *expr;
  629. label tlbl, flbl;
  630. {
  631. /* code_expr() is the parser's interface to the expression code
  632. generator. If line number trace is wanted, it generates a
  633. lin instruction. EVAL() is called directly.
  634. */
  635. #ifndef LINT
  636. if (! options['L']) /* profiling */
  637. C_lin((arith)(expr->ex_line));
  638. #ifdef DBSYMTAB
  639. if (options['g']) db_line(expr->ex_file, (unsigned int)expr->ex_line);
  640. #endif
  641. EVAL(expr, val, code, tlbl, flbl);
  642. #else /* LINT */
  643. lint_expr(expr, code ? USED : IGNORED);
  644. #endif /* LINT */
  645. }
  646. /* The FOR/WHILE/DO/SWITCH stacking mechanism:
  647. stack_stmt() has to be called at the entrance of a
  648. for, while, do or switch statement to indicate the
  649. EM labels where a subsequent break or continue causes
  650. the program to jump to.
  651. */
  652. static struct stmt_block *stmt_stack; /* top of statement stack */
  653. /* code_break() generates EM code needed at the occurrence of "break":
  654. it generates a branch instruction to the break label of the
  655. innermost statement in which break has a meaning.
  656. As "break" is legal in any of 'while', 'do', 'for' or 'switch',
  657. which are the only ones that are stacked, only the top of
  658. the stack is interesting.
  659. */
  660. code_break()
  661. {
  662. register struct stmt_block *stmt_block = stmt_stack;
  663. #ifdef DBSYMTAB
  664. if (options['g']) db_line(dot.tk_file, dot.tk_line);
  665. #endif /* DBSYMTAB */
  666. if (stmt_block)
  667. C_bra(stmt_block->st_break);
  668. else
  669. error("break not inside for, while, do or switch");
  670. }
  671. /* code_continue() generates EM code needed at the occurrence of
  672. "continue":
  673. it generates a branch instruction to the continue label of the
  674. innermost statement in which continue has a meaning.
  675. */
  676. code_continue()
  677. {
  678. register struct stmt_block *stmt_block = stmt_stack;
  679. while (stmt_block) {
  680. if (stmt_block->st_continue) {
  681. #ifdef DBSYMTAB
  682. if (options['g']) db_line(dot.tk_file, dot.tk_line);
  683. #endif /* DBSYMTAB */
  684. C_bra(stmt_block->st_continue);
  685. return;
  686. }
  687. stmt_block = stmt_block->next;
  688. }
  689. error("continue not inside for, while or do");
  690. }
  691. stack_stmt(break_label, cont_label)
  692. label break_label, cont_label;
  693. {
  694. register struct stmt_block *stmt_block = new_stmt_block();
  695. stmt_block->next = stmt_stack;
  696. stmt_block->st_break = break_label;
  697. stmt_block->st_continue = cont_label;
  698. stmt_stack = stmt_block;
  699. }
  700. unstack_stmt()
  701. {
  702. /* unstack_stmt() unstacks the data of a statement
  703. which may contain break or continue
  704. */
  705. register struct stmt_block *sbp = stmt_stack;
  706. stmt_stack = sbp->next;
  707. free_stmt_block(sbp);
  708. }
  709. static label prc_name;
  710. prc_entry(name)
  711. char *name;
  712. {
  713. if (options['p']) {
  714. C_df_dlb(prc_name = data_label());
  715. C_rom_scon(name, (arith) (strlen(name) + 1));
  716. C_lae_dlb(prc_name, (arith) 0);
  717. C_cal("procentry");
  718. C_asp(pointer_size);
  719. }
  720. }
  721. prc_exit()
  722. {
  723. if (options['p']) {
  724. C_lae_dlb(prc_name, (arith) 0);
  725. C_cal("procexit");
  726. C_asp(pointer_size);
  727. }
  728. }
  729. #ifdef DBSYMTAB
  730. db_line(file, line)
  731. char *file;
  732. unsigned int line;
  733. {
  734. static unsigned oldline;
  735. static char *oldfile;
  736. if (file != oldfile || line != oldline) {
  737. C_ms_std((char *) 0, N_SLINE, (int) line);
  738. oldline = line;
  739. oldfile = file;
  740. }
  741. }
  742. #endif /* DBSYMTAB */