Beispiel #1
0
/* split a line into words */
static int
split_words (char **result_word, char *str)
{
    static const char delim[] = " \f\n\r\t\v,";
    char *token;
    int num_words;

    /* release previously allocated words */
    for (num_words = 0; num_words < SPLIT_WORDS_MAX; num_words++)
    {
        if (result_word[num_words])
        {
            free (result_word[num_words]);
            result_word[num_words] = NULL;
        } // if
    } // for

    /* split line */
    token = strtok (str, delim);
    num_words = 0;
    while (token && (num_words < SPLIT_WORDS_MAX))
    {
        result_word[num_words] = Safe_strdup (token);
        num_words++;
        token = strtok (NULL, delim);
    } // while

    return num_words;
}
Beispiel #2
0
/* create a structure for a pic processor */
static PIC_device *
create_pic (char *pic_name, int maxram, int bankmsk, int confsiz,
            int config[MAX_NUM_CONFIGS], int program, int data, int eeprom,
            int io, int is_enhanced)
{
  PIC_device *new_pic;
  char *simple_pic_name = sanitise_processor_name (pic_name);

  new_pic = Safe_calloc (1, sizeof (PIC_device));
  new_pic->name = Safe_strdup (simple_pic_name);

  new_pic->defMaxRAMaddrs = maxram;
  new_pic->bankMask = bankmsk;
  new_pic->num_configs = confsiz;
  memcpy(new_pic->config, config, MAX_NUM_CONFIGS * sizeof(int));

  new_pic->programMemSize = program;
  new_pic->dataMemSize = data;
  new_pic->eepromMemSize = eeprom;
  new_pic->ioPins = io;
  new_pic->isEnhancedCore = is_enhanced;

  new_pic->ram = rangeRAM;

  Pics[num_of_supported_PICS] = new_pic;
  num_of_supported_PICS++;

  return new_pic;
}
Beispiel #3
0
/* create a structure for a pic processor */
static PIC_device *
create_pic (char *pic_name, int maxram, int bankmsk, int confsiz,
            int program, int data, int eeprom, int io)
{
    PIC_device *new_pic;
    char *simple_pic_name = sanitise_processor_name (pic_name);

    new_pic = Safe_calloc (1, sizeof (PIC_device));
    new_pic->name = Safe_strdup (simple_pic_name);

    new_pic->defMaxRAMaddrs = maxram;
    new_pic->bankMask = bankmsk;
    new_pic->hasSecondConfigReg = confsiz > 1;

    new_pic->programMemSize = program;
    new_pic->dataMemSize = data;
    new_pic->eepromMemSize = eeprom;
    new_pic->ioPins = io;

    new_pic->ram = rangeRAM;

    Pics[num_of_supported_PICS] = new_pic;
    num_of_supported_PICS++;

    return new_pic;
}
Beispiel #4
0
/** Given a file with path information in the binary files directory,
    returns what PREFIX must be to get this path.  Used for discovery
    of where SDCC is installed.  Returns NULL if the path is
    impossible.
*/
char *
getPrefixFromBinPath (const char *prel)
{
  strcpy(scratchFileName, prel);
  /* Strip off the /sdcc at the end */
  *strrchr(scratchFileName, DIR_SEPARATOR_CHAR) = '\0';
  /* Compute what the difference between the prefix and the bin dir
     should be. */
  getPathDifference (buffer, PREFIX, BINDIR);

  /* Verify that the path in has the expected suffix */
  if (strlen(buffer) > strlen(scratchFileName))
    {
      /* Not long enough */
      return NULL;
    }

  if (pathEquivalent (buffer, scratchFileName + strlen(scratchFileName) - strlen(buffer)) == FALSE)
    {
      /* Doesn't match */
      return NULL;
    }

  scratchFileName[strlen(scratchFileName) - strlen(buffer)] = '\0';

  return Safe_strdup (scratchFileName);
}
Beispiel #5
0
/*-----------------------------------------------------------------*/
static void
add_line_node (const char *line)
{
  lineNode *pl;

  pl = Safe_alloc (sizeof (lineNode));

#if 1
  memcpy (pl, (lineElem_t *) & genLine.lineElement, sizeof (lineElem_t));
#else
  pl->ic = genLine.lineElement.ic;
  pl->isInline = genLine.lineElement.isInline;
  pl->isComment = genLine.lineElement.isComment;
  pl->isDebug = genLine.lineElement.isDebug;
  pl->isLabel = genLine.lineElement.isLabel;
  pl->visited = genLine.lineElement.visited;
  pl->aln = genLine.lineElement.aln;
#endif

  pl->line = Safe_strdup (line);

  if (genLine.lineCurr)
    {
      pl->next = NULL;
      genLine.lineCurr->next = pl;
      pl->prev = genLine.lineCurr;
      genLine.lineCurr = pl;
    }
  else
    {
      pl->prev = pl->next = NULL;
      genLine.lineCurr = genLine.lineHead = pl;
    }
}
Beispiel #6
0
static bool _pblaze_parseOptions(int *pargc, char **argv, int *i)
{
    char *dialecttype;

    if (ISOPT(DIALECT_OPT)) {
      dialecttype = getStringArg(DIALECT_OPT, argv, i, *pargc);
    	if (!STRCASECMP(dialecttype, "pblazeide"))
    	    pblaze_options.dialect = 0;
    	else if (!STRCASECMP(dialecttype, "kcpsm3"))
    	    pblaze_options.dialect = 1;
    	else {
    	    fprintf(stderr, "Unknown dialect type: %s\nAvaiable options: pblazeide or kcpsm3\n", dialecttype);
    	    exit(EXIT_FAILURE);
    	}
	    return TRUE;
    }
    
    if (ISOPT(PORTKW_OPT)) {
        pblaze_options.portKw = Safe_strdup(getStringArg(PORTKW_OPT, argv, i, *pargc));
        return TRUE;
    }

    if (ISOPT(ACKNOWLEDGEMENT_OPT)) {
	    fprintf(stderr, "The development of this pblaze-port was supported by the Czech Ministry of Education, Youth and Sports grant 2C06008 Virtual Laboratory of Microprocessor Technology Application (visit the website http://www.vlam.cz).");
	    exit(EXIT_FAILURE);
	    return TRUE;
    }

    return FALSE;
}
Beispiel #7
0
/*-----------------------------------------------------------------*/
lineNode *
newLineNode (const char *line)
{
  lineNode *pl;

  pl = Safe_alloc (sizeof (lineNode));
  pl->line = Safe_strdup (line);
  pl->ic = NULL;
  return pl;
}
Beispiel #8
0
void 
shash_add (hTab ** h, const char *szKey, const char *szValue)
{
  char *val;
  int key = _hash (szKey);

  /* Find value of the item */
  val = (char *)hTabFindByKey(*h, key, szKey, _compare);
  /* Delete any that currently exist */
  hTabDeleteByKey(h, key, szKey, _compare);
  /* Deallocate old value in not NULL */
  if (val != NULL)
    Safe_free(val);
  /* Duplicate new value if not NULL */
  if (szValue != NULL)
    szValue = Safe_strdup(szValue);
  /* Now add in ours */
  hTabAddItemLong (h, key, Safe_strdup (szKey), (void *)szValue);
}
Beispiel #9
0
/* Mangling format:
    _fun_policy_params
    where:
      policy is the function policy
      params is the parameter format

   policy format:
    rsp
    where:
      r is 'r' for reentrant, 's' for static functions
      s is 'c' for callee saves, 'r' for caller saves
      f is 'f' for profiling on, 'x' for profiling off
    examples:
      rr - reentrant, caller saves
   params format:
    A combination of register short names and s to signify stack variables.
    examples:
      bds - first two args appear in BC and DE, the rest on the stack
      s - all arguments are on the stack.
*/
static char *
_mangleSupportFunctionName(char *original)
{
  char buffer[128];

  sprintf(buffer, "%s_rr%s_%s", original,
          options.profile ? "f" : "x",
          options.noRegParams ? "s" : "bds" /* MB: but the library only has hds variants ??? */
          );

  return Safe_strdup(buffer);
}
Beispiel #10
0
/** Given an array of string pointers and another string, adds the
    string to the end of the list.  The end of the list is assumed to
    be the first NULL pointer.
*/
void
addToList (const char **list, const char *str)
{
  /* This is the bad way to do things :) */
  while (*list)
    list++;
  *list = Safe_strdup (str);
  if (!*list)
    {
      werror (E_OUT_OF_MEM, __FILE__, 0);
      exit (1);
    }
  *(++list) = NULL;
}
Beispiel #11
0
int
pic14_stringInSet(const char *str, set **world, int autoAdd)
{
  char *s;

  if (!str) return 1;
  assert(world);

  for (s = setFirstItem(*world); s; s = setNextItem(*world))
  {
    /* found in set */
    if (0 == strcmp(s, str)) return 1;
  }

  /* not found */
  if (autoAdd) addSet(world, Safe_strdup(str));
  return 0;
}
Beispiel #12
0
static void
_mcs51_finaliseOptions (void)
{
  if (options.noXinitOpt)
    port->genXINIT=0;

  switch (options.model)
    {
    case MODEL_SMALL:
      port->mem.default_local_map = data;
      port->mem.default_globl_map = data;
      port->s.gptr_size = 3;
      break;
    case MODEL_MEDIUM:
      port->mem.default_local_map = pdata;
      port->mem.default_globl_map = pdata;
      port->s.gptr_size = 3;
      break;
    case MODEL_LARGE:
    case MODEL_HUGE:
      port->mem.default_local_map = xdata;
      port->mem.default_globl_map = xdata;
      port->s.gptr_size = 3;
      break;
    default:
      port->mem.default_local_map = data;
      port->mem.default_globl_map = data;
      break;
    }

  if (options.parms_in_bank1)
    addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));

  /* mcs51 has an assembly coded float library that's almost always reentrant */
  if (!options.useXstack)
    options.float_rent = 1;

  if (options.omitFramePtr)
    port->stack.reent_overhead = 0;

  /* set up external stack location if not explicitly specified */
  if (!options.xstack_loc)
    options.xstack_loc = options.xdata_loc;
}
Beispiel #13
0
static void
_pic14_finaliseOptions (void)
{
  struct dbuf_s dbuf;

  pCodeInitRegisters();

  port->mem.default_local_map = data;
  port->mem.default_globl_map = data;

  dbuf_init (&dbuf, 512);
  dbuf_printf (&dbuf, "-D__SDCC_PROCESSOR=\"%s\"", port->processor);
  addSet (&preArgvSet, Safe_strdup (dbuf_detach_c_str (&dbuf)));

    {
      char *upperProc, *p1, *p2;
      int len;

      dbuf_set_length (&dbuf, 0);
      len = strlen (port->processor);
      upperProc = Safe_malloc (len);
      for (p1 = port->processor, p2 = upperProc; *p1; ++p1, ++p2)
        {
          *p2 = toupper (*p1);
        }
      dbuf_append (&dbuf, "-D__SDCC_PIC", sizeof ("-D__SDCC_PIC") - 1);
      dbuf_append (&dbuf, upperProc, len);
      addSet (&preArgvSet, dbuf_detach_c_str (&dbuf));
    }

  if (!pic14_options.no_warn_non_free && !options.use_non_free)
    {
      fprintf(stderr,
              "WARNING: Command line option --use-non-free not present.\n"
              "         When compiling for PIC14/PIC16, please provide --use-non-free\n"
              "         to get access to device headers and libraries.\n"
              "         If you do not use these, you may provide --no-warn-non-free\n"
              "         to suppress this warning (not recommended).\n");
    } // if

}
Beispiel #14
0
int
main(int argc, char *argv[]){

	int c;

	static struct option long_options[] = {
		{"netbackup-service-host", required_argument, NULL, 1},
		{"netbackup-filename", required_argument, NULL, 2},
		{"netbackup-block-size", required_argument, NULL, 3},
		{NULL, 0, NULL, 0}
	};

	int optindex;
	progname = (char *)get_progname(argv[0]);

	if (argc > 1)
	{
		if ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-?") == 0))
		{
			help(progname);
			exit(0);
		}
		if ((strcmp(argv[1], "--version") == 0) || (strcmp(argv[1], "-V") == 0))
		{
			puts("pg_dump (PostgreSQL) " PG_VERSION);
			exit(0);
		}
	}

	while((c = getopt_long(argc, argv, "123", long_options, &optindex)) != -1)
	{
		switch(c)
		{
			case 1:
				netbackupServiceHost = Safe_strdup(optarg);
				break;
			case 2:
				netbackupRestoreFilename = Safe_strdup(optarg);
				break;
			case 3:
				netbackupBlockSize = atoi(optarg);
				break;
			default:
				fprintf(stderr, _("Wrong option entered. Try \"%s --help\" for more information.\n"), progname);
				exit(1);
		}
	}

	if (optind < argc)
	{
		fprintf(stderr, _("%s: Too many command-line arguments (first is \"%s\")\n"), progname, argv[optind + 1]);
		fprintf(stderr, _("Try \"%s --help\" for more information\n"), progname);
		exit(1);
	}

	if (netbackupServiceHost == NULL)
	{
		mpp_err_msg("ERROR", "gp_bsa_dump_agent", "Need to provide --netbackup-service-host mandatory param.\nTry \"%s --help\" for more information\n", progname);
		exit(1);
	}

	if (netbackupRestoreFilename == NULL)
	{
		mpp_err_msg("ERROR", "gp_bsa_dump_agent", "Need to provide NetBackup Dump File Path.\nTry \"%s --help\" for more information\n", progname);
		exit(1);
	}

	BackupFilePathLength = strlen(netbackupRestoreFilename);
	BackupFilePathName = (char *)malloc(sizeof(char) *(1 + BackupFilePathLength));
	if(BackupFilePathName == NULL){
		mpp_err_msg("ERROR", "gp_bsa_restore_agent", "Failed to allocate memory for Restore Filename\n");
		exit(1);
	}
	memset(BackupFilePathName, 0x00, (1 + BackupFilePathLength));
	strncpy(BackupFilePathName, netbackupRestoreFilename, (1 + BackupFilePathLength));

	NetBackupServiceHost = (char *)malloc(sizeof(char) *(1 + strlen(netbackupServiceHost)));
	if(NetBackupServiceHost == NULL){
		mpp_err_msg("ERROR", "gp_bsa_dump_agent", "Failed to allocate memory for NetBackup Service Hostname\n");
		exit(1);
	}
	memset(NetBackupServiceHost, 0x00, (1 + strlen(netbackupServiceHost)));
	strncpy(NetBackupServiceHost, netbackupServiceHost, (1 + strlen(netbackupServiceHost)));

	if(initBSARestoreSession(NetBackupServiceHost) != 0){
		mpp_err_msg("ERROR", "gp_bsa_restore_agent", "Failed to initialize the NetBackup BSA session to perform Restore\n");
		exit(1);
	}

	if(getBSARestoreObject(BackupFilePathName) != 0){
		mpp_err_msg("ERROR", "gp_bsa_restore_agent", "Failed to get the NetBackup BSA restore object to perform Restore\n");
		exit(1);
	}

	if(getBSARestoreData(netbackupBlockSize) != 0){
		mpp_err_msg("ERROR", "gp_bsa_restore_agent", "Failed to get data from NetBackup in order to perform Restore\n");
		exit(1);
	}

	if(endBSARestoreSession() != 0){
		mpp_err_msg("ERROR", "gp_bsa_restore_agent", "Failed to end the NetBackup BSA session after completion of Restore\n");
		exit(1);
	}

	free(BackupFilePathName);
	free(NetBackupServiceHost);
	free(netbackupRestoreFilename);
	free(netbackupServiceHost);
	exit(0);
}
Beispiel #15
0
static bool
_json_parseOptions (int *pargc, char **argv, int *i)
{
	/* TODO: allow port-specific command line options to specify
	 * segment names here.
	 */
  int j=0;
  //char *stkmodel;

    /* check for arguments that have associated an integer variable */
    while(json_optionsTable[j].pparameter) {
      if(ISOPT( json_optionsTable[j].longOpt )) {
        (*(int *)json_optionsTable[j].pparameter)++;
        return TRUE;
      }
      j++;
    }
/*
    if(ISOPT(STACK_MODEL)) {
      stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc);
      if(!STRCASECMP(stkmodel, "small"))picoBlaze_options.stack_model = 0;
      else if(!STRCASECMP(stkmodel, "large"))picoBlaze_options.stack_model = 1;
      else {
        fprintf(stderr, "Unknown stack model: %s", stkmodel);
        exit(EXIT_FAILURE);
      }
      return TRUE;
    }

    if(ISOPT(IVT_LOC)) {
      picoBlaze_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
      fprintf(stderr, "%s:%d setting interrupt vector addresses 0x%x\n", __FILE__, __LINE__, picoBlaze_options.ivt_loc);
      return TRUE;
    }

    if(ISOPT(USE_CRT)) {
      picoBlaze_options.no_crt = 0;
      picoBlaze_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) );

      return TRUE;
    }

    if (ISOPT(NO_OPTIMIZE_GOTO)) {
      picoBlaze_options.opt_flags |= OF_NO_OPTIMIZE_GOTO;
      return TRUE;
    }

    if(ISOPT(OPTIMIZE_CMP)) {
      picoBlaze_options.opt_flags |= OF_OPTIMIZE_CMP;
      return TRUE;
    }

    if (ISOPT(OPTIMIZE_DF)) {
      picoBlaze_options.opt_flags |= OF_OPTIMIZE_DF;
      return TRUE;
    }
*/

	if (ISOPT(GEN_JSON)) {
		json_options.json_flag = TRUE;
		if (ISOPT(GEN_JSONFILE)) {	// inside block because JSON and JSON-FILE have common starting substring checked in arguments
			json_options.json_dumpfile = Safe_strdup( getStringArg(GEN_JSONFILE, argv, i, *pargc) );
		}
		return TRUE;
	}

  return FALSE;
}
Beispiel #16
0
static int
do_pragma(int id, const char *name, const char *cp)
{
  struct pragma_token_s token;
  int err = 0;
  int processed = 1;

  init_pragma_token(&token);

  switch (id)
    {
    case P_BANK:
      {
        struct dbuf_s buffer;

        dbuf_init(&buffer, 128);

        cp = get_pragma_token(cp, &token);

        switch (token.type)
          {
          case TOKEN_EOL:
            err = 1;
            break;

          case TOKEN_INT:
            switch (_G.asmType)
              {
              case ASM_TYPE_ASXXXX:
                dbuf_printf (&buffer, "CODE_%d", token.val.int_val);
                break;

              case ASM_TYPE_RGBDS:
                dbuf_printf (&buffer, "CODE,BANK[%d]", token.val.int_val);
                break;

              case ASM_TYPE_ISAS:
                /* PENDING: what to use for ISAS? */
                dbuf_printf (&buffer, "CODE,BANK(%d)", token.val.int_val);
                break;

              default:
                wassert (0);
              }
            break;

          default:
            {
              const char *str = get_pragma_string (&token);

              dbuf_append_str (&buffer, (0 == strcmp("BASE", str)) ? "HOME" : str);
            }
            break;
          }

        cp = get_pragma_token (cp, &token);
        if (TOKEN_EOL != token.type)
          {
            err = 1;
            break;
          }

        dbuf_c_str (&buffer);
        /* ugly, see comment in src/port.h (borutr) */
        gbz80_port.mem.code_name = dbuf_detach (&buffer);
        code->sname = gbz80_port.mem.code_name;
        options.code_seg = (char *)gbz80_port.mem.code_name;
      }
      break;

    case P_PORTMODE:
      { /*.p.t.20030716 - adding pragma to manipulate z80 i/o port addressing modes */
        const char *str;

        cp = get_pragma_token (cp, &token);

        if (TOKEN_EOL == token.type)
          {
            err = 1;
            break;
          }

        str = get_pragma_string (&token);

        cp = get_pragma_token (cp, &token);
        if (TOKEN_EOL != token.type)
          {
            err = 1;
            break;
          }

        if (!strcmp(str, "z80"))
          { z80_opts.port_mode = 80; }
        else if(!strcmp(str, "z180"))
          { z80_opts.port_mode = 180; }
        else if(!strcmp(str, "save"))
          { z80_opts.port_back = z80_opts.port_mode; }
        else if(!strcmp(str, "restore" ))
          { z80_opts.port_mode = z80_opts.port_back; }
        else
          err = 1;
      }
      break;

    case P_CODESEG:
    case P_CONSTSEG:
      {
        char *segname;

        cp = get_pragma_token (cp, &token);
        if (token.type == TOKEN_EOL)
          {
            err = 1;
            break;
          }

        segname = Safe_strdup (get_pragma_string(&token));

        cp = get_pragma_token (cp, &token);
        if (token.type != TOKEN_EOL)
          {
            Safe_free (segname);
            err = 1;
            break;
          }

        if (id == P_CODESEG)
          {
            if (options.code_seg) Safe_free(options.code_seg);
            options.code_seg = segname;
          }
        else
          {
            if (options.const_seg) Safe_free(options.const_seg);
            options.const_seg = segname;
          }
      }
      break;

    default:
      processed = 0;
      break;
  }

  get_pragma_token(cp, &token);

  if (1 == err)
    werror(W_BAD_PRAGMA_ARGUMENTS, name);

  free_pragma_token(&token);
  return processed;
}
Beispiel #17
0
/*-----------------------------------------------------------------*/
void
genInline (iCode * ic)
{
  char *buf, *bp, *begin;
  bool inComment = FALSE;

  D (emitcode (";", "genInline"));

  genLine.lineElement.isInline += (!options.asmpeep);

  buf = bp = begin = Safe_strdup (IC_INLINE (ic));

  /* Emit each line as a code */
  while (*bp)
    {
      switch (*bp)
        {
        case ';':
          inComment = TRUE;
          ++bp;
          break;

        case '\x87':
        case '\n':
          inComment = FALSE;
          *bp++ = '\0';

          /* Don't emit leading whitespaces */
          while (isspace (*begin))
            ++begin;

          if (*begin)
            emitcode (begin, NULL);

          begin = bp;
          break;

        default:
          /* Add \n for labels, not dirs such as c:\mydir */
          if (!inComment && (*bp == ':') && (isspace ((unsigned char) bp[1])))
            {
              ++bp;
              *bp = '\0';
              ++bp;
              emitcode (begin, NULL);
              begin = bp;
            }
          else
            ++bp;
          break;
        }
    }
  if (begin != bp)
    {
      /* Don't emit leading whitespaces */
      while (isspace (*begin))
        ++begin;

      if (*begin)
        emitcode (begin, NULL);
    }

  Safe_free (buf);

  /* consumed; we can free it here */
  dbuf_free (IC_INLINE (ic));

  genLine.lineElement.isInline -= (!options.asmpeep);
}
Beispiel #18
0
static char *
parseIvalAst (ast *node, int *inCodeSpace) {
#define LEN 4096
    char *buffer = NULL;
    char *left, *right;

    if (IS_AST_VALUE(node)) {
        value *val = AST_VALUE(node);
        symbol *sym = IS_AST_SYM_VALUE(node) ? AST_SYMBOL(node) : NULL;
        if (inCodeSpace && val->type
                && (IS_FUNC(val->type) || IS_CODE(getSpec(val->type))))
        {
            *inCodeSpace = 1;
        }
        if (inCodeSpace && sym
                && (IS_FUNC(sym->type)
                    || IS_CODE(getSpec(sym->type))))
        {
            *inCodeSpace = 1;
        }

        DEBUGprintf ("%s: AST_VALUE\n", __FUNCTION__);
        if (IS_AST_LIT_VALUE(node)) {
            buffer = Safe_alloc(LEN);
            SNPRINTF(buffer, LEN, "0x%lx", AST_ULONG_VALUE (node));
        } else if (IS_AST_SYM_VALUE(node)) {
            assert ( AST_SYMBOL(node) );
            /*
            printf ("sym %s: ", AST_SYMBOL(node)->rname);
            printTypeChain(AST_SYMBOL(node)->type, stdout);
            printTypeChain(AST_SYMBOL(node)->etype, stdout);
            printf ("\n---sym %s: done\n", AST_SYMBOL(node)->rname);
            */
            buffer = Safe_strdup(AST_SYMBOL(node)->rname);
        } else {
            assert ( !"Invalid values type for initializers in AST." );
        }
    } else if (IS_AST_OP(node)) {
        DEBUGprintf ("%s: AST_OP\n", __FUNCTION__);
        switch (node->opval.op) {
        case CAST:
            assert (node->right);
            buffer = parseIvalAst(node->right, inCodeSpace);
            DEBUGprintf ("%s: %s\n", __FUNCTION__, buffer);
            break;
        case '&':
            assert ( node->left && !node->right );
            buffer = parseIvalAst(node->left, inCodeSpace);
            DEBUGprintf ("%s: %s\n", __FUNCTION__, buffer);
            break;
        case '+':
            assert (node->left && node->right );
            left = parseIvalAst(node->left, inCodeSpace);
            right = parseIvalAst(node->right, inCodeSpace);
            buffer = Safe_alloc(LEN);
            SNPRINTF(buffer, LEN, "(%s + %s)", left, right);
            DEBUGprintf ("%s: %s\n", __FUNCTION__, buffer);
            Safe_free(left);
            Safe_free(right);
            break;
        case '[':
            assert ( node->left && node->right );
            assert ( IS_AST_VALUE(node->left) && AST_VALUE(node->left)->sym );
            right = parseIvalAst(node->right, inCodeSpace);
            buffer = Safe_alloc(LEN);
            SNPRINTF(buffer, LEN, "(%s + %u * %s)",
                    AST_VALUE(node->left)->sym->rname, getSize(AST_VALUE(node->left)->type), right);
            Safe_free(right);
            DEBUGprintf ("%s: %s\n", __FUNCTION__, &buffer[0]);
            break;
        default:
            assert ( !"Unhandled operation in initializer." );
            break;
        }
    } else {
        assert ( !"Invalid construct in initializer." );
    }

    return (buffer);
}
Beispiel #19
0
static void
_ds390_finaliseOptions (void)
{
  if (options.noXinitOpt) {
    port->genXINIT=0;
  }

  /* Hack-o-matic: if we are using the flat24 model,
   * adjust pointer sizes.
   */
  if (options.model != MODEL_FLAT24)  {
      fprintf (stderr,
               "*** warning: ds390 port small and large model experimental.\n");
      if (options.model == MODEL_LARGE)
      {
        port->mem.default_local_map = xdata;
        port->mem.default_globl_map = xdata;
      }
      else
      {
        port->mem.default_local_map = data;
        port->mem.default_globl_map = data;
      }
  }
  else {
    port->s.fptr_size = 3;
    port->s.gptr_size = 4;

    port->stack.isr_overhead += 2;      /* Will save dpx on ISR entry. */

    port->stack.call_overhead += 2;     /* This acounts for the extra byte
                                 * of return addres on the stack.
                                 * but is ugly. There must be a
                                 * better way.
                                 */

    port->mem.default_local_map = xdata;
    port->mem.default_globl_map = xdata;

    if (!options.stack10bit)
    {
    fprintf (stderr,
             "*** error: ds390 port only supports the 10 bit stack mode.\n");
    } else {
        if (!options.stack_loc) options.stack_loc = 0x400008;
    }

    /* generate native code 16*16 mul/div */
    if (options.useAccelerator)
            port->support.muldiv=2;
    else
            port->support.muldiv=1;

     /* Fixup the memory map for the stack; it is now in
     * far space and requires a FPOINTER to access it.
     */
    istack->fmap = 1;
    istack->ptrType = FPOINTER;

    if (options.parms_in_bank1) {
        addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1"));
    }
  }  /* MODEL_FLAT24 */
}
Beispiel #20
0
static void
_pic14_do_link (void)
{
  /*
   * link command format:
   * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
   *
   */
#define LFRM  "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}"
  hTab *linkValues = NULL;
  char *lcmd;
  set *tSet = NULL;
  int ret;
  char * procName;

  shash_add (&linkValues, "linker", "gplink");

  /* LIBRARY SEARCH DIRS */
  mergeSets (&tSet, libPathsSet);
  mergeSets (&tSet, libDirsSet);
  shash_add (&linkValues, "incdirs", joinStrSet (processStrSet (tSet, "-I", NULL, shell_escape)));

  joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape));
  shash_add (&linkValues, "sysincdirs", joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape)));

  shash_add (&linkValues, "lflags", joinStrSet (linkOptionsSet));

  {
    char *s = shell_escape (fullDstFileName ? fullDstFileName : dstFileName);

    shash_add (&linkValues, "outfile", s);
    Safe_free (s);
  }

  if (fullSrcFileName)
    {
      struct dbuf_s dbuf;
      char *s;

      dbuf_init (&dbuf, 128);

      dbuf_append_str (&dbuf, fullDstFileName ? fullDstFileName : dstFileName);
      dbuf_append (&dbuf, ".o", 2);
      s = shell_escape (dbuf_c_str (&dbuf));
      dbuf_destroy (&dbuf);
      shash_add (&linkValues, "user_ofile", s);
      Safe_free (s);
    }

  shash_add (&linkValues, "ofiles", joinStrSet (processStrSet (relFilesSet, NULL, NULL, shell_escape)));

  /* LIBRARIES */
  procName = processor_base_name ();
  if (!procName)
    procName = "16f877";

  addSet (&libFilesSet, Safe_strdup (pic14_getPIC()->isEnhancedCore ?
          "libsdcce.lib" : "libsdcc.lib"));

    {
      struct dbuf_s dbuf;

      dbuf_init (&dbuf, 128);
      dbuf_append (&dbuf, "pic", sizeof ("pic") - 1);
      dbuf_append_str (&dbuf, procName);
      dbuf_append (&dbuf, ".lib", sizeof (".lib") - 1);
      addSet (&libFilesSet, dbuf_detach_c_str (&dbuf));
    }

  shash_add (&linkValues, "libs", joinStrSet (processStrSet (libFilesSet, NULL, NULL, shell_escape)));

  lcmd = msprintf(linkValues, LFRM);
  ret = sdcc_system (lcmd);
  Safe_free (lcmd);

  if (ret)
    exit (1);
}