#!/usr/bin/perl
+use strict;
+
+sub plaintext {
+ print $_[0];
+}
sub ins {
my $bits = $_[0];
my $pvline;
my @bitlist;
my $tabular;
+ my $count = 0;
+ my @fields;
+ my $i;
+ my $x;
+ my @fieldnames;
+ my @flagnames = ('SF', 'CF', 'OF', 'ZF');
+ my $section = "\\subsubsection";
+
+ if($_[9]) {
+ $section = "\\item ";
+ }
-
- $count = 0;
@fields = split(/\|/, $_[3]);
foreach my $field (@fields) {
#remove heading and trailing spaces
if($fieldn =~ m/^[^\(.]*\(\s*([0-1]+)\s*\).*$/) {
if(length($1) == $fields[$count]) {
- push(@bitlist,$1);
+ push(@bitlist,'S'.$1);
$fieldn =~ s/\s?\(\s*[0-1]+\s*\)//;
$pvline = 1;
}
else {
- $x = '';
- for($i = 1; $i <= $fields[$count]; $i++) {
- $x .= 'X';
- }
- push(@bitlist,$x);
+ $x = 'LX';
+ push(@bitlist,$x);
}
}
else {
- $x = '';
- for($i = 1; $i <= $fields[$count]; $i++) {
- $x .= 'X';
- }
+ $x = 'LX';
push(@bitlist,$x);
}
#$tabular .= $fieldn.": ". $bits." \\\\";
$count++;
}
- $bitlist = join("",@bitlist);
#$tabular .= "\\textbf{names:} @fieldnames \n";
#$tabular .= "\\textbf{bitlist:} $bitlist \n";
$count = $bits-1;
- $tabular = "\\begin{center} \n \\resizebox{\\textwidth}{!}{\n";
+ $tabular = $section."{\\texttt{".$_[1]."} -- ".$_[2]."}\n";
+ $tabular .= "\\begin{center} \n \\resizebox{\\textwidth}{!}{\n";
$tabular .= "\\begin{tabular}{|l|";
for($i = $bits-1; $i >= 0; $i--) {
#build table
$bline .= "\\\\ \\hline \n";
}
- #build bitvalue
- $vline .= substr($bitlist,($bits-1)-$i,1);
- if($i != 0) {
- $vline .= " & ";
- }
- else {
- $vline .= "\\\\ \\hline \n";
- }
-
- #build nameline
+ #build nameline and bitvalue
#because of multicolumn we need to limit execution
if($i == $count) {
$nline .= "\\multicolumn{@fields[0]}{>{\\columncolor{names}}c|}{@fieldnames[0]}";
+ if(substr(@bitlist[0],0,1) eq "L") {
+ $vline .= "\\multicolumn{@fields[0]}{>{\\columncolor{bitval}}c|}{".substr(@bitlist[0],1)."}";
+ }
+ else {
+ for(my $j = 1; $j <= @fields[0]; $j++) {
+ $vline .= substr(@bitlist[0],$j,1);
+ if($j != @fields[0]) {
+ $vline .= " & ";
+ }
+ }
+ }
+
#update count
$count -= @fields[0];
if($count < 0) {
$nline .= "\\\\ \\hline \n";
+ $vline .= "\\\\ \\hline \n";
}
else {
$nline .= " & ";
+ $vline .= " & ";
}
+ shift(@bitlist);
shift(@fieldnames);
shift(@fields);
}
$tabular .= "\\cellcolor{title}Field &". $nline;
$tabular .= "\\end{tabular}\n}\n \\end{center}\n";
+ if($_[5]) {
+ $tabular .= "\\paragraph{Description:}~\\\\ \n ".$_[5]. "\n";
+ }
+
+ if($_[6]) {
+ $count = 0;
+ my @flags = split(/\|/, $_[6]);
+
+ if(scalar(@flags) == scalar(@flagnames)) {
+ $tabular .= "\\paragraph{Flags:} \n";
+
+ foreach my $flag (@flags) {
+ #remove heading and trailing spaces
+ $flag =~ s/^\s+//;
+ $flag =~ s/\s+$//;
+ if(length($flag) > 0 ) {
+ $tabular .= "\\subparagraph{".$flagnames[$count].":} ".$flag." \n";
+ }
+ $count++;
+ }
+ }
+
+ }
+
+ if($_[7]) {
+ $tabular .= "\\paragraph{Example:}~\\\\ \n \\begin{lstlisting} \n ".$_[7]. " \\end{lstlisting}\n";
+ }
+
+ print $tabular;
+
+ if($_[8]) {
+ print "\\paragraph{Aliases to this Instruction:} \n";
+ my @aliases = split(/\|/, $_[8]);
+
+ print "\\begin{list}{\\labelitemi}{\\leftmargin=0em \\itemindent=1em}";
+
+
+ foreach my $alias (@aliases) {
+ my $long;
+ my $sub;
+ my @params;
+ my $namelist = $_[4];
+
+ @params = split(/-/, $alias);
+ $sub = @params[0];
+ $long = @params[1];
+ shift(@params); shift(@params);
+
+ foreach my $vals (@params) {
+ my $field;
+ my $val;
+ ($field, $val) = split(/\//, $vals);
+
+ my @fieldnames = split(/\|/, $namelist);
+
+ $fieldnames[$field] = $fieldnames[$field]."(".$val.")";
+ $namelist = join("|",@fieldnames);
+ }
+
+ ins($_[0], $sub, $long,$_[3], $namelist, '', '', '', '',1);
+ }
+ print "\\end{list}";
+ }
- return $tabular;
}
if($#ARGV != 0) {
die "Usage: gentex.pl <file.ptex>";
}
-open(DATA, "<".$ARGV[0]) || die "Couldn't open file $ARGV[0] for read!";
-
-$output = $ARGV[0];
+my $output = $ARGV[0];
+my $input = $ARGV[0];
$output =~ s/\.[^.]*$//;
$output .= ".tex";
-open(OUTPUT, ">".$output) || die "Couldn't open file $output for output!";
-
-while(<DATA>)
-{
- $res = eval "$_";
- print OUTPUT $res;
-}
+open STDOUT, '>', $output or die "Can't redirect STDOUT: $!";
-close(DATA);
-close(OUTPUT);
+do $input;