isa: made a command with perltex for fancy ISA
authorMartin Perner <martin@perner.cc>
Wed, 20 Oct 2010 18:28:07 +0000 (20:28 +0200)
committerMartin Perner <martin@perner.cc>
Wed, 20 Oct 2010 18:33:47 +0000 (20:33 +0200)
isasty/Makefile [new file with mode: 0644]
isasty/isa.tex [new file with mode: 0644]
isasty/isa_file.tex [new file with mode: 0644]
isasty/isa_gen.tex [new file with mode: 0644]
isasty/perltex.sty [new file with mode: 0644]

diff --git a/isasty/Makefile b/isasty/Makefile
new file mode 100644 (file)
index 0000000..387fed0
--- /dev/null
@@ -0,0 +1,20 @@
+SHELL := bash
+
+LATEX := pdflatex
+
+all: noperltex.sty
+       $(LATEX) isa.tex
+
+noperltex.sty: isa_file.tex
+       @if $(SHELL) -c 'perltex --help' > /dev/null 2>&1; then \
+               perltex --makesty --latex=pdflatex isa_gen.tex; \
+               rm -f isa_gen.pdf isa_gen.log isa_gen.aux isa_gen.dfpl isa_gen.frpl isa_gen.lgpl isa_gen.topl isa_gen.pipe; \
+       else \
+               echo "no perltex installed! i hope you have the builded files";\
+       fi
+
+clean:
+       @rm -f isa.aux isa.log isa.pdf
+
+cleanall: clean
+       @rm -f noperltex.sty noperltex-*.tex
diff --git a/isasty/isa.tex b/isasty/isa.tex
new file mode 100644 (file)
index 0000000..9a6289d
--- /dev/null
@@ -0,0 +1,148 @@
+\documentclass[a4paper,12pt]{scrartcl}
+
+\usepackage{noperltex}
+
+\usepackage{graphicx}
+
+\usepackage{colortbl}
+
+\definecolor{title}{rgb}{0.86,0.86,0.86}
+\definecolor{bit}{rgb}{0.8,0.86,0.8}
+\definecolor{bitval}{rgb}{0.8,0.8,0.8}
+\definecolor{names}{rgb}{0.86,0.93,0.86}
+
+\arrayrulecolor{black}
+
+\begin{document}
+
+\perlnewcommand{\ins}[5]
+{
+       my $bits = $_[0];
+       my $bline;
+       #bit value line
+       my $vline;
+       my $nline;
+       #print bit value line
+       my $pvline;
+       my @bitlist;
+       my $tabular;
+
+
+       $count = 0;
+       @fields = split(/\|/, $_[3]);
+       foreach my $field (@fields) {
+               #remove heading and trailing spaces
+               $field =~ s/^\s+//;
+               $field =~ s/\s+$//;
+
+               $count += $field;
+               #$tabular .= $field." \\\\";
+       }
+
+       if($count != $bits) {
+               return "Num of Fields not equal to Bits!";
+       }
+       $count = 0;
+       @fieldnames = split(/\|/, $_[4]);
+
+       if(scalar(@fields) != scalar(@fieldnames)) {
+               return "Num of Fields != Num of Names";
+       }
+
+       $pvline = 0;
+       foreach my $fieldn (@fieldnames) {
+               #remove heading and trailing spaces
+               $fieldn =~ s/^\s+//;
+               $fieldn =~ s/\s+$//;
+
+               if($fieldn =~ m/^[^\(.]*\(\s*([0-1]+)\s*\).*$/) {
+                       if(length($1) == $fields[$count]) {
+                               push(@bitlist,$1);
+                               $fieldn =~  s/\s?\(\s*[0-1]+\s*\)//;
+                               $pvline = 1;
+                       }
+                       else {
+                               $x = '';
+                               for($i = 1; $i <= $fields[$count]; $i++) {
+                                       $x .= 'X';
+                               }
+                               push(@bitlist,$x);
+                       }
+               }
+               else {
+                       $x = '';
+                       for($i = 1; $i <= $fields[$count]; $i++) {
+                               $x .= 'X';
+                       }
+                       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 .= "\\begin{tabular}{|l|";
+       for($i = $bits-1; $i >= 0; $i--) {
+               #build table
+               $tabular .= "c|";
+
+               #build bitcount
+               $bline .= $i;
+               if($i != 0) {
+                       $bline .= " & ";
+               }
+               else {
+                       $bline .= "\\\\ \\hline \n";
+               }
+
+               #build bitvalue
+               $vline .= substr($bitlist,($bits-1)-$i,1);
+               if($i != 0) {
+                       $vline .= " & ";
+               }
+               else {
+                       $vline .= "\\\\ \\hline \n";
+               }
+
+               #build nameline
+               #because of multicolumn we need to limit execution
+               if($i == $count) {
+                       $nline .= "\\multicolumn{@fields[0]}{>{\\columncolor{names}}c|}{@fieldnames[0]}";
+
+                       #update count
+                       $count -= @fields[0];
+
+                       if($count <= 0) {
+                               $nline .= "\\\\ \\hline \n";
+                       }
+                       else {
+                               $nline .= " & ";
+                       }
+
+                       shift(@fieldnames);
+                       shift(@fields);
+               }
+       }
+       $tabular .= "} \\hline \n";
+       $tabular .= "\\multicolumn{".($bits+1)."}{|>{\\columncolor{title}}c|}{\\textbf{".$_[1]."} (".$_[2].")} \\\\ \\hline \n";
+       $tabular .= "\\rowcolor{bit} \\cellcolor{title} &". $bline;
+       if($pvline == 1) {
+               $tabular .= "\\rowcolor{bitval} \\cellcolor{title}Values &". $vline;
+       }
+       $tabular .= "\\cellcolor{title}Field &". $nline;
+       $tabular .= "\\end{tabular}\n}\n \\end{center}\n";
+
+
+       return $tabular;
+}
+
+\input{isa_file}
+
+\end{document}
+
diff --git a/isasty/isa_file.tex b/isasty/isa_file.tex
new file mode 100644 (file)
index 0000000..2acfc52
--- /dev/null
@@ -0,0 +1,15 @@
+\section{meine demo}
+
+\ins{32}{lfm}{load from memory}{5| 3| 13| 11}{opcode (10010) | lol \texttt{bla} (1011) | w00t $4+4 = \frac{16}{2}$ | m00}
+
+\section{from wiki}
+
+\ins{16}{lfm}{load from memory}{3 |1   |1   |5    |6}{  |FOO |BAR |QUUX |LEETNESS }
+
+\ins{32}{lfm}{load from memory}{ 3 | 13 | 16}{ lol |w00t | m00}
+
+\ins{32}{addi}{Add Immediate}{6 | 5 | 5 | 16 }{OpCode | rD | rA | SIMM }
+
+\ins{32}{addi}{Add Immediate}{6 | 5 | 5 | 16}{OpCode (001110) | Register Destination|Register A (Source1)| SIMM (16-bit signed integer)}
+
+
diff --git a/isasty/isa_gen.tex b/isasty/isa_gen.tex
new file mode 100644 (file)
index 0000000..da04030
--- /dev/null
@@ -0,0 +1,148 @@
+\documentclass[a4paper,12pt]{scrartcl}
+
+\usepackage{perltex}
+
+\usepackage{graphicx}
+
+\usepackage{colortbl}
+
+\definecolor{title}{rgb}{0.86,0.86,0.86}
+\definecolor{bit}{rgb}{0.8,0.86,0.8}
+\definecolor{bitval}{rgb}{0.8,0.8,0.8}
+\definecolor{names}{rgb}{0.86,0.93,0.86}
+
+\arrayrulecolor{black}
+
+\begin{document}
+
+\perlnewcommand{\ins}[5]
+{
+       my $bits = $_[0];
+       my $bline;
+       #bit value line
+       my $vline;
+       my $nline;
+       #print bit value line
+       my $pvline;
+       my @bitlist;
+       my $tabular;
+
+
+       $count = 0;
+       @fields = split(/\|/, $_[3]);
+       foreach my $field (@fields) {
+               #remove heading and trailing spaces
+               $field =~ s/^\s+//;
+               $field =~ s/\s+$//;
+
+               $count += $field;
+               #$tabular .= $field." \\\\";
+       }
+
+       if($count != $bits) {
+               return "Num of Fields not equal to Bits!";
+       }
+       $count = 0;
+       @fieldnames = split(/\|/, $_[4]);
+
+       if(scalar(@fields) != scalar(@fieldnames)) {
+               return "Num of Fields != Num of Names";
+       }
+
+       $pvline = 0;
+       foreach my $fieldn (@fieldnames) {
+               #remove heading and trailing spaces
+               $fieldn =~ s/^\s+//;
+               $fieldn =~ s/\s+$//;
+
+               if($fieldn =~ m/^[^\(.]*\(\s*([0-1]+)\s*\).*$/) {
+                       if(length($1) == $fields[$count]) {
+                               push(@bitlist,$1);
+                               $fieldn =~  s/\s?\(\s*[0-1]+\s*\)//;
+                               $pvline = 1;
+                       }
+                       else {
+                               $x = '';
+                               for($i = 1; $i <= $fields[$count]; $i++) {
+                                       $x .= 'X';
+                               }
+                               push(@bitlist,$x);
+                       }
+               }
+               else {
+                       $x = '';
+                       for($i = 1; $i <= $fields[$count]; $i++) {
+                               $x .= 'X';
+                       }
+                       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 .= "\\begin{tabular}{|l|";
+       for($i = $bits-1; $i >= 0; $i--) {
+               #build table
+               $tabular .= "c|";
+
+               #build bitcount
+               $bline .= $i;
+               if($i != 0) {
+                       $bline .= " & ";
+               }
+               else {
+                       $bline .= "\\\\ \\hline \n";
+               }
+
+               #build bitvalue
+               $vline .= substr($bitlist,($bits-1)-$i,1);
+               if($i != 0) {
+                       $vline .= " & ";
+               }
+               else {
+                       $vline .= "\\\\ \\hline \n";
+               }
+
+               #build nameline
+               #because of multicolumn we need to limit execution
+               if($i == $count) {
+                       $nline .= "\\multicolumn{@fields[0]}{>{\\columncolor{names}}c|}{@fieldnames[0]}";
+
+                       #update count
+                       $count -= @fields[0];
+
+                       if($count <= 0) {
+                               $nline .= "\\\\ \\hline \n";
+                       }
+                       else {
+                               $nline .= " & ";
+                       }
+
+                       shift(@fieldnames);
+                       shift(@fields);
+               }
+       }
+       $tabular .= "} \\hline \n";
+       $tabular .= "\\multicolumn{".($bits+1)."}{|>{\\columncolor{title}}c|}{\\textbf{".$_[1]."} (".$_[2].")} \\\\ \\hline \n";
+       $tabular .= "\\rowcolor{bit} \\cellcolor{title} &". $bline;
+       if($pvline == 1) {
+               $tabular .= "\\rowcolor{bitval} \\cellcolor{title}Values &". $vline;
+       }
+       $tabular .= "\\cellcolor{title}Field &". $nline;
+       $tabular .= "\\end{tabular}\n}\n \\end{center}\n";
+
+
+       return $tabular;
+}
+
+\input{isa_file}
+
+\end{document}
+
diff --git a/isasty/perltex.sty b/isasty/perltex.sty
new file mode 100644 (file)
index 0000000..1aff9fc
--- /dev/null
@@ -0,0 +1,266 @@
+%%
+%% This is file `perltex.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% perltex.dtx  (with options: `package')
+%% 
+%% This is a generated file.
+%% 
+%% Copyright (C) 2010 Scott Pakin <scott+pt@pakin.org>
+%% 
+%% This file may be distributed and/or modified under the conditions of
+%% the LaTeX Project Public License, either version 1.3c of this license
+%% or (at your option) any later version.  The latest version of this
+%% license is in:
+%% 
+%%    http://www.latex-project.org/lppl.txt
+%% 
+%% and version 1.3c or later is part of all distributions of LaTeX version
+%% 2006/05/20 or later.
+%% 
+\NeedsTeXFormat{LaTeX2e}[1999/12/01]
+\ProvidesPackage{perltex}
+    [2010/07/10 v2.1 LaTeX macros for use with PerlTeX]
+\newif\ifplmac@required \plmac@requiredtrue
+\DeclareOption{optional}{\plmac@requiredfalse} \ProcessOptions\relax
+\newif\ifperl
+\perltrue
+\@ifundefined{plmac@tag}{\perlfalse}{}
+\@ifundefined{plmac@tofile}{\perlfalse}{}
+\@ifundefined{plmac@fromfile}{\perlfalse}{}
+\@ifundefined{plmac@toflag}{\perlfalse}{}
+\@ifundefined{plmac@fromflag}{\perlfalse}{}
+\@ifundefined{plmac@doneflag}{\perlfalse}{}
+\@ifundefined{plmac@pipe}{\perlfalse}{}
+\ifperl
+\else
+  \ifplmac@required
+    \PackageError{perltex}{Document must be compiled using perltex}
+      {Instead of compiling your document directly with latex, you need
+       to\MessageBreak use the perltex script.  \space perltex sets up
+       a variety of macros needed by\MessageBreak the perltex
+       package as well as a listener process needed for\MessageBreak
+       communication between LaTeX and Perl.}
+    \else
+      \bgroup
+        \obeyspaces
+        \typeout{perltex: Document was compiled without using the perltex script;}
+        \typeout{         it may not print as desired.}
+      \egroup
+  \fi
+\fi
+\def\perlnewcommand{%
+  \let\plmac@command=\newcommand
+  \let\plmac@next=\relax
+  \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
+}
+\def\perlrenewcommand{%
+  \let\plmac@next=\relax
+  \let\plmac@command=\renewcommand
+  \@ifnextchar*{\plmac@newcommand@i}{\plmac@newcommand@i!}%
+}
+\def\plmac@newcommand@i#1#2{%
+  \ifx#1*%
+    \def\plmac@starchar{*}%
+  \else
+    \def\plmac@starchar{}%
+  \fi
+  \def\plmac@macname{#2}%
+  \let\plmac@oldbody=#2\relax
+  \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
+    \expandafter\string\plmac@macname}%
+  \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
+}
+\def\plmac@newcommand@ii[#1]{%
+  \def\plmac@numargs{#1}%
+  \@ifnextchar[{\plmac@newcommand@iii@opt}
+               {\plmac@newcommand@iii@no@opt}%]
+}
+\def\plmac@newcommand@iii@opt[#1]{%
+  \def\plmac@defarg{#1}%
+  \plmac@haveargs
+}
+\def\plmac@newcommand@iii@no@opt{%
+  \let\plmac@defarg=\relax
+  \plmac@haveargs
+}
+\newtoks\plmac@perlcode
+\def\plmac@haveargs{%
+  \begingroup
+    \let\do\@makeother\dospecials
+    \catcode`\^^M=\active
+    \newlinechar`\^^M
+    \endlinechar=`\^^M
+    \catcode`\{=1
+    \catcode`\}=2
+    \afterassignment\plmac@havecode
+    \global\plmac@perlcode
+}
+{\catcode`\^^M=11\gdef\plmac@sep{^^M}}
+\newcount\plmac@argnum
+\def\plmac@havecode{%
+  \endgroup
+  \edef\plmac@define@sub{%
+    \noexpand\plmac@write@perl{DEF\plmac@sep
+      \plmac@tag\plmac@sep
+      \plmac@cleaned@macname\plmac@sep
+      \plmac@tag\plmac@sep
+      \the\plmac@perlcode
+    }%
+  }%
+  \plmac@define@sub
+  \edef\plmac@body{%
+    USE\plmac@sep
+    \plmac@tag\plmac@sep
+    \plmac@cleaned@macname
+  }%
+  \let\plmac@hash=\relax
+  \plmac@argnum=\@ne
+  \loop
+    \ifnum\plmac@numargs<\plmac@argnum
+    \else
+      \edef\plmac@body{%
+        \plmac@body\plmac@sep\plmac@tag\plmac@sep
+        \plmac@hash\plmac@hash\number\plmac@argnum}%
+      \advance\plmac@argnum by \@ne
+  \repeat
+  \let\plmac@hash=##%
+  \expandafter\let\plmac@macname=\relax
+  \ifx\plmac@defarg\relax
+    \edef\plmac@define@command{%
+      \noexpand\plmac@command\plmac@starchar{\plmac@macname}%
+      [\plmac@numargs]{%
+        \noexpand\plmac@write@perl{\plmac@body}%
+      }%
+  }%
+  \else
+    \edef\plmac@define@command{%
+      \noexpand\plmac@command\plmac@starchar{\plmac@macname}%
+      [\plmac@numargs][\plmac@defarg]{%
+        \noexpand\plmac@write@perl{\plmac@body}%
+      }%
+  }%
+  \fi
+  \expandafter\let\plmac@macname=\plmac@oldbody
+  \plmac@define@command
+  \plmac@next
+}
+\def\perlnewenvironment{%
+  \let\plmac@command=\newcommand
+  \let\plmac@next=\plmac@end@environment
+  \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
+}
+\def\perlrenewenvironment{%
+  \let\plmac@command=\renewcommand
+  \let\plmac@next=\plmac@end@environment
+  \@ifnextchar*{\plmac@newenvironment@i}{\plmac@newenvironment@i!}%
+}
+\def\plmac@newenvironment@i#1#2{%
+  \ifx#1*%
+    \def\plmac@starchar{*}%
+  \else
+    \def\plmac@starchar{}%
+  \fi
+  \def\plmac@envname{#2}%
+  \expandafter\def\expandafter\plmac@macname\expandafter{\csname#2\endcsname}%
+  \expandafter\let\expandafter\plmac@oldbody\plmac@macname\relax
+  \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
+    \expandafter\string\plmac@macname}%
+  \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
+}
+\def\plmac@end@environment{%
+  \expandafter\def\expandafter\plmac@next\expandafter{\expandafter
+    \let\csname end\plmac@envname\endcsname=\plmac@end@macro
+    \let\plmac@next=\relax
+  }%
+  \def\plmac@macname{\plmac@end@macro}%
+  \expandafter\let\expandafter\plmac@oldbody\csname end\plmac@envname\endcsname
+  \expandafter\def\expandafter\plmac@cleaned@macname\expandafter{%
+    \expandafter\string\plmac@macname}%
+  \@ifnextchar[{\plmac@newcommand@ii}{\plmac@newcommand@ii[0]}%]
+}
+\def\perldo{%
+  \begingroup
+    \let\do\@makeother\dospecials
+    \catcode`\^^M=\active
+    \newlinechar`\^^M
+    \endlinechar=`\^^M
+    \catcode`\{=1
+    \catcode`\}=2
+    \afterassignment\plmac@have@run@code
+    \global\plmac@perlcode
+}
+\def\plmac@have@run@code{%
+  \endgroup
+  \edef\plmac@run@code{%
+    \noexpand\plmac@write@perl{RUN\plmac@sep
+      \plmac@tag\plmac@sep
+      N/A\plmac@sep
+      \plmac@tag\plmac@sep
+      \the\plmac@perlcode
+    }%
+  }%
+  \plmac@run@code
+}
+\newif\ifplmac@file@exists
+\newcommand{\plmac@await@existence}[1]{%
+  \begin{lrbox}{\@tempboxa}%
+    \input\plmac@pipe
+  \end{lrbox}%
+  \loop
+    \IfFileExists{#1}%
+                 {\plmac@file@existstrue}%
+                 {\plmac@file@existsfalse}%
+    \ifplmac@file@exists
+    \else
+  \repeat
+}
+\newwrite\plmac@outfile
+\newcommand{\plmac@write@perl}{%
+  \begingroup
+    \let\do\@makeother\dospecials
+    \catcode`\^^M=\active
+    \newlinechar`\^^M
+    \endlinechar=`\^^M
+    \catcode`\{=1
+    \catcode`\}=2
+    \plmac@write@perl@i
+}
+\ifperl
+  \newcommand{\plmac@write@perl@i}[1]{%
+      \immediate\openout\plmac@outfile=\plmac@tofile\relax
+      \let\protect=\noexpand
+      \def\begin{\noexpand\begin}%
+      \def\end{\noexpand\end}%
+      \immediate\write\plmac@outfile{#1}%
+      \immediate\closeout\plmac@outfile
+    \endgroup
+    \immediate\openout\plmac@outfile=\plmac@toflag\relax
+    \immediate\closeout\plmac@outfile
+    \plmac@await@existence\plmac@fromflag
+    \immediate\openout\plmac@outfile=\plmac@tofile\relax
+    \immediate\closeout\plmac@outfile
+    \plmac@await@existence\plmac@doneflag
+    \input\plmac@fromfile\relax
+  }
+\else
+  \newcommand{\plmac@write@perl@i}[1]{\endgroup}
+  \gdef\plmac@show@placeholder#1#2\@empty{%
+    \ifx#1D\relax
+      \endgroup
+    \else
+      \endgroup
+      \fbox{Perl\TeX}%
+    \fi
+  }%
+  \AtBeginDocument{%
+    \renewcommand{\plmac@write@perl@i}[1]{%
+      \plmac@show@placeholder#1\@empty
+    }%
+  }
+\fi
+\endinput
+%%
+%% End of file `perltex.sty'.