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;
+}
+
--- /dev/null
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <orc/orc.h>
+#include <orc-test/orctest.h>
+
+
+int error = FALSE;
+
+void test_opcode (OrcStaticOpcode *opcode);
+void test_opcode_const (OrcStaticOpcode *opcode);
+void test_opcode_param (OrcStaticOpcode *opcode);
+
+int
+main (int argc, char *argv[])
+{
+ int i;
+ OrcOpcodeSet *opcode_set;
+
+ orc_init();
+ orc_test_init();
+
+ opcode_set = orc_opcode_set_get ("sys");
+
+ for(i=0;i<opcode_set->n_opcodes;i++){
+ printf("/* %s %d,%d,%d */\n",
+ opcode_set->opcodes[i].name,
+ opcode_set->opcodes[i].dest_size[0],
+ opcode_set->opcodes[i].src_size[0],
+ opcode_set->opcodes[i].src_size[1]);
+ test_opcode (opcode_set->opcodes + i);
+ }
+ for(i=0;i<opcode_set->n_opcodes;i++){
+ printf("/* %s const %d,%d,%d */\n",
+ opcode_set->opcodes[i].name,
+ opcode_set->opcodes[i].dest_size[0],
+ opcode_set->opcodes[i].src_size[0],
+ opcode_set->opcodes[i].src_size[1]);
+ test_opcode_const (opcode_set->opcodes + i);
+ }
+ for(i=0;i<opcode_set->n_opcodes;i++){
+ printf("/* %s param %d,%d,%d */\n",
+ opcode_set->opcodes[i].name,
+ opcode_set->opcodes[i].dest_size[0],
+ opcode_set->opcodes[i].src_size[0],
+ opcode_set->opcodes[i].src_size[1]);
+ test_opcode_param (opcode_set->opcodes + i);
+ }
+
+ if (error) return 1;
+ return 0;
+}
+
+void
+test_opcode (OrcStaticOpcode *opcode)
+{
+ OrcProgram *p;
+ OrcTestResult ret;
+
+ p = orc_test_get_program_for_opcode (opcode);
+ if (!p) return;
+
+ ret = orc_test_gcc_compile_mips (p);
+ if (ret == ORC_TEST_FAILED) {
+ printf("%s", orc_program_get_asm_code (p));
+ error = TRUE;
+ return;
+ }
+
+ orc_program_free (p);
+}
+
+void
+test_opcode_const (OrcStaticOpcode *opcode)
+{
+ OrcProgram *p;
+ OrcTestResult ret;
+
+ p = orc_test_get_program_for_opcode_const (opcode);
+ if (!p) return;
+
+ ret = orc_test_gcc_compile_mips (p);
+ if (ret == ORC_TEST_FAILED) {
+ printf("%s", orc_program_get_asm_code (p));
+ error = TRUE;
+ return;
+ }
+
+ orc_program_free (p);
+}
+
+void
+test_opcode_param (OrcStaticOpcode *opcode)
+{
+ OrcProgram *p;
+ OrcTestResult ret;
+
+ p = orc_test_get_program_for_opcode_param (opcode);
+ if (!p) return;
+
+ ret = orc_test_gcc_compile_mips (p);
+ if (ret == ORC_TEST_FAILED) {
+ printf("%s", orc_program_get_asm_code (p));
+ error = TRUE;
+ return;
+ }
+
+ orc_program_free (p);
+}
+
+