asm.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (c) 1982 Regents of the University of California */
  2. static char sccsid[] = "@(#)asm.c 1.2 12/15/82";
  3. /*
  4. * Assembly language dependent symbol routines.
  5. */
  6. #include "defs.h"
  7. #include "symbols.h"
  8. #include "asm.h"
  9. #include "languages.h"
  10. #include "tree.h"
  11. #include "eval.h"
  12. #include "operators.h"
  13. #include "mappings.h"
  14. #include "process.h"
  15. #include "runtime.h"
  16. #include "machine.h"
  17. #define isdouble(range) ( \
  18. range->symvalue.rangev.upper == 0 and range->symvalue.rangev.lower > 0 \
  19. )
  20. /*
  21. * Initialize assembly language information.
  22. */
  23. public asm_init()
  24. {
  25. Language lang;
  26. lang = language_define("assembler", ".s");
  27. language_setop(lang, L_PRINTDECL, asm_printdecl);
  28. language_setop(lang, L_PRINTVAL, asm_printval);
  29. language_setop(lang, L_TYPEMATCH, asm_typematch);
  30. }
  31. /*
  32. * Test if two types are compatible.
  33. */
  34. public Boolean asm_typematch(type1, type2)
  35. Symbol type1, type2;
  36. {
  37. Boolean b;
  38. b = false;
  39. return b;
  40. }
  41. public asm_printdecl(s)
  42. Symbol s;
  43. {
  44. switch (s->class) {
  45. case VAR:
  46. case REF:
  47. printf("&%s = 0x%x", symname(s), s->symvalue.offset);
  48. break;
  49. case PROC:
  50. case FUNC:
  51. printf("%s (0x%x):", symname(s), codeloc(s));
  52. break;
  53. default:
  54. error("class %s in c_printdecl", classname(s));
  55. }
  56. putchar('\n');
  57. }
  58. /*
  59. * Print out the value on the top of the expression stack
  60. * in the format for the type of the given symbol.
  61. */
  62. public asm_printval(s)
  63. register Symbol s;
  64. {
  65. register Symbol t;
  66. register Integer len;
  67. switch (s->class) {
  68. case ARRAY:
  69. t = rtype(s->type);
  70. if (t->class == RANGE and istypename(t->type, "$char")) {
  71. len = size(s);
  72. sp -= len;
  73. printf("\"%.*s\"", len, sp);
  74. } else {
  75. printarray(s);
  76. }
  77. break;
  78. default:
  79. printf("0x%x", pop(Integer));
  80. break;
  81. }
  82. }