reg.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * Author: Hans van Staveren
  6. */
  7. #include "assert.h"
  8. #include "param.h"
  9. #include "types.h"
  10. #include "line.h"
  11. #include "tes.h"
  12. #include "proinf.h"
  13. #include "alloc.h"
  14. #include <em_spec.h>
  15. #include <em_pseu.h>
  16. #include <em_mes.h>
  17. #include "ext.h"
  18. #include "util.h"
  19. #include "putline.h"
  20. void regvar(arg_p ap)
  21. {
  22. reg_p rp;
  23. int i;
  24. rp = newreg();
  25. i=0;
  26. while (ap!=(arg_p)0 && ap->a_typ==ARGOFF && i<4) {
  27. rp->r_par[i++]=ap->a_a.a_offset;
  28. ap=ap->a_next;
  29. }
  30. /*
  31. * Omit incomplete messages
  32. */
  33. switch(i) {
  34. default:assert(FALSE);
  35. case 0:
  36. case 1:
  37. case 2: oldreg(rp); return;
  38. case 3: rp->r_par[3]= (offset) 0; break;
  39. case 4: break;
  40. }
  41. rp->r_next = curpro.freg;
  42. curpro.freg = rp;
  43. }
  44. int inreg(offset off)
  45. {
  46. register reg_p rp;
  47. for (rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next)
  48. if( rp->r_par[0] == off)
  49. return(TRUE);
  50. return(FALSE);
  51. }
  52. void outregs()
  53. {
  54. reg_p rp,tp;
  55. int i;
  56. for(rp=curpro.freg; rp != (reg_p) 0; rp = tp) {
  57. tp = rp->r_next;
  58. outinst(ps_mes);
  59. outoff((offset)ms_reg);
  60. for(i=0;i<4;i++)
  61. outoff(rp->r_par[i]);
  62. outinst(sp_cend);
  63. oldreg(rp);
  64. }
  65. /* List of register messages is followed by an empty ms_reg
  66. * unless an ms_gto was in this procedure, then the ms_gto
  67. * will be output. Kludgy.
  68. */
  69. outinst(ps_mes);
  70. outoff((offset)(curpro.gtoproc? ms_gto : ms_reg));
  71. outinst(sp_cend);
  72. curpro.freg = (reg_p) 0;
  73. }
  74. /* outtes() handles the output of the top elt. messages */
  75. void outtes() {
  76. num_p *npp, np;
  77. for (npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++) {
  78. for (np = *npp; np != (num_p) 0; np=np->n_next) {
  79. if (! (np->n_flags & NUMSET) || np->n_size == 0 ||
  80. (np->n_flags & NUMCOND)) continue;
  81. outinst(ps_mes);
  82. outoff((offset)ms_tes);
  83. outoff((offset)np->n_number);
  84. outoff((offset)np->n_size);
  85. outoff((offset)((np->n_flags & NUMFALLTHROUGH) ? 1 : 0));
  86. outinst(sp_cend);
  87. }
  88. }
  89. }
  90. void incregusage(offset off)
  91. {
  92. #ifndef GLOBAL_OPT
  93. reg_p rp;
  94. /* If we're optimizing the output of the global optimizer
  95. * we must not change the count fields of the register messages.
  96. */
  97. for(rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next)
  98. if (rp->r_par[0]==off) {
  99. rp->r_par[3]++;
  100. return;
  101. }
  102. #endif
  103. }