summaryrefslogtreecommitdiff
path: root/orc-test
diff options
context:
space:
mode:
authorGuillaume Emont <guijemont@igalia.com>2012-10-29 16:54:33 +0100
committerGuillaume Emont <guijemont@igalia.com>2012-12-28 15:17:45 +0100
commit89e32ea1fb2661c2bac6dc5336b227b408ec8dea (patch)
tree28b2785bccc7836b9484e92fa4e2cfc441d73b31 /orc-test
parentf06fda5e673e8f44cbe0b090c3745fa74428cad4 (diff)
mips: added test for binary code generation
Diffstat (limited to 'orc-test')
-rw-r--r--orc-test/orctest.c96
-rw-r--r--orc-test/orctest.h1
2 files changed, 97 insertions, 0 deletions
diff --git a/orc-test/orctest.c b/orc-test/orctest.c
index 7cd08af..814e641 100644
--- a/orc-test/orctest.c
+++ b/orc-test/orctest.c
@@ -1055,3 +1055,99 @@ orc_test_performance_full (OrcProgram *program, int flags,
return ave/(n*m);
}
+#define MIPS_PREFIX "mipsel-linux-gnu-"
+
+OrcTestResult
+orc_test_gcc_compile_mips (OrcProgram *p)
+{
+ char cmd[300];
+ char *base;
+ char source_filename[100];
+ char obj_filename[100];
+ char dis_filename[100];
+ char dump_filename[100];
+ char dump_dis_filename[100];
+ int ret;
+ FILE *file;
+ OrcCompileResult result;
+ OrcTarget *target;
+ unsigned int flags;
+
+ base = "temp-orc-test";
+
+ sprintf(source_filename, "%s-source.s", base);
+ sprintf(obj_filename, "%s.o", base);
+ sprintf(dis_filename, "%s-source.dis", base);
+ sprintf(dump_filename, "%s-dump.bin", base);
+ sprintf(dump_dis_filename, "%s-dump.dis", base);
+
+ target = orc_target_get_by_name ("mips");
+ flags = orc_target_get_default_flags (target);
+ flags |= ORC_TARGET_CLEAN_COMPILE;
+
+ result = orc_program_compile_full (p, target, flags);
+ if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result)) {
+ //printf (" no code generated: %s\n", orc_program_get_error (p));
+ return ORC_TEST_INDETERMINATE;
+ }
+
+ fflush (stdout);
+
+ file = fopen (source_filename, "w");
+ fprintf(file, "%s", orc_target_get_preamble (target));
+ fprintf(file, "%s", orc_program_get_asm_code (p));
+ fclose (file);
+
+ file = fopen (dump_filename, "w");
+ ret = fwrite(p->orccode->code, p->orccode->code_size, 1, file);
+ fclose (file);
+
+ sprintf (cmd, MIPS_PREFIX "gcc -mips32r2 -mdspr2 -Wall "
+ "-c %s -o %s", source_filename, obj_filename);
+ ret = system (cmd);
+ if (ret != 0) {
+ ORC_ERROR ("mips gcc failed");
+ return ORC_TEST_INDETERMINATE;
+ }
+
+ sprintf (cmd, MIPS_PREFIX "objdump -Dr -j .text %s >%s", obj_filename, dis_filename);
+ ret = system (cmd);
+ if (ret != 0) {
+ ORC_ERROR ("objdump failed");
+ return ORC_TEST_INDETERMINATE;
+ }
+
+ sprintf (cmd, MIPS_PREFIX "objcopy -I binary "
+ "-O elf32-tradlittlemips -B mips:isa32r2 "
+ "--rename-section .data=.text "
+ "--redefine-sym _binary_temp_orc_test_dump_bin_start=%s "
+ "%s %s", p->name, dump_filename, obj_filename);
+ ret = system (cmd);
+ if (ret != 0) {
+ printf("objcopy failed\n");
+ return ORC_TEST_INDETERMINATE;
+ }
+
+ sprintf (cmd, MIPS_PREFIX "objdump -Dr %s >%s", obj_filename, dump_dis_filename);
+ ret = system (cmd);
+ if (ret != 0) {
+ printf("objdump failed\n");
+ return ORC_TEST_INDETERMINATE;
+ }
+
+ sprintf (cmd, "diff -u %s %s", dis_filename, dump_dis_filename);
+ ret = system (cmd);
+ if (ret != 0) {
+ printf("diff failed\n");
+ return ORC_TEST_FAILED;
+ }
+
+ remove (source_filename);
+ remove (obj_filename);
+ remove (dis_filename);
+ remove (dump_filename);
+ remove (dump_dis_filename);
+
+ return ORC_TEST_OK;
+}
+
diff --git a/orc-test/orctest.h b/orc-test/orctest.h
index 53d15c9..4aab067 100644
--- a/orc-test/orctest.h
+++ b/orc-test/orctest.h
@@ -21,6 +21,7 @@ void orc_test_init (void);
OrcTestResult orc_test_gcc_compile (OrcProgram *p);
OrcTestResult orc_test_gcc_compile_neon (OrcProgram *p);
OrcTestResult orc_test_gcc_compile_c64x (OrcProgram *p);
+OrcTestResult orc_test_gcc_compile_mips (OrcProgram *p);
void orc_test_random_bits (void *data, int n_bytes);
OrcTestResult orc_test_compare_output (OrcProgram *program);
OrcTestResult orc_test_compare_output_full (OrcProgram *program, int flags);