init_glob.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* S H A R E D F I L E
  7. *
  8. * I N I T _ G L O B L S
  9. *
  10. */
  11. #include "types.h"
  12. #include "debug.h"
  13. #include "global.h"
  14. #include "alloc.h"
  15. #include "map.h"
  16. extern short nrglobals;
  17. int init_globals(void *dummy)
  18. {
  19. /* Assign a 'global variable number (o_globnr) to
  20. * every global variable for which we want to
  21. * maintain ud-info. We do not maintain ud-info
  22. * for a global variable if:
  23. * - it is part of a ROM data block (so it will never be changed)
  24. * - it's size is not known
  25. * - it overlaps another variable (e.g. LOE X+2 ; LDE X)
  26. */
  27. dblock_p d;
  28. obj_p obj, prev = 0;
  29. short nr = 1;
  30. offset ill_zone, x;
  31. for (d = fdblock; d != (dblock_p) 0; d = d->d_next) {
  32. ill_zone = (offset) 0;
  33. for (obj = d->d_objlist; obj != (obj_p) 0; obj = obj->o_next) {
  34. if (d->d_pseudo == DROM ||
  35. obj->o_size == UNKNOWN_SIZE) {
  36. obj->o_globnr = 0; /* var. not considered */
  37. continue;
  38. }
  39. if (obj->o_off < ill_zone) {
  40. obj->o_globnr = 0; /* var. not considered */
  41. if (prev != (obj_p) 0 && prev->o_globnr != 0) {
  42. prev->o_globnr = 0;
  43. nr--;
  44. }
  45. } else {
  46. obj->o_globnr = nr++;
  47. }
  48. if ((x = obj->o_off + obj->o_size) > ill_zone) {
  49. ill_zone = x;
  50. }
  51. prev = obj;
  52. }
  53. }
  54. nrglobals = nr -1;
  55. return 0;
  56. }