Skip to content

Commit

Permalink
Add a new prototype API function to write a PackFile PMC out to a .pb…
Browse files Browse the repository at this point in the history
…c file. This will be used to implement the -o and -r commandline options in the front-end
  • Loading branch information
Whiteknight committed Jan 23, 2011
1 parent 6e800f9 commit 2f0411b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/embed/api.c
Expand Up @@ -530,6 +530,46 @@ Parrot_api_serialize_bytecode_pmc(Parrot_PMC interp_pmc, Parrot_PMC pbc,

/*
=item <Parrot_Int Parrot_api_write_bytecode_to_file(Parrot_PMC interp_pmc,
Parrot_PMC pbc, Parrot_String filename)>
Write out a PackFile PMC to a .pbc file
=cut
*/

PARROT_API
Parrot_Int
Parrot_api_write_bytecode_to_file(Parrot_PMC interp_pmc, Parrot_PMC pbc,
Parrot_String filename)
{
ASSERT_ARGS(Parrot_api_write_bytecode_to_file)
EMBED_API_CALLIN(interp_pmc, interp)
PMC * filepmc = PMCNULL;
PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc);
if (!pf)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
"Could not get packfile.");
else {
PIOHANDLE fp = PIO_OPEN(interp, filename, PIO_F_WRITE);
if (fp == PIO_INVALID_HANDLE)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
"Cannot open output file %Ss", filename);
else {
const Parrot_Int size = PackFile_pack_size(interp, pf) * sizeof (opcode_t);
opcode_t * const packed = (opcode_t*)mem_sys_allocate(size);
PackFile_pack(interp, pf, packed);
PIO_WRITE(interp, fp, (char *)packed, size);
}
PIOCLOSE(interp, fp);
}

EMBED_API_CALLOUT(interp_pmc, interp)
}

/*
=item C<Parrot_Int Parrot_api_set_warnings(Parrot_PMC interp_pmc, Parrot_Int
flags)>
Expand Down

0 comments on commit 2f0411b

Please sign in to comment.