blob: b3fb0bb19f3db7e5b372a9eb79902fc59889ac90 [file] [log] [blame]
Colin Cross7bb052a2015-02-03 12:59:37 -08001// Inferno utils/6a/a.h
2// http://code.google.com/p/inferno-os/source/browse/utils/6a/a.h
3//
4// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
6// Portions Copyright © 1997-1999 Vita Nuova Limited
7// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
8// Portions Copyright © 2004,2006 Bruce Ellis
9// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
10// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
11// Portions Copyright © 2009 The Go Authors. All rights reserved.
12//
13// Permission is hereby granted, free of charge, to any person obtaining a copy
14// of this software and associated documentation files (the "Software"), to deal
15// in the Software without restriction, including without limitation the rights
16// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17// copies of the Software, and to permit persons to whom the Software is
18// furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included in
21// all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29// THE SOFTWARE.
30
31#include <bio.h>
32#include <link.h>
33#include "../6l/6.out.h"
34
35#ifndef EXTERN
36#define EXTERN extern
37#endif
38
39#undef getc
40#undef ungetc
41#undef BUFSIZ
42
43#define getc ccgetc
44#define ungetc ccungetc
45
46typedef struct Sym Sym;
47typedef struct Ref Ref;
48typedef struct Io Io;
49typedef struct Addr2 Addr2;
50
51#define MAXALIGN 7
52#define FPCHIP 1
53#define NSYMB 500
54#define BUFSIZ 8192
55#define HISTSZ 20
56#ifndef EOF
57#define EOF (-1)
58#endif
59#define IGN (-2)
60#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
61#define NHASH 503
62#define STRINGSZ 200
63#define NMACRO 10
64
65struct Sym
66{
67 Sym* link;
68 Ref* ref;
69 char* macro;
70 vlong value;
71 ushort type;
72 char *name;
73 char sym;
74};
75#define S ((Sym*)0)
76
77struct Ref
78{
79 int class;
80};
81
82EXTERN struct
83{
84 char* p;
85 int c;
86} fi;
87
88struct Io
89{
90 Io* link;
91 char b[BUFSIZ];
92 char* p;
93 short c;
94 short f;
95};
96#define I ((Io*)0)
97
98struct Addr2
99{
100 Addr from;
101 Addr to;
102};
103
104enum
105{
106 CLAST,
107 CMACARG,
108 CMACRO,
109 CPREPROC,
110};
111
112EXTERN int debug[256];
113EXTERN Sym* hash[NHASH];
114EXTERN char** Dlist;
115EXTERN int nDlist;
116EXTERN int newflag;
117EXTERN char* hunk;
118EXTERN char** include;
119EXTERN Io* iofree;
120EXTERN Io* ionext;
121EXTERN Io* iostack;
122EXTERN int32 lineno;
123EXTERN int nerrors;
124EXTERN int32 nhunk;
125EXTERN int ninclude;
126EXTERN int32 nsymb;
127EXTERN Addr nullgen;
128EXTERN char* outfile;
129EXTERN int pass;
130EXTERN int32 pc;
131EXTERN int peekc;
132EXTERN int32 stmtline;
133EXTERN int sym;
134EXTERN char* symb;
135EXTERN int thechar;
136EXTERN char* thestring;
137EXTERN int32 thunk;
138EXTERN Biobuf obuf;
139EXTERN Link* ctxt;
140EXTERN Biobuf bstdout;
141
142void* alloc(int32);
143void* allocn(void*, int32, int32);
144void ensuresymb(int32);
145void errorexit(void);
146void pushio(void);
147void newio(void);
148void newfile(char*, int);
149Sym* slookup(char*);
150Sym* lookup(void);
151void syminit(Sym*);
152int32 yylex(void);
153int getc(void);
154int getnsc(void);
155void unget(int);
156int escchar(int);
157void cinit(void);
158void checkscale(int);
159void pinit(char*);
160void cclean(void);
161int isreg(Addr*);
162void outcode(int, Addr2*);
163void outhist(void);
164void zaddr(Addr*, int);
165void zname(char*, int, int);
166int filbuf(void);
167Sym* getsym(void);
168void domacro(void);
169void macund(void);
170void macdef(void);
171void macexpand(Sym*, char*);
172void macinc(void);
173void macprag(void);
174void maclin(void);
175void macif(int);
176void macend(void);
177void dodefine(char*);
178void prfile(int32);
179void linehist(char*, int);
180void gethunk(void);
181void yyerror(char*, ...);
182int yyparse(void);
183void setinclude(char*);
184int assemble(char*);