changeset 8:37a10fd62ea9

add programs for prototype generation checking
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sat, 21 Feb 2015 21:19:46 +0900
parents e1e9a4eac42d
children 34365a1eb6a3
files protoGenCheck/Makefile protoGenCheck/fibonacci.c protoGenCheck/noProtoFibonacci.c
diffstat 3 files changed, 79 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/protoGenCheck/Makefile	Sat Feb 21 21:19:46 2015 +0900
@@ -0,0 +1,13 @@
+CC=/Users/e105711/prog/seminar/CbC/llvmInst/Debug+Asserts/bin/clang
+TARGET=noProtoFibonacci fibonacci
+
+.SUFFIXES: .c .o
+
+.c.o:
+	$(CC) -o $<
+
+all: $(TARGET)
+
+clean:
+	rm -f $(TARGET)
+	rm -f *.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/protoGenCheck/fibonacci.c	Sat Feb 21 21:19:46 2015 +0900
@@ -0,0 +1,35 @@
+/*
+  calculate fibonacci progression.
+  Author : Kaito Tokumori
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+__code fibonacci(int loop);
+__code calcLoop(int before, int current, int loop);
+__code print_answer(int answer);
+
+int main(int argc, char **argv) {
+  int i;
+  i = atoi(argv[1]);
+
+  goto fibonacci(i);
+}
+
+__code fibonacci(int loop) {
+  goto calcLoop(0, 1, loop);
+}
+
+__code calcLoop(int before, int current, int loop) {
+  if ( loop > 1) {
+    goto calcLoop(current, before+current, loop-1);
+  }else{
+    goto print_answer(current);
+  }
+}
+
+__code print_answer(int answer) {
+  printf("factorial = %d\n",answer);
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/protoGenCheck/noProtoFibonacci.c	Sat Feb 21 21:19:46 2015 +0900
@@ -0,0 +1,31 @@
+/*
+  Prototype generator check. CbC compiler should compile this code without errors and warnings.
+  Author : Kaito Tokumori
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv) {
+  int i;
+  i = atoi(argv[1]);
+
+  goto fibonacci(i);
+}
+
+__code fibonacci(int loop) {
+  goto calcLoop(0, 1, loop);
+}
+
+__code calcLoop(int before, int current, int loop) {
+  if ( loop > 1) {
+    goto calcLoop(current, before+current, loop-1);
+  }else{
+    goto print_answer(current);
+  }
+}
+
+__code print_answer(int answer) {
+  printf("factorial = %d\n",answer);
+  exit(0);
+}