a.h 3.0 KB

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