3 # Copyright (C) 2008, The Perl Foundation.
9 print do { local $/; <DATA
> };
14 .include
'library/config.pir'
24 (infile
, cfile
, objfile
, exefile
) = 'handle_args'(argv
)
26 if $I0 goto open_outfile
27 die "infile not specified"
31 outfh
= open cfile
, '>'
32 if outfh
goto args_handled
33 die "infile not specified"
37 data
= 'generate_data'(infile
)
38 out
= 'program_code'(data
)
42 'compile_file'(cfile
, objfile
)
43 'link_file'(objfile
, exefile
)
56 if argc
== 2 goto proper_args
60 .local string infile
, cfile
, objfile
, obj
, exefile
, exe
70 infile_len
= length infile
73 cfile
= substr infile
, 0, infile_len
77 objfile
= substr infile
, 0, infile_len
79 exefile
= substr infile
, 0, infile_len
82 # substitute .c for .pbc
83 # remove .c for executable
85 # TODO this should complain about results/returns mismatch
86 .return(infile
, cfile
, objfile
, exefile
)
94 infh
= open infile
, '<'
96 if infh
goto file_open
97 die "cannot open infile"
100 # read the file one opcode at a time -- for simplicity. optimize later
101 .local int buffer_size
103 buffer_size
= $P0['longsize'] # sizeof (opcode_t)
105 .local string bytecode
112 all_bytes
= new
'ResizablePMCArray'
114 .local int string_length
115 .local string byte_string
117 .local int bytes_per_line
122 at_eof
= infh
.'eof'()
123 if at_eof
goto end_loop
125 # read one byte at a time
126 byte_string
= read infh
, 1
127 string_length
= length byte_string
128 unless string_length
goto end_loop
130 # convert byte to integer
131 byte
= ord byte_string
132 # convert integer to string
134 # add string for the byte
138 $I0 = size
% bytes_per_line
139 if $I0 != 0 goto loop
144 data
['BYTECODE'] = bytecode
153 .local string template
, out
155 template
= 'pc_template'()
156 out
= 'merge_data'(template
, data
)
162 # template data functions
169 const Parrot_UInt1 program_code[] = {
173 const int bytecode_size = @SIZE@;
187 #include "parrot/parrot.h"
188 #include "parrot/embed.h"
197 int main
(int argc
, char
*argv
[])
200 Parrot_Interp interp
;
202 Parrot_set_config_hash
();
204 interp
= Parrot_new
( NULL
);
209 Parrot_set_executable_name
(interp
, string_from_cstring
(interp
, argv
[0], 0));
210 Parrot_set_flag
(interp
, PARROT_DESTROY_FLAG
);
212 pf
= PackFile_new
(interp
, 0);
214 if (!PackFile_unpack
(interp
, pf
, (const opcode_t
*)program_code
, bytecode_size
))
217 do_sub_pragmas
(interp
, pf
->cur_cs, PBC_PBC
, NULL
);
219 Parrot_loadbc
(interp
, pf
);
221 PackFile_fixup_subs
(interp
, PBC_MAIN
, NULL
);
222 Parrot_runcode
(interp
, argc
, argv
);
223 Parrot_destroy
(interp
);
224 Parrot_exit
(interp
, 0);
231 # template merging functions
233 .param string template
237 iter
= new
'Iterator', data
239 .local string symbol
, value
242 unless iter
goto it_done
244 symbol
= 'get_symbol'($P0)
247 $I0 = index template
, symbol
248 if -1 == $I0 goto repl_done
250 substr template
, $I0, $I1, value
263 $S1 = concat
$S0, var
264 $S1 = concat
$S1, $S0
272 .param string objfile
275 .local string cc
, ccflags
, cc_o_out
, osname
, build_dir
, slash
277 ccflags
= $P0['ccflags']
278 cc_o_out
= $P0['cc_o_out']
279 osname
= $P0['osname']
280 build_dir
= $P0['build_dir']
283 .local string includedir
, pathquote
284 includedir
= concat build_dir
, slash
285 includedir
= concat includedir
, 'include'
287 unless osname
== 'MSWin32' goto not_windows
291 .local string compile
298 compile
.= includedir
307 status
= spawnw compile
308 unless status
goto compiled
310 die "compilation failed"
319 .param string objfile
320 .param string exefile
323 .local string cc
, ld
, link_dynamic
, linkflags
, ld_out
, libparrot
, libs
, o
324 .local string rpath
, osname
, build_dir
, slash
, icushared
327 link_dynamic
= $P0['link_dynamic']
328 linkflags
= $P0['linkflags']
329 ld_out
= $P0['ld_out']
330 libparrot
= $P0['libparrot_ldflags']
333 rpath
= $P0['rpath_blib']
334 osname
= $P0['osname']
335 build_dir
= $P0['build_dir']
337 icushared
= $P0['icu_shared']
339 .local string config
, pathquote
340 config
= concat build_dir
, slash
343 config
.= 'parrot_config'
346 unless osname
== 'MSWin32' goto not_windows
348 $I0 = index cc
, 'gcc'
349 if $I0 > -1 goto not_windows
350 libparrot
= concat slash
, libparrot
351 libparrot
= concat build_dir
, libparrot
381 unless status
goto linked
394 # cperl-indent-level: 4
397 # vim: expandtab shiftwidth=4: