Rune - Change regsave burden for syscalls
[rune.git] / librune / export.h
1 /*
2  * EXPORT.H
3  *
4  * (c)Copyright 1993-2014, Matthew Dillon, All Rights Reserved.  See the  
5  *    COPYRIGHT file at the base of the distribution.
6  */
7
8 /*
9  * Headers needed by others using this library
10  */
11 #include <sys/types.h>
12 #include <stdint.h>
13 #include <limits.h>
14
15 #include "lex.h"
16 #include "sym.h"
17 #include "type.h"
18 #include "decl.h"
19 #include "exp.h"
20 #include "stmt.h"
21 #include "parse.h"
22 #include "insn.h"
23 #include "context.h"
24
25 /*
26  * debug_lex.c
27  */
28 void LexDebugLine(token_t *tok);
29
30 /*
31  * decl.c
32  */
33 Declaration *FindDeclId(SemGroup *db, string_t id, int *eno);
34 Declaration *FindDeclIdLevel(SemGroup *db, string_t id, int level, int *eno);
35 Declaration *FindDeclByIndex(SemGroup *sg, int index);
36 void DeclPrintError(Declaration *d, int type);
37 Declaration *FindDeclPath(LexRef *lexRef, SemGroup *osg, SemGroup *sg,
38                         Type *nomatch, string_t *ary, int mask,
39                         int *visibility, int level, int *eno);
40 Declaration *FindDeclPathAltContext(LexRef *lexRef, SemGroup *osg, SemGroup *sg,
41                         Type *nomatch, string_t *ary, int mask,
42                         int *visibility, int level, int *eno);
43 void *FindDLLSymbol(SemGroup *osg, SemGroup *sg, string_t id);
44 int DeclarationCacheable(Declaration *d);
45
46 /*
47  * exp.c
48  */
49 void ExpPrintError(Exp *exp, int type);
50 int64_t resolveGetConstExpInt64(Exp *exp);
51 float128_t resolveGetConstExpFloat128(Exp *exp);
52
53 /*
54  * lex.c
55  */
56 Lex *LexOpen(const char *path, token_t *tok);
57 void LexClose(Lex **plex);
58 int LexRedactToken(token_t *tok, int bytes);
59 int LexPeekToken(token_t *tok);
60 int LexToken(token_t *tok);
61 int LexSkipToken(token_t *tok, int type);
62 int LexStripQuotes(token_t *tok, token_t *tmp);
63 int LexError(token_t *tok, int err);
64 void LexPrintError(token_t *tok);
65 void LexPrintRef(LexRef *lr, int type);
66 void LexInitRef(LexRef *lr, token_t *tok);
67 void LexDupRef(LexRef *s, LexRef *d);
68 void LexDoneRef(LexRef *lr);
69 const char *LexErrStr(token_t *tok);
70
71 /*
72  * misc.c
73  */
74 void LibRuneInit(void);
75
76 /*
77  * heap.c
78  */
79 void *heapAlloc(PointerStor *ps, Type *type);
80
81 /*
82  * parse.c
83  */
84 int ParseOpen(Stmt *st, Parse **pp, void **dll);
85 void ParseDone(Parse *p);
86 void ParseClose(Parse **pp);
87 void AddImportPath(const char *path, int flags);
88 void PrefixImportPaths(const char *basePath);
89
90 /*
91  * parse1.c
92  */
93 int ParseModule(Parse *p, Stmt *st, int t);
94 int ParseStmt(Parse *p, int t, Stmt **pst);
95 int ParseDeclarationStmt(Parse *p, int t, int idRequired, Stmt **pst,
96                         int dop, Scope *scope);
97
98 /*
99  * parse2.c
100  */
101 int ParseScopeQual(Parse *p, int t, Scope *scope);
102 int ParseStorageQual(Parse *p, int t, int *pmask);
103 int ParseDeclaration(Parse *p, int t, Declaration **pd, int idRequired,
104                         int dop, Scope *scope);
105 int ParseType(Parse *p, int t, Type **ptype, int sqflags);
106 int ParseDeclType(Parse *p, int t, Type **ptype, SemGroup **psg,
107                         int scopeFlags, int rqflags, string_t *id,
108                         int idRequired);
109
110 /*
111  * parse3.c
112  */
113 int ParseExp(Parse *p, int t, Exp **pexp);
114 int ParseParenthesizedExp(Parse *p, int t, Exp **pexp, int docomp);
115 int ParseBracketedExp(Parse *p, int t, Exp **pexp);
116 int ParseNotExp(Parse *p, int t, Exp **pexp);
117
118 /*
119  * resolve.c
120  */
121 void ResolveProject(Parse *p, Stmt *st);
122 void CollapseProject(Stmt *st);
123
124 /*
125  * stmt.c
126  */
127 Stmt *BuildRootImportStmt(const char *path);
128 void StmtPrintError(Stmt *st, int type);
129
130 /*
131  * strtable.c
132  */
133 string_t StrTableEscapeQuotedString(const char *str, int len, int term);
134 string_t StrTableAlloc(const char *str, int len, int special);
135 string_t StrTableToken(token_t *tok);
136 string_t StrTableInt(int v);
137 string_t StrTableDup(string_t str);
138 int     StrTableSpecial(string_t id);
139 int     StrTableLen(string_t id);
140 int     StrCmpToken(string_t id, token_t *tok);
141 void ReplaceStrTable(string_t *pstr, string_t id);
142 void RelStrTable(string_t *pstr);
143 const char *StripPathId(const char *path, int *len);
144 int SimpleIntToken(token_t *tok, int *rv);
145 int SimpleRunesizeToken(token_t *tok, runesize_t *rv);
146 int StrTableEnumerate(string_t id);
147
148 /*
149  * sym.c
150  */
151 int SymKeywordFind(const char *ptr, int len, int t);
152
153 /*
154  * type.c
155  */
156 char *TypeToStr(Type *type, char **pstr);
157 int SameType(Type *t1, Type *t2, int sqFlags2);
158 int SimilarType(Type *t1, Type *t2);
159 int SimilarSemGroup(SemGroup *s1, SemGroup *s2);
160 int MatchType(Type *super, Type *type);
161 void InternalRegisterType(const char *str, const char *linkname, Type *type);
162 Type *InternalRegisteredTypeLookup(string_t id);
163 void initType(Type *type, typelist_t *list, int op);
164 void initQualType(Type *type, typelist_t *list, int op, int sqflags);
165 void initPtrType(Type *type, Type *ptrto, int sqflags);
166 void initCPtrType(Type *type, Type *ptrto, int sqflags);
167 SemGroup *BaseType(Type **ptype);
168
169 GlobInfo *GetGlobInfo(const char *label,
170                         runesize_t beg_off, runesize_t end_off,
171                         SemGroup *rssg, Type *type);
172
173 /*
174  * High-level Interpreter and Generator
175  */
176 runctx_p RunUnresolvedStmt(runctx_p ct, Stmt *st);
177 genctx_p GenUnresolvedStmt(genctx_p ct, Stmt *st);
178
179 void RunUnresolvedExp(runctx_p ct, rundata_t *data, Exp *exp);
180 int64_t Run64DefaultExp(runctx_p ct, Exp *exp);
181 gendata_t *GenUnresolvedExp(genctx_p ct, Exp *exp);
182
183 extern int RuneInlineComplexity;
184
185 extern typelist_t DynamicTypeList;
186 extern typelist_t CompoundTypeList;
187 extern typelist_t ArgsTypeList;
188 extern typelist_t StorageTypeList;
189
190 extern void **DefaultDynamicVector;
191
192 extern Type DynamicRValueType;
193 extern Type DynamicLValueType;
194 extern Type NumericType;
195 extern Type IntegralType;
196 extern Type SIntegerType;
197 extern Type UIntegerType;
198 extern Type VoidType;
199 extern Type BoolType;
200 extern Type Int8Type;
201 extern Type UInt8Type;
202 extern Type Int16Type;
203 extern Type UInt16Type;
204 extern Type Int32Type;
205 extern Type UInt32Type;
206 extern Type Int64Type;
207 extern Type UInt64Type;
208 extern Type Int128Type;
209 extern Type UInt128Type;
210
211 extern Type FloatType;
212 extern Type Float32Type;
213 extern Type Float64Type;
214 extern Type Float128Type;
215
216 extern Type CCharType;
217 extern Type StrType;            /* NOTE: const char *, chars are unsigned */
218 extern Type CharPtrType;
219 extern Type CharPtrPtrType;
220 extern Type VoidPtrType;
221 extern Type VoidRefType;
222 extern Type CVoidPtrType;
223 extern Type LVoidPtrType;
224 extern Type PointerType;        /* generic pointer placeholder */
225 extern Type PointerInfoType;
226
227 extern Type LexRefType;         /* run-time access class tie-ins */
228 extern Type ScopeType;
229 extern Type DeclarationType;
230 extern Type SemGroupType;
231 extern Type TypeType;
232 extern Type FILLERTypeType;
233 extern Type FILLERDeclType;
234
235 extern Type IntPtrType;
236 extern Type UIntPtrType;
237 extern Type OffType;
238 extern Type SizeType;
239
240 extern Type *BaseTypeAry[];
241 extern typereglist_t TypeRegList;
242