3 # Copyright (C) 2008, The Perl Foundation.
9 (my $compile = shift) =~ s/\\\n/ /gm;
11 $compile = `$^X tools/dev/cc_flags.pl --return-only $compile`;
12 my $template = do { local $/; <DATA
> };
14 printf( $template, $compile );
19 .include
'library/config.pir'
28 (infile
, cfile
, exefile
) = 'handle_args'(argv
)
30 if $I0 goto open_outfile
31 die "infile not specified"
35 outfh
= open cfile
, '>'
36 if outfh
goto args_handled
37 die "infile not specified"
41 data
= 'generate_data'(infile
)
42 out
= 'program_code'(data
)
46 compile_file
(cfile
, exefile
)
59 if argc
== 2 goto proper_args
63 .local string infile
, cfile
, exefile
, exe
72 infile_len
= length infile
75 cfile
= 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
, 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
119 at_eof
= infh
.'eof'()
120 if at_eof
goto end_loop
122 # read one byte at a time
123 byte_string
= read infh
, 1
124 string_length
= length byte_string
125 unless string_length
goto end_loop
127 # convert byte to integer
128 byte
= ord byte_string
129 # convert integer to string
131 # add string for the byte
138 data
['BYTECODE'] = bytecode
147 .local string template
, out
149 template
= 'pc_template'()
150 out
= 'merge_data'(template
, data
)
156 # template data functions
163 int8_t program_code[] = {
167 int bytecode_size = @SIZE@;
181 #include "parrot/parrot.h"
182 #include "parrot/embed.h"
185 # define int8_t signed__int8
195 int main
(int argc
, const char
*argv
[])
199 Parrot_Interp interp
= Parrot_new
( NULL
);
204 pf
= PackFile_new
(interp
, 0);
206 if (!PackFile_unpack
(interp
, pf
, (opcode_t
*)program_code
, bytecode_size
))
209 do_sub_pragmas
(interp
, pf
->cur_cs, PBC_PBC
, NULL
);
211 Parrot_loadbc
(interp
, pf
);
213 PackFile_fixup_subs
(interp
, PBC_MAIN
, NULL
);
214 Parrot_runcode
(interp
, argc
, argv
);
215 Parrot_destroy
(interp
);
216 Parrot_exit
(interp
, 0);
225 # template merging functions
227 .param string template
231 iter
= new
'Iterator', data
233 .local string symbol
, value
236 unless iter
goto it_done
238 symbol
= 'get_symbol'($P0)
241 $I0 = index template
, symbol
242 if -1 == $I0 goto repl_done
244 substr template
, $I0, $I1, value
257 $S1 = concat
$S0, var
258 $S1 = concat
$S1, $S0
266 .param string exefile
268 .local string compile
275 status
= spawnw compile
276 unless status
goto compiled
279 die "compilation failed"
289 # cperl-indent-level: 4
292 # vim: expandtab shiftwidth=4: