OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [cuc/] [load.c] - Diff between revs 883 and 897

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 883 Rev 897
Line 19... Line 19...
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdarg.h>
#include <assert.h>
#include <assert.h>
 
#include "sim-config.h"
#include "cuc.h"
#include "cuc.h"
#include "opcode/or32.h"
#include "opcode/or32.h"
#include "insn.h"
#include "insn.h"
 
 
static const cuc_conv conv[] = {
static const cuc_conv conv[] = {
Line 246... Line 247...
 
 
/* expands signed comparisons to three instructions */
/* expands signed comparisons to three instructions */
void expand_signed ()
void expand_signed ()
{
{
  int i, j, num_sig = 0, d;
  int i, j, num_sig = 0, d;
  for (i = 0; i < num_insn; i++) if (insn[i].type & IT_SIGNED) num_sig++;
  for (i = 0; i < num_insn; i++)
 
    if (insn[i].type & IT_SIGNED && !(insn[i].type & IT_MEMORY)) num_sig++;
 
 
  d = num_insn + num_sig * 2;
  d = num_insn + num_sig * 2;
  assert (d < MAX_INSNS);
  assert (d < MAX_INSNS);
 
 
  /* Split signed instructions */
  /* Split signed instructions */
  for (i = num_insn - 1; i >= 0; i--) if (insn[i].type & IT_SIGNED) {
  for (i = num_insn - 1; i >= 0; i--)
    /* We will expand signed memory later */
    /* We will expand signed memory later */
    if (insn[i].type & IT_MEMORY) continue;
    if (insn[i].type & IT_SIGNED && !(insn[i].type & IT_MEMORY)) {
    insn[--d] = insn[i];
    insn[--d] = insn[i];
    insn[d].op[1] = d - 2; insn[d].opt[1] = OPT_REF;
    insn[d].op[1] = d - 2; insn[d].opt[1] = OPT_REF;
    insn[d].op[2] = d - 1; insn[d].opt[2] = OPT_REF;
    insn[d].op[2] = d - 1; insn[d].opt[2] = OPT_REF;
 
 
    insn[--d] = insn[i];
    insn[--d] = insn[i];
Line 288... Line 290...
      if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
      if (insn[i].opt[j] & OPT_REF || insn[i].opt[j] & OPT_JUMP)
        insn[i].op[j] = reloc[insn[i].op[j]];
        insn[i].op[j] = reloc[insn[i].op[j]];
  } else insn[i].type &= ~IT_SIGNED;
  } else insn[i].type &= ~IT_SIGNED;
}
}
 
 
/* Loads from file into global array insn */
/* Loads function from file into global array insn.
void cuc_load (char *in_fn)
   Function returns nonzero if function cannot be converted. */
 
int cuc_load (char *in_fn)
{
{
  int i, j, in_delay;
  int i, j, in_delay;
  FILE *fi;
  FILE *fi;
  int func_return = 0;
  int func_return = 0;
  num_insn = 0;
  num_insn = 0;
Line 325... Line 328...
      } else if (strcmp (name, "l.jr") == 0 && func_return == 0) {
      } else if (strcmp (name, "l.jr") == 0 && func_return == 0) {
        func_return = 1;
        func_return = 1;
        change_insn_type (&insn[i], II_NOP);
        change_insn_type (&insn[i], II_NOP);
        continue;
        continue;
      } else {
      } else {
        fprintf (stderr, "Instruction #%i: \"%s\" not supported.\n", i, name);
        cucdebug (1, "Instruction #%i: \"%s\" not supported.\n", i, name);
        exit (1);
        log ("Instruction #%i: \"%s\" not supported.\n", i, name);
 
        return 1;
      }
      }
      if (f < 0) { /* l.j */
      if (f < 0) { /* l.j */
        /* repair params */
        /* repair params */
        change_insn_type (&insn[i], II_BF);
        change_insn_type (&insn[i], II_BF);
        insn[i].op[0] = i + insn[i].op[0]; insn[i].opt[0] = OPT_JUMP;
        insn[i].op[0] = i + insn[i].op[0]; insn[i].opt[0] = OPT_JUMP;
Line 368... Line 372...
          if (conv[j].to & II_SIGNED) insn[i].type |= IT_SIGNED;
          if (conv[j].to & II_SIGNED) insn[i].type |= IT_SIGNED;
          if (conv[j].to & II_MEM) insn[i].type |= IT_MEMORY | IT_VOLATILE;
          if (conv[j].to & II_MEM) insn[i].type |= IT_MEMORY | IT_VOLATILE;
          change_insn_type (&insn[i], conv[j].to & II_MASK);
          change_insn_type (&insn[i], conv[j].to & II_MASK);
          break;
          break;
        }
        }
      if (insn[i].index < 0) {
      if (insn[i].index < 0 || insn[i].index == II_NOP && insn[i].op[0] != 0) {
        fprintf (stderr, "Instruction #%i: \"%s\" not supported (2).\n", i, name);
        cucdebug (1, "Instruction #%i: \"%s\" not supported (2).\n", i, name);
        exit (1);
        log ("Instruction #%i: \"%s\" not supported (2).\n", i, name);
 
        return 1;
      }
      }
    }
    }
  }
  }
  num_insn = i;
  num_insn = i;
  fclose (fi);
  fclose (fi);
  if (func_return != 2) {
  if (func_return != 2) {
    fprintf (stderr, "Unsupported function structure.\n");
    cucdebug (1, "Unsupported function structure.\n");
    exit (1);
    log ("Unsupported function structure.\n");
 
    return 1;
  }
  }
 
 
  log ("Number of instructions loaded = %i\n", num_insn);
  log ("Number of instructions loaded = %i\n", num_insn);
  if (cuc_debug >= 3) print_cuc_insns ("INITIAL", 1);
  if (cuc_debug >= 3) print_cuc_insns ("INITIAL", 1);
 
 
  log ("Converting.\n");
  log ("Converting.\n");
  remove_dslots ();
  remove_dslots ();
  if (cuc_debug >= 6) print_cuc_insns ("NO_DELAY_SLOTS", 0);
  if (cuc_debug >= 6) print_cuc_insns ("NO_DELAY_SLOTS", 0);
 
 
  if (calling_convention) {
  if (config.cuc.calling_convention) {
    detect_locals ();
    detect_locals ();
    if (cuc_debug >= 7) print_cuc_insns ("AFTER_LOCALS", 0);
    if (cuc_debug >= 7) print_cuc_insns ("AFTER_LOCALS", 0);
  }
  }
  expand_memory ();
  expand_memory ();
  if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_MEM", 0);
  if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_MEM", 0);
 
 
  expand_signed ();
  expand_signed ();
  if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_SIG", 0);
  if (cuc_debug >= 3) print_cuc_insns ("AFTER_EXP_SIG", 0);
 
  return 0;
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.