示例#1
0
void emit_ta_code (FILE* outfile, astree* root) {
   if (root == NULL) return;
   preorder(root);
   emit_prefix(outfile);
   emit_main(root, outfile);
   free (struct_prefix);
   free (func_prefix);
   free (var_prefix);
   free (strcon_prefix);
   free (main_string);
   free_syms();

}
示例#2
0
//--------------------------------------------------------------------------
static void load_symbols(const char *file)
{
  free_syms();
  if ( file == NULL )
    return;
  char cfgpath[QMAXPATH];
  const char *rfile = getsysfile(cfgpath, sizeof(cfgpath), file, CFG_SUBDIR);
  if ( rfile == NULL )
  {
NOFILE:
//    warning("Can't open %s, symbol definitions are not loaded", file);
    return;
  }
  FILE *fp = fopenRT(rfile);
  if ( fp == NULL )
    goto NOFILE;
  int ln = 0;
  char line[MAXSTR];
  while ( qfgets(line, sizeof(line), fp) )
  {
    ln++;
    line[strlen(line)-1] = '\0';
    trim(line);
    if ( line[0] == ';' || line[0] == ' ' || line[0] == '\0' ) continue;
    char word[MAXSTR];
    int addr;
    if ( sscanf(line, "%s %i", word, &addr) != 2 )
    {
      warning("%s: syntax error at line %d", file, ln);
      break;
    }
    int i;
    for ( i=0; i < numsyms; i++)
    {
      if ( syms[i].address == addr && strcmp(syms[i].name, word) != 0 )
      {
        warning("%s: duplicate address %#x at line %d", file, addr, ln);
        break;
      }
    }
    if ( i != numsyms ) break;
    syms = qrealloc_array<sym_t>(syms, numsyms + 1);
    if ( syms == NULL ) nomem("h8/500 symbols");
    syms[numsyms].address = addr;
    syms[numsyms].name = qstrdup(word);
    numsyms++;
  }
  qfclose(fp);
}
示例#3
0
static int notify(processor_t::idp_notify msgid, ...)
{
  va_list va;
  va_start(va, msgid);

// A well behaving processor module should call invoke_callbacks()
// in his notify() function. If this function returns 0, then
// the processor module should process the notification itself
// Otherwise the code should be returned to the caller:

  int code = invoke_callbacks(HT_IDP, msgid, va);
  if ( code ) return code;

  switch ( msgid )
  {
    case processor_t::init:
//      __emit__(0xCC);   // debugger trap
      helper.create("$ h8/500");
      inf.mf = 1;
    default:
      break;

    case processor_t::term:
      free_syms();
      break;

    case processor_t::oldfile:   // old file loaded
      idpflags = ushort(helper.altval(-1) + 1);
      create_segment_registers();
      // no break
    case processor_t::newfile:   // new file loaded
      load_symbols("h8500.cfg");
      inf.mf = 1;
      break;

    case processor_t::closebase:
    case processor_t::savebase:
      helper.altset(-1, idpflags - 1);
      break;

    case processor_t::newseg:    // new segment
      {
        segment_t *sptr = va_arg(va, segment_t *);
        sptr->defsr[BR-ph.regFirstSreg] = 0;
        sptr->defsr[DP-ph.regFirstSreg] = 0;
      }
      break;

    case processor_t::is_jump_func:
      {
        const func_t *pfn = va_arg(va, const func_t *);
        ea_t *jump_target = va_arg(va, ea_t *);
        return is_jump_func(pfn, jump_target);
      }

    case processor_t::is_sane_insn:
      return is_sane_insn(va_arg(va, int));

    case processor_t::may_be_func:
                                // can a function start here?
                                // arg: none, the instruction is in 'cmd'
                                // returns: probability 0..100
                                // 'cmd' structure is filled upon the entrace
                                // the idp module is allowed to modify 'cmd'
      return may_be_func();

  }
  va_end(va);
  return 1;
}