gmarkall / manycore_form_compiler

MCFC is deprecated. See https://code.launchpad.net/~grm08/ffc/pyop2
https://code.launchpad.net/~grm08/ffc/pyop2
GNU General Public License v3.0
3 stars 1 forks source link

Add support for inserting arbitrary strings into the output. #44

Closed gmarkall closed 12 years ago

gmarkall commented 12 years ago

This could be risky, but it is the case that since the transform_to_physical stuff doesn't change very much, it would be handy to be able to write it out as a string. If we are judicious in our use of this AST node then we shouldn't get too many problems with composing different bits of AST in the future.

Arbitrary strings can be inserted into the AST using the ArbitraryString node. An example of how to use it is provided in driver.py, which just inserts a comment to the generated code advertising MCFC.

gmarkall commented 12 years ago

(I'm not emotionally attached to this idea - I won't be offended if you'd like to reject it entirely :-) )

kynan commented 12 years ago

Would it make sense to have a dedicated comment node? It could take a list of strings which would be unparsed to a comment line per element. Or just take a string and wrap it round at say 78 columns.

Nevertheless I'm not opposed to the idea of a node for arbitrary strings.

gmarkall commented 12 years ago

The point of this isn't really for comments - it's for the blocks of code we might see in transform_to_physical, like:

          invJ_local[0] =  J_local_T[3];
          invJ_local[1] = -J_local_T[2];
          invJ_local[2] = -J_local_T[1];
          invJ_local[3] =  J_local_T[0];

These bit's don't change very much, so we could get away with inserting them as a string into the AST. This is in contrast to trying to write code that generates the AST for these expressions, or (more complicatedly) trying to write a parser for C that reads this in as an AST.

The comment-generation that I added just seemed like the simplest way to provide an example of the use of the ArbitraryString class.

kynan commented 12 years ago

Agreed. I do see the use case for that sort of code block.