llvm.org GIT mirror llvm / 90fd79a
llvm-c-test: Make them C89-compliant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193254 91177308-0d34-0410-b5e6-96231b3b80d8 NAKAMURA Takumi 5 years ago
5 changed file(s) with 29 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
4343 LLVMValueRef param) {
4444 LLVMValueRef stack[MAX_DEPTH];
4545 int depth = 0;
46 int i;
4647
47 for (int i = 0; i < ntokens; i++) {
48 for (i = 0; i < ntokens; i++) {
4849 char tok = tokens[i][0];
4950 switch (tok) {
5051 case '+':
6566
6667 break;
6768
68 case '@':
69 case '@': {
70 LLVMValueRef off;
71
6972 if (depth < 1) {
7073 printf("stack underflow\n");
7174 return NULL;
7275 }
7376
74 LLVMValueRef off = LLVMBuildGEP(builder, param, &stack[depth - 1], 1, "");
77 off = LLVMBuildGEP(builder, param, &stack[depth - 1], 1, "");
7578 stack[depth - 1] = LLVMBuildLoad(builder, off, "");
7679
7780 break;
81 }
7882
7983 default: {
8084 char *end;
107111
108112 static void handle_line(char **tokens, int ntokens) {
109113 char *name = tokens[0];
114 LLVMValueRef param;
115 LLVMValueRef res;
110116
111117 LLVMModuleRef M = LLVMModuleCreateWithName(name);
112118
118124 LLVMBuilderRef builder = LLVMCreateBuilder();
119125 LLVMPositionBuilderAtEnd(builder, LLVMAppendBasicBlock(F, "entry"));
120126
121 LLVMValueRef param;
122127 LLVMGetParams(F, ¶m);
123128 LLVMSetValueName(param, "in");
124129
125 LLVMValueRef res = build_from_tokens(tokens + 1, ntokens - 1, builder, param);
130 res = build_from_tokens(tokens + 1, ntokens - 1, builder, param);
126131 if (res) {
127132 char *irstr = LLVMPrintModuleToString(M);
128133 puts(irstr);
1919 #include
2020
2121 static void pprint(int pos, unsigned char *buf, int len, const char *disasm) {
22 int i;
2223 printf("%04x: ", pos);
23 for (int i = 0; i < 8; i++) {
24 for (i = 0; i < 8; i++) {
2425 if (i < len) {
2526 printf("%02x ", buf[i]);
2627 } else {
3334
3435 static void do_disassemble(const char *triple, unsigned char *buf, int siz) {
3536 LLVMDisasmContextRef D = LLVMCreateDisasm(triple, NULL, 0, NULL, NULL);
37 char outline[1024];
38 int pos;
3639
3740 if (!D) {
3841 printf("ERROR: Couldn't create disassebler for triple %s\n", triple);
3942 return;
4043 }
4144
42 char outline[1024];
43 int pos = 0;
45 pos = 0;
4446 while (pos < siz) {
4547 size_t l = LLVMDisasmInstruction(D, buf + pos, siz - pos, 0, outline,
4648 sizeof(outline));
6062 unsigned char disbuf[128];
6163 size_t disbuflen = 0;
6264 char *triple = tokens[0];
65 int i;
6366
6467 printf("triple: %s\n", triple);
6568
66 for (int i = 1; i < ntokens; i++) {
69 for (i = 1; i < ntokens; i++) {
6770 disbuf[disbuflen++] = strtol(tokens[i], NULL, 16);
6871 if (disbuflen >= sizeof(disbuf)) {
6972 fprintf(stderr, "Warning: Too long line, truncating\n");
5757 if (LLVMIsDeclaration(f)) {
5858 printf("FunctionDeclaration: %s\n", LLVMGetValueName(f));
5959 } else {
60 LLVMBasicBlockRef bb;
61 LLVMValueRef isn;
6062 unsigned nisn = 0;
6163 unsigned nbb = 0;
6264
6365 printf("FunctionDefinition: %s [#bb=%u]\n", LLVMGetValueName(f),
6466 LLVMCountBasicBlocks(f));
6567
66 for (LLVMBasicBlockRef bb = LLVMGetFirstBasicBlock(f); bb;
68 for (bb = LLVMGetFirstBasicBlock(f); bb;
6769 bb = LLVMGetNextBasicBlock(bb)) {
6870 nbb++;
69 for (LLVMValueRef isn = LLVMGetFirstInstruction(bb); isn;
71 for (isn = LLVMGetFirstInstruction(bb); isn;
7072 isn = LLVMGetNextInstruction(isn)) {
7173 nisn++;
7274 if (LLVMIsACallInst(isn)) {
1919 int object_list_sections(void) {
2020 LLVMMemoryBufferRef MB;
2121 LLVMObjectFileRef O;
22 LLVMSectionIteratorRef sect;
2223 char *msg = NULL;
2324
2425 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
3233 exit(1);
3334 }
3435
35 LLVMSectionIteratorRef sect = LLVMGetSections(O);
36 sect = LLVMGetSections(O);
3637 while (!LLVMIsSectionIteratorAtEnd(O, sect)) {
3738 printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect),
3839 LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect));
5051 int object_list_symbols(void) {
5152 LLVMMemoryBufferRef MB;
5253 LLVMObjectFileRef O;
54 LLVMSectionIteratorRef sect;
55 LLVMSymbolIteratorRef sym;
5356 char *msg = NULL;
5457
5558 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
6366 exit(1);
6467 }
6568
66 LLVMSectionIteratorRef sect = LLVMGetSections(O);
67 LLVMSymbolIteratorRef sym = LLVMGetSymbols(O);
69 sect = LLVMGetSections(O);
70 sym = LLVMGetSymbols(O);
6871 while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
6972
7073 LLVMMoveToContainingSection(sect, sym);
1414 #include
1515
1616 int targets_list(void) {
17 LLVMTargetRef t;
1718 LLVMInitializeAllTargetInfos();
1819 LLVMInitializeAllTargets();
1920
20 for (LLVMTargetRef t = LLVMGetFirstTarget(); t; t = LLVMGetNextTarget(t)) {
21 for (t = LLVMGetFirstTarget(); t; t = LLVMGetNextTarget(t)) {
2122 printf("%s", LLVMGetTargetName(t));
2223 if (LLVMTargetHasJIT(t))
2324 printf(" (+jit)");