19 my @flagnames = ('SF', 'CF', 'OF', 'ZF');
23 @fields = split(/\|/, $_[3]);
24 foreach my $field (@fields) {
25 #remove heading and trailing spaces
30 #$tabular .= $field." \\\\";
34 return "Num of Fields not equal to Bits!";
37 @fieldnames = split(/\|/, $_[4]);
39 if(scalar(@fields) != scalar(@fieldnames)) {
40 return "Num of Fields != Num of Names";
44 foreach my $fieldn (@fieldnames) {
45 #remove heading and trailing spaces
49 if($fieldn =~ m/^[^\(.]*\(\s*([0-1]+)\s*\).*$/) {
50 if(length($1) == $fields[$count]) {
51 push(@bitlist,'S'.$1);
52 $fieldn =~ s/\s?\(\s*[0-1]+\s*\)//;
64 #$tabular .= $fieldn.": ". $bits." \\\\";
68 #$tabular .= "\\textbf{names:} @fieldnames \n";
69 #$tabular .= "\\textbf{bitlist:} $bitlist \n";
73 $tabular = "\\subsubsection{".$_[1]."}\n";
74 $tabular .= "\\begin{center} \n \\resizebox{\\textwidth}{!}{\n";
75 $tabular .= "\\begin{tabular}{|l|";
76 for($i = $bits-1; $i >= 0; $i--) {
86 $bline .= "\\\\ \\hline \n";
89 #build nameline and bitvalue
90 #because of multicolumn we need to limit execution
92 $nline .= "\\multicolumn{@fields[0]}{>{\\columncolor{names}}c|}{@fieldnames[0]}";
94 if(substr(@bitlist[0],0,1) eq "L") {
95 $vline .= "\\multicolumn{@fields[0]}{>{\\columncolor{bitval}}c|}{".substr(@bitlist[0],1)."}";
98 for(my $j = 1; $j <= @fields[0]; $j++) {
99 $vline .= substr(@bitlist[0],$j,1);
100 if($j != @fields[0]) {
107 $count -= @fields[0];
110 $nline .= "\\\\ \\hline \n";
111 $vline .= "\\\\ \\hline \n";
123 $tabular .= "} \\hline \n";
124 $tabular .= "\\multicolumn{".($bits+1)."}{|>{\\columncolor{title}}c|}{\\textbf{".$_[1]."} (".$_[2].")} \\\\ \\hline \n";
125 $tabular .= "\\rowcolor{bit} \\cellcolor{title} &". $bline;
127 $tabular .= "\\rowcolor{bitval} \\cellcolor{title}Values &". $vline;
129 $tabular .= "\\cellcolor{title}Field &". $nline;
130 $tabular .= "\\end{tabular}\n}\n \\end{center}\n";
133 $tabular .= "\\paragraph{Description:}~\\\\ \n ".$_[5]. "\n";
138 my @flags = split(/\|/, $_[6]);
140 if(scalar(@flags) == scalar(@flagnames)) {
141 $tabular .= "\\paragraph{Flags:} \n";
143 foreach my $flag (@flags) {
144 #remove heading and trailing spaces
147 if(length($flag) > 0 ) {
148 $tabular .= "\\subparagraph{".$flagnames[$count].":} ".$flag." \n";
157 $tabular .= "\\paragraph{Example:}~\\\\ \n \\begin{lstlisting} \n ".$_[7]. " \\end{lstlisting}\n";
161 $tabular .= "\\paragraph{Aliases to this Instruction:}~\\\\\ \n";
162 my @aliases = split(/\|/, $_[8]);
164 $tabular .= "\\begin{table}[!h] \n \\centering \n \\begin{tabular}{|c|c|} \\hline \n";
165 $tabular .= "Alias & ".$_[1]." equivalent \\\\ \\hline \n";
166 foreach my $alias (@aliases) {
169 ($from, $equv) = split(/-/, $alias);
170 $tabular .= $from . " & ".$equv." \\\\ \\hline \n";
172 $tabular .= "\\end{tabular} \n \\caption{Aliases to the instruction ".$_[1]."} \n \\end{table}";
179 die "Usage: gentex.pl <file.ptex>";
182 my $output = $ARGV[0];
183 my $input = $ARGV[0];
185 $output =~ s/\.[^.]*$//;
188 open STDOUT, '>', $output or die "Can't redirect STDOUT: $!";