a.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #include <lib9.h>
  2. #include <bio.h>
  3. #include "../qc/q.out.h"
  4. #ifndef EXTERN
  5. #define EXTERN extern
  6. #endif
  7. typedef struct Sym Sym;
  8. typedef struct Gen Gen;
  9. typedef struct Io Io;
  10. typedef struct Hist Hist;
  11. #define MAXALIGN 7
  12. #define FPCHIP 1
  13. #define NSYMB 8192
  14. #define BUFSIZ 8192
  15. #define HISTSZ 20
  16. #define NINCLUDE 10
  17. #define NHUNK 10000
  18. #define EOF (-1)
  19. #define IGN (-2)
  20. #define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
  21. #define NHASH 503
  22. #define STRINGSZ 200
  23. #define NMACRO 10
  24. #define ALLOC(lhs, type)\
  25. while(nhunk < sizeof(type))\
  26. gethunk();\
  27. lhs = (type*)hunk;\
  28. nhunk -= sizeof(type);\
  29. hunk += sizeof(type);
  30. #define ALLOCN(lhs, len, n)\
  31. if(lhs+len != hunk || nhunk < n) {\
  32. while(nhunk <= len)\
  33. gethunk();\
  34. memmove(hunk, lhs, len);\
  35. lhs = hunk;\
  36. hunk += len;\
  37. nhunk -= len;\
  38. }\
  39. hunk += n;\
  40. nhunk -= n;
  41. struct Sym
  42. {
  43. Sym* link;
  44. char* macro;
  45. long value;
  46. ushort type;
  47. char *name;
  48. char sym;
  49. };
  50. #define S ((Sym*)0)
  51. struct
  52. {
  53. char* p;
  54. int c;
  55. } fi;
  56. struct Io
  57. {
  58. Io* link;
  59. char b[BUFSIZ];
  60. char* p;
  61. short c;
  62. short f;
  63. };
  64. #define I ((Io*)0)
  65. struct
  66. {
  67. Sym* sym;
  68. short type;
  69. } h[NSYM];
  70. struct Gen
  71. {
  72. Sym* sym;
  73. long offset;
  74. short type;
  75. short reg;
  76. short xreg;
  77. short name;
  78. ushort mask;
  79. double dval;
  80. char sval[8];
  81. };
  82. struct Hist
  83. {
  84. Hist* link;
  85. char* name;
  86. long line;
  87. long offset;
  88. };
  89. #define H ((Hist*)0)
  90. enum
  91. {
  92. CLAST,
  93. CMACARG,
  94. CMACRO,
  95. CPREPROC
  96. };
  97. EXTERN char debug[256];
  98. EXTERN Sym* hash[NHASH];
  99. EXTERN char* Dlist[30];
  100. EXTERN int nDlist;
  101. EXTERN Hist* ehist;
  102. EXTERN int newflag;
  103. EXTERN Hist* hist;
  104. EXTERN char* hunk;
  105. EXTERN char* include[NINCLUDE];
  106. EXTERN Io* iofree;
  107. EXTERN Io* ionext;
  108. EXTERN Io* iostack;
  109. EXTERN long lineno;
  110. EXTERN int nerrors;
  111. EXTERN long nhunk;
  112. EXTERN int nosched;
  113. EXTERN int ninclude;
  114. EXTERN Gen nullgen;
  115. EXTERN char* outfile;
  116. EXTERN int pass;
  117. EXTERN char* pathname;
  118. EXTERN long pc;
  119. EXTERN int peekc;
  120. EXTERN int sym;
  121. EXTERN char symb[NSYMB];
  122. EXTERN int thechar;
  123. EXTERN char* thestring;
  124. EXTERN long thunk;
  125. EXTERN Biobuf obuf;
  126. void errorexit(void);
  127. void pushio(void);
  128. void newio(void);
  129. void newfile(char*, int);
  130. Sym* slookup(char*);
  131. Sym* lookup(void);
  132. void syminit(Sym*);
  133. long yylex(void);
  134. int getc(void);
  135. int getnsc(void);
  136. void unget(int);
  137. int escchar(int);
  138. void cinit(void);
  139. void pinit(char*);
  140. void cclean(void);
  141. void outcode(int, Gen*, int, Gen*);
  142. void outgcode(int, Gen*, int, Gen*, Gen*);
  143. void zname(char*, int, int);
  144. void zaddr(Gen*, int);
  145. void ieeedtod(Ieee*, double);
  146. int filbuf(void);
  147. Sym* getsym(void);
  148. void domacro(void);
  149. void macund(void);
  150. void macdef(void);
  151. void macexpand(Sym*, char*);
  152. void macinc(void);
  153. void macprag(void);
  154. void maclin(void);
  155. void macif(int);
  156. void macend(void);
  157. void dodefine(char*);
  158. void prfile(long);
  159. void outhist(void);
  160. void linehist(char*, int);
  161. void gethunk(void);
  162. void yyerror(char*, ...);
  163. int yyparse(void);
  164. void setinclude(char*);
  165. int assemble(char*);
  166. /*
  167. * system-dependent stuff from ../cc/compat.c
  168. */
  169. enum /* keep in synch with ../cc/cc.h */
  170. {
  171. Plan9 = 1<<0,
  172. Unix = 1<<1,
  173. Windows = 1<<2
  174. };
  175. int mywait(int*);
  176. int mycreat(char*, int);
  177. int systemtype(int);
  178. int pathchar(void);
  179. char* mygetwd(char*, int);
  180. int myexec(char*, char*[]);
  181. int mydup(int, int);
  182. int myfork(void);
  183. int mypipe(int*);
  184. void* mysbrk(ulong);