/
exec_start.c
183 lines (140 loc) · 3.99 KB
/
exec_start.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
$Id$
=head1 NAME
src/exec_start.c - Call compiled code
=head1 SYNOPSIS
I<What goes here?>
=head1 DESCRIPTION
Exec is a tool for using the JIT at compile time to generate native
executables.
=head2 Functions
=over 4
=cut
*/
#include "parrot/parrot.h"
#include "parrot/string.h"
#include "parrot/exec.h"
#include "parrot/jit.h"
#define JIT_EMIT 1
#include "parrot/jit_emit.h"
#include "parrot/embed.h"
opcode_t* run_compiled(Interp *interpreter,
opcode_t *cur_opcode, opcode_t *code_start);
/*
=item C<static void
setup_argv(Interp *interpreter, int argc, char ** argv)>
Stolen from F<embed.c>.
=cut
*/
static void
setup_argv(Interp *interpreter, int argc, char ** argv)
{
INTVAL i;
PMC *userargv;
if (Interp_debug_TEST(interpreter, PARROT_START_DEBUG_FLAG)) {
PIO_eprintf(interpreter,
"*** Parrot VM: Setting up ARGV array in P5. Current argc: %d ***\n",
argc);
}
userargv = pmc_new_noinit(interpreter, enum_class_SArray);
/* immediately anchor pmc to root set */
REG_PMC(5) = userargv;
VTABLE_set_pmc_keyed_int(interpreter, interpreter->iglobals,
(INTVAL)IGLOBALS_ARGV_LIST, userargv);
VTABLE_init(interpreter, userargv);
VTABLE_set_integer_native(interpreter, userargv, argc);
for (i = 0; i < argc; i++) {
/* Run through argv, adding everything to @ARGS. */
STRING *arg = string_make(interpreter, argv[i], strlen(argv[i]),
"binary", PObj_external_FLAG);
if (Interp_debug_TEST(interpreter, PARROT_START_DEBUG_FLAG)) {
PIO_eprintf(interpreter, "\t%vd: %s\n", i, argv[i]);
}
VTABLE_push_string(interpreter, userargv, arg);
}
}
/*
=item C<int main(int argc, char **argv)>
The run-loop.
=cut
*/
int
main(int argc, char **argv) {
long *opp;
int dummy_var;
Interp * interpreter;
struct PackFile * pf;
opcode_t *code_start;
INTVAL i;
PMC *userargv;
extern char *program_code;
extern long opcode_map;
extern int bytecode_offset;
#if defined(JIT_CGP)
extern void * exec_prederef_code;
#endif
extern int Parrot_exec_run;
extern struct PackFile_Constant *exec_const_table;
extern struct PackFile_Constant const_table;
extern Interp interpre;
/* s. exec.c */
Parrot_exec_run = 1;
/* s. packfile.c (PackFile_ConstTable_unpack()) */
exec_const_table = &const_table;
interpreter = Parrot_new(NULL);
if (!interpreter) {
return 1;
}
Parrot_init(interpreter);
run_native = run_compiled;
/* TODO make also a shared variant of PackFile_new */
pf = PackFile_new(interpreter, 0);
if (!PackFile_unpack(interpreter, pf, (opcode_t *)(&program_code),
sizeof(&program_code)))
{
printf( "Can't unpack.\n" );
return 1;
}
fixup_subs(interpreter, pf->cur_cs, PBC_PBC, NULL);
Parrot_loadbc(interpreter, pf);
setup_argv(interpreter, argc, argv);
/* opcode_map has the offset of each opcode in the compiled code
* this modifies it to be address of the opcode.
*/
opp = &opcode_map;
for (i = 0; i < (int)interpre.code->base.size; i++) {
opp[i] += (long)run_compiled;
}
#if defined(JIT_CGP)
exec_init_prederef(interpreter, &exec_prederef_code);
#endif
Parrot_set_run_core(interpreter, PARROT_EXEC_CORE);
interpreter->code->base.data =
(opcode_t *)&((&program_code)[bytecode_offset]);
Parrot_exec_run = 0;
runops(interpreter, 0);
/*
run_compiled(interpreter,
(opcode_t *)&((&program_code)[bytecode_offset]));
*/
exit(0);
}
/*
=back
=head1 SEE ALSO
F<include/parrot/exec.h>, F<include/parrot/exec_save.h>, F<src/exec.c>
and F<src/exec_start.c>.
=head1 HISTORY
Initial version by Daniel Grunblatt on 2003.6.9
=cut
*/
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/