[ARM] MVE compare vector splat combine
[llvm-complete.git] / tools / llvm-c-test / object.c
blob53ffb1acaffe663d7563418abfb059fdd732a152
1 /*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
2 |* *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 |* Exceptions. *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This file implements the --object-list-sections and --object-list-symbols *|
11 |* commands in llvm-c-test. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
15 #include "llvm-c-test.h"
16 #include "llvm-c/Object.h"
17 #include <stdio.h>
18 #include <stdlib.h>
20 int llvm_object_list_sections(void) {
21 LLVMMemoryBufferRef MB;
22 LLVMBinaryRef O;
23 LLVMSectionIteratorRef sect;
25 char *outBufferErr = NULL;
26 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &outBufferErr)) {
27 fprintf(stderr, "Error reading file: %s\n", outBufferErr);
28 free(outBufferErr);
29 exit(1);
32 char *outBinaryErr = NULL;
33 O = LLVMCreateBinary(MB, LLVMGetGlobalContext(), &outBinaryErr);
34 if (!O || outBinaryErr) {
35 fprintf(stderr, "Error reading object: %s\n", outBinaryErr);
36 free(outBinaryErr);
37 exit(1);
40 sect = LLVMObjectFileCopySectionIterator(O);
41 while (sect && !LLVMObjectFileIsSectionIteratorAtEnd(O, sect)) {
42 printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect),
43 LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect));
45 LLVMMoveToNextSection(sect);
48 LLVMDisposeSectionIterator(sect);
50 LLVMDisposeBinary(O);
52 LLVMDisposeMemoryBuffer(MB);
54 return 0;
57 int llvm_object_list_symbols(void) {
58 LLVMMemoryBufferRef MB;
59 LLVMBinaryRef O;
60 LLVMSectionIteratorRef sect;
61 LLVMSymbolIteratorRef sym;
63 char *outBufferErr = NULL;
64 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &outBufferErr)) {
65 fprintf(stderr, "Error reading file: %s\n", outBufferErr);
66 free(outBufferErr);
67 exit(1);
70 char *outBinaryErr = NULL;
71 O = LLVMCreateBinary(MB, LLVMGetGlobalContext(), &outBinaryErr);
72 if (!O || outBinaryErr) {
73 fprintf(stderr, "Error reading object: %s\n", outBinaryErr);
74 free(outBinaryErr);
75 exit(1);
78 sect = LLVMObjectFileCopySectionIterator(O);
79 sym = LLVMObjectFileCopySymbolIterator(O);
80 while (sect && sym && !LLVMObjectFileIsSymbolIteratorAtEnd(O, sym)) {
82 LLVMMoveToContainingSection(sect, sym);
83 printf("%s @0x%08" PRIx64 " +%" PRIu64 " (%s)\n", LLVMGetSymbolName(sym),
84 LLVMGetSymbolAddress(sym), LLVMGetSymbolSize(sym),
85 LLVMGetSectionName(sect));
87 LLVMMoveToNextSymbol(sym);
90 LLVMDisposeSymbolIterator(sym);
92 LLVMDisposeBinary(O);
94 LLVMDisposeMemoryBuffer(MB);
96 return 0;