stop accepting begin/end around function bodies in the .ll parser, this isn't pascal anymore.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133244 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2011-06-17 06:42:57 +00:00
parent 7a1b9bdd2b
commit 6b7c89ee09
27 changed files with 7 additions and 678 deletions

View File

@ -471,7 +471,6 @@ lltok::Kind LLLexer::LexIdentifier() {
if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
return lltok::kw_##STR;
KEYWORD(begin); KEYWORD(end);
KEYWORD(true); KEYWORD(false);
KEYWORD(declare); KEYWORD(define);
KEYWORD(global); KEYWORD(constant);

View File

@ -2835,10 +2835,9 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
/// ParseFunctionBody
/// ::= '{' BasicBlock+ '}'
/// ::= 'begin' BasicBlock+ 'end' // FIXME: remove in LLVM 3.0
///
bool LLParser::ParseFunctionBody(Function &Fn) {
if (Lex.getKind() != lltok::lbrace && Lex.getKind() != lltok::kw_begin)
if (Lex.getKind() != lltok::lbrace)
return TokError("expected '{' in function body");
Lex.Lex(); // eat the {.
@ -2848,10 +2847,10 @@ bool LLParser::ParseFunctionBody(Function &Fn) {
PerFunctionState PFS(*this, Fn, FunctionNumber);
// We need at least one basic block.
if (Lex.getKind() == lltok::rbrace || Lex.getKind() == lltok::kw_end)
if (Lex.getKind() == lltok::rbrace)
return TokError("function body requires at least one basic block");
while (Lex.getKind() != lltok::rbrace && Lex.getKind() != lltok::kw_end)
while (Lex.getKind() != lltok::rbrace)
if (ParseBasicBlock(PFS)) return true;
// Eat the }.

View File

@ -32,7 +32,6 @@ namespace lltok {
exclaim, // !
kw_x,
kw_begin, kw_end,
kw_true, kw_false,
kw_declare, kw_define,
kw_global, kw_constant,

View File

@ -1,25 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
declare void @"foo"(i31 %i, i63 %j, i10 %k)
; foo test basic arith operations
define void @"foo"(i31 %i, i63 %j, i10 %k)
begin
%t1 = trunc i63 %j to i31
%t2 = add i31 %t1, %i
%t20 = add i31 3, %t1
%t3 = zext i31 %i to i63
%t4 = sub i63 %t3, %j
%t40 = sub i63 %j, -100
%t5 = mul i10 %k, 7
%t6 = sdiv i63 %j, -2
%t7 = udiv i63 %j, %t3
%t8 = urem i10 %k, 10
%t9 = srem i10 %k, -10
ret void
end

View File

@ -1,24 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
declare void @"foo"(i31 %i, i33 %j)
; foo test basic bitwise operations
define void @"foo"(i31 %i, i33 %j)
begin
%t1 = trunc i33 %j to i31
%t2 = and i31 %t1, %i
%t3 = sext i31 %i to i33
%t4 = or i33 %t3, %j
%t5 = xor i31 %t2, 7
%t6 = shl i31 %i, 2
%t7 = trunc i31 %i to i8
%t8 = shl i8 %t7, 3
%t9 = lshr i33 %j, 31
%t7z = zext i8 %t7 to i33
%t10 = ashr i33 %j, %t7z
ret void
end

View File

@ -1,26 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
declare void @"foo"(i31 %i, i1280 %j, i1 %k, float %f)
; foo test basic arith operations
define void @"foo"(i31 %i, i1280 %j, i1 %k, float %f)
begin
%t1 = trunc i1280 %j to i31
%t2 = trunc i31 %t1 to i1
%t3 = zext i31 %i to i1280
%t4 = sext i31 %i to i1280
%t5 = fptoui float 0x400921FA00000000 to i31
%t6 = uitofp i31 %t5 to double
%t7 = fptosi double 0xC0934A456D5CFAAD to i28
%t8 = sitofp i8 -1 to double
%t9 = uitofp i8 255 to double
ret void
end

View File

@ -1,43 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
define i55 @"simpleIcmp"(i55 %i0, i55 %j0)
begin
%t1 = icmp eq i55 %i0, %j0
%t2 = icmp ne i55 %i0, %j0
%t3 = icmp ult i55 %i0, %j0
%t4 = icmp sgt i55 %i0, %j0
%t5 = icmp ule i55 %i0, %j0
%t6 = icmp sge i55 %i0, %j0
%t7 = icmp eq i55 %i0, 1098765432
%t8 = icmp ne i55 %i0, -31415926
%t9 = icmp ult i55 10000, %j0
%t10 = icmp sgt i55 -10000, %j0
ret i55 %i0
end
define i31 @"phitest"(i12 %i)
begin
HasArg:
%n1 = add i12 1, %i
br label %Continue
Continue:
%n = phi i12 [%n1, %HasArg], [%next, %Continue]
%next = add i12 1, %n
br label %Continue
end
define i18 @"select"(i18 %i)
begin
%t = icmp sgt i18 %i, 100
%k = select i1 %t, i18 %i, i18 999
ret i18 %k
end

View File

@ -1,24 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
@MyVar = external global i19
@MyIntList = external global { i39 *, i19 }
external global i19 ; i19*:0
@AConst = constant i19 -123
@AString = constant [4 x i8] c"test"
@ZeroInit = global { [100 x i19 ], [40 x float ] } { [100 x i19] zeroinitializer,
[40 x float] zeroinitializer }
define i19 @"foo"(i19 %blah)
begin
store i19 5, i19* @MyVar
%idx = getelementptr { i39 *, i19 } * @MyIntList, i64 0, i32 1
store i19 12, i19* %idx
ret i19 %blah
end

View File

@ -1,56 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
;; This is an irreducible flow graph
define void @"irreducible"(i1 %cond)
begin
br i1 %cond, label %X, label %Y
X:
br label %Y
Y:
br label %X
end
;; This is a pair of loops that share the same header
define void @"sharedheader"(i1 %cond)
begin
br label %A
A:
br i1 %cond, label %X, label %Y
X:
br label %A
Y:
br label %A
end
;; This is a simple nested loop
define void @"nested"(i1 %cond1, i1 %cond2, i1 %cond3)
begin
br label %Loop1
Loop1:
br label %Loop2
Loop2:
br label %Loop3
Loop3:
br i1 %cond3, label %Loop3, label %L3Exit
L3Exit:
br i1 %cond2, label %Loop2, label %L2Exit
L2Exit:
br i1 %cond1, label %Loop1, label %L1Exit
L1Exit:
ret void
end

View File

@ -1,33 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
%myty = type i55
%myfn = type float (i55,double,i55,i16)
type i55(%myfn*)
type i55(i55)
type i55(i55(i55)*)
%thisfuncty = type i55 (i55) *
declare void @F(%thisfuncty, %thisfuncty, %thisfuncty)
; This function always returns zero
define i55 @zarro(i55 %Func)
begin
Startup:
add i55 0, 10
ret i55 0
end
define i55 @test(i55)
begin
call void @F(%thisfuncty @zarro, %thisfuncty @test, %thisfuncty @foozball)
ret i55 0
end
define i55 @foozball(i55)
begin
ret i55 0
end

View File

@ -1,26 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
@MyVar = external global i27
@MyIntList = external global { \2 *, i27 }
external global i27 ; i27*:0
@AConst = constant i27 123
@AString = constant [4 x i8] c"test"
@ZeroInit = global { [100 x i27 ], [40 x float ] } { [100 x i27] zeroinitializer,
[40 x float] zeroinitializer }
define i27 @"foo"(i27 %blah)
begin
store i27 5, i27 *@MyVar
%idx = getelementptr { \2 *, i27 } * @MyIntList, i64 0, i32 1
store i27 12, i27* %idx
ret i27 %blah
end

View File

@ -1,24 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
define i63 @"test"(i63 %X)
begin
ret i63 %X
end
define i63 @"fib"(i63 %n)
begin
%T = icmp ult i63 %n, 2 ; {i1}:0
br i1 %T, label %BaseCase, label %RecurseCase
RecurseCase:
%result = call i63 @test(i63 %n)
br label %BaseCase
BaseCase:
%X = phi i63 [1, %0], [2, %RecurseCase]
ret i63 %X
end

View File

@ -1,52 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
declare i32 @"atoi"(i8 *)
define i63 @"fib"(i63 %n)
begin
icmp ult i63 %n, 2 ; {i1}:1
br i1 %1, label %BaseCase, label %RecurseCase
BaseCase:
ret i63 1
RecurseCase:
%n2 = sub i63 %n, 2
%n1 = sub i63 %n, 1
%f2 = call i63(i63) * @fib(i63 %n2)
%f1 = call i63(i63) * @fib(i63 %n1)
%result = add i63 %f2, %f1
ret i63 %result
end
define i63 @"realmain"(i32 %argc, i8 ** %argv)
begin
icmp eq i32 %argc, 2 ; {i1}:1
br i1 %1, label %HasArg, label %Continue
HasArg:
; %n1 = atoi(argv[1])
%n1 = add i32 1, 1
br label %Continue
Continue:
%n = phi i32 [%n1, %HasArg], [1, %0]
%N = sext i32 %n to i63
%F = call i63(i63) *@fib(i63 %N)
ret i63 %F
end
define i63 @"trampoline"(i63 %n, i63(i63)* %fibfunc)
begin
%F = call i63(i63) *%fibfunc(i63 %n)
ret i63 %F
end
define i32 @"main"()
begin
%Result = call i63 @trampoline(i63 10, i63(i63) *@fib)
%Result2 = trunc i63 %Result to i32
ret i32 %Result2
end

View File

@ -1,13 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
declare i31 @"bar"(i31 %in)
define i31 @"foo"(i31 %blah)
begin
%xx = call i31 @bar(i31 %blah)
ret i31 %xx
end

View File

@ -1,108 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
; This file contains the output from the following compiled C code:
; typedef struct list {
; struct list *Next;
; i32 Data;
; } list;
;
; // Iterative insert fn
; void InsertIntoListTail(list **L, i32 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, i32 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*, i36 }
declare i8 *@"malloc"(i32)
;;**********************
;;**********************
define void @"InsertIntoListTail"(%list** %L, i36 %Data)
begin
bb1:
%reg116 = load %list** %L ;;<%list*>
%cast1004 = inttoptr i64 0 to %list* ;;<%list*>
%cond1000 = icmp eq %list* %reg116, %cast1004 ;;<i1>
br i1 %cond1000, label %bb3, label %bb2
bb2:
%reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ;;<%list**>
%cast1010 = bitcast %list** %reg117 to %list*** ;;<%list***>
%reg118 = load %list*** %cast1010 ;;<%list**>
%reg109 = load %list** %reg118 ;;<%list*>
%cast1005 = inttoptr i64 0 to %list* ;;<%list*>
%cond1001 = icmp ne %list* %reg109, %cast1005 ;;<i1>
br i1 %cond1001, label %bb2, label %bb3
bb3:
%reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ;;<%list**>
%cast1006 = bitcast %list** %reg119 to i8** ;;<i8**>
%reg111 = call i8* @malloc(i32 16) ;;<i8*>
store i8* %reg111, i8** %cast1006 ;;<void>
%reg112 = ptrtoint i8* %reg111 to i64
%reg1002 = add i64 %reg112, 8
%reg1005 = inttoptr i64 %reg1002 to i8* ;;<i8*>
%cast1008 = bitcast i8* %reg1005 to i36* ;;<i36*>
store i36 %Data, i36* %cast1008 ;;<void>
%cast1003 = inttoptr i64 0 to i64* ;;<i64*>
%cast1009 = bitcast i8* %reg111 to i64** ;;<i64**>
store i64* %cast1003, i64** %cast1009 ;;<void>
ret void
end
define %list* @"FindData"(%list* %L, i36 %Data)
begin
bb1:
br label %bb2
bb2:
%reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ] ;;<%list*>
%cast1014 = inttoptr i64 0 to %list* ;;<%list*>
%cond1011 = icmp ne %list* %reg115, %cast1014 ;;<i1>
br i1 %cond1011, label %bb4, label %bb3
bb3:
ret %list* null
bb4:
%idx = getelementptr %list* %reg115, i64 0, i32 1 ;;<i36>
%reg111 = load i36* %idx
%cond1013 = icmp ne i36 %reg111, %Data ;;<i1>
br i1 %cond1013, label %bb6, label %bb5
bb5:
ret %list* %reg115
bb6:
%idx2 = getelementptr %list* %reg115, i64 0, i32 0 ;;<%list*>
%reg116 = load %list** %idx2
br label %bb2
end

View File

@ -1,28 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
%FunTy = type i31(i31)
define void @"invoke"(%FunTy *%x)
begin
%foo = call %FunTy* %x(i31 123)
ret void
end
define i31 @"main"(i31 %argc, i8 **%argv, i8 **%envp)
begin
%retval = call i31 (i31) *@test(i31 %argc)
%two = add i31 %retval, %retval
%retval2 = call i31 @test(i31 %argc)
%two2 = add i31 %two, %retval2
call void @invoke (%FunTy* @test)
ret i31 %two2
end
define i31 @"test"(i31 %i0)
begin
ret i31 %i0
end

View File

@ -1,13 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
%x = type i19
define i19 @"foo"(i19 %in)
begin
label:
ret i19 2
end

View File

@ -1,28 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
%inners = type {float, {i8 } }
%struct = type { i33 , {float, {i8 } } , i64 }
define i33 @testfunction(i33 %i0, i33 %j0)
begin
alloca i8, i32 5
%ptr = alloca i33 ; yields {i33*}:ptr
store i33 3, i33* %ptr ; yields {void}
%val = load i33* %ptr ; yields {i33}:val = i33 %3
%sptr = alloca %struct ; yields {%struct*}:sptr
%nsptr = getelementptr %struct * %sptr, i64 0, i32 1 ; yields {inners*}:nsptr
%ubsptr = getelementptr %inners * %nsptr, i64 0, i32 1 ; yields {{i8}*}:ubsptr
%idx = getelementptr {i8} * %ubsptr, i64 0, i32 0
store i8 4, i8* %idx
%fptr = getelementptr %struct * %sptr, i64 0, i32 1, i32 0 ; yields {float*}:fptr
store float 4.0, float * %fptr
ret i33 3
end

View File

@ -1,21 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
define i31 @"simpleArith"(i31 %i0, i31 %j0)
begin
%t1 = add i31 %i0, %j0
%t2 = sub i31 %i0, %j0
%t3 = mul i31 %t1, %t2
%t4 = udiv i31 %t1, %t2
%t5 = sdiv i31 %t1, %t2
%t6 = urem i31 %t1, %t2
%t7 = srem i31 %t1, %t2
%t8 = shl i31 %t1, 9
%t9 = lshr i31 %t1, 9
%t10= ashr i31 %t1, 9
%f1 = sitofp i31 %t1 to float
%f2 = fdiv float 4.0, %f1
ret i31 %t3
end

View File

@ -1,32 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
@somestr = constant [11x i8] c"hello world"
@array = constant [2 x i55] [ i55 12, i55 52 ]
constant { i55, i55 } { i55 4, i55 3 }
define [2 x i55]* @testfunction(i55 %i0, i55 %j0)
begin
ret [2x i55]* @array
end
define i8* @otherfunc(i55, double)
begin
%somestr = getelementptr [11x i8]* @somestr, i64 0, i64 0
ret i8* %somestr
end
define i8* @yetanotherfunc(i55, double)
begin
ret i8* null ; Test null
end
define i55 @negativeUnsigned() {
ret i55 -1
}
define i55 @largeSigned() {
ret i55 3900000000
}

View File

@ -1,23 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
define i31 @"simpleIcmp"(i31 %i0, i31 %j0)
begin
%t1 = icmp eq i31 %i0, %j0
%t2 = icmp ne i31 %i0, %j0
%t3 = icmp ult i31 %i0, %j0
%t4 = icmp sgt i31 %i0, %j0
%t5 = icmp ule i31 %i0, %j0
%t6 = icmp sge i31 %i0, %j0
%t7 = icmp eq i31 %i0, 1098765432
%t8 = icmp ne i31 %i0, -31415926
%t9 = icmp ult i31 10000, %j0
%t10 = icmp sgt i31 -10000, %j0
ret i31 %i0
end

View File

@ -1,13 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
define i31 @"simpleAdd"(i31 %i0, i31 %j0)
begin
%t1 = xor i31 %i0, %j0
%t2 = or i31 %i0, %j0
%t3 = and i31 %t1, %t2
ret i31 %t3
end

View File

@ -1,15 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
define i31 @"simpleAdd"(i31 %i0, i31 %j0)
begin
%t1 = xor i31 %i0, %j0
%t2 = or i31 %i0, %j0
%t3 = and i31 %t1, %t2
%t4 = shl i31 %i0, 2
%t5 = ashr i31 %i0, 2
%t6 = lshr i31 %j0, 22
ret i31 %t3
end

View File

@ -1,24 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
%i35 = type i35
define i35 @"squared"(%i35 %i0)
begin
switch i35 %i0, label %Default [
i35 1, label %Case1
i35 2, label %Case2
i35 4, label %Case4 ]
Default:
ret i35 -1 ; Unrecognized input value
Case1:
ret i35 1
Case2:
ret i35 4
Case4:
ret i35 16
end

View File

@ -1,14 +0,0 @@
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
declare i31 @"printf"(i8*, ...) ;; Prototype for: i32 __builtin_printf(const char*, ...)
define i31 @"testvarar"()
begin
call i31(i8*, ...) *@printf(i8 * null, i31 12, i8 42)
ret i31 %1
end

View File

@ -1,7 +1,6 @@
; RUN: opt < %s -adce
define i32 @"main"(i32 %argc)
begin
define i32 @"main"(i32 %argc) {
br label %2
%retval = phi i32 [ %argc, %2 ] ; <i32> [#uses=2]
@ -9,5 +8,4 @@ begin
ret i32 %two
br label %1
end
}

View File

@ -4,7 +4,6 @@
; delcared return type of the function they live in.
;
define i32 @testfunc()
begin
define i32 @testfunc() {
ret i32* null
end
}