From: David Schleef Date: Sat, 28 Mar 2009 07:00:49 +0000 (-0700) Subject: Add a compile/disassemble/diff test function X-Git-Tag: orc-0.4.0~81 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=505e0369d0f3ab89a3682d875d7ad8af8ea1bc52;p=platform%2Fupstream%2Forc.git Add a compile/disassemble/diff test function --- diff --git a/orc-test/orctest.c b/orc-test/orctest.c index 64fb0b3..05b935d 100644 --- a/orc-test/orctest.c +++ b/orc-test/orctest.c @@ -1,10 +1,77 @@ #include +#include +#include + void orc_test_init (void) { + orc_init (); + +} + + + + +int +orc_test_gcc_compile (OrcProgram *p) +{ + char cmd[200]; + int ret; + FILE *file; + + ret = orc_program_compile (p); + if (!ret) { + return FALSE; + } + fflush (stdout); + + file = fopen ("tmp.s", "w"); + fprintf(file, "%s", orc_program_get_asm_code (p)); + fclose (file); + + file = fopen ("dump", "w"); + ret = fwrite(p->code, p->code_size, 1, file); + fclose (file); + + ret = system ("gcc -Wall -c tmp.s"); + if (ret != 0) { + printf("gcc failed\n"); + return FALSE; + } + + ret = system ("objdump -dr tmp.o >tmp.dis"); + if (ret != 0) { + printf("objdump failed\n"); + return FALSE; + } + + sprintf (cmd, "objcopy -I binary -O elf32-i386 -B i386 " + "--rename-section .data=.text " + "--redefine-sym _binary_dump_start=%s " + "dump tmp.o", p->name); + ret = system (cmd); + if (ret != 0) { + printf("objcopy failed\n"); + return FALSE; + } + + ret = system ("objdump -Dr tmp.o >tmp-dump.dis"); + if (ret != 0) { + printf("objdump failed\n"); + return FALSE; + } + + ret = system ("diff -u tmp.dis tmp-dump.dis"); + if (ret != 0) { + printf("diff failed\n"); + return FALSE; + } + + return TRUE; } + diff --git a/orc-test/orctest.h b/orc-test/orctest.h index 6b08953..a8ca59f 100644 --- a/orc-test/orctest.h +++ b/orc-test/orctest.h @@ -8,6 +8,7 @@ ORC_BEGIN_DECLS void orc_test_init (void); +int orc_test_gcc_compile (OrcProgram *p); ORC_END_DECLS