llvm.org GIT mirror llvm / 6a26a01
Use report_fatal_error more consistently in the C API echo test git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260849 91177308-0d34-0410-b5e6-96231b3b80d8 Amaury Sechet 4 years ago
1 changed file(s) with 33 addition(s) and 73 deletion(s). Raw diff Collapse all Expand all
154154
155155 static ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) {
156156 unsigned Count = LLVMCountParams(Src);
157 if (Count != LLVMCountParams(Dst)) {
158 fprintf(stderr, "Parameter count mismatch\n");
159 exit(-1);
160 }
157 if (Count != LLVMCountParams(Dst))
158 report_fatal_error("Parameter count mismatch");
161159
162160 ValueMap VMap;
163161 if (Count == 0)
182180 SrcNext = LLVMGetNextParam(SrcCur);
183181 DstNext = LLVMGetNextParam(DstCur);
184182 if (SrcNext == nullptr && DstNext == nullptr) {
185 if (SrcCur != SrcLast) {
186 fprintf(stderr, "SrcLast param does not match End\n");
187 exit(-1);
188 }
189
190 if (DstCur != DstLast) {
191 fprintf(stderr, "DstLast param does not match End\n");
192 exit(-1);
193 }
194
183 if (SrcCur != SrcLast)
184 report_fatal_error("SrcLast param does not match End");
185 if (DstCur != DstLast)
186 report_fatal_error("DstLast param does not match End");
195187 break;
196188 }
197189
198 if (SrcNext == nullptr) {
199 fprintf(stderr, "SrcNext was unexpectedly null\n");
200 exit(-1);
201 }
202
203 if (DstNext == nullptr) {
204 fprintf(stderr, "DstNext was unexpectedly null\n");
205 exit(-1);
206 }
190 if (SrcNext == nullptr)
191 report_fatal_error("SrcNext was unexpectedly null");
192 if (DstNext == nullptr)
193 report_fatal_error("DstNext was unexpectedly null");
207194
208195 LLVMValueRef SrcPrev = LLVMGetPreviousParam(SrcNext);
209 if (SrcPrev != SrcCur) {
210 fprintf(stderr, "SrcNext.Previous param is not Current\n");
211 exit(-1);
212 }
196 if (SrcPrev != SrcCur)
197 report_fatal_error("SrcNext.Previous param is not Current");
213198
214199 LLVMValueRef DstPrev = LLVMGetPreviousParam(DstNext);
215 if (DstPrev != DstCur) {
216 fprintf(stderr, "DstNext.Previous param is not Current\n");
217 exit(-1);
218 }
200 if (DstPrev != DstCur)
201 report_fatal_error("DstNext.Previous param is not Current");
219202
220203 SrcCur = SrcNext;
221204 DstCur = DstNext;
222205 }
223206
224 if (Count != 0) {
225 fprintf(stderr, "Parameter count does not match iteration\n");
226 exit(-1);
227 }
207 if (Count != 0)
208 report_fatal_error("Parameter count does not match iteration");
228209
229210 return VMap;
230211 }
514495 }
515496 }
516497
517 const char *Name = LLVMGetBasicBlockName(Src);
518
519498 LLVMValueRef V = LLVMBasicBlockAsValue(Src);
520499 if (!LLVMValueIsBasicBlock(V) || LLVMValueAsBasicBlock(V) != Src)
521500 report_fatal_error("Basic block is not a basic block");
522501
502 const char *Name = LLVMGetBasicBlockName(Src);
523503 const char *VName = LLVMGetValueName(V);
524504 if (Name != VName)
525505 report_fatal_error("Basic block name mismatch");
540520 LLVMValueRef Last = LLVMGetLastInstruction(Src);
541521
542522 if (First == nullptr) {
543 if (Last != nullptr) {
544 fprintf(stderr, "Has no first instruction, but last one\n");
545 exit(-1);
546 }
547
523 if (Last != nullptr)
524 report_fatal_error("Has no first instruction, but last one");
548525 return BB;
549526 }
550527
558535 CloneInstruction(Cur, Builder);
559536 Next = LLVMGetNextInstruction(Cur);
560537 if (Next == nullptr) {
561 if (Cur != Last) {
562 fprintf(stderr, "Final instruction does not match Last\n");
563 exit(-1);
564 }
565
538 if (Cur != Last)
539 report_fatal_error("Final instruction does not match Last");
566540 break;
567541 }
568542
569543 LLVMValueRef Prev = LLVMGetPreviousInstruction(Next);
570 if (Prev != Cur) {
571 fprintf(stderr, "Next.Previous instruction is not Current\n");
572 exit(-1);
573 }
544 if (Prev != Cur)
545 report_fatal_error("Next.Previous instruction is not Current");
574546
575547 Cur = Next;
576548 }
594566 Count--;
595567 Next = LLVMGetNextBasicBlock(Cur);
596568 if (Next == nullptr) {
597 if (Cur != Last) {
598 fprintf(stderr, "Final basic block does not match Last\n");
599 exit(-1);
600 }
601
569 if (Cur != Last)
570 report_fatal_error("Final basic block does not match Last");
602571 break;
603572 }
604573
605574 LLVMBasicBlockRef Prev = LLVMGetPreviousBasicBlock(Next);
606 if (Prev != Cur) {
607 fprintf(stderr, "Next.Previous basic bloc is not Current\n");
608 exit(-1);
609 }
575 if (Prev != Cur)
576 report_fatal_error("Next.Previous basic bloc is not Current");
610577
611578 Cur = Next;
612579 }
613580
614 if (Count != 0) {
615 fprintf(stderr, "Basic block count does not match iterration\n");
616 exit(-1);
617 }
581 if (Count != 0)
582 report_fatal_error("Basic block count does not match iterration");
618583 }
619584 };
620585
642607 clone_function(Cur, Dst);
643608 Next = LLVMGetNextFunction(Cur);
644609 if (Next == nullptr) {
645 if (Cur != End) {
646 fprintf(stderr, "Last function does not match End\n");
647 exit(-1);
648 }
649
610 if (Cur != End)
611 report_fatal_error("Last function does not match End");
650612 break;
651613 }
652614
653615 LLVMValueRef Prev = LLVMGetPreviousFunction(Next);
654 if (Prev != Cur) {
655 fprintf(stderr, "Next.Previous function is not Current\n");
656 exit(-1);
657 }
616 if (Prev != Cur)
617 report_fatal_error("Next.Previous function is not Current");
658618
659619 Cur = Next;
660620 }