* docs/pmc.pod:
[parrot.git] / src / exec_start.c
blobae9889c74235976cc875c20df6c1f527bfa9215b
1 /*
2 Copyright (C) 2001-2006, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 src/exec_start.c - Call compiled code
9 =head1 SYNOPSIS
11 I<What goes here?>
13 =head1 DESCRIPTION
15 Exec is a tool for using the JIT at compile time to generate native
16 executables.
18 =head2 Functions
20 =over 4
22 =cut
26 #include "parrot/parrot.h"
27 #include "parrot/string.h"
28 #include "parrot/exec.h"
29 #include "jit.h"
30 #define JIT_EMIT 1
31 #include "jit_emit.h"
32 #include "parrot/embed.h"
34 opcode_t* run_compiled(Interp *interpreter,
35 opcode_t *cur_opcode, opcode_t *code_start);
39 =item C<int main(int argc, char * argv[])>
41 The run-loop.
43 =cut
47 int
48 main(int argc, char * argv[])
50 /* long * opp; */
51 Interp * interpreter;
52 struct PackFile * pf;
53 opcode_t * code_start;
54 extern char * program_code;
55 /* extern long opcode_map; */
56 /* extern int bytecode_offset; */
57 #if defined(JIT_CGP)
58 extern void * exec_prederef_code;
59 #endif
60 /* extern int Parrot_exec_run; */
61 /* extern struct PackFile_Constant *exec_const_table; */
62 /* extern struct PackFile_Constant const_table; */
63 extern Interp interpre;
65 /* s. exec.c */
66 /* Parrot_exec_run = 1; */
67 /* s. packfile.c (PackFile_ConstTable_unpack()) */
68 /* exec_const_table = &const_table; */
69 interpreter = Parrot_new(NULL);
70 if (!interpreter) {
71 return 1;
74 /* run_native = run_compiled; */
75 /* TODO make also a shared variant of PackFile_new */
76 pf = PackFile_new(interpreter, 0);
78 if (!PackFile_unpack(interpreter, pf, (opcode_t *)(&program_code),
79 sizeof(&program_code)))
81 printf( "Can't unpack.\n" );
82 return 1;
84 Parrot_loadbc(interpreter, pf);
85 PackFile_fixup_subs(interpreter, PBC_PBC, NULL);
87 /* opcode_map has the offset of each opcode in the compiled code
88 * this modifies it to be address of the opcode.
91 opp = &opcode_map;
92 for (i = 0; i < (int)interpre.code->base.size; i++) {
93 opp[i] += (long)run_compiled;
97 #if defined(JIT_CGP)
98 exec_init_prederef(interpreter, &exec_prederef_code);
99 #endif
100 /* Parrot_set_run_core(interpreter, PARROT_EXEC_CORE);
101 interpreter->code->base.data =
102 (opcode_t *)&((&program_code)[bytecode_offset]);
103 Parrot_exec_run = 0; */
104 Parrot_runcode(interpreter, argc, argv);
106 run_compiled(interpreter,
107 (opcode_t *)&((&program_code)[bytecode_offset]));
109 Parrot_exit(interpreter, 0);
114 =back
116 =head1 SEE ALSO
118 F<include/parrot/exec.h>, F<src/exec_save.h>, F<src/exec.c>
119 and F<compilers/imcc/main.c>.
121 =head1 HISTORY
123 Initial version by Daniel Grunblatt on 2003.6.9
125 =cut
131 * Local variables:
132 * c-file-style: "parrot"
133 * End:
134 * vim: expandtab shiftwidth=4: