Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

B-C-1.04_05

git-svn-id: http://perl-compiler.googlecode.com/svn/trunk@6 ed534f1a-1453-0410-ab30-dfc593a8b23c
  • Loading branch information...
commit bb57d2021c558ed31b90099063c8bf4fd7e04985 1 parent 67b941c
@rurban authored
View
18 B/Bytecode.pm
@@ -738,13 +738,15 @@ sub compile {
*newasm = *endasm = sub { };
*asm = sub { print " @_\n" };
*nice = sub ($) { print "\n@_\n" };
+ } elsif (/^-v/) {
+ *nice = sub ($) { print STDERR "@_\n" };
} elsif (/^-H/) {
require ByteLoader;
$head = "#! $^X
use ByteLoader $ByteLoader::VERSION;
";
#FIXME!
- undef $head;
+ #undef $head;
} elsif (/^-k/) {
keep_syn;
} elsif (/^-o(.*)$/) {
@@ -841,16 +843,15 @@ later by the ByteLoader module and executed as a regular Perl script.
=over 4
+=item B<-H>
+
+prepend a C<use ByteLoader VERSION;> line to the produced bytecode.
+
=item B<-b>
Save all the BEGIN blocks. Normally only BEGIN blocks that C<require>
other files (ex. C<use Foo;>) are saved.
-=item B<-H>
-
-prepend a C<use ByteLoader VERSION;> line to the produced bytecode.
-Does not work currently.
-
=item B<-k>
keep the syntax tree - it is stripped by default.
@@ -864,6 +865,11 @@ put the bytecode in <outfile> instead of dumping it to STDOUT.
scan the script for C<# line ..> directives and for <goto LABEL>
expressions. When gotos are found keep the syntax tree.
+=item B<-S>
+
+Output assembler source rather than piping it
+through the assembler and outputting bytecode.
+
=back
=head1 KNOWN BUGS
View
2  B/C.pm
@@ -8,7 +8,7 @@
package B::C;
-our $VERSION = '1.04_04';
+our $VERSION = '1.04_05';
package B::C::Section;
View
12 ByteLoader/bytecode.h
@@ -201,7 +201,6 @@ typedef HEK *hekindex;
if(av_len((AV*) PL_regex_pad[0]) > -1) { \
repointer = av_pop((AV*)PL_regex_pad[0]); \
cPMOPx(o)->op_pmoffset = SvIV(repointer); \
- SvREPADTMP_off(repointer); \
sv_setiv(repointer,PTR2IV(rx)); \
} else { \
repointer = newSViv(PTR2IV(rx)); \
@@ -291,6 +290,10 @@ typedef HEK *hekindex;
#define set_clonex(fp)
#endif
+#ifndef PL_preprocess
+#define PL_preprocess 0
+#endif
+
#define BSET_data(dummy,arg) \
STMT_START { \
GV *gv; \
@@ -305,7 +308,7 @@ typedef HEK *hekindex;
set_clonex(PL_RSFP); \
/* Mark this internal pseudo-handle as clean */ \
IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; \
- if (PL_preprocess) \
+ if ((PERL_VERSION < 11) && PL_preprocess) \
IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; \
else if ((PerlIO*)PL_RSFP == PerlIO_stdin()) \
IoTYPE(GvIOp(gv)) = IoTYPE_STD; \
@@ -479,4 +482,9 @@ typedef HEK *hekindex;
if (sz != PTRSIZE) { \
HEADER_FAIL("different PTRSIZE"); \
} \
+ BGET_strconst(str); /* 12345678 */ \
+ if (strNE(str, "12345678")) { \
+ HEADER_FAIL2("cannot yet convert different byteorders (want %s, you have %s)", \
+ "12345678", str); \
+ } \
} STMT_END
View
9 ByteLoader/byterun.c
@@ -55,7 +55,7 @@ byterun(pTHX_ struct byteloader_state *bstate)
register int insn;
U32 isjit = 0;
U32 ix;
- SV *specialsv_list[6];
+ SV *specialsv_list[7];
BYTECODE_HEADER_CHECK; /* croak if incorrect platform, set isjit if PLJC magic header */
if (isjit) {
@@ -65,6 +65,10 @@ byterun(pTHX_ struct byteloader_state *bstate)
bstate->bs_obj_list_fill = 31;
bstate->bs_obj_list[0] = NULL; /* first is always Null */
bstate->bs_ix = 1;
+ DEBUG_l( Perl_deb(aTHX_ "(bstate.bs_fdata.idx %d)\n", bstate->bs_fdata->idx));
+ DEBUG_l( Perl_deb(aTHX_ "(bstate.bs_fdata.next_out %d)\n", bstate->bs_fdata->next_out));
+ DEBUG_l( Perl_deb(aTHX_ "(bstate.bs_fdata.datasv %p:\"%s\")\n", bstate->bs_fdata->datasv,
+ SvPV_nolen(bstate->bs_fdata->datasv)));
specialsv_list[0] = Nullsv;
specialsv_list[1] = &PL_sv_undef;
@@ -75,7 +79,8 @@ byterun(pTHX_ struct byteloader_state *bstate)
specialsv_list[6] = (SV*)pWARN_STD;
while ((insn = BGET_FGETC()) != EOF) {
- switch (insn) {
+ DEBUG_l( Perl_deb(aTHX_ "(insn %d)\n", insn));
+ switch (insn) {
case INSN_COMMENT: /* 35 */
{
comment_t arg;
View
2  ByteLoader/jitrun.c
@@ -94,7 +94,7 @@ jitrun(pTHX_ struct byteloader_state *bstate)
jit_func bc_func = (jit_func) (jit_set_ip(codeBuffer).iptr); /* Function ptr */
#ifdef DEBUGGING
- disassemble(stderr, codeBuffer, jit_get_ip().ptr);
+ //disassemble(stderr, codeBuffer, jit_get_ip().ptr);
#endif
jit_flush_code(codeBuffer, jit_get_ip().ptr);
View
5 ByteLoader/jitrun.h
@@ -59,8 +59,9 @@
*/
/* DATA handle reader */
-int jit_getc(struct byteloader_fdata *);
-int jit_read(struct byteloader_fdata *, char *, size_t, size_t);
+/* int bl_getc(struct byteloader_fdata *);
+ int bl_read(struct byteloader_fdata *, char *, size_t, size_t);
+*/
#include <lightning.h>
View
11 Changes
@@ -1,6 +1,17 @@
Started with B-C-1.04_01. The perl compiler was previously in CORE.
TODO: Try to get info about earlier versions.
+1.04_05 2008-02-18 rurban
+ * added t/test.pl and t/test*.sh to MANIFEST.
+ * fixed ByteLoader reading from the <DATA> filter.
+ * fixed -H .plc header parsing
+ * updated Bytecode options in NOTES and pod
+ * added -O=Bytecode,-v option
+ * fixed PL_preprocess and SvREPADTMP_off for 5.11
+
+1.04_04 2008-02-08 rurban
+ * added jitcompiler macros
+
1.04_03 2008-02-05 rurban
* added Jit and Asm layout, fixed Makefile deps
View
3  MANIFEST
@@ -58,6 +58,9 @@ t/c.t
t/cc.t
t/o.t
t/stash.t
+t/test.pl
+t/testplc.sh
+t/testc.sh
TESTS
Todo
META.yml Module meta-data (added by MakeMaker)
View
2  META.yml
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: B-C
-version: 1.04_04
+version: 1.04_05
abstract: ~
license: ~
author: ~
View
8 Makefile.PL
@@ -1,7 +1,7 @@
use ExtUtils::MakeMaker;
use Config;
use File::Spec;
-use 5.009005;
+#use 5.009005;
my $core = grep { $_ eq 'PERL_CORE=1' } @ARGV;
@@ -9,7 +9,7 @@ WriteMakefile(
NAME => "B::C",
VERSION_FROM => "B/C.pm",
# 'scripts/assemble','scripts/disassemble',
- PL_FILES => {'script/perlcc.PL' => 'bin/perlcc' },
+ PL_FILES => {'script/perlcc.PL' => '$(INST_BIN)/perlcc' },
PREREQ_PM => {
'B::Concise' => '0.74',
'B' => '1.17',
@@ -28,6 +28,10 @@ sub headerpath {
package MY;
+sub x_libscan {
+ return 0 unless $_[1] =~ /\.pm$/;
+}
+
sub post_constants {
"\nLIBS = $Config::Config{libs}\n"
}
View
26 NOTES
@@ -2,6 +2,8 @@ C backend invocation
If there are any non-option arguments, they are taken to be
names of objects to be saved (probably doesn't work properly yet).
Without extra arguments, it saves the main program.
+ -q Be quiet. STDOUT goes to $O::BEGIN_output
+ -qq Be very quiet. Also suppress "Syntax OK"
-ofilename Output to filename instead of STDOUT
-v Verbose (currently gives a few compilation statistics)
-- Force end of options
@@ -35,7 +37,10 @@ Examples
CC backend invocation
If there are any non-option arguments, they are taken to be names of
subs to be saved. Without extra arguments, it saves the main program.
+ -q Be quiet. STDOUT goes to $O::BEGIN_output
+ -qq Be very quiet. Also suppress "Syntax OK"
-ofilename Output to filename instead of STDOUT
+NYI -v Be verbose.
-- Force end of options
-uPackname Force apparently unused subs from package Packname to
be compiled. This allows programs to use eval "foo()"
@@ -101,7 +106,10 @@ Bytecode backend invocation
If there are any non-option arguments, they are taken to be
names of objects to be saved (probably doesn't work properly yet).
Without extra arguments, it saves the main program.
+ -q Be quiet. STDOUT goes to $O::BEGIN_output
+ -qq Be very quiet. Also suppress "Syntax OK"
-ofilename Output to filename instead of STDOUT.
+NYI -v Be verbose.
-- Force end of options.
-f Force optimisations on or off one at a time.
Each can be preceded by no- to turn the option off.
@@ -121,10 +129,10 @@ Bytecode backend invocation
run-time but leaving them out will make it impossible
to recompile or disassemble the resulting program.
It will also stop "goto label" statements from working.
- -On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
+NYI -On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
-O1 sets -fcompress-nullops -fomit-sequence numbers.
-O6 adds -fstrip-syntax-tree.
- -D Debug options (concat or separate flags like perl -D)
+NYI -D Debug options (concat or separate flags like perl -D)
o OPs, prints each OP as it's processed.
b print debugging information about bytecompiler progress
a tells the assembler to include source assembler lines
@@ -132,13 +140,23 @@ Bytecode backend invocation
C prints each CV taken from the final symbol tree walk.
-S Output assembler source rather than piping it
through the assembler and outputting bytecode.
- -m Compile as a module rather than a standalone program.
+ -H add #! perl shebang header
+ -s scan and keep keep syntax tree if goto op found.
+ scan the script for C<# line ..> directives and for <goto LABEL>
+ expressions. When gotos are found keep the syntax tree.
+ -b Save all the BEGIN blocks. Normally only BEGIN blocks that require
+ other files (ex. use Foo;) are saved.
+ -k keep syntax tree to disassemble the plc.
+ it is stripped by default.
+ -TI testing, dump the @INC av
+ -TF file testing, sets COP::file
+ -m Compile as a module rather than a standalone program.
Currently this just means that the bytecodes for
initialising main_start, main_root and curpad are
omitted.
Example
- perl -MO=Bytecode,-O6,-o,foo.plc foo.pl
+ perl -MO=Bytecode,-O6,-H,-ofoo.plc foo.pl
perl -MO=Bytecode,-S foo.pl > foo.S
assemble foo.S > foo.plc
View
2  Todo
@@ -16,7 +16,6 @@ CvOUTSIDE for ordinary subs
DATA filehandle for standalone Bytecode program (easy)
DATA filehandle for multiple bytecode-compiled modules (harder)
DATA filehandle for C-compiled program (yet harder)
-parse -H Bytecode header
* Features
@@ -31,6 +30,7 @@ module dependencies
new Asm and JIT backend, PLJC ByteLoader magic
* Optimisations
+
collapse LISTOPs to UNOPs or BASEOPs
compile-time qw(), constant subs
global analysis of variables, type hints etc.
View
11 bytecode.pl
@@ -110,7 +110,9 @@ package B::Asmdata;
register int insn;
U32 isjit = 0;
U32 ix;
- SV *specialsv_list[6];
+EOT
+printf BYTERUN_C " SV *specialsv_list[%d];\n", scalar @specialsv_name;
+print BYTERUN_C <<'EOT';
BYTECODE_HEADER_CHECK; /* croak if incorrect platform, set isjit if PLJC magic header */
if (isjit) {
@@ -120,6 +122,10 @@ package B::Asmdata;
bstate->bs_obj_list_fill = 31;
bstate->bs_obj_list[0] = NULL; /* first is always Null */
bstate->bs_ix = 1;
+ DEBUG_l( Perl_deb(aTHX_ "(bstate.bs_fdata.idx %d)\n", bstate->bs_fdata->idx));
+ DEBUG_l( Perl_deb(aTHX_ "(bstate.bs_fdata.next_out %d)\n", bstate->bs_fdata->next_out));
+ DEBUG_l( Perl_deb(aTHX_ "(bstate.bs_fdata.datasv %p:\"%s\")\n", bstate->bs_fdata->datasv,
+ SvPV_nolen(bstate->bs_fdata->datasv)));
EOT
@@ -130,7 +136,8 @@ package B::Asmdata;
print BYTERUN_C <<'EOT';
while ((insn = BGET_FGETC()) != EOF) {
- switch (insn) {
+ DEBUG_l( Perl_deb(aTHX_ "(insn %d)\n", insn));
+ switch (insn) {
EOT
View
30 jitcompiler.pl
@@ -4,24 +4,31 @@
=head1 JIT or ASM?
-Two possible native code attempts:
+Possible native code attempts:
-1. Use B<GNU lightning> to compile to jit at eval-time, and
- jitrun the whole codebuffer, the appended insns instead
- of looping through the opcode tree.
- Possibly dump the jitted codebuffer as PLJC .plc files, to save
- next startup parse time.
+1. Use some jit library, such as B<GNU lightning>, to compile to jit
+ at eval-time, and jitrun the whole codebuffer, the appended insns
+ instead of looping through the opcode tree. Possibly dump the
+ jitted codebuffer as PLJC .plc files, to save next startup parse
+ time.
This must be done with jit macro trickery on the C level.
-2. Use a self-written B<B::Asm> library to dump architectur specific
+ LLVM has some nice SSA optimizations.
+ See L<http://llvm.org/ProjectsWithLLVM/2002-Spring-CS497CZ-Jello.pdf>
+
+2. Use perl6 jit.
+ http://www.parrotcode.org/docs/jit.html#EXAMPLE
+ This already has optimizations for immediate and strict integer ops.
+
+3. Use a self-written B<B::Asm> library to dump architectur specific
asm insns directly.
Either dump the jitted codebuffer as PLJC .plc files, or construct
the necessary OS headers directly. For writing the PE/COFF format
see e.g. my L<C::DynaLib> pl2exe or Audreys L<Win32::Exe>, for writing
Elf see e.g. L<GNU libjit>.
- This could be done on a higher Perl level, and avoids the lightning
+ This could be done on a higher Perl level, and avoids the C-level
macro abstraction.
=head1 OPTIMIZATIONS
@@ -166,7 +173,7 @@ BEGIN
jit_func bc_func = (jit_func) (jit_set_ip(codeBuffer).iptr); /* Function ptr */
#ifdef DEBUGGING
- disassemble(stderr, codeBuffer, jit_get_ip().ptr);
+ //disassemble(stderr, codeBuffer, jit_get_ip().ptr);
#endif
jit_flush_code(codeBuffer, jit_get_ip().ptr);
@@ -235,8 +242,9 @@ BEGIN
*/
/* DATA handle reader */
-int jit_getc(struct byteloader_fdata *);
-int jit_read(struct byteloader_fdata *, char *, size_t, size_t);
+/* int bl_getc(struct byteloader_fdata *);
+ int bl_read(struct byteloader_fdata *, char *, size_t, size_t);
+*/
#include <lightning.h>
View
4 script/perlcc
@@ -1,5 +1,5 @@
-#!/usr/local/bin/perl5.10.0-nt
- eval 'exec /usr/local/bin/perl5.10.0-nt -S $0 ${1+"$@"}'
+#!/usr/bin/perl
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
--$running_under_some_shell;
View
15 t/testc.sh
@@ -0,0 +1,15 @@
+OCMD="perld -Mblib -MO=C,-DcACM,"
+CCMD="gcc -DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -fno-strict-aliasing -I/usr/local/include -I/usr/lib/perl5/5.10/cygwin/CORE"
+LCMD=" -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--stack,8388608 -Wl,--enable-auto-image-base -L/usr/local/lib -L/usr/lib/perl5/5.10/cygwin/CORE -lperl -ldl -lcrypt -lgdbm_compat -lperl"
+
+echo "print 'hi'" > ccode1.pl
+echo ${OCMD}-occode1.c ccode1.pl
+echo $CCMD ccode1.c $LCMD -o ccode1.exe
+${OCMD}-occode1.c ccode1.pl
+$CCMD ccode1.c $LCMD -o ccode1.exe
+
+echo "for (1,2,3) { print if /\d/ }" > ccode2.pl
+echo ${OCMD}-occode2.c ccode2.pl
+echo $CCMD ccode2.c $LCMD -o ccode2.exe
+${OCMD}-occode2.c ccode2.pl
+$CCMD ccode2.c $LCMD -o ccode2.exe
View
28 t/testplc.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+PERL=perld
+OCMD="$PERL -Mblib -MO=Bytecode,"
+ICMD="$PERL -Mblib -MByteLoader"
+
+echo "print 'hi'" > bytecode1.pl
+echo ${OCMD}-obytecode1.plc bytecode1.pl
+${OCMD}-obytecode1.plc bytecode1.pl
+${OCMD}-O6,-obytecode1O6.plc bytecode1.pl
+${OCMD}-k,-obytecode1k.plc bytecode1.pl
+${OCMD}-S,-obytecode1S.asm bytecode1.pl
+$PERL -Mblib script/assemble bytecode1S.asm bytecode1S.plc
+$PERL -Mblib script/disassemble bytecode1k.plc > bytecode1k.asm
+${OCMD}-TI,-obytecode1TI.plc bytecode1.pl
+${OCMD}-H,-obytecode1H.plc bytecode1.pl
+echo ${ICMD} bytecode1.plc
+${ICMD} bytecode1.plc
+
+echo "for (1,2,3) { print if /\d/ }" > bytecode2.pl
+echo ${OCMD}-obytecode2.plc bytecode2.pl
+${OCMD}-obytecode2.plc bytecode2.pl
+echo ${ICMD} bytecode2.plc
+${ICMD} bytecode2.plc
+
+echo "package MY::Test;" > bytecode1.pm
+echo "print 'hi'" >> bytecode1.pm
+echo ${OCMD}-m,-obytecode1.pmc bytecode1.pm
+${OCMD}-obytecode1.pmc bytecode1.pm
Please sign in to comment.
Something went wrong with that request. Please try again.