[add support for including basic profiling code in the generated executable
John Meacham <john@repetae.net>**20051021215515] hunk ./C/FromGrin.hs 79
-        return $ cfunction { cFuncComments = show n, cFuncReturnType = fr, cFuncName = toTag n, cFuncArgs = as', cFuncBody = s  } where
+        return $ cfunction { cFuncComments = show n, cFuncReturnType = fr, cFuncName = toTag n, cFuncArgs = as', cFuncBody = finc:s  } where
hunk ./C/FromGrin.hs 81
+    finc = CSExpr (CEFunCall "function_inc" [])
hunk ./C/FromGrin.hs 137
+    statement (CSExpr $ CEFunCall "update_inc" [])
hunk ./C/FromGrin.hs 147
+    statement (CSExpr $ CEFunCall "update_inc" [])
hunk ./C/FromGrin.hs 327
-    return [CSSwitch tag ls' ]
+    return [case_inc, CSSwitch tag ls' ]
hunk ./C/FromGrin.hs 341
-    return [CSSwitch v'' ls' ]
+    return [case_inc, CSSwitch v'' ls' ]
hunk ./C/FromGrin.hs 354
+case_inc = (CSExpr $ CEFunCall "case_inc" [])
hunk ./C/FromGrin.hs 360
+{-# NOINLINE compileGrin #-}
hunk ./E/LetFloat.hs 195
-                let ln = maximum [Map.findWithDefault 0 (tVr v Unknown) ans | v <- (snub $ concat (snds ts))  List.\\ [ i | (TVr { tvrIdent = i },_) <- ts ] ]
+                let ln = maximum $ 0:[Map.findWithDefault 0 (tVr v Unknown) ans | v <- (snub $ concat (snds ts))  List.\\ [ i | (TVr { tvrIdent = i },_) <- ts ] ]
hunk ./FlagOpts.flags 15
+profile embed profiling code
hunk ./Main.hs 354
+
+    --let flLevels = annotateBindings mempty lc
+    --print flLevels
+    --printCheckName dataTable lc
hunk ./Main.hs 454
-        let comm = shellQuote $ [optCC options, "-std=gnu99", "-foptimize-sibling-calls", "-O", {- "-funit-at-a-time", -} "-g", "-Wall", "-o", fn, cf ] ++ rls ++ optCCargs options  ++ boehmOpts
+        let profileOpts | fopts FO.Profile = ["-D_JHC_PROFILE"]
+                      | otherwise = []
+        let comm = shellQuote $ [optCC options, "-std=gnu99", "-foptimize-sibling-calls", "-O", {- "-funit-at-a-time", -} "-g", "-Wall", "-o", fn, cf ] ++ rls ++ optCCargs options  ++ boehmOpts ++ profileOpts
hunk ./data/jhc_rts.c 42
+#ifdef _JHC_PROFILE
+static uintmax_t prof_memory_allocated;
+static uintmax_t prof_function_calls;
+static uintmax_t prof_case_statements;
+static uintmax_t prof_updates;
+
+#define malloc(n) ( prof_memory_allocated += (n), malloc( (n) ) )
+#define update_inc() prof_updates++
+#define function_inc() prof_function_calls++
+#define case_inc() prof_case_statements++
+#else
+#define update_inc()  do { } while(0)
+#define function_inc()  do { } while(0)
+#define case_inc()  do { } while(0)
+#endif
+
+
+
+static void
+jhc_print_profile(void) {
+#ifdef _JHC_PROFILE
+        wprintf(L"Memory Allocated: %llu\n", (long long)prof_memory_allocated);
+        wprintf(L"Function Calls:   %llu\n", (long long)prof_function_calls);
+        wprintf(L"Case Statements:  %llu\n", (long long)prof_case_statements);
+        wprintf(L"Updates:          %llu\n", (long long)prof_updates);
+#endif
+}
hunk ./data/jhc_rts.c 78
+        jhc_print_profile();
hunk ./data/jhc_rts.c 80
+}
+
+static void A_NORETURN A_UNUSED
+jhc_exit(int n) {
+        jhc_print_profile();
+        exit(n);
hunk ./data/jhc_rts.c 90
-    fputs(s,stderr);
-    fputs("\n",stderr);
-    exit(255);
+        fputs(s,stderr);
+        fputs("\n",stderr);
+        jhc_print_profile();
+        exit(255);