9a6289dfa171a091093dbe165fb36bd0a8b79d62
[calu.git] / isasty / isa.tex
1 \documentclass[a4paper,12pt]{scrartcl}
2
3 \usepackage{noperltex}
4
5 \usepackage{graphicx}
6
7 \usepackage{colortbl}
8
9 \definecolor{title}{rgb}{0.86,0.86,0.86}
10 \definecolor{bit}{rgb}{0.8,0.86,0.8}
11 \definecolor{bitval}{rgb}{0.8,0.8,0.8}
12 \definecolor{names}{rgb}{0.86,0.93,0.86}
13
14 \arrayrulecolor{black}
15
16 \begin{document}
17
18 \perlnewcommand{\ins}[5]
19 {
20         my $bits = $_[0];
21         my $bline;
22         #bit value line
23         my $vline;
24         my $nline;
25         #print bit value line
26         my $pvline;
27         my @bitlist;
28         my $tabular;
29
30
31         $count = 0;
32         @fields = split(/\|/, $_[3]);
33         foreach my $field (@fields) {
34                 #remove heading and trailing spaces
35                 $field =~ s/^\s+//;
36                 $field =~ s/\s+$//;
37
38                 $count += $field;
39                 #$tabular .= $field." \\\\";
40         }
41
42         if($count != $bits) {
43                 return "Num of Fields not equal to Bits!";
44         }
45         $count = 0;
46         @fieldnames = split(/\|/, $_[4]);
47
48         if(scalar(@fields) != scalar(@fieldnames)) {
49                 return "Num of Fields != Num of Names";
50         }
51
52         $pvline = 0;
53         foreach my $fieldn (@fieldnames) {
54                 #remove heading and trailing spaces
55                 $fieldn =~ s/^\s+//;
56                 $fieldn =~ s/\s+$//;
57
58                 if($fieldn =~ m/^[^\(.]*\(\s*([0-1]+)\s*\).*$/) {
59                         if(length($1) == $fields[$count]) {
60                                 push(@bitlist,$1);
61                                 $fieldn =~  s/\s?\(\s*[0-1]+\s*\)//;
62                                 $pvline = 1;
63                         }
64                         else {
65                                 $x = '';
66                                 for($i = 1; $i <= $fields[$count]; $i++) {
67                                         $x .= 'X';
68                                 }
69                                 push(@bitlist,$x);
70                         }
71                 }
72                 else {
73                         $x = '';
74                         for($i = 1; $i <= $fields[$count]; $i++) {
75                                 $x .= 'X';
76                         }
77                         push(@bitlist,$x);
78                 }
79                 #$tabular .= $fieldn.": ". $bits." \\\\";
80                 $count++;
81         }
82         $bitlist = join("",@bitlist);
83
84         #$tabular .= "\\textbf{names:} @fieldnames \n";
85         #$tabular .= "\\textbf{bitlist:} $bitlist \n";
86
87         $count = $bits-1;
88
89         $tabular = "\\begin{center} \n \\resizebox{\\textwidth}{!}{\n";
90         $tabular .= "\\begin{tabular}{|l|";
91         for($i = $bits-1; $i >= 0; $i--) {
92                 #build table
93                 $tabular .= "c|";
94
95                 #build bitcount
96                 $bline .= $i;
97                 if($i != 0) {
98                         $bline .= " & ";
99                 }
100                 else {
101                         $bline .= "\\\\ \\hline \n";
102                 }
103
104                 #build bitvalue
105                 $vline .= substr($bitlist,($bits-1)-$i,1);
106                 if($i != 0) {
107                         $vline .= " & ";
108                 }
109                 else {
110                         $vline .= "\\\\ \\hline \n";
111                 }
112
113                 #build nameline
114                 #because of multicolumn we need to limit execution
115                 if($i == $count) {
116                         $nline .= "\\multicolumn{@fields[0]}{>{\\columncolor{names}}c|}{@fieldnames[0]}";
117
118                         #update count
119                         $count -= @fields[0];
120
121                         if($count <= 0) {
122                                 $nline .= "\\\\ \\hline \n";
123                         }
124                         else {
125                                 $nline .= " & ";
126                         }
127
128                         shift(@fieldnames);
129                         shift(@fields);
130                 }
131         }
132         $tabular .= "} \\hline \n";
133         $tabular .= "\\multicolumn{".($bits+1)."}{|>{\\columncolor{title}}c|}{\\textbf{".$_[1]."} (".$_[2].")} \\\\ \\hline \n";
134         $tabular .= "\\rowcolor{bit} \\cellcolor{title} &". $bline;
135         if($pvline == 1) {
136                 $tabular .= "\\rowcolor{bitval} \\cellcolor{title}Values &". $vline;
137         }
138         $tabular .= "\\cellcolor{title}Field &". $nline;
139         $tabular .= "\\end{tabular}\n}\n \\end{center}\n";
140
141
142         return $tabular;
143 }
144
145 \input{isa_file}
146
147 \end{document}
148