Skip to content

Commit

Permalink
Suppress debug output when not requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed Mar 28, 2011
1 parent 8a041c8 commit 9671e11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
22 changes: 13 additions & 9 deletions compilers/opsc/src/Ops/JIT.pm
Expand Up @@ -8,6 +8,9 @@ LLVM JITter?

class Ops::JIT;

# Debug outputs.
has $!debug;

# Ops::OpsFile
has $!ops_file;
has %!ops;
Expand All @@ -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;

Expand Down Expand Up @@ -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<basic_blocks>{$i} := hash(
label => "L$i",
Expand Down Expand Up @@ -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<basic_blocks>{$i}<bb>);
Expand Down Expand Up @@ -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> := $op;
self.process($_, %c) for @($op);
%c.delete('op');
Expand All @@ -385,7 +389,7 @@ our multi method process(PAST::Var $var, %c) {
if $var.scope eq 'register' {
my $num := $var.name;
my $type := %c<op>.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);
}
Expand Down Expand Up @@ -414,7 +418,7 @@ our method access_arg:type<ki> ($num, %ctx) {
}

our method access_arg:type<ic> ($num, %ctx) {
say("# $num <ic> { self._opcode_at($num, %ctx) }");
$!debug && say("# $num <ic> { self._opcode_at($num, %ctx) }");
LLVM::Constant::integer(self._opcode_at($num, %ctx));
}

Expand All @@ -432,7 +436,7 @@ our method access_arg:type<sc> ($num, %ctx) {
s = c[I]
%r = box s
};
say("# $num<sc> '$res'");
$!debug && say("# $num<sc> '$res'");
#$!builder.global_string_ptr($res, :name<.SCONST>);

my $strings := $!builder.call(
Expand Down Expand Up @@ -532,7 +536,7 @@ our multi method process(String $str, %c) {

our method process:macro<goto_offset>(PAST::Op $chunk, %c) {
my $offset := ~$chunk[0].value; # FIXME
say("# macro<goto_offset> '$offset'");
$!debug && say("# macro<goto_offset> '$offset'");
my $target := %c<cur_opcode> + $offset;
my $jump_to := %c<basic_blocks>{$target}<bb>;

Expand All @@ -544,7 +548,7 @@ our method process:macro<goto_offset>(PAST::Op $chunk, %c) {
}

our method process:macro<goto_address>(PAST::Op $chunk, %c) {
say("# macro<goto_address>");
$!debug && say("# macro<goto_address>");
# FIXME
$!builder.store(
LLVM::Constant::null(
Expand Down
5 changes: 3 additions & 2 deletions t/jit/test.t
Expand Up @@ -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');

Expand All @@ -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);
Expand Down

0 comments on commit 9671e11

Please sign in to comment.