Index: TEST.sc.Makefile
===================================================================
--- TEST.sc.Makefile	(revision 0)
+++ TEST.sc.Makefile	(revision 0)
@@ -0,0 +1,325 @@
+##===- TEST.sc.Makefile ------------------------------------*- Makefile -*-===##
+#
+# This test exercises the SAFECode passes.
+#
+##===----------------------------------------------------------------------===##
+
+RUNTIMELIMIT := 5400
+
+include $(PROJ_OBJ_ROOT)/Makefile.common
+
+ifdef DEBUG_SAFECODE
+CFLAGS := -g -O0 -fno-strict-aliasing -fno-merge-constants
+LLCFLAGS := -disable-fp-elim -disable-cfi
+LLVMLDFLAGS := -disable-opt
+OPTZN_PASSES := -mem2reg -simplifycfg -adce
+WHOLE_PROGRAM_BC_SUFFIX := linked.rbc
+else
+CFLAGS := -O2 -fno-strict-aliasing -fno-merge-constants
+LLCFLAGS := -disable-fp-elim -disable-cfi
+OPTZN_PASSES := -std-compile-opts
+WHOLE_PROGRAM_BC_SUFFIX := llvm.bc
+endif
+
+CURDIR  := $(shell cd .; pwd)
+PROGDIR := $(shell cd $(LLVM_SRC_ROOT)/projects/test-suite; pwd)/
+RELDIR  := $(subst $(PROGDIR),,$(CURDIR))
+GCCLD    = $(LLVM_OBJ_ROOT)/$(CONFIGURATION)/bin/gccld
+SC       := $(RUNTOOLSAFELY) $(LOPT) \
+            -reg-argv -reg-byval-args -reg-custom-alloc -reg-globals \
+            -reg-runtime-init -reg-stack-obj \
+            -lschecks -gepchecks -exactcheck-opt -oob-rewriter \
+            -debuginstrument 
+
+SC_RT := libsc_dbg_rt libpoolalloc_bitmap
+
+PA_RT_O  := $(addprefix $(LLVM_OBJ_ROOT)/$(CONFIGURATION)/lib/,$(addsuffix .a,$(SC_RT)))
+PA_RT_BC := $(addprefix $(LLVM_OBJ_ROOT)/$(CONFIGURATION)/lib/,$(addsuffix .bca,$(SC_RT)))
+
+# SC_STATS - Run opt with the -stats and -time-passes options, capturing the
+# output to a file.
+SC_STATS = $(SC) -stats -time-passes -info-output-file=$(CURDIR)/$@.info
+
+#
+# Add libraries necessary for linking.
+#
+ifeq ($(OS),Darwin)
+LDFLAGS += -lpthread
+else
+LDFLAGS += -lrt -lpthread
+endif
+
+#
+# When compiling on Linux, statically link in libstdc++.
+# For other platforms, link it in normally.
+#
+ifeq ($(OS),Linux)
+STATICFLAGS := -static
+else
+STATICFLAGS :=
+endif
+
+#
+# DEBUGGING
+#   o) Don't add -g to CFLAGS, CXXFLAGS, or CPPFLAGS; these are used by the
+#      rules to compile code with llvm-gcc and enable LLVM debug information;
+#      this, in turn, causes test cases to fail unnecessairly.
+#CBECFLAGS += -g
+
+#
+# Create a SAFECode (technically, Jones-Kelly) executable.
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.bc): \
+Output/%.jk.bc: Output/%.$(WHOLE_PROGRAM_BC_SUFFIX) $(LOPT)
+	-@rm -f $(CURDIR)/$@.info
+	-$(SC_STATS) $< -f -o $@ 2>&1 > $@.out
+
+#
+# These rules compile the new .bc file into a .c file using llc
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.s): \
+Output/%.jk.s: Output/%.jk.bc $(LLC)
+	-$(LLC) $(LLCFLAGS) $< -o $@
+
+$(PROGRAMS_TO_TEST:%=Output/%.jk.cbe.c): \
+Output/%.jk.cbe.c: Output/%.jk.bc $(LLC)
+	-$(LLC) -march=c $(LLCFLAGS) -f $< -o $@
+
+#
+# These rules compile the CBE .c file into a final executable
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk): \
+Output/%.jk: Output/%.jk.s
+	-$(CC) $(CFLAGS) $< $(LLCLIBS) $(PA_RT_O) $(LDFLAGS) -o $@ $(STATICFLAGS) -lstdc++
+
+##############################################################################
+# Rules for running executables and generating reports
+##############################################################################
+
+ifndef PROGRAMS_HAVE_CUSTOM_RUN_RULES
+
+#
+# This rule runs the generated executable, generating timing information, for
+# normal test programs
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.out-llc): \
+Output/%.jk.out-llc: Output/%.jk
+	-$(RUNSAFELY) $(STDIN_FILENAME) $@ $< $(RUN_OPTIONS)
+
+else
+
+#
+# This rule runs the generated executable, generating timing information, for
+# SPEC
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.out-llc): \
+Output/%.jk.out-llc: Output/%.jk
+	-$(SPEC_SANDBOX) jk-$(RUN_TYPE) $@ $(REF_IN_DIR) \
+             $(RUNSAFELY) $(STDIN_FILENAME) $(STDOUT_FILENAME) \
+                  ../../$< $(RUN_OPTIONS)
+	-(cd Output/jk-$(RUN_TYPE); cat $(LOCAL_OUTPUTS)) > $@
+	-cp Output/jk-$(RUN_TYPE)/$(STDOUT_FILENAME).time $@.time
+
+endif
+
+# This rule diffs the post-poolallocated version to make sure we didn't break
+# the program!
+$(PROGRAMS_TO_TEST:%=Output/%.jk.diff-llc): \
+Output/%.jk.diff-llc: Output/%.out-nat Output/%.jk.out-llc
+	@cp Output/$*.out-nat Output/$*.jk.out-nat
+	-$(DIFFPROG) llc $*.jk $(HIDEDIFF)
+
+# This rule wraps everything together to build the actual output the report is
+# generated from.
+#
+$(PROGRAMS_TO_TEST:%=Output/%.$(TEST).report.txt): \
+Output/%.$(TEST).report.txt: Output/%.out-nat                \
+                             Output/%.jk.diff-llc         \
+                             Output/%.LOC.txt
+	@echo > $@
+	@echo ">>> ========= " \'$*\' Program >> $@
+	@-if test -f Output/$*.out-nat; then \
+	  printf "GCC-RUN-TIME: " >> $@;\
+	  grep "^user" Output/$*.out-nat.time >> $@;\
+        fi
+	@-if test -f Output/$*.jk.diff-llc; then \
+	  printf "CBE-RUN-TIME-NORMAL: " >> $@;\
+	  grep "^user" Output/$*.jk.out-llc.time >> $@;\
+        fi
+	@-if test -f Output/$*.safecode.diff-llc; then \
+	  printf "CBE-RUN-TIME-SAFECODE: " >> $@;\
+	  grep "^user" Output/$*.safecode.out-llc.time >> $@;\
+	fi
+	printf "LOC: " >> $@
+	cat Output/$*.LOC.txt >> $@
+
+$(PROGRAMS_TO_TEST:%=test.$(TEST).%): \
+test.$(TEST).%: Output/%.$(TEST).report.txt
+	@echo "---------------------------------------------------------------"
+	@echo ">>> ========= '$(RELDIR)/$*' Program"
+	@echo "---------------------------------------------------------------"
+	@cat $<
+
+REPORT_DEPENDENCIES := $(PA_RT_O) $(PA_SO) $(PROGRAMS_TO_TEST:%=Output/%.llvm.bc) $(LLC) $(LOPT)
+##===- TEST.sc.Makefile ------------------------------------*- Makefile -*-===##
+#
+# This test exercises the SAFECode passes.
+#
+##===----------------------------------------------------------------------===##
+
+RUNTIMELIMIT := 5400
+
+include $(PROJ_OBJ_ROOT)/Makefile.common
+
+ifdef DEBUG_SAFECODE
+CFLAGS := -g -O0 -fno-strict-aliasing -fno-merge-constants
+LLCFLAGS := -disable-fp-elim -disable-cfi
+LLVMLDFLAGS := -disable-opt
+OPTZN_PASSES := -mem2reg -simplifycfg -adce
+WHOLE_PROGRAM_BC_SUFFIX := linked.rbc
+else
+CFLAGS := -O2 -fno-strict-aliasing -fno-merge-constants
+LLCFLAGS := -disable-cfi
+OPTZN_PASSES := -std-compile-opts
+WHOLE_PROGRAM_BC_SUFFIX := llvm.bc
+endif
+
+CURDIR  := $(shell cd .; pwd)
+PROGDIR := $(shell cd $(LLVM_SRC_ROOT)/projects/test-suite; pwd)/
+RELDIR  := $(subst $(PROGDIR),,$(CURDIR))
+GCCLD    = $(LLVM_OBJ_ROOT)/$(CONFIGURATION)/bin/gccld
+SC       := $(RUNTOOLSAFELY) $(LOPT) \
+            -reg-argv -reg-byval-args -reg-custom-alloc -reg-globals \
+            -reg-runtime-init -reg-stack-obj \
+            -lschecks -gepchecks -exactcheck-opt -debuginstrument
+
+SC_RT := libsc_dbg_rt libpoolalloc_bitmap
+
+PA_RT_O  := $(addprefix $(LLVM_OBJ_ROOT)/$(CONFIGURATION)/lib/,$(addsuffix .a,$(SC_RT)))
+PA_RT_BC := $(addprefix $(LLVM_OBJ_ROOT)/$(CONFIGURATION)/lib/,$(addsuffix .bca,$(SC_RT)))
+
+# SC_STATS - Run opt with the -stats and -time-passes options, capturing the
+# output to a file.
+SC_STATS = $(SC) -stats -time-passes -info-output-file=$(CURDIR)/$@.info
+
+#
+# Add libraries necessary for linking.
+#
+ifeq ($(OS),Darwin)
+LDFLAGS += -lpthread
+else
+LDFLAGS += -lrt -lpthread
+endif
+
+#
+# When compiling on Linux, statically link in libstdc++.
+# For other platforms, link it in normally.
+#
+ifeq ($(OS),Linux)
+STATICFLAGS := -static
+else
+STATICFLAGS :=
+endif
+
+#
+# DEBUGGING
+#   o) Don't add -g to CFLAGS, CXXFLAGS, or CPPFLAGS; these are used by the
+#      rules to compile code with llvm-gcc and enable LLVM debug information;
+#      this, in turn, causes test cases to fail unnecessairly.
+#CBECFLAGS += -g
+
+#
+# Create a SAFECode (technically, Jones-Kelly) executable.
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.bc): \
+Output/%.jk.bc: Output/%.$(WHOLE_PROGRAM_BC_SUFFIX) $(LOPT)
+	-@rm -f $(CURDIR)/$@.info
+	-$(SC_STATS) $< -f -o $@ 2>&1 > $@.out
+
+#
+# These rules compile the new .bc file into a .c file using llc
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.s): \
+Output/%.jk.s: Output/%.jk.bc $(LLC)
+	-$(LLC) $(LLCFLAGS) $< -o $@
+
+$(PROGRAMS_TO_TEST:%=Output/%.jk.cbe.c): \
+Output/%.jk.cbe.c: Output/%.jk.bc $(LLC)
+	-$(LLC) -march=c $(LLCFLAGS) -f $< -o $@
+
+#
+# These rules compile the CBE .c file into a final executable
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk): \
+Output/%.jk: Output/%.jk.s
+	-$(CC) $(CFLAGS) $< $(LLCLIBS) $(PA_RT_O) $(LDFLAGS) -o $@ $(STATICFLAGS) -lstdc++
+
+##############################################################################
+# Rules for running executables and generating reports
+##############################################################################
+
+ifndef PROGRAMS_HAVE_CUSTOM_RUN_RULES
+
+#
+# This rule runs the generated executable, generating timing information, for
+# normal test programs
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.out-llc): \
+Output/%.jk.out-llc: Output/%.jk
+	-$(RUNSAFELY) $(STDIN_FILENAME) $@ $< $(RUN_OPTIONS)
+
+else
+
+#
+# This rule runs the generated executable, generating timing information, for
+# SPEC
+#
+$(PROGRAMS_TO_TEST:%=Output/%.jk.out-llc): \
+Output/%.jk.out-llc: Output/%.jk
+	-$(SPEC_SANDBOX) jk-$(RUN_TYPE) $@ $(REF_IN_DIR) \
+             $(RUNSAFELY) $(STDIN_FILENAME) $(STDOUT_FILENAME) \
+                  ../../$< $(RUN_OPTIONS)
+	-(cd Output/jk-$(RUN_TYPE); cat $(LOCAL_OUTPUTS)) > $@
+	-cp Output/jk-$(RUN_TYPE)/$(STDOUT_FILENAME).time $@.time
+
+endif
+
+# This rule diffs the post-poolallocated version to make sure we didn't break
+# the program!
+$(PROGRAMS_TO_TEST:%=Output/%.jk.diff-llc): \
+Output/%.jk.diff-llc: Output/%.out-nat Output/%.jk.out-llc
+	@cp Output/$*.out-nat Output/$*.jk.out-nat
+	-$(DIFFPROG) llc $*.jk $(HIDEDIFF)
+
+# This rule wraps everything together to build the actual output the report is
+# generated from.
+#
+$(PROGRAMS_TO_TEST:%=Output/%.$(TEST).report.txt): \
+Output/%.$(TEST).report.txt: Output/%.out-nat                \
+                             Output/%.jk.diff-llc         \
+                             Output/%.LOC.txt
+	@echo > $@
+	@echo ">>> ========= " \'$*\' Program >> $@
+	@-if test -f Output/$*.out-nat; then \
+	  printf "GCC-RUN-TIME: " >> $@;\
+	  grep "^user" Output/$*.out-nat.time >> $@;\
+        fi
+	@-if test -f Output/$*.jk.diff-llc; then \
+	  printf "CBE-RUN-TIME-NORMAL: " >> $@;\
+	  grep "^user" Output/$*.jk.out-llc.time >> $@;\
+        fi
+	@-if test -f Output/$*.safecode.diff-llc; then \
+	  printf "CBE-RUN-TIME-SAFECODE: " >> $@;\
+	  grep "^user" Output/$*.safecode.out-llc.time >> $@;\
+	fi
+	printf "LOC: " >> $@
+	cat Output/$*.LOC.txt >> $@
+
+$(PROGRAMS_TO_TEST:%=test.$(TEST).%): \
+test.$(TEST).%: Output/%.$(TEST).report.txt
+	@echo "---------------------------------------------------------------"
+	@echo ">>> ========= '$(RELDIR)/$*' Program"
+	@echo "---------------------------------------------------------------"
+	@cat $<
+
+REPORT_DEPENDENCIES := $(PA_RT_O) $(PA_SO) $(PROGRAMS_TO_TEST:%=Output/%.llvm.bc) $(LLC) $(LOPT)
Index: TEST.sc.report
===================================================================
--- TEST.sc.report	(revision 0)
+++ TEST.sc.report	(revision 0)
@@ -0,0 +1,118 @@
+##=== TEST.debug.report - Report description for SAFECode ----*- perl -*---===##
+#
+# This file defines a report to be generated for the debugging tool version of
+# SAFECode.
+#
+##===----------------------------------------------------------------------===##
+
+# Sort by program name
+$SortCol = 0;
+$TrimRepeatedPrefix = 1;
+
+# FormatTime - Convert a time from 1m23.45 into 83.45
+sub FormatTime {
+  my $Time = shift;
+  if ($Time =~ m/([0-9]+)[m:]([0-9.]+)/) {
+    return sprintf("%7.3f", $1*60.0+$2);
+  }
+
+  return sprintf("%6.2f", $Time);
+}
+
+
+sub RuntimePercent {
+  my ($Cols, $Col) = @_;
+  if ($Cols->[$Col-1] ne "*" and $Cols->[4] ne "*" and
+      $Cols->[4] != "0") {
+    return sprintf "%7.2f", 100*$Cols->[$Col-1]/$Cols->[4];
+  } else {
+    return "n/a";
+  }
+}
+
+@LatexColumns = (1, 5, 8, 12, 9, 13, 14, 15, 2, 16);
+
+my $FREEBENCH = 'MultiSource/Benchmarks/FreeBench';
+my $PTRDIST   = 'MultiSource/Benchmarks/Ptrdist';
+
+# These are the columns for the report.  The first entry is the header for the
+# column, the second is the regex to use to match the value.  Empty list create
+# seperators, and closures may be put in for custom processing.
+(
+# Name
+ ["Name:" , '\'([^\']+)\' Program'],
+ ["LOC"   , 'LOC:\s*([0-9]+)'],
+ [],
+# Times
+ ["GCC",           'GCC-RUN-TIME: user\s*([.0-9m:]+)', \&FormatTime],
+ [],
+ ["SC",            'CBE-RUN-TIME-NORMAL: user\s*([.0-9m:]+)', \&FormatTime],
+# ["NumPools",      '([0-9]+).*Number of pools allocated'],
+# ["Typesafe",      '([0-9]+).*Number of typesafe pools'],
+# ["BumpPtr",       '([0-9]+).*Number of bump pointer pools'],
+# ["PFE",           '([0-9]+).*Number of poolfree.s elided'],
+# ["NumArgs",       '([0-9]+).*Number of function arguments added'],
+# ["MaxArgs",       '([0-9]+).*Maximum function arguments added'],
+# ["Nonprofit",     '([0-9]+).*Number of DSNodes not profitable'],
+ []
+);
+
+##=== TEST.debug.report - Report description for SAFECode ----*- perl -*---===##
+#
+# This file defines a report to be generated for the debugging tool version of
+# SAFECode.
+#
+##===----------------------------------------------------------------------===##
+
+# Sort by program name
+$SortCol = 0;
+$TrimRepeatedPrefix = 1;
+
+# FormatTime - Convert a time from 1m23.45 into 83.45
+sub FormatTime {
+  my $Time = shift;
+  if ($Time =~ m/([0-9]+)[m:]([0-9.]+)/) {
+    return sprintf("%7.3f", $1*60.0+$2);
+  }
+
+  return sprintf("%6.2f", $Time);
+}
+
+
+sub RuntimePercent {
+  my ($Cols, $Col) = @_;
+  if ($Cols->[$Col-1] ne "*" and $Cols->[4] ne "*" and
+      $Cols->[4] != "0") {
+    return sprintf "%7.2f", 100*$Cols->[$Col-1]/$Cols->[4];
+  } else {
+    return "n/a";
+  }
+}
+
+@LatexColumns = (1, 5, 8, 12, 9, 13, 14, 15, 2, 16);
+
+my $FREEBENCH = 'MultiSource/Benchmarks/FreeBench';
+my $PTRDIST   = 'MultiSource/Benchmarks/Ptrdist';
+
+# These are the columns for the report.  The first entry is the header for the
+# column, the second is the regex to use to match the value.  Empty list create
+# seperators, and closures may be put in for custom processing.
+(
+# Name
+ ["Name:" , '\'([^\']+)\' Program'],
+ ["LOC"   , 'LOC:\s*([0-9]+)'],
+ [],
+# Times
+ ["GCC",           'GCC-RUN-TIME: user\s*([.0-9m:]+)', \&FormatTime],
+ [],
+ ["SC",            'CBE-RUN-TIME-NORMAL: user\s*([.0-9m:]+)', \&FormatTime],
+# ["NumPools",      '([0-9]+).*Number of pools allocated'],
+# ["Typesafe",      '([0-9]+).*Number of typesafe pools'],
+# ["BumpPtr",       '([0-9]+).*Number of bump pointer pools'],
+# ["PFE",           '([0-9]+).*Number of poolfree.s elided'],
+# ["NumArgs",       '([0-9]+).*Number of function arguments added'],
+# ["MaxArgs",       '([0-9]+).*Maximum function arguments added'],
+# ["Nonprofit",     '([0-9]+).*Number of DSNodes not profitable'],
+ []
+);
+
