Esempio n. 1
1
static struct block *cast_expression(struct block *block)
{
    struct typetree *type;
    struct token tok;
    struct symbol *sym;

    /* This rule needs two lookahead; to see beyond the initial parenthesis if
     * it is actually a cast or an expression. */
    if (peek().token == '(') {
        tok = peekn(2);
        switch (tok.token) {
        case IDENTIFIER:
            sym = sym_lookup(&ns_ident, tok.strval);
            if (!sym || sym->symtype != SYM_TYPEDEF)
                break;
        case FIRST(type_name):
            consume('(');
            type = declaration_specifiers(NULL);
            if (peek().token != ')') {
                type = declarator(type, NULL);
            }
            consume(')');
            block = cast_expression(block);
            block->expr = eval_cast(block, block->expr, type);
            return block;
        default:
            break;
        }
    }

    return unary_expression(block);
}
Esempio n. 2
0
void sym_init(void)
{
	struct symbol *sym;
	struct utsname uts;
	char *p;
	static bool inited = false;

	if (inited)
		return;
	inited = true;

	uname(&uts);

	sym = sym_lookup("ARCH", 0);
	sym->type = S_STRING;
	sym->flags |= SYMBOL_AUTO;
	p = getenv("ARCH");
	if (p)
		sym_add_default(sym, p);

	sym = sym_lookup("KERNELVERSION", 0);
	sym->type = S_STRING;
	sym->flags |= SYMBOL_AUTO;
	p = getenv("KERNELVERSION");
	if (p)
		sym_add_default(sym, p);

	sym = sym_lookup("UNAME_RELEASE", 0);
	sym->type = S_STRING;
	sym->flags |= SYMBOL_AUTO;
	sym_add_default(sym, uts.release);
}
Esempio n. 3
0
void sym_init(void)
{
	struct symbol *sym;
	char *p;
	static bool inited = false;

	if (inited)
		return;
	inited = true;

	sym = sym_lookup("VERSION", 0);
	sym->type = S_STRING;
	sym->flags |= SYMBOL_AUTO;
	p = getenv("VERSION");
	if (p)
		sym_add_default(sym, p);

	sym = sym_lookup("TARGET_ARCH", 0);
	sym->type = S_STRING;
	sym->flags |= SYMBOL_AUTO;
	p = getenv("TARGET_ARCH");
	if (p)
		sym_add_default(sym, p);

}
Esempio n. 4
0
void
print_exec_counts ()
{
  Sym **sorted_bbs, *sym;
  unsigned int i, j, len;

  if (first_output)
    first_output = FALSE;
  else
    printf ("\f\n");

  /* Sort basic-blocks according to function name and line number:  */
  sorted_bbs = (Sym **) xmalloc (symtab.len * sizeof (sorted_bbs[0]));
  len = 0;

  for (sym = symtab.base; sym < symtab.limit; ++sym)
    {
      /* Accept symbol if it's in the INCL_EXEC table
	 or there is no INCL_EXEC table
	 and it does not appear in the EXCL_EXEC table.  */
      if (sym_lookup (&syms[INCL_EXEC], sym->addr)
	  || (syms[INCL_EXEC].len == 0
	      && !sym_lookup (&syms[EXCL_EXEC], sym->addr)))
	{
	  sorted_bbs[len++] = sym;
	}
    }

  qsort (sorted_bbs, len, sizeof (sorted_bbs[0]), cmp_bb);

  /* Output basic-blocks:  */

  for (i = 0; i < len; ++i)
    {
      sym = sorted_bbs [i];
      
      if (sym->ncalls > 0 || ! ignore_zeros)
	{
	  /* FIXME: This only works if bfd_vma is unsigned long.  */
	  printf (_("%s:%d: (%s:0x%lx) %lu executions\n"),
		  sym->file ? sym->file->name : _("<unknown>"), sym->line_num,
		  sym->name, (unsigned long) sym->addr, sym->ncalls);
	}

      for (j = 0; j < NBBS && sym->bb_addr[j]; j ++)
	{
	  if (sym->bb_calls[j] > 0 || ! ignore_zeros)
	    {
	      /* FIXME: This only works if bfd_vma is unsigned long.  */
	      printf (_("%s:%d: (%s:0x%lx) %lu executions\n"),
		      sym->file ? sym->file->name : _("<unknown>"), sym->line_num,
		      sym->name, (unsigned long) sym->bb_addr[j],
		      sym->bb_calls[j]);
	    }
	}
    }
  free (sorted_bbs);
}
Esempio n. 5
0
File: testext.c Progetto: uarka/gawk
static awk_value_t *
var_test(int nargs, awk_value_t *result)
{
	awk_value_t value, value2;
	awk_value_t *valp;

	assert(result != NULL);
	make_number(0.0, result);

	if (nargs != 1) {
		printf("var_test: nargs not right (%d should be 1)\n", nargs);
		goto out;
	}

	/* look up PROCINFO - should fail */
	if (sym_lookup("PROCINFO", AWK_ARRAY, & value))
		printf("var_test: sym_lookup of PROCINFO failed - got a value!\n");
	else
		printf("var_test: sym_lookup of PROCINFO passed - did not get a value\n");

	/* look up a reserved variable - should pass */
	if (sym_lookup("ARGC", AWK_NUMBER, & value))
		printf("var_test: sym_lookup of ARGC passed - got a value!\n");
	else
		printf("var_test: sym_lookup of ARGC failed - did not get a value\n");

	/* now try to set it - should fail */
	value.num_value++;
	if (sym_update("ARGC", & value))
		printf("var_test: sym_update of ARGC passed and should not have!\n");
	else
		printf("var_test: sym_update of ARGC failed - correctly\n");

	/* look up variable whose name is passed in, should pass */
	if (get_argument(0, AWK_STRING, & value)) {
		if (sym_lookup(value.str_value.str, AWK_STRING, & value2)) {
			/* change the value, should be reflected in awk script */
			valp = make_number(42.0, & value2);

			if (sym_update(value.str_value.str, valp)) {
				printf("var_test: sym_update(\"%s\") succeeded\n", value.str_value.str);
			} else {
				printf("var_test: sym_update(\"%s\") failed\n", value.str_value.str);
				goto out;
			}
		} else {
			printf("var_test: sym_lookup(\"%s\") failed\n", value.str_value.str);
			goto out;
		}
	} else {
		printf("var_test: get_argument() failed\n");
		goto out;
	}

	make_number(1.0, result);
out:
	return result;
}
Esempio n. 6
0
File: cc.c Progetto: Fedjmike/mini-c
void factor () {
    lvalue = false;

    if (see("true") || see("false")) {
        fprintf(output, "mov eax, %d\n", see("true") ? 1 : 0);
        next();

    } else if (token == token_ident) {
        int global = sym_lookup(globals, global_no, buffer);
        int local = sym_lookup(locals, local_no, buffer);

        require(global >= 0 || local >= 0, "no symbol '%s' declared\n");
        next();

        if (see("=") || see("++") || see("--"))
            lvalue = true;

        if (global >= 0)
            fprintf(output, "%s eax, [%s]\n", is_fn[global] || lvalue ? "lea" : "mov", globals[global]);

        else if (local >= 0)
            fprintf(output, "%s eax, [ebp%+d]\n", lvalue ? "lea" : "mov", offsets[local]);

    } else if (token == token_int || token == token_char) {
        fprintf(output, "mov eax, %s\n", buffer);
        next();

    } else if (token == token_str) {
        fputs(".section .rodata\n", output);
        int str = emit_label(new_label());

        //Consecutive string literals are concatenated
        while (token == token_str) {
            fprintf(output, ".ascii %s\n", buffer);
            next();
        }

        fputs(".byte 0\n"
              ".section .text\n", output);

        fprintf(output, "mov eax, offset _%08d\n", str);

    } else if (try_match("(")) {
        expr(0);
        match(")");

    } else
        error("expected an expression, found '%s'\n");
}
Esempio n. 7
0
void create_node(char *id, char *ifs)
{
    int status;
    pid_t pid;
    char *argv[5];
    char fd_buf[4*sizeof(int)+4];
    int fd[2];
    station_s *station;
    
    pthread_mutex_lock(&station_table_lock);
    if(!sym_lookup(&station_table, id)) {
        status = pipe(fd);
        if(status < 0) {
            perror("Error Creating Pipe");
            exit(EXIT_FAILURE);
        }
        sprintf(fd_buf, "%d.%d", fd[0], fd[1]);
        argv[0] = CLIENT_PATH;
        argv[1] = id;
        argv[2] = ifs;
        argv[3] = fd_buf;
        argv[4] = NULL;
        
        pid = fork();
        if(pid) {
            /* wait for SIGUSR1 from child */
            pause();
            
            station = alloc(sizeof(*station));
            station->pid = pid;
            station->pipe[0] = fd[0];
            station->pipe[1] = fd[1];
            
            sym_insert(&station_table, id, (sym_data_u){.ptr = station});
        }
Esempio n. 8
0
void sym_init(void)
{
	struct symbol *sym;
#ifndef __MINGW32__
	struct utsname uts;
#endif
	static bool inited = false;

	if (inited)
		return;
	inited = true;

#ifndef __MINGW32__
	uname(&uts);
#endif

	sym = sym_lookup("UNAME_RELEASE", 0);
	sym->type = S_STRING;
	sym->flags |= SYMBOL_AUTO;
#ifndef __MINGW32__
	sym_add_default(sym, uts.release);
#else
	sym_add_default(sym, "mingw-unknown");
#endif
}
Esempio n. 9
0
int sym_insert( struct symTable *st, const char *name, struct Value val )
{
	int index = sym_hash( name );
	struct Symbol *head = st->table[index];
	struct Symbol *sb = sym_lookup( st, name );
	if( sb != 0 )
	{
		/* the symbol exists, update its value */
		/* if the symbol's value type is STRING type, free the memory first */
		if( sb->val.type == SB_VAR_STRING )
		{
			free( sb->val.sval );
		}
		sb->val = val;
	}
	else
	{
		/* create a new symbol and insert it */
		struct Symbol *new_sb = (struct Symbol*) malloc( sizeof( struct Symbol ) );
		new_sb->name = (char*) malloc( strlen( name ) + 1 );
		strcpy( new_sb->name, name );
		new_sb->val = val;
		new_sb->next = head;
		st->table[index] = new_sb;
	}

	return 0;
}	
Esempio n. 10
0
int sym_insert_array( struct symTable *st, const char *name, size_t size )
{
	struct Symbol *sb = sym_lookup( st, name );
	if( sb != 0 )
	{
		return -1;
	}
	else
	{
		size_t i;
		int index = sym_hash( name );
		struct Symbol *head = st->table[index];
		struct Symbol *new_sb = (struct Symbol*) malloc( sizeof( struct Symbol ) );
		new_sb->name = (char*) malloc( strlen( name ) + 1 );
		strcpy( new_sb->name, name );
		new_sb->val.type = SB_VAR_ARRAY;
		new_sb->val.size = size;
		new_sb->val.aval = (struct Value *) malloc( sizeof( struct Value ) * size );
		for( i = 0; i < size; ++ i )
		{
			new_sb->val.aval[i].type = SB_VAR_NUM;
			new_sb->val.aval[i].dval = 0;
		}
		new_sb->next = head;
		st->table[index] = new_sb;	
	}

	return 0;
}
Esempio n. 11
0
File: testext.c Progetto: uarka/gawk
static awk_value_t *
test_indirect_vars(int nargs, awk_value_t *result)
{
	awk_value_t value;
	char *name = "NR";

	(void) nargs;		/* silence warnings */
	assert(result != NULL);
	make_number(0.0, result);

	/* system("rm testexttmp.txt") */
	(void) unlink("testexttmp.txt");

	if (sym_lookup(name, AWK_NUMBER, & value))
		printf("test_indirect_var: sym_lookup of %s passed\n", name);
	else {
		printf("test_indirect_var: sym_lookup of %s failed\n", name);
		goto out;
	}

	printf("test_indirect_var: value of NR is %g\n", value.num_value);

	make_number(1.0, result);
out:
	return result;
}
Esempio n. 12
0
File: testext.c Progetto: uarka/gawk
static awk_value_t *
test_scalar_reserved(int nargs, awk_value_t *result)
{
	awk_value_t new_value;
	awk_value_t the_scalar;

	(void) nargs;		/* silence warnings */
	make_number(0.0, result);

	/* look up a reserved variable - should pass */
	if (sym_lookup("ARGC", AWK_SCALAR, & the_scalar)) {
		printf("test_scalar_reserved: sym_lookup of ARGC passed - got a value!\n");
	} else {
		printf("test_scalar_reserved: sym_lookup of ARGC failed - did not get a value\n");
		goto out;
	}

	/* updating it should fail */
	make_number(42.0, & new_value);
	if (! sym_update_scalar(the_scalar.scalar_cookie, & new_value)) {
		printf("test_scalar_reserved: could not update new_value2 for ARGC - pass\n");
	} else {
		printf("test_scalar_reserved: was able to update new_value2 for ARGC - fail\n");
		goto out;
	}

	make_number(1.0, result);

out:
	return result;
}
Esempio n. 13
0
/* Parse call to builtin symbol __builtin_va_start, which is the result of
 * calling va_start(arg, s). Return type depends on second input argument.
 */
static struct block *parse__builtin_va_start(struct block *block)
{
    const struct typetree *type;
    struct symbol *sym;
    struct token param;
    int is_invalid;

    consume('(');
    block = assignment_expression(block);
    consume(',');
    param = consume(IDENTIFIER);
    sym = sym_lookup(&ns_ident, param.strval);

    type = &current_func()->symbol->type;
    is_invalid = !sym || sym->depth != 1 || !is_function(type);
    is_invalid = is_invalid || !nmembers(type) || strcmp(
        get_member(type, nmembers(type) - 1)->name, param.strval);

    if (is_invalid) {
        error("Second parameter of va_start must be last function argument.");
        exit(1);
    }

    consume(')');
    block->expr = eval__builtin_va_start(block, block->expr);
    return block;
}
Esempio n. 14
0
static char *conf_expand_value(const char *in)
{
	struct symbol *sym;
	const char *src;
	static char res_value[SYMBOL_MAXLENGTH];
	char *dst, name[SYMBOL_MAXLENGTH];

	res_value[0] = 0;
	dst = name;
	while ((src = strchr(in, '$'))) {
		strncat(res_value, in, src - in);
		src++;
		dst = name;
		while (isalnum((int)*src) || *src == '_')
			*dst++ = *src++;
		*dst = 0;
		sym = sym_lookup(name, 0);
		sym_calc_value(sym);
		strcat(res_value, sym_get_string_value(sym));
		in = src;
	}
	strcat(res_value, in);

	return res_value;
}
Esempio n. 15
0
void sym_set_scalar(int width, int *eval_flags, 
                    scalar_t sc, ident_t id, sym_t sym){
   int ivalue;

   /* Find the symbol - it is does not exist make a new one */
   sym_t newsym = sym_lookup(id, sym);
   if (newsym == NULL) {
      newsym = new_sym(id, sym);
   }

   /* Make sure that any existing one is of the right type */
   if (newsym->type == SYM_VECTOR) {
      /* errx(1, "%s is not a scalar", ident_str(id)); */
      fprintf(stderr, "%s is not a scalar(lowercase)\n", ident_str(id));
      exit(1);
   }

   /* Create a new scalar if needed */
   if (newsym->type == SYM_UNKNOWN || newsym->scalar->width < width) {
      if (newsym->type == SYM_SCALAR)
         scalar_free(newsym->scalar);
      newsym->type = SYM_SCALAR;
      newsym->scalar = new_scalar(width);
   }

   /* Copy in the values */
   for (ivalue=0; ivalue < width; ivalue++) {
      if (eval_flags != NULL && !eval_flags[ivalue]) continue;
      newsym->scalar->vals[ivalue] = sc->vals[ivalue];
   }
   return;
}
Esempio n. 16
0
int main(int ac, char **av)
{
	struct symbol *sym;
	char *mode;
	int res;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	conf_parse(av[1]);
	conf_read(NULL);

	sym = sym_lookup("KERNELVERSION", 0);
	sym_calc_value(sym);
	sprintf(menu_backtitle, _("Linux Kernel v%s Configuration"),
		sym_get_string_value(sym));

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}

	tcgetattr(1, &ios_org);
	atexit(conf_cleanup);
	init_wsize();
	reset_dialog();
	init_dialog(menu_backtitle);
	do {
		conf(&rootmenu);
		dialog_clear();
		res = dialog_yesno(NULL,
				   _("Do you wish to save your "
				     "new kernel configuration?\n"
				     "<ESC><ESC> to continue."),
				   6, 60);
	} while (res == KEY_ESC);
	end_dialog();
	if (res == 0) {
		if (conf_write(NULL)) {
			fprintf(stderr, _("\n\n"
				"Error during writing of the kernel configuration.\n"
				"Your kernel configuration changes were NOT saved."
				"\n\n"));
			return 1;
		}
		printf(_("\n\n"
			"*** End of Linux kernel configuration.\n"
			"*** Execute 'make' to build the kernel or try 'make help'."
			"\n\n"));
	} else {
		fprintf(stderr, _("\n\n"
			"Your kernel configuration changes were NOT saved."
			"\n\n"));
	}

	return 0;
}
Esempio n. 17
0
int main(int ac, char **av)
{
	struct symbol *sym;
	char *mode;
	int stat;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	conf_parse(av[1]);
	conf_read(NULL);

	sym = sym_lookup("KERNELVERSION", 0);
	sym_calc_value(sym);
	sprintf(menu_backtitle, _("swupdate %s Configuration"),
		sym_get_string_value(sym));

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}

	tcgetattr(1, &ios_org);
	atexit(conf_cleanup);
	init_wsize();
	conf(&rootmenu);

	do {
		cprint_init();
		cprint("--yesno");
		cprint(_("Do you wish to save your new configuration?"));
		cprint("5");
		cprint("60");
		stat = exec_conf();
	} while (stat < 0);

	if (stat == 0) {
		if (conf_write(NULL)) {
			fprintf(stderr, _("\n\n"
				"Error during writing of the configuration.\n"
				"Your configuration changes were NOT saved."
				"\n\n"));
			return 1;
		}
		printf(_("\n\n"
			"*** End of configuration.\n"
			"*** Execute 'make' to build the project or try 'make help'."
			"\n\n"));
	} else {
		fprintf(stderr, _("\n\n"
			"Your configuration changes were NOT saved."
			"\n\n"));
	}

	return 0;
}
Esempio n. 18
0
static struct block *primary_expression(struct block *block)
{
    const struct symbol *sym;
    struct token tok;

    switch ((tok = next()).token) {
    case IDENTIFIER:
        sym = sym_lookup(&ns_ident, tok.strval);
        if (!sym) {
            error("Undefined symbol '%s'.", tok.strval);
            exit(1);
        }
        /* Special handling for builtin pseudo functions. These are expected to
         * behave as macros, thus should be no problem parsing as function call
         * in primary expression. Constructs like (va_arg)(args, int) will not
         * work with this scheme. */
        if (!strcmp("__builtin_va_start", sym->name)) {
            block = parse__builtin_va_start(block);
        } else if (!strcmp("__builtin_va_arg", sym->name)) {
            block = parse__builtin_va_arg(block);
        } else {
            block->expr = var_direct(sym);
        }
        break;
    case INTEGER_CONSTANT:
        block->expr = var_int(tok.intval);
        break;
    case '(':
        block = expression(block);
        consume(')');
        break;
    case STRING:
        sym =
            sym_add(&ns_ident,
                ".LC",
                type_init(T_ARRAY, &basic_type__char, strlen(tok.strval) + 1),
                SYM_STRING_VALUE,
                LINK_INTERN);

        /* Store string value directly on symbol, memory ownership is in string
         * table from previously called str_register. The symbol now exists as
         * if it was declared static char .LC[] = "...". */
        ((struct symbol *) sym)->string_value = tok.strval;

        /* Result is an IMMEDIATE of type [] char, with a reference to the new
         * symbol containing the string literal. Will decay into char * on
         * evaluation. */
        block->expr = var_direct(sym);
        assert(block->expr.kind == IMMEDIATE);
        break;
    default:
        error("Unexpected '%s', not a valid primary expression.", tok.strval);
        exit(1);
    }

    return block;
}
Esempio n. 19
0
static int l_spank_job_control_unsetenv (lua_State *L)
{
    unsetenv_f f = sym_lookup ("spank_job_control_unsetenv");

    if (f == NULL)
        return l_spank_error_msg (L,
                "spank_job_control_unsetenv not implemented in this version");

    return l_do_unsetenv (L, f);
}
Esempio n. 20
0
vector_t sym_lookup_vector(ident_t id, sym_t sym){
   sym_t s = sym_lookup(id, sym);
   if (!s) {
      /* errx(1, "%s undefined", ident_str(id)); */
      fprintf(stderr, "%s undefined\n", ident_str(id));
      exit(1);
   }
   if (s->type != SYM_VECTOR)
      return NULL;
   return s->vector;
}
Esempio n. 21
0
void sym_set_vector(int width, int *eval_flags, 
                    vector_t v, ident_t id, sym_t sym){
   int ivalue, iel;
   scalar_t sc;

   /* Find the symbol - it is does not exist make a new one */
   sym_t newsym = sym_lookup(id, sym);
   if (newsym == NULL) {
      newsym = new_sym(id, sym);
   }

   /* Make sure that any existing one is of the right type */
   if (newsym->type == SYM_SCALAR) {
      /* errx(1, "%s is not a vector", ident_str(id)); */
      fprintf(stderr, "%s is not a vector\n", ident_str(id));
      exit(1);
   }

   /* Create a new vector if needed - either it does not exist or the
      length is changing or the width is increasing*/
   if (newsym->type == SYM_UNKNOWN || newsym->vector->len != v->len ||
      (newsym->vector->len > 0 && newsym->vector->el[0]->width < width) ) {

      /* Free an existing vector. If eval_flags is set, then we cannot
         change the length of the vector */
      if (newsym->type == SYM_VECTOR) {
         if (eval_flags != NULL && newsym->vector->len != v->len) {
            /* errx(1, "assigned vector must match length of %s in if", 
                    ident_str(id)); */
            fprintf(stderr, "assigned vector must match length of %s in if", 
                    ident_str(id));
            exit(1);
         }
         vector_free(newsym->vector);
      }
      newsym->type = SYM_VECTOR;
      newsym->vector = new_vector();
      for (iel=0; iel < v->len; iel++) {
         sc = new_scalar(width);
         vector_append(newsym->vector, sc);
         scalar_free(sc);
      }
   }

   /* Copy in the values */
   for (ivalue=0; ivalue < width; ivalue++) {
      if (eval_flags != NULL && !eval_flags[ivalue]) continue;
      for (iel=0; iel < v->len; iel++) {
         newsym->vector->el[iel]->vals[ivalue] = v->el[iel]->vals[ivalue];
      }
   }

   return;
}
Esempio n. 22
0
int main(int ac, char **av)
{
	struct symbol *sym;
	char *mode;
	int stat;

	conf_parse(av[1]);
	conf_read(NULL);

	sym = sym_lookup("KERNELRELEASE", 0);
	sym_calc_value(sym);
	sprintf(menu_backtitle, "Linux Kernel v%s Configuration",
		sym_get_string_value(sym));

	mode = getenv("MENUCONFIG_MODE");
	if (mode) {
		if (!strcasecmp(mode, "single_menu"))
			single_menu_mode = 1;
	}

	tcgetattr(1, &ios_org);
	atexit(conf_cleanup);
	init_wsize();
	conf(&rootmenu);

	do {
		cprint_init();
		cprint("--yesno");
		cprint("Do you wish to save your new kernel configuration?");
		cprint("5");
		cprint("60");
		stat = exec_conf();
	} while (stat < 0);

	if (stat == 0) {
		if (conf_write(NULL)) {
			fprintf(stderr, "\n\n"
				"Error during writing of the kernel configuration.\n"
				"Your kernel configuration changes were NOT saved."
				"\n\n");
			return 1;
		}
		printf("\n\n"
			"*** End of Linux kernel configuration.\n"
			"*** Execute 'make' to build the kernel or try 'make help'."
			"\n\n");
	} else {
		fprintf(stderr, "\n\n"
			"Your kernel configuration changes were NOT saved."
			"\n\n");
	}

	return 0;
}
Esempio n. 23
0
static gimli_iter_status_t search_for_sym(const char *k, int klen,
    void *item, void *arg)
{
  gimli_mapped_object_t file = item;
  struct find_sym *find = arg;

  find->sym = sym_lookup(file, find->name);
  if (find->sym) return GIMLI_ITER_STOP;

  return GIMLI_ITER_CONT;
}
Esempio n. 24
0
void
aarch64_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
{
  bfd_vma pc, dest_pc, offset;
  unsigned int insn;
  Sym *child;

  DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
			  parent->name, (unsigned long) p_lowpc,
			  (unsigned long) p_highpc));

  for (pc = p_lowpc; pc < p_highpc; pc += 4)
    {

      insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
				    + pc - core_text_sect->vma));

      if ((insn & BRANCH_MASK) == BRANCH_PATTERN)
	{
	  DBG (CALLDEBUG,
	       printf ("[find_call] 0x%lx: bl", (unsigned long) pc));

	  /* Regular pc relative addressing check that this is the
	     address of a function.  */
	  offset = ((((bfd_vma) insn & 0x3ffffff) ^ 0x2000000) - 0x2000000) << 2;

	  dest_pc = pc + offset;

	  if (hist_check_address (dest_pc))
	    {
	      child = sym_lookup (&symtab, dest_pc);

	      if (child)
		{
		  DBG (CALLDEBUG,
		       printf ("\tdest_pc=0x%lx, (name=%s, addr=0x%lx)\n",
			       (unsigned long) dest_pc, child->name,
			       (unsigned long) child->addr));

		  if (child->addr == dest_pc)
		    {
		      /* a hit.  */
		      arc_add (parent, child, (unsigned long) 0);
		      continue;
		    }
		}
	    }

	  /* Something funny going on.  */
	  DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
	}
    }
}
Esempio n. 25
0
void
i386_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
{
  unsigned char *instructp;
  Sym *child;
  bfd_vma pc, destpc;

  DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
			  parent->name, (unsigned long) p_lowpc,
			  (unsigned long) p_highpc));

  for (pc = p_lowpc; pc < p_highpc; ++pc)
    {
      instructp = (unsigned char *) core_text_space + pc - core_text_sect->vma;
      if (i386_iscall (instructp))
	{
	  DBG (CALLDEBUG,
	       printf ("[findcall]\t0x%lx:call", (unsigned long) pc));
	  /*
	   *  regular pc relative addressing
	   *    check that this is the address of
	   *    a function.
	   */

	  destpc = bfd_get_32 (core_bfd[0], instructp + 1) + pc + 5;
	  if (hist_check_address (destpc))
	    {
	      child = sym_lookup (&symtab, destpc);
	      if (child && child->addr == destpc)
		{
		  /*
		   *      a hit
		   */
		  DBG (CALLDEBUG,
		       printf ("\tdestpc 0x%lx (%s)\n",
			       (unsigned long) destpc, child->name));
		  arc_add (parent, child, (unsigned long) 0);
		  instructp += 4;	/* call is a 5 byte instruction */
		  continue;
		}
	    }
	  /*
	   *  else:
	   *    it looked like a callf, but it:
	   *      a) wasn't actually a callf, or
	   *      b) didn't point to a known function in the symtab, or
	   *      c) something funny is going on.
	   */
	  DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
	}
    }
}
Esempio n. 26
0
File: fe.cpp Progetto: nlsynth/nli
void FE::InitSyms() {
  sym_def = sym_lookup("def");
  sym_enum = sym_lookup("enum");
  sym_func = sym_lookup("func");
  sym_import = sym_lookup("import");
  sym_struct = sym_lookup("struct");
  sym_spawn = sym_lookup("spawn");
}
Esempio n. 27
0
scalar_t sym_lookup_scalar(ident_t id, sym_t sym){
   sym_t s = sym_lookup(id, sym);
   if (!s) {
      /* errx(1, "%s undefined", ident_str(id)); */
      fprintf(stderr, "%s undefined\n", ident_str(id));
      exit(1);
   }
   if (s->type != SYM_SCALAR) {
      /* errx(1, "%s is not scalar (lowercase)", ident_str(id)); */
      fprintf(stderr, "%s is not scalar (lowercase)\n", ident_str(id));
      exit(1);
   }
   return s->scalar;
}
Esempio n. 28
0
File: symbol.c Progetto: nrhtr/elixr
XR xr_sym(const char *str)
{
    XR sym = sym_lookup(str);

    if (sym == VAL_NIL) {
        /* Create a new symbol and intern it in 
         * global symbol table */
        sym = _xr_sym_alloc(str);
        ((struct XRSymbol*)sym)->interned = 1;
        xr_sym_put(sym);
    }
    
    return sym;
}
Esempio n. 29
0
/*
 *  recognizes keywords and identifiers
 */
static int id(lex_t *t)
{
    unsigned h;
    const struct tab *p;

    assert(t);

    clx_tok = hash_string(LEX_SPELL(t));
    h = hashkey(clx_tok, NELEM(tab));
    for (p = tab[h]; p; p = p->link)
        if (p->key == clx_tok)
            return p->code;

    clx_sym = sym_lookup(clx_tok, sym_ident);
    return LEX_ID;
}
Esempio n. 30
0
void sym_init(void)
{
	struct symbol *sym;
	struct utsname uts;
	static bool inited = false;

	if (inited)
		return;
	inited = true;

	uname(&uts);

	sym = sym_lookup("UNAME_RELEASE", 0);
	sym->type = S_STRING;
	sym->flags |= SYMBOL_AUTO;
	sym_add_default(sym, uts.release);
}