diff --git a/compilers/opsc/src/Ops/JIT.pm b/compilers/opsc/src/Ops/JIT.pm index 4e0922f090..995471015d 100644 --- a/compilers/opsc/src/Ops/JIT.pm +++ b/compilers/opsc/src/Ops/JIT.pm @@ -8,6 +8,9 @@ LLVM JITter? class Ops::JIT; +# Debug outputs. +has $!debug; + # Ops::OpsFile has $!ops_file; has %!ops; @@ -34,7 +37,8 @@ has $!opcode_ptr_type; =item new Create new JITter for given PBC and OpsFile. -method new(Str $pbc, Ops::File $ops_file, OpLib $oplib) { +method new(Str $pbc, Ops::File $ops_file, OpLib $oplib, :$debug?) { + $!debug := ?$debug; $!ops_file := $ops_file; $!oplib := $oplib; @@ -258,7 +262,7 @@ method _create_basic_blocks(%jit_context) { # Get op my $op := $!oplib{$opname}; - say("# $opname"); + $!debug && say("# $opname"); my $bb := $leave.insert_before("L$i"); %jit_context{$i} := hash( label => "L$i", @@ -296,7 +300,7 @@ method _jit_ops(%jit_context) { my $opname := $!opmap[$id]; # Real opname my $op := $!oplib{$opname}; # Get op - say("# jit $opname "); + $!debug && say("# jit $opname "); # Position Builder to previousely created BB. $!builder.set_position(%jit_context{$i}); @@ -360,7 +364,7 @@ We stop on :flow ops because PCC will interrupt "C" flow and our PCC is way too complext to implement it in JITter. method process_op(Ops::Op $op, %c) { - say("# Handling { $op.full_name }"); + $!debug && say("# Handling { $op.full_name }"); %c := $op; self.process($_, %c) for @($op); %c.delete('op'); @@ -385,7 +389,7 @@ our multi method process(PAST::Var $var, %c) { if $var.scope eq 'register' { my $num := $var.name; my $type := %c.arg_type($num - 1); - say("# Handling '$type' register"); + $!debug && say("# Handling '$type' register"); my $sub := pir::find_sub_not_null__ps('access_arg:type<' ~ $type ~ '>'); $sub(self, $num, %c); } @@ -414,7 +418,7 @@ our method access_arg:type ($num, %ctx) { } our method access_arg:type ($num, %ctx) { - say("# $num { self._opcode_at($num, %ctx) }"); + $!debug && say("# $num { self._opcode_at($num, %ctx) }"); LLVM::Constant::integer(self._opcode_at($num, %ctx)); } @@ -432,7 +436,7 @@ our method access_arg:type ($num, %ctx) { s = c[I] %r = box s }; - say("# $num '$res'"); + $!debug && say("# $num '$res'"); #$!builder.global_string_ptr($res, :name<.SCONST>); my $strings := $!builder.call( @@ -532,7 +536,7 @@ our multi method process(String $str, %c) { our method process:macro(PAST::Op $chunk, %c) { my $offset := ~$chunk[0].value; # FIXME - say("# macro '$offset'"); + $!debug && say("# macro '$offset'"); my $target := %c + $offset; my $jump_to := %c{$target}; @@ -544,7 +548,7 @@ our method process:macro(PAST::Op $chunk, %c) { } our method process:macro(PAST::Op $chunk, %c) { - say("# macro"); + $!debug && say("# macro"); # FIXME $!builder.store( LLVM::Constant::null( diff --git a/t/jit/test.t b/t/jit/test.t index 627647fd58..282c79d3d2 100644 --- a/t/jit/test.t +++ b/t/jit/test.t @@ -4,6 +4,7 @@ pir::load_bytecode("opsc.pbc"); # Some preparation +my $debug := 0; my $pir := 't/compilers/opsc/data/03.pir'; my $pbc := subst($pir, / 'pir' $/, 'pbc'); @@ -18,10 +19,10 @@ my $oplib := pir::new__psp("OpLib", "core_ops"); my $ops_file := Ops::File.new("t/jit/jitted.ops", :oplib($oplib), :core(0), - :quiet(0), + :quiet(!$debug), ); -my $jitter := Ops::JIT.new($pbc, $ops_file, $oplib); +my $jitter := Ops::JIT.new($pbc, $ops_file, $oplib, debug => $debug); my $start := 0; my %jit_context := $jitter.jit($start);