code.c 18 KB

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