| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | |
| 2 | ;; TODO: |
| 3 | ;; [ ] Get rid out outside class & begin stuff |
| 4 | ;; [ ] Allow global const pool to be expanded continually |
| 5 | ;; [ ] Support global variable declaration & definition |
| 6 | ;; [ ] Support function definition: %fib = prototype ulong (ulong) |
| 7 | ;; [x] Support Type definition |
| 8 | |
| 9 | implementation |
| 10 | |
| 11 | ulong "fib"(ulong %n) |
| 12 | begin |
| 13 | setlt ulong %n, 2 ; {bool}:0 |
| 14 | br bool %0, label %BaseCase, label %RecurseCase |
| 15 | |
| 16 | BaseCase: |
| 17 | ret ulong 1 |
| 18 | |
| 19 | RecurseCase: |
| 20 | %n2 = sub ulong %n, 2 |
| 21 | %n1 = sub ulong %n, 1 |
| 22 | %f2 = call ulong(ulong) %fib(ulong %n2) |
| 23 | %f1 = call ulong(ulong) %fib(ulong %n1) |
| 24 | %result = add ulong %f2, %f1 |
| 25 | ret ulong %result |
| 26 | end |
| 27 | |
| 28 | ulong "main"(int %argc, sbyte ** %argv) |
| 29 | ;; %n2 = int 1 |
| 30 | begin |
| 31 | seteq int %argc, 2 ; {bool}:0 |
| 32 | br bool %0, label %HasArg, label %Continue |
| 33 | HasArg: |
| 34 | ; %n1 = atoi(argv[1]) |
| 35 | ;;; %n1 = add int 1, 1 |
| 36 | br label %Continue |
| 37 | |
| 38 | Continue: |
| 39 | ;;; %n = phi int %n1, %n2 |
| 40 | %N = add ulong 1, 1 ;; TODO: CAST |
| 41 | %F = call ulong(ulong) %fib(ulong %N) |
| 42 | ret ulong %F |
| 43 | end |