mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
llvm-c-test: Make them C89-compliant.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193254 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e21c3137e1
commit
90fd79a222
@ -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);
|
||||
|
@ -20,8 +20,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
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");
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
@ -15,10 +15,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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)");
|
||||
|
Loading…
Reference in New Issue
Block a user