[llvm-commits] CVS: llvm/projects/Stacker/samples/Makefile goof.st prime.st
Brian Gaeke
gaeke at cs.uiuc.edu
Sun Nov 23 20:58:45 PST 2003
Changes in directory llvm/projects/Stacker/samples:
Makefile updated: 1.1 -> 1.2
goof.st updated: 1.1 -> 1.2
prime.st updated: 1.1 -> 1.2
---
Log message:
Apply patches from PR136
---
Diffs of the changes: (+110 -15)
Index: llvm/projects/Stacker/samples/Makefile
diff -u llvm/projects/Stacker/samples/Makefile:1.1 llvm/projects/Stacker/samples/Makefile:1.2
--- llvm/projects/Stacker/samples/Makefile:1.1 Sun Nov 23 11:55:19 2003
+++ llvm/projects/Stacker/samples/Makefile Sun Nov 23 20:57:25 2003
@@ -14,34 +14,46 @@
#
DIRS =
-TESTS = fibonacci hello prime
+SAMPLES = fibonacci hello prime
-all :: $(TESTS)
+all :: $(SAMPLES)
ifdef OPTIMIZE
%.bc : %.st
- stkrc -e -o - $< | opt -stats -q -f -o $*.bc \
+ @$(ECHO) "Compiling and Optimizing $< to $*.bc"
+ $(VERB)stkrc -e -o - $< | opt -stats -q -f -o $*.bc \
-aa-eval -adce -branch-combine -cee -constmerge -constprop -dce -die -ds-aa \
-ds-opt -gcse -globaldce -indvars -inline -instcombine \
-ipconstprop -licm -loopsimplify -mem2reg -pre -sccp -simplifycfg \
-tailcallelim -verify
else
%.bc : %.st
- stkrc -e -f -o $*.bc $<
+ @$(ECHO) "Compiling $< to $*.bc"
+ $(VERB)stkrc -e -f -o $*.bc $<
endif
%.s : %.bc
- llc -f -o $*.s $<
+ @$(ECHO) "Compiling $< to $*.s"
+ $(VERB)llc -f -o $*.s $<
% : %.s
- gcc -g -L$(BUILD_OBJ_ROOT)/lib/Debug -lstkr_runtime -o $* $*.s
+ @$(ECHO) "Compiling and Linking $< to $*"
+ $(VERB)gcc -g -L$(BUILD_OBJ_ROOT)/lib/Debug -lstkr_runtime -o $* $*.s
%.ll : %.bc
- llvm-dis -f -o $*.ll $<
+ @$(ECHO) "Disassembling $< to $*.ll"
+ $(VERB)llvm-dis -f -o $*.ll $<
%.bc : $(BUILD_OBJ_ROOT)/tools/Debug/stkrc
.PRECIOUS: %.bc %.s %.ll %.st
+
+SAMPLES_LL = $(SAMPLES:%=%.ll)
+SAMPLES_BC = $(SAMPLES:%=%.bc)
+SAMPLES_S = $(SAMPLES:%=%.s)
+
+clean ::
+ $(VERB)rm -f gmon.out $(SAMPLES_LL) $(SAMPLES_BC) $(SAMPLES_S) $(SAMPLES)
#
# Include the Master Makefile that knows how to build all.
#
Index: llvm/projects/Stacker/samples/goof.st
diff -u llvm/projects/Stacker/samples/goof.st:1.1 llvm/projects/Stacker/samples/goof.st:1.2
--- llvm/projects/Stacker/samples/goof.st:1.1 Sun Nov 23 11:55:19 2003
+++ llvm/projects/Stacker/samples/goof.st Sun Nov 23 20:57:25 2003
@@ -1 +1,25 @@
-: defmebaby 23 0 = ;
+#
+# goof
+#
+: print_one
+ --
+ SWAP
+ >s
+ DROP
+;
+: print_it
+ WHILE
+ print_one
+ END
+;
+
+: MAIN
+ "MICKEY: I said she was f'in goofy!"
+ "MICKEY: I didn't say she was insane."
+ "JUDGE: Yet you provide no evidence of this and I do not concur."
+ "JUDGE: In your pleadings you claim that Mini Mouse is insane."
+ "MICKEY: Well, what do you mean, your honor?"
+ "JUDGE: Mr. Mouse, I find your grounds for divorce insufficient. "
+ 6
+ print_it
+;
Index: llvm/projects/Stacker/samples/prime.st
diff -u llvm/projects/Stacker/samples/prime.st:1.1 llvm/projects/Stacker/samples/prime.st:1.2
--- llvm/projects/Stacker/samples/prime.st:1.1 Sun Nov 23 11:55:19 2003
+++ llvm/projects/Stacker/samples/prime.st Sun Nov 23 20:57:25 2003
@@ -139,7 +139,7 @@
################################################################################
: consider_prime
DUP ( save the prime number to consider )
- 10000 < IF ( check to see if we are done yet )
+ 1000000 < IF ( check to see if we are done yet )
done ( we are done, call "done" )
ENDIF
++ ( increment to next prime number )
@@ -157,6 +157,8 @@
# STACK>: empty
################################################################################
: find_primes
+ "Prime Numbers: " >s CR ( say hello )
+ DROP ( get rid of that pesky string )
1 ( stoke the fires )
print ( print the first one, we know its prime )
WHILE ( loop while the prime to consider is non zero )
@@ -165,12 +167,69 @@
;
################################################################################
-# The MAIN program just prints a banner and calls find_primes.
-# STACK<: empty
-# STACK>: empty
+#
+################################################################################
+: say_yes
+ >d ( Print the prime number )
+ " is prime." ( push string to output )
+ >s ( output it )
+ CR ( print carriage return )
+ DROP ( pop string )
+;
+
+: say_no
+ >d ( Print the prime number )
+ " is NOT prime." ( push string to put out )
+ >s ( put out the string )
+ CR ( print carriage return )
+ DROP ( pop string )
+;
+
+################################################################################
+# This definition processes a single command line argument and determines if it
+# is a prime number or not.
+# STACK<:
+# n - number of arguments
+# arg1 - the prime numbers to examine
+# STACK>:
+# n-1 - one less than number of arguments
+# arg2 - we processed one argument
+################################################################################
+: do_one_argument
+ -- ( decrement loop counter )
+ SWAP ( get the argument value )
+ is_prime IF ( determine if its prime )
+ say_yes ( uhuh )
+ ELSE
+ say_no ( nope )
+ ENDIF
+ DROP ( done with that argument )
+;
+
+################################################################################
+# The MAIN program just prints a banner and processes its arguments.
+# STACK<:
+# n - number of arguments
+# ... - the arguments
+################################################################################
+: process_arguments
+ WHILE ( while there are more arguments )
+ do_one_argument ( process one argument )
+ END
+;
+
+################################################################################
+# The MAIN program just prints a banner and processes its arguments.
+# STACK<: arguments
################################################################################
: MAIN
- "Prime Numbers: " >s CR ( say hello )
- DROP ( get rid of that pesky string )
- find_primes ( see how many we can find )
+ NIP ( get rid of the program name )
+ -- ( reduce number of arguments )
+ DUP ( save the arg counter )
+ 1 <= IF ( See if we got an argument )
+ process_arguments ( tell user if they are prime )
+ ELSE
+ find_primes ( see how many we can find )
+ ENDIF
+ 0 ( push return code )
;
More information about the llvm-commits
mailing list