a.h 3.6 KB

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