This does about the minimum necessary for assembly analysis to work. It assumes
that any function it hasn't been able to analyse itself needs 512 bytes (most
need far less); it doesn't do any flow analysis; it doesn't do a lot of sanity
checking. However, it produces sensible numbers, and works with the demos I've
tried so far.
I was originally going to make this a separate tool, but there are a number of
bits of the code can be nicely reused, so it's a separate "operating mode" in
the existing program (as is parse-only mode now).
Note that this feature makes two assumptions:
- Constant folding has already been performed on the tree
- Array subscript literals will all be simply of type A.IntLiteral (with type A.Int), without any retyping, any expressions, etc
This patch is a bit large, being as it encompasses two major changes:
1. The addition of the first version of a parallel usage checker. The usage checker uses the generics library (like
the other passes) to work out if the parallel usage rules are broken. It mainly consists of:
a) a function used to determine which variables are written to/read from in given bits of code, and
b) a function that applies a) across the members of any par construct in the file, and checks that
the expected usage rules hold
The parallel usage checker is in an early stage, but I think the design is sensible - at least for doing the variable
and array usage. The channel usage checker will require some slightly different functionality, and
I am not considering the abbreviation checker yet.
2. As a consquence of adding a second test file (UsageCheckTest) alongside the first (RainParseTest), I have
created a TestMain class that is intended to run all tests for all parts of Tock. I have also extracted some
useful helper functions (for creating the expected results of tests) into a file named TestUtil. I've also
modified the Makefil accordingly.
There are a few other minor changes to RainParse/RainParseTest that are also included in the patch as separating them
would have been tricky.
I have added my favourite compiler option "-fwarn-unused-binds" to the Makefile. I've then changed GenerateCPPCSP to have one explicit export, and the
combination of the two would spot any future mistakes like not including the genAlt function in then GenOps structure (see previous patch). This
new warning option already spots one problem with GenerateC, and I have a feeling it will also be useful in future.
It was my own fault of - I changed the genVariable' function in GenerateCPPCSP but forgot to move it out of the "taken verbatim from GenerateC" function,
so Adam removed it during the tidy-up. I've reinstated it from the old version - I need the ".access()" part for accessing individual array elements.
... and update GenerateCPPCSP to do so. This works by having a structure of
operations (GenOps) through which all the recursive calls go, and having
GenerateCPPCSP replace only the operations that it wants to override.
Previously the arrays used the Blitz++ library, but this was not totally satisfactory. I have therefore resorted (after looking at many different
libraries) to using std::vector (which could perhaps be boost::array instead) coupled with a roll-my-own "array view" class (tockArrayView) that
easily allows all the functionality that we need from arrays (slicing, indexing, copying, unknown dimensions,retyping,reshaping). I have also
had to introduce a nasty little wrapper class tockBool, because vector<bool> is a specialisation that totally breaks things. If I do move to
boost::array, I will be able to remove tockBool.
C++CSP backend has been added. It consists of a support header file and one new Haskell module: GenerateCPPCSP
The module is largely based on GenerateC, changed as needed.
There is a large section at the bottom of the file with verbatim copy-and-paste from GenerateC,
due to wanting the same functionality, but for calls to use my C++CSP generation not the C generation --
hence I cannot simply import those functions.
The backend can generate code for cgtests 0 through 16 (incl) that will compile as valid C++. The majority of the
tests pass when run (some do segfault, admittedly). However some arrays still need more testing/work, particularly:
- timers
- array slices
- retyping
The tock_support_cppcsp.h header makes use of tock_support.h, but I had to add a few #ifnders to the latter
file so that I can use it with C++CSP and block out some of the CIF stuff.
... which required a bunch of stuff:
- Record handling in the literal evaluator (to solve a nasty problem with
record literals documented in the code).
- Splitting abbrevModeOfVariable into two functions which do the two
(different) things it was previously used for.
- Clean up how arrays are handled in GenerateC.
- Fix the pullup rules for record literals containing arrays.