From 6a8f91e3e9f7e6be546ca897445efb5d21be6e27 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 7 Sep 2001 23:00:46 +0000 Subject: [PATCH] New testcase to deal with lists git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@503 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Feature/recursivetype.ll | 102 ++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 test/Feature/recursivetype.ll diff --git a/test/Feature/recursivetype.ll b/test/Feature/recursivetype.ll new file mode 100644 index 00000000000..ce8214507c6 --- /dev/null +++ b/test/Feature/recursivetype.ll @@ -0,0 +1,102 @@ +; This file contains the output from the following compiled C code: +; typedef struct list { +; struct list *Next; +; int Data; +; } list; +; +; // Iterative insert fn +; void InsertIntoListTail(list **L, int Data) { +; while (*L) +; L = &(*L)->Next; +; *L = (list*)malloc(sizeof(list)); +; (*L)->Data = Data; +; (*L)->Next = 0; +; } +; +; // Recursive list search fn +; list *FindData(list *L, int Data) { +; if (L == 0) return 0; +; if (L->Data == Data) return L; +; return FindData(L->Next, Data); +; } +; +; void DoListStuff() { +; list *MyList = 0; +; InsertIntoListTail(&MyList, 100); +; InsertIntoListTail(&MyList, 12); +; InsertIntoListTail(&MyList, 42); +; InsertIntoListTail(&MyList, 1123); +; InsertIntoListTail(&MyList, 1213); +; +; if (FindData(MyList, 75)) foundIt(); +; if (FindData(MyList, 42)) foundIt(); +; if (FindData(MyList, 700)) foundIt(); +; } + +%list = type { %list*, int } + +declare sbyte *"malloc"(uint) + +;;********************** +implementation +;;********************** + +void "InsertIntoListTail"(%list** %L, int %Data) +begin +bb1: + %reg116 = load %list** %L ;;<%list*> + %cast1004 = cast ulong 0 to %list* ;;<%list*> + %cond1000 = seteq %list* %reg116, %cast1004 ;; + br bool %cond1000, label %bb3, label %bb2 + +bb2: + %reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ;;<%list**> + %cast1010 = cast %list** %reg117 to %list*** ;;<%list***> + %reg118 = load %list*** %cast1010 ;;<%list**> + %reg109 = load %list** %reg118 ;;<%list*> + %cast1005 = cast ulong 0 to %list* ;;<%list*> + %cond1001 = setne %list* %reg109, %cast1005 ;; + br bool %cond1001, label %bb2, label %bb3 + +bb3: + %reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ;;<%list**> + %cast1006 = cast %list** %reg119 to sbyte** ;; + %reg111 = call sbyte* %malloc(uint 16) ;; + store sbyte* %reg111, sbyte** %cast1006 ;; + %cast1007 = cast ulong 8 to sbyte* ;; + %reg1002 = add sbyte* %reg111, %cast1007 ;; + %cast1008 = cast sbyte* %reg1002 to int* ;; + store int %Data, int* %cast1008 ;; + %cast1003 = cast ulong 0 to ulong* ;; + %cast1009 = cast sbyte* %reg111 to ulong** ;; + store ulong* %cast1003, ulong** %cast1009 ;; + ret void +end + +%list* "FindData"(%list* %L, int %Data) +begin +bb1: + br label %bb2 + +bb2: + %reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ] ;;<%list*> + %cast1014 = cast ulong 0 to %list* ;;<%list*> + %cond1011 = setne %list* %reg115, %cast1014 ;; + br bool %cond1011, label %bb4, label %bb3 + +bb3: + %cast1015 = cast ulong 0 to %list* ;;<%list*> + ret %list* %cast1015 + +bb4: + %reg111 = load %list* %reg115, ubyte 1 ;; + %cond1013 = setne int %reg111, %Data ;; + br bool %cond1013, label %bb6, label %bb5 + +bb5: + ret %list* %reg115 + +bb6: + %reg116 = load %list* %reg115, ubyte 0 ;;<%list*> + br label %bb2 +end