stab.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * (c) copyright 1990 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. * Author: Ceriel J.H. Jacobs
  6. */
  7. /* D E B U G G E R S Y M B O L T A B L E */
  8. /* $Id$ */
  9. #include "dbsymtab.h"
  10. #ifdef DBSYMTAB
  11. #include <alloc.h>
  12. #include <em_arith.h>
  13. #include <em_label.h>
  14. #include <em_code.h>
  15. #include <stb.h>
  16. #include "LLlex.h"
  17. #include "def.h"
  18. #include "type.h"
  19. #include "idf.h"
  20. #include "const.h"
  21. #include "scope.h"
  22. #include "main.h"
  23. #include "node.h"
  24. #define INCR_SIZE 64
  25. extern int proclevel;
  26. extern char *sprint();
  27. static struct db_str {
  28. unsigned sz;
  29. char *base;
  30. char *currpos;
  31. } db_str;
  32. static
  33. create_db_str()
  34. {
  35. if (! db_str.base) {
  36. db_str.base = Malloc(INCR_SIZE);
  37. db_str.sz = INCR_SIZE;
  38. }
  39. db_str.currpos = db_str.base;
  40. }
  41. static
  42. addc_db_str(c)
  43. int c;
  44. {
  45. int df = db_str.currpos - db_str.base;
  46. if (df >= db_str.sz-1) {
  47. db_str.sz += INCR_SIZE;
  48. db_str.base = Realloc(db_str.base, db_str.sz);
  49. db_str.currpos = db_str.base + df;
  50. }
  51. *db_str.currpos++ = c;
  52. *db_str.currpos = '\0';
  53. }
  54. static
  55. adds_db_str(s)
  56. char *s;
  57. {
  58. while (*s) addc_db_str(*s++);
  59. }
  60. static
  61. stb_type(tp, assign_num)
  62. register struct type *tp;
  63. {
  64. char buf[128];
  65. static int stb_count;
  66. if (tp->tp_dbindex > 0) {
  67. adds_db_str(sprint(buf, "%d", tp->tp_dbindex));
  68. return;
  69. }
  70. if (tp->tp_dbindex < 0) {
  71. if (tp->next == 0) {
  72. adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
  73. return;
  74. }
  75. tp->tp_dbindex = -tp->tp_dbindex;
  76. }
  77. if (tp->tp_dbindex == 0 && assign_num) {
  78. tp->tp_dbindex = ++stb_count;
  79. }
  80. if (tp->tp_dbindex > 0) {
  81. adds_db_str(sprint(buf, "%d=", tp->tp_dbindex));
  82. }
  83. if (tp == void_type) {
  84. adds_db_str(sprint(buf, "%d", tp->tp_dbindex));
  85. return;
  86. }
  87. switch(tp->tp_fund) {
  88. /* simple types ... */
  89. case T_INTEGER:
  90. case T_LONG: {
  91. arith l = full_mask[(int)tp->tp_size] & ~(1L << (tp->tp_size*8-1));
  92. adds_db_str(sprint(buf,
  93. "r%d;%ld;%ld",
  94. tp->tp_dbindex,
  95. (long) -l-1,
  96. (long) l));
  97. }
  98. break;
  99. case T_REAL:
  100. adds_db_str(sprint(buf,
  101. "r%d;%ld;0",
  102. tp->tp_dbindex,
  103. (long)tp->tp_size));
  104. break;
  105. case T_CHAR:
  106. adds_db_str(sprint(buf,
  107. "r%d;0;255",
  108. tp->tp_dbindex));
  109. break;
  110. /* constructed types ... */
  111. case T_SUBRANGE:
  112. adds_db_str(sprint(buf,
  113. "r%d;%ld;%ld",
  114. tp->next->tp_dbindex,
  115. (long) tp->sub_lb,
  116. (long) tp->sub_ub));
  117. break;
  118. case T_POINTER:
  119. if (tp->next) {
  120. addc_db_str('*');
  121. stb_type(tp->next, 0);
  122. if (tp->tp_dbindex < 0) tp->tp_dbindex = -tp->tp_dbindex;
  123. }
  124. else {
  125. tp->tp_dbindex = - ++stb_count;
  126. adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
  127. }
  128. break;
  129. case T_SET:
  130. addc_db_str('S');
  131. stb_type(tp->next, 0);
  132. adds_db_str(sprint(buf, ";%ld;%ld;", (long) tp->tp_size, 0L));
  133. break;
  134. case T_ARRAY:
  135. addc_db_str('a');
  136. if (IsConformantArray(tp)) {
  137. addc_db_str('r');
  138. stb_type(tp->next, 0);
  139. adds_db_str(sprint(buf, ";A%ld;Z%ld", (long) tp->arr_cfdescr, (long) tp->arr_cfdescr));
  140. }
  141. else {
  142. stb_type(tp->next, 0);
  143. }
  144. addc_db_str(';');
  145. stb_type(tp->arr_elem, 0);
  146. break;
  147. case T_ENUMERATION:
  148. addc_db_str('e');
  149. {
  150. register struct def *edef = tp->enm_enums;
  151. while (edef) {
  152. adds_db_str(sprint(buf, "%s:%ld,",
  153. edef->df_idf->id_text,
  154. (long) edef->enm_val));
  155. edef = edef->enm_next;
  156. }
  157. }
  158. addc_db_str(';');
  159. break;
  160. case T_RECORD:
  161. adds_db_str(sprint(buf, "s%ld", (long) tp->tp_size));
  162. {
  163. register struct def *sdef = tp->rec_scope->sc_def;
  164. while (sdef) {
  165. adds_db_str(sdef->df_idf->id_text);
  166. addc_db_str(':');
  167. stb_type(sdef->df_type, 0);
  168. adds_db_str(sprint(buf,
  169. ",%ld,%ld;",
  170. sdef->fld_off*8L,
  171. sdef->df_type->tp_size*8L));
  172. sdef = sdef->df_nextinscope;
  173. }
  174. }
  175. addc_db_str(';');
  176. break;
  177. case T_PROCEDURE:
  178. case T_FUNCTION:
  179. addc_db_str('Q');
  180. stb_type(tp->next ? tp->next : void_type, 0);
  181. {
  182. register struct paramlist *p = tp->prc_params;
  183. int paramcount = 0;
  184. while (p) {
  185. paramcount++;
  186. p = p->next;
  187. }
  188. adds_db_str(sprint(buf, ",%d;", paramcount));
  189. p = tp->prc_params;
  190. while (p) {
  191. addc_db_str(IsVarParam(p)
  192. ? 'v'
  193. : IsConformantArray(TypeOfParam(p))
  194. ? 'i'
  195. : 'p');
  196. stb_type(TypeOfParam(p), 0);
  197. addc_db_str(';');
  198. p = p->next;
  199. }
  200. }
  201. break;
  202. case T_FILE:
  203. addc_db_str('L');
  204. stb_type(tp->next, 0);
  205. break;
  206. case T_STRING:
  207. addc_db_str('*');
  208. stb_type(char_type, 0);
  209. break;
  210. }
  211. }
  212. stb_addtp(s, tp)
  213. char *s;
  214. struct type *tp;
  215. {
  216. create_db_str();
  217. adds_db_str(s);
  218. addc_db_str(':');
  219. addc_db_str('t');
  220. stb_type(tp, 1);
  221. addc_db_str(';');
  222. C_ms_stb_cst(db_str.base,
  223. N_LSYM,
  224. tp == void_type || tp->tp_size > 32767
  225. ? 0
  226. : (IsPacked(tp) ? (int) tp->tp_psize : (int)tp->tp_size),
  227. (arith) 0);
  228. }
  229. stb_string(df, kind)
  230. register struct def *df;
  231. long kind;
  232. {
  233. register struct type *tp = df->df_type;
  234. char buf[64];
  235. create_db_str();
  236. adds_db_str(df->df_idf->id_text);
  237. addc_db_str(':');
  238. if (kind == D_MODULE) {
  239. adds_db_str(sprint(buf, "M%d;", df->prc_vis->sc_count));
  240. C_ms_stb_pnam(db_str.base, N_FUN, proclevel, "_m_a_i_n");
  241. return;
  242. }
  243. switch((int)kind) {
  244. case D_PROCEDURE:
  245. case D_FUNCTION:
  246. adds_db_str(sprint(buf, "Q%d;", df->prc_vis->sc_count));
  247. stb_type(tp->next ? tp->next : void_type, 0);
  248. addc_db_str(';');
  249. C_ms_stb_pnam(db_str.base, N_FUN, proclevel, df->df_idf->id_text);
  250. {
  251. register struct paramlist *p = tp->prc_params;
  252. while (p) {
  253. stb_string(p->par_def, D_VARIABLE);
  254. p = p->next;
  255. }
  256. }
  257. for (df = df->prc_vis->sc_scope->sc_def; df; df = df->df_nextinscope) {
  258. if (df->df_kind == D_LBOUND ||
  259. df->df_kind == D_UBOUND) {
  260. stb_string(df, df->df_kind);
  261. }
  262. }
  263. break;
  264. case D_END:
  265. case D_PEND:
  266. adds_db_str(sprint(buf, "E%d;", df->prc_vis->sc_count));
  267. C_ms_stb_cst(db_str.base, N_SCOPE, proclevel, (arith)0);
  268. break;
  269. case D_VARIABLE:
  270. if (df->df_flags & D_VARPAR) { /* VAR parameter */
  271. addc_db_str('v');
  272. stb_type(tp, 0);
  273. addc_db_str(';');
  274. C_ms_stb_cst(db_str.base, N_PSYM, 0, df->var_off);
  275. }
  276. else if (df->df_flags & D_VALPAR) { /* value parameter */
  277. addc_db_str(IsConformantArray(tp)
  278. ? 'i'
  279. : 'p');
  280. stb_type(tp, 0);
  281. addc_db_str(';');
  282. C_ms_stb_cst(db_str.base, N_PSYM, 0, df->var_off);
  283. }
  284. else if (!proclevel) {
  285. addc_db_str('G');
  286. stb_type(tp, 0);
  287. addc_db_str(';');
  288. C_ms_stb_dnam(db_str.base, N_LCSYM, 0, df->var_name, (arith) 0);
  289. }
  290. else { /* local variable */
  291. stb_type(tp, 1); /* assign type num to avoid
  292. difficult to parse string */
  293. addc_db_str(';');
  294. C_ms_stb_cst(db_str.base, N_LSYM, 0, df->var_off);
  295. }
  296. break;
  297. case D_LBOUND:
  298. case D_UBOUND:
  299. addc_db_str(kind == D_LBOUND ? 'A' : 'Z');
  300. addc_db_str('p');
  301. stb_type(tp, 0);
  302. addc_db_str(';');
  303. C_ms_stb_cst(db_str.base, N_PSYM, 0, df->bnd_type->arr_cfdescr);
  304. break;
  305. case D_TYPE:
  306. addc_db_str('t');
  307. stb_type(tp, 1);
  308. addc_db_str(';');
  309. C_ms_stb_cst(db_str.base,
  310. N_LSYM,
  311. tp == void_type || tp->tp_size > 32767
  312. ? 0
  313. : (IsPacked(tp) ? (int) tp->tp_psize : (int)tp->tp_size),
  314. (arith) 0);
  315. break;
  316. case D_CONST:
  317. addc_db_str('c');
  318. addc_db_str('=');
  319. tp = BaseType(tp);
  320. switch(tp->tp_fund) {
  321. case T_INTEGER:
  322. case T_LONG:
  323. case T_POINTER:
  324. case T_PROCEDURE:
  325. adds_db_str(sprint(buf, "i%ld;", (long) df->con_const->nd_INT));
  326. break;
  327. case T_CHAR:
  328. adds_db_str(sprint(buf, "c%ld;", (long) df->con_const->nd_INT));
  329. break;
  330. case T_REAL:
  331. addc_db_str('r');
  332. adds_db_str(df->con_const->nd_REL);
  333. addc_db_str(';');
  334. break;
  335. case T_STRINGCONST: {
  336. register char *p = df->con_const->nd_STR;
  337. adds_db_str("s'");
  338. while (*p) {
  339. if (*p == '\'' || *p == '\\') {
  340. addc_db_str('\\');
  341. }
  342. addc_db_str(*p++);
  343. }
  344. adds_db_str("';");
  345. }
  346. break;
  347. case T_ENUMERATION:
  348. addc_db_str('e');
  349. stb_type(tp, 0);
  350. adds_db_str(sprint(buf, ",%ld;", (long) df->con_const->nd_INT));
  351. break;
  352. case T_SET: {
  353. register int i;
  354. addc_db_str('S');
  355. stb_type(tp, 0);
  356. for (i = 0; i < tp->tp_size; i++) {
  357. adds_db_str(sprint(buf, ",%ld",
  358. (long) (df->con_const->nd_set[i/(int) word_size] >> (8*(i%(int)word_size)))&0377));
  359. }
  360. addc_db_str(';');
  361. }
  362. break;
  363. }
  364. C_ms_stb_cst(db_str.base,
  365. N_LSYM,
  366. tp->tp_size <= 32767 ? (int)tp->tp_size : 0,
  367. (arith) 0);
  368. break;
  369. }
  370. }
  371. #endif /* DBSYMTAB */