diff --git a/tools/llvm-c-test/calc.c b/tools/llvm-c-test/calc.c index c34ff7baf0c..3119ccf8e9a 100644 --- a/tools/llvm-c-test/calc.c +++ b/tools/llvm-c-test/calc.c @@ -44,8 +44,9 @@ static LLVMValueRef build_from_tokens(char **tokens, int ntokens, LLVMValueRef param) { LLVMValueRef stack[MAX_DEPTH]; int depth = 0; + int i; - for (int i = 0; i < ntokens; i++) { + for (i = 0; i < ntokens; i++) { char tok = tokens[i][0]; switch (tok) { case '+': @@ -66,16 +67,19 @@ static LLVMValueRef build_from_tokens(char **tokens, int ntokens, break; - case '@': + case '@': { + LLVMValueRef off; + if (depth < 1) { printf("stack underflow\n"); return NULL; } - LLVMValueRef off = LLVMBuildGEP(builder, param, &stack[depth - 1], 1, ""); + off = LLVMBuildGEP(builder, param, &stack[depth - 1], 1, ""); stack[depth - 1] = LLVMBuildLoad(builder, off, ""); break; + } default: { char *end; @@ -108,6 +112,8 @@ static LLVMValueRef build_from_tokens(char **tokens, int ntokens, static void handle_line(char **tokens, int ntokens) { char *name = tokens[0]; + LLVMValueRef param; + LLVMValueRef res; LLVMModuleRef M = LLVMModuleCreateWithName(name); @@ -119,11 +125,10 @@ static void handle_line(char **tokens, int ntokens) { LLVMBuilderRef builder = LLVMCreateBuilder(); LLVMPositionBuilderAtEnd(builder, LLVMAppendBasicBlock(F, "entry")); - LLVMValueRef param; LLVMGetParams(F, ¶m); LLVMSetValueName(param, "in"); - LLVMValueRef res = build_from_tokens(tokens + 1, ntokens - 1, builder, param); + res = build_from_tokens(tokens + 1, ntokens - 1, builder, param); if (res) { char *irstr = LLVMPrintModuleToString(M); puts(irstr); diff --git a/tools/llvm-c-test/disassemble.c b/tools/llvm-c-test/disassemble.c index 4b3d37b7d94..eb40bf3d446 100644 --- a/tools/llvm-c-test/disassemble.c +++ b/tools/llvm-c-test/disassemble.c @@ -20,8 +20,9 @@ #include static void pprint(int pos, unsigned char *buf, int len, const char *disasm) { + int i; printf("%04x: ", pos); - for (int i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) { if (i < len) { printf("%02x ", buf[i]); } else { @@ -34,14 +35,15 @@ static void pprint(int pos, unsigned char *buf, int len, const char *disasm) { static void do_disassemble(const char *triple, unsigned char *buf, int siz) { LLVMDisasmContextRef D = LLVMCreateDisasm(triple, NULL, 0, NULL, NULL); + char outline[1024]; + int pos; if (!D) { printf("ERROR: Couldn't create disassebler for triple %s\n", triple); return; } - char outline[1024]; - int pos = 0; + pos = 0; while (pos < siz) { size_t l = LLVMDisasmInstruction(D, buf + pos, siz - pos, 0, outline, sizeof(outline)); @@ -61,10 +63,11 @@ static void handle_line(char **tokens, int ntokens) { unsigned char disbuf[128]; size_t disbuflen = 0; char *triple = tokens[0]; + int i; printf("triple: %s\n", triple); - for (int i = 1; i < ntokens; i++) { + for (i = 1; i < ntokens; i++) { disbuf[disbuflen++] = strtol(tokens[i], NULL, 16); if (disbuflen >= sizeof(disbuf)) { fprintf(stderr, "Warning: Too long line, truncating\n"); diff --git a/tools/llvm-c-test/module.c b/tools/llvm-c-test/module.c index 50e6e9c6de1..180238664f6 100644 --- a/tools/llvm-c-test/module.c +++ b/tools/llvm-c-test/module.c @@ -58,16 +58,18 @@ int module_list_functions(void) { if (LLVMIsDeclaration(f)) { printf("FunctionDeclaration: %s\n", LLVMGetValueName(f)); } else { + LLVMBasicBlockRef bb; + LLVMValueRef isn; unsigned nisn = 0; unsigned nbb = 0; printf("FunctionDefinition: %s [#bb=%u]\n", LLVMGetValueName(f), LLVMCountBasicBlocks(f)); - for (LLVMBasicBlockRef bb = LLVMGetFirstBasicBlock(f); bb; + for (bb = LLVMGetFirstBasicBlock(f); bb; bb = LLVMGetNextBasicBlock(bb)) { nbb++; - for (LLVMValueRef isn = LLVMGetFirstInstruction(bb); isn; + for (isn = LLVMGetFirstInstruction(bb); isn; isn = LLVMGetNextInstruction(isn)) { nisn++; if (LLVMIsACallInst(isn)) { diff --git a/tools/llvm-c-test/object.c b/tools/llvm-c-test/object.c index c94e3af3b07..27929286542 100644 --- a/tools/llvm-c-test/object.c +++ b/tools/llvm-c-test/object.c @@ -20,6 +20,7 @@ int object_list_sections(void) { LLVMMemoryBufferRef MB; LLVMObjectFileRef O; + LLVMSectionIteratorRef sect; char *msg = NULL; if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) { @@ -33,7 +34,7 @@ int object_list_sections(void) { exit(1); } - LLVMSectionIteratorRef sect = LLVMGetSections(O); + sect = LLVMGetSections(O); while (!LLVMIsSectionIteratorAtEnd(O, sect)) { printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect), LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect)); @@ -51,6 +52,8 @@ int object_list_sections(void) { int object_list_symbols(void) { LLVMMemoryBufferRef MB; LLVMObjectFileRef O; + LLVMSectionIteratorRef sect; + LLVMSymbolIteratorRef sym; char *msg = NULL; if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) { @@ -64,8 +67,8 @@ int object_list_symbols(void) { exit(1); } - LLVMSectionIteratorRef sect = LLVMGetSections(O); - LLVMSymbolIteratorRef sym = LLVMGetSymbols(O); + sect = LLVMGetSections(O); + sym = LLVMGetSymbols(O); while (!LLVMIsSymbolIteratorAtEnd(O, sym)) { LLVMMoveToContainingSection(sect, sym); diff --git a/tools/llvm-c-test/targets.c b/tools/llvm-c-test/targets.c index fccea09fecc..252c2e02a67 100644 --- a/tools/llvm-c-test/targets.c +++ b/tools/llvm-c-test/targets.c @@ -15,10 +15,11 @@ #include int targets_list(void) { + LLVMTargetRef t; LLVMInitializeAllTargetInfos(); LLVMInitializeAllTargets(); - for (LLVMTargetRef t = LLVMGetFirstTarget(); t; t = LLVMGetNextTarget(t)) { + for (t = LLVMGetFirstTarget(); t; t = LLVMGetNextTarget(t)) { printf("%s", LLVMGetTargetName(t)); if (LLVMTargetHasJIT(t)) printf(" (+jit)");