state.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "tables.h"
  10. #include "types.h"
  11. #include <cgg_cg.h>
  12. #include "data.h"
  13. #include "result.h"
  14. #include "state.h"
  15. #include "extern.h"
  16. #include "salloc.h"
  17. #include "utils.h"
  18. #include "state.h"
  19. extern int nstab; /* salloc.c */
  20. void savestatus(state_p sp)
  21. {
  22. sp->st_sh = stackheight;
  23. bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t));
  24. sp->st_na = nallreg;
  25. bmove((short *)allreg,(short *)sp->st_ar,nallreg*sizeof(int));
  26. sp->st_ct = curtoken;
  27. bmove((short *)dollar,(short *)sp->st_do,LONGESTPATTERN*sizeof(result_t));
  28. bmove((short *)machregs,(short *)sp->st_mr,NREGS*sizeof(struct reginfo));
  29. sp->st_ne = nemlines;
  30. bmove((short *)emlines,(short *)sp->st_el,nemlines*sizeof(struct emline));
  31. sp->st_em = emp;
  32. sp->st_se = saveemp;
  33. sp->st_tl = tokpatlen;
  34. sp->st_ns = nstab;
  35. }
  36. void restorestatus(state_p sp)
  37. {
  38. stackheight = sp->st_sh;
  39. bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
  40. nallreg = sp->st_na;
  41. bmove((short *)sp->st_ar,(short *)allreg,nallreg*sizeof(int));
  42. curtoken = sp->st_ct;
  43. bmove((short *)sp->st_do,(short *)dollar,LONGESTPATTERN*sizeof(result_t));
  44. bmove((short *)sp->st_mr,(short *)machregs,NREGS*sizeof(struct reginfo));
  45. nemlines = sp->st_ne;
  46. bmove((short *)sp->st_el,(short *)emlines,nemlines*sizeof(struct emline));
  47. emp = sp->st_em;
  48. saveemp = sp->st_se;
  49. tokpatlen = sp->st_tl;
  50. popstr(sp->st_ns);
  51. }
  52. void bmove(short *from, short *to, int nbytes)
  53. {
  54. if (nbytes<=0)
  55. return;
  56. assert(sizeof(short)==2 && (nbytes&1)==0);
  57. nbytes>>=1;
  58. do
  59. *to++ = *from++;
  60. while (--nbytes);
  61. }