summaryrefslogtreecommitdiffstats
path: root/gen-stapmark.h
blob: 6e1a63e089b6197cc86457d1edbd8ce4d63c0a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/perl 

sub bitset {
    my $num = shift;
    my $bit = shift;
    return ($num & (1 << $bit));
}

sub gensn {
    my $permutation = shift;
    my $arity = shift;

    my $SN = "";
    for (0..$arity-1) { $SN .= bitset($permutation,$_) ? "S" : "N"; }

    print "#define STAP_MARK" . ($arity>0?"_":"") . $SN . "(n";
    for (0..$arity-1) { print ",a" . (($_)+1); }
    print ") do { \\\n";
    print "  static void (*__systemtap_mark_##n##_" . $SN . ")(";
    for (0..$arity-1) { if ($_) { print ",";} 
                        print bitset($permutation,$_) 
                               ? "const char *"
                               : "int64_t"; }
    print "); \\\n";
    print "  if (unlikely (__systemtap_mark_##n##_" . $SN . ")) \\\n";
    print "    (void) (__systemtap_mark_##n##_" . $SN . "(";
    for (0..$arity-1) { if ($_) { print ",";} 
                        print "(a" . (($_)+1) . ")"; }
    print ")); \\\n";
    print "} while (0)\n\n";
}

sub permute {
    my $arity = shift;
    for (0 .. (1<<$arity)-1) {
        &gensn ($_, $arity);
    }
}


die "give me one number" unless $#ARGV == 0;

print "/* Generated by '$0 @ARGV' on " . gmtime() . " */\n\n";

for (0 .. $ARGV[0]) {
    &permute($_);
}