11 bool ConstVtables
= 0;
12 bool VIDeclarations
= 0;
14 bool ExpandAllAutos
= 0;
15 bool Streams_Closed
= false;
16 bool ExceptionsUsed
= 1;
17 bool GlobInitUsed
= 0;
21 bool HaveAliases
= 0; /* not well removed by gcc and produce bigger binaries */
22 bool StdcallMembers
= 0;
24 bool EHUnwind
= EHDEFAULT
;
25 bool GoodOldC
= false;
33 Token nodcl
[] = { -1 };
34 Token xargs
[] = { RESERVED_x
, -1 };
36 // null invalid structure && type
38 enter_struct (NOOBJ
, 1, 0, 0, 0, 0);
43 p
[0] = B_PURE
; p
[1] = -1;
44 typeID_NOTYPE
= enter_type (p
);
45 p
[0] = B_SINT
; p
[1] = -1;
46 typeID_int
= enter_type (p
);
48 typeID_uint
= enter_type (p
);
50 typeID_float
= enter_type (p
);
52 typeID_void
= enter_type (p
);
53 sintprintf (p
, B_SCHAR
, '*', -1);
54 typeID_charP
= enter_type (p
);
56 typeID_voidP
= enter_type (p
);
58 typeID_intP
= enter_type (p
);
59 sintprintf (p
, B_SCHAR
, '(', typeID_int
, INTERNAL_ARGEND
, '*', -1);
60 typeID_ebn_f
= enter_type (p
);
64 enter_global_object (RESERVED___FUNCTION__
, typeID_charP
);
65 enter_global_object (RESERVED___PRETTY_FUNCTION__
, typeID_charP
);
66 if ((t
= Lookup_Symbol ("__builtin_va_list")))
67 enter_typedef (t
, typeID_voidP
);
69 if ((t
= Lookup_Symbol ("__lwcbuiltin_get_estack"))) {
70 sintprintf (p
, typeID_voidP
, '(', INTERNAL_ARGEND
, -1);
71 xdeclare_function (&Global
, t
, t
, enter_type (p
), nodcl
, xargs
, FUNCP_NOTHROW
, 0,0);
73 if ((t
= Lookup_Symbol ("__lwcbuiltin_set_estack"))) {
74 sintprintf (p
, B_VOID
, '(', typeID_voidP
, INTERNAL_ARGEND
, -1);
75 xdeclare_function (&Global
, t
, t
, enter_type (p
), nodcl
, xargs
, FUNCP_NOTHROW
, 0,0);
78 if ((t
= Lookup_Symbol ("__builtin_expect"))) {
79 sintprintf (p
, B_SINT
, '(', typeID_int
, typeID_int
, INTERNAL_ARGEND
, -1);
80 xdeclare_function (&Global
, t
, t
, enter_type (p
), nodcl
, xargs
, FUNCP_NOTHROW
, 0,0);
82 if ((t
= Lookup_Symbol ("__builtin_stdarg_start"))) {
83 sintprintf (p
, B_VOID
, '(', B_ELLIPSIS
, INTERNAL_ARGEND
, '*', -1);
84 xdeclare_function (&Global
, t
, t
, enter_type (p
), nodcl
, xargs
, 0, 0, 0);
86 if ((t
= Lookup_Symbol ("__builtin_va_end"))) {
87 sintprintf (p
, B_VOID
, '(', B_ELLIPSIS
, INTERNAL_ARGEND
, '*', -1);
88 xdeclare_function (&Global
, t
, t
, enter_type (p
), nodcl
, xargs
, 0, 0, 0);
91 if (t
= Lookup_Symbol ("__builtin_popcount")) {
92 sintprintf (p
, B_SINT
, '(', typeID_int
, INTERNAL_ARGEND
, -1);
93 xdeclare_function (&Global
, t
, t
, enter_type (p
), nodcl
, xargs
, FUNCP_NOTHROW
, 0,0);
95 if (t
= Lookup_Symbol ("__builtin_constant_p")) {
96 sintprintf (p
, B_SINT
, '(', B_ELLIPSIS
, INTERNAL_ARGEND
, -1);
97 xdeclare_function (&Global
, t
, t
, enter_type (p
), nodcl
, xargs
, FUNCP_NOTHROW
, 0,0);
99 sintprintf (p
, B_VOID
, '(', typeID_uint
, INTERNAL_ARGEND
, '*', -1);
100 xdeclare_function (&Global
, INTERN_alloca
, INTERN_alloca
,
101 enter_type (p
), nodcl
, xargs
, FUNCP_NOTHROW
, 0, 0);
103 // xdeclare_function (&Global, RESERVED_alloca, RESERVED_alloca,
104 // enter_type (p), nodcl, xargs, FUNCP_NOTHROW, 0, 0);
107 name_derrive_union
= new_symbol (DERRIVE_UNION
);
109 zinit
[0] = RESERVED_0
, zinit
[1] = -1;
111 GLOBAL_INIT_FUNC
= new_stream ();
112 Token GIF
= new_symbol (GLOBINITF
);
113 outprintf (GLOBAL_INIT_FUNC
, RESERVED_static
, RESERVED_void
, GIF
, '(', ')',
114 RESERVED___attribute__
, '(', '(', RESERVED_constructor
, ')', ')', ';',
115 RESERVED_static
, RESERVED_void
, GIF
, '(', ')', '{', -1);
121 output_itoken (GLOBAL_INIT_FUNC
, '}');
122 #ifdef COMMENT_OUTPUT
123 output_itoken (GLOBAL
, new_symbol (COMMENT_SECTION_OBJCTOR
));
125 concate_streams (GLOBAL
, GLOBAL_INIT_FUNC
);
128 output_itoken (GLOBAL
, new_symbol ("\n#error there were errors in lwc expressions\n"));
131 static const char stdc
[] =
132 "#define __STDC__ 1\n"
133 "#define __STDC_VERSION__ 199901L\n"
136 static const char stddef
[] =
139 // * * * STILL DOESN'T WORK. shitty Glibc crap
140 "#define NULL ((void*)0)\n"
141 "typedef __SIZE_TYPE__ size_t;\n"
142 "typedef __PTRDIFF_TYPE__ ptrdiff_t;\n"
143 "typedef __WCHAR_TYPE__ wchar_t;\n"
144 "typedef __WINT_TYPE__ wint_t;\n"
147 "extern void * malloc (unsigned int);\n"
148 #if INTER_alloca == RESERVED_alloca
149 "extern void * alloca (unsigned int);\n"
151 "extern void free (void*);\n"
154 static const char stdlwc
[] =
160 #define PROGRESS(x) if (debugflag.PROGRESS) fputs (COLS x COLE"...\n", stderr);
163 int main (int argc
, char **argv
)
165 srand (time (NULL
) ^ getpid () ^ (int) argv
^ (int) &argc
^ (int) main
);
170 PROGRESS ("preprocessing");
171 preproc (argc
- 1, argv
+ 1);
175 yydo_mem ((char*)sys_defs
, sizeof sys_defs
- 1);
176 yydo_mem ((char*)stdc
, sizeof stdc
- 1);
179 yydo_mem ((char*)stddef
, sizeof stddef
- 1);
181 yydo_mem ((char*)stdlwc
, sizeof stdlwc
- 1);
182 if (yydo (main_file
)) {
183 fprintf (stderr
, "No such file or directory\n");
196 if (debugflag
.SHOWPROG
) {
198 for (i
=0; CODE
[i
] != -1; i
++)
199 PRINTF ("%i %s %c", i
, expand (CODE
[i
]),i
%6 ? '\t':'\n');
202 if (debugflag
.SHOWCPP
) {
203 FILE *F
= fopen (PREPROCOUT
, "w");
205 for (i
=0; CODE
[i
] != -1; i
++)
206 fprintf (F
, "%s ", expand (CODE
[i
]));
211 FPROTOS
= new_stream ();
212 GLOBAL
= new_stream ();
213 INTERNAL_CODE
= new_stream ();
214 VIRTUALTABLES
= new_stream ();
215 VTABLE_DECLARATIONS
= new_stream ();
216 STRUCTS
= new_stream ();
217 GVARS
= new_stream ();
218 INCLUDE
= new_stream ();
219 REGEXP_CODE
= new_stream ();
220 AUTOFUNCTIONS
= new_stream ();
221 FUNCDEFCODE
= new_stream ();
223 output_itoken (INCLUDE
, new_symbol (strdup ("/* lightweight c++ "LWC_VERSION
" */\n")));
224 #ifdef COMMENT_OUTPUT
225 output_itoken (INCLUDE
, new_symbol (COMMENT_SECTION_INCLUDE
));
226 output_itoken (FPROTOS
, new_symbol (COMMENT_SECTION_PROTOTYPES
));
227 output_itoken (GLOBAL
, new_symbol (COMMENT_SECTION_GLOBAL
));
228 output_itoken (INTERNAL_CODE
, new_symbol (COMMENT_SECTION_INNERCODE
));
229 output_itoken (VIRTUALTABLES
, new_symbol (COMMENT_SECTION_VIRTUALTABLES
));
230 output_itoken (VTABLE_DECLARATIONS
, new_symbol (COMMENT_SECTION_VTDEF
));
231 output_itoken (STRUCTS
, new_symbol (COMMENT_SECTION_STRUCTS
));
232 output_itoken (GVARS
, new_symbol (COMMENT_SECTION_GVARS
));
233 output_itoken (REGEXP_CODE
, new_symbol (COMMENT_SECTION_REGEXP
));
234 output_itoken (AUTOFUNCTIONS
, new_symbol (COMMENT_SECTION_AUTOFUNCTIONS
));
235 output_itoken (FUNCDEFCODE
, new_symbol (COMMENT_SECTION_FUNCTIONS
));
239 PROGRESS ("parsing translation unit")
242 PROGRESS ("compiling functions");
244 while (specialize_abstracts ());
246 PROGRESS ("auto functions")
247 define_auto_functions ();
249 PROGRESS ("making data structures");
253 export_virtual_table_instances ();
256 export_virtual_definitions ();
258 if (MainModule
) export_virtual_definitions ();
259 else export_virtual_static_definitions ();
262 if (Global
) export_fspace (Global
);
263 outprintf (FPROTOS
, RESERVED_void
, '*', RESERVED_malloc
, '(', RESERVED_unsigned
,
264 RESERVED_int
, ')', ';', RESERVED_void
, RESERVED_free
, '(', ')', ';', -1);
266 PROGRESS ("expanding output");
267 concate_streams (INCLUDE
, GLOBAL
);
269 concate_streams (GLOBAL
, STRUCTS
);
270 concate_streams (GLOBAL
, VTABLE_DECLARATIONS
);
271 concate_streams (GLOBAL
, FPROTOS
);
272 concate_streams (GLOBAL
, GVARS
);
273 concate_streams (GLOBAL
, REGEXP_CODE
);
274 concate_streams (GLOBAL
, INTERNAL_CODE
);
275 concate_streams (GLOBAL
, AUTOFUNCTIONS
);
276 concate_streams (GLOBAL
, FUNCDEFCODE
);
277 concate_streams (GLOBAL
, VIRTUALTABLES
);
281 if (!debugflag
.NOSTDOUT
)
283 export_output (GLOBAL
);