aboutsummaryrefslogtreecommitdiff
path: root/Tools/CodeGen/CodeGen.m
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2011-09-28 10:36:51 +0200
committerIan Hinder <ian.hinder@aei.mpg.de>2011-09-29 20:57:09 +0200
commitde54d405ee8b39cc90dbf2b9e2b432b392076259 (patch)
treee81baa419db257d1b4500805faa491fe2c78f358 /Tools/CodeGen/CodeGen.m
parente8de06836ab40996977ae915ad3378aa60a05e81 (diff)
Add Stringify to convert C code statements to a C string
This takes a list of code statements and returns a C string containing this code. This is used to capture the generated C code and pass it to the OpenCL run time.
Diffstat (limited to 'Tools/CodeGen/CodeGen.m')
-rw-r--r--Tools/CodeGen/CodeGen.m14
1 files changed, 14 insertions, 0 deletions
diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m
index 6ed87d0..b65c42f 100644
--- a/Tools/CodeGen/CodeGen.m
+++ b/Tools/CodeGen/CodeGen.m
@@ -130,6 +130,8 @@ BoundaryLoop::usage = "";
BoundaryWithGhostsLoop::usage = "";
GenericGridLoop::usage = "";
+Stringify::usage = "";
+
NameRoot::usage = "";
PartitionVarList::usage = "";
Quote::usage = "Quote[x] returns x surrounded by quotes";
@@ -216,6 +218,18 @@ CommaInitSeparated[l_] :=
+(* Turn a section of code into a string:
+ 1. quote all quotes (replace all quotes with backslash-quote)
+ 2. break the string into lines to make it readable (replace all newlines
+ with quote-newline-quote)
+ 3. surround the result with quotes *)
+Stringify[x_] := "\"" <>
+ StringReplace[StringReplace[FlattenBlock[x],
+ "\"" -> "\\\""], "\n" -> "\\n\"\n\""] <>
+ "\"\n";
+
+
+
NameRoot[name_] := Module[{dropNumberRule, root},
dropNumberRule = {"1" -> "", "2" -> "", "3" -> "", "4" -> "", "5" -> "",