OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [or1200/] [doc/] [preprocess.pl] - Blame information for rev 645

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 645 julius
#!/usr/bin/perl
2
# Preprocessing of the spec file.
3
# So far the table with the instruction list is modified.
4
# Output is printed to stdout.
5
 
6
use warnings;
7
use strict;
8
use POSIX qw (ceil);
9
 
10
if (@ARGV != 1) {
11
    print "Usage: preprocess.pl infile ('-' for stdin)\n";
12
    exit 1;
13
}
14
 
15
my $infile = $ARGV[0];
16
 
17
if ($infile eq '-') {
18
    open(INPUT, '<-') or die $!;
19
} else {
20
    open(INPUT, '<', $infile) or die $!;
21
}
22
 
23
my @inst_table;
24
my $insts_per_col = 18;
25
my $inst_line = 0;
26
my $inst_header;
27
my $inst_footer;
28
 
29
while (<INPUT>) {
30
    if (/^\| Instruction mnemonic/../^\|==/) {
31
        chomp;
32
        if (/^\| Instruction mnemonic/) {
33
            $inst_header = $_;
34
            next;
35
        } elsif (/^\|==/) {
36
            $inst_footer = $_;
37
            next;
38
        }
39
        if ($inst_line < $insts_per_col) {
40
            push @inst_table, $_;
41
        } else {
42
            $inst_table[$inst_line % $insts_per_col] .= "\t" . $_;
43
        }
44
        $inst_line++;
45
    } else {
46
        if (@inst_table) {
47
            # complete the rows that have their last column empty
48
            for (my $i = $inst_line % $insts_per_col; $i < $insts_per_col; $i++) {
49
                $inst_table[$i] .= "\t|\t|";
50
            }
51
            my $cols = ceil($inst_line / $insts_per_col);
52
            print $inst_header x $cols . "\n";
53
            print join("\n", @inst_table) . "\n";
54
            print $inst_footer . "\n";
55
            @inst_table = ();
56
        }
57
        print $_;
58
    }
59
}
60
close INPUT or die $!;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.