From de54d405ee8b39cc90dbf2b9e2b432b392076259 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Wed, 28 Sep 2011 10:36:51 +0200 Subject: 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. --- Tools/CodeGen/CodeGen.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Tools/CodeGen/CodeGen.m') 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" -> "", -- cgit v1.2.3