Пример #1
0
/* recursively convert an AST expression into a BDD */
DdNode* bdd_expr(DdManager* m, symbol** symtab, ast_node* expr) {
    int i;
    DdNode* ret, *tmp1, *tmp2;
    switch (expr->tag) {
    case _id_expr:                     /* simply return that variable's BDD */
        if ((i = symtab_lookup(symtab, expr->name)) < 0) {
            printf("Error: variable '%s' not found in symbol table\n", expr->name);
            exit(1);
        }
        ret = Cudd_bddIthVar(m, symtab_lookup(symtab, expr->name));
        break;
    case _lit_expr:                    /* return a BDD 1 or 0 */
        ret = expr->val ? Cudd_ReadOne(m) : Cudd_ReadLogicZero(m);
        break;
    case _not_expr:                    /* return complement BDD */
        tmp1 = bdd_expr(m, symtab, expr->children[EXPR1]);
        ret = Cudd_Not(tmp1);
        Cudd_Ref(ret);
        Cudd_RecursiveDeref(m, tmp1);
        break;
    case _and_expr:                    /* return logical AND */
        tmp1 = bdd_expr(m, symtab, expr->children[EXPR1]);
        tmp2 = bdd_expr(m, symtab, expr->children[EXPR2]);
        ret = Cudd_bddAnd(m, tmp1, tmp2);
        Cudd_Ref(ret);
        Cudd_RecursiveDeref(m, tmp1);
        Cudd_RecursiveDeref(m, tmp2);
        break;
    case _or_expr:                     /* return logical OR */
        tmp1 = bdd_expr(m, symtab, expr->children[EXPR1]);
        tmp2 = bdd_expr(m, symtab, expr->children[EXPR2]);
        ret = Cudd_bddOr(m, tmp1, tmp2);
        Cudd_Ref(ret);
        Cudd_RecursiveDeref(m, tmp1);
        Cudd_RecursiveDeref(m, tmp2);
        break;
    case _eq_expr:                     /* check for equality, return 1 or 0 */
        tmp1 = bdd_expr(m, symtab, expr->children[EXPR1]);
        tmp2 = bdd_expr(m, symtab, expr->children[EXPR2]);
        if (Cudd_EquivDC(m, tmp1, tmp2, Cudd_ReadLogicZero(m)))
            ret = Cudd_ReadOne(m);
        else
            ret = Cudd_ReadLogicZero(m);
        Cudd_RecursiveDeref(m, tmp1);
        Cudd_RecursiveDeref(m, tmp2);
        break;
    case _impl_expr:                   /* return logical implication (!a|b) */
        tmp1 = Cudd_Not(bdd_expr(m, symtab, expr->children[EXPR1]));
        tmp2 = bdd_expr(m, symtab, expr->children[EXPR2]);
        ret = Cudd_bddOr(m, tmp1, tmp2);
        Cudd_Ref(ret);
        Cudd_RecursiveDeref(m, tmp1);
        Cudd_RecursiveDeref(m, tmp2);
        break;
    default:
        printf("Error: invalid expression\n");
        exit(1);
    }
    return ret;
}
Пример #2
0
static symbol_t *
find_tag (ty_meta_e meta, symbol_t *tag, type_t *type)
{
	const char *tag_name;
	symbol_t   *sym;

	if (tag) {
		tag_name = va ("tag %s", tag->name);
	} else {
		const char *path = GETSTR (pr.source_file);
		const char *file = strrchr (path, '/');
		if (!file++)
			file = path;
		tag_name = va ("tag .%s.%d", file, pr.source_line);
	}
	sym = symtab_lookup (current_symtab, tag_name);
	if (sym) {
		if (sym->table == current_symtab && sym->type->meta != meta)
			error (0, "%s defined as wrong kind of tag", tag->name);
		if (sym->type->meta == meta)
			return sym;
	}
	sym = new_symbol (tag_name);
	if (!type)
		type = new_type ();
	if (!type->name)
		type->name = sym->name;
	sym->type = type;
	sym->type->type = ev_invalid;
	sym->type->meta = meta;
	sym->sy_type = sy_type;
	return sym;
}
Пример #3
0
/**
 * Allocate a prefix as a shorthand for the URI.
 *
 * @return prefix string to use, which will be freed by symbol tables
 * when leaving scope.
 */
static const char *
xfmt_new_prefix(struct xfmt_pass2 *xp2, const char *uri)
{
    const char *prefix = NULL;
    bool free_prefix = FALSE;

    /* The URI must not already exist in the symbol table */
    g_assert(NULL == symtab_lookup(xp2->uris, uri));

    /*
     * Check whether user has a preference for the prefix to use.
     *
     * If there is a prefix, there must be no identical prefix in scope
     * currently.
     */

    if (xp2->uri2prefix != NULL)
        prefix = nv_table_lookup_str(xp2->uri2prefix, uri);

    if (prefix != NULL) {
        const char *used_uri = symtab_lookup(xp2->prefixes, prefix);

        if (used_uri != NULL) {
            g_carp("XFMT cannot use prefix '%s' for '%s': "
                   "already used by '%s'", prefix, uri, used_uri);
            prefix = NULL;
        }
    }

    /*
     * Allocate a new prefix if required.
     */

    if (NULL == prefix) {
        prefix = h_strdup_printf("ns%u", xp2->pcount++);
        free_prefix = TRUE;
    }

    /*
     * Record associations in the symbol tables.
     */

    xfmt_ns_declare(xp2, prefix, uri, free_prefix);

    return prefix;
}
Пример #4
0
/* formula for assignment: pc ^ var' <=> expr ^ pc' ^ same(pc, var) */
DdNode* bdd_mk_assign(DdManager *m, pos* postab, cfg_node* host, int proc) {
    DdNode* tmp1 = Cudd_bddIthVar(m, symtab_lookup(postab->vars_, host->node->name));
    DdNode* tmp2 = bdd_expr(m, postab->vars, host->node->children[EXPR]);
    DdNode* ret = Cudd_bddXnor(m, tmp1, tmp2);
    Cudd_Ref(ret);                       /* encode assignment with XNOR */
    Cudd_RecursiveDeref(m, tmp2);
    ret = bdd_encode_pc(m, ret, postab->pc, postab->pc_size, proc,
                        host->node->id); /* encode program counter */
    tmp1 = bdd_same(m, postab, symtab_lookup(postab->vars, host->node->name),
                    proc);               /* encode unchanging variables */
    tmp2 = ret;
    ret = Cudd_bddAnd(m, tmp1, tmp2);
    Cudd_Ref(ret);
    Cudd_RecursiveDeref(m, tmp1);
    Cudd_RecursiveDeref(m, tmp2);
    return ret;
}
Пример #5
0
static jl_sym_t *_jl_symbol(const char *str, size_t len)
{
    jl_sym_t *volatile *slot;
    jl_sym_t *node = symtab_lookup(&symtab, str, len, &slot);
    if (node == NULL) {
        JL_LOCK(&symbol_table_lock); // Might GC
        // Someone might have updated it, check and look up again
        if (*slot != NULL && (node = symtab_lookup(slot, str, len, &slot))) {
            JL_UNLOCK(&symbol_table_lock); // Might GC
            return node;
        }
        node = mk_symbol(str, len);
        jl_atomic_store_release(slot, node);
        JL_UNLOCK(&symbol_table_lock); // Might GC
    }
    return node;
}
Пример #6
0
value_t symbol(char *str)
{
    symbol_t **pnode;

    pnode = symtab_lookup(&symtab, str);
    if (*pnode == NULL)
        *pnode = mk_symbol(str);
    return tagptr(*pnode, TAG_SYM);
}
Пример #7
0
Файл: pb-xform.c Проект: mpw/p2
IDENT *
lookup_struct (char *name)
{
  ENTRY *e = symtab_lookup(symtab[OTH], name);
  if (e == NULL)
    return(NULL);
  else
    return(e->ident);
}
Пример #8
0
jl_sym_t *jl_symbol(const char *str)
{
    jl_sym_t **pnode;

    pnode = symtab_lookup(&symtab, str);
    if (*pnode == NULL)
        *pnode = mk_symbol(str);
    return *pnode;
}
Пример #9
0
void
inifile_del(inifile_t *self, const char *sec, const char *key)
{
  inisec_t *s = symtab_lookup(&self->if_sections, sec);
  if( s != 0 )
  {
    inisec_del(s, key);
  }
}
Пример #10
0
double retrieve(char *varname) {

	int address;

	if (address = symtab_lookup(varname) != -1) {
		return memory[address];
	}

	exit(UNDECLARED_VARIABLE_EXCEPTION);

}
Пример #11
0
jl_sym_t *jl_symbol(const char *str)
{
    jl_sym_t **pnode;
    jl_sym_t *parent;
    pnode = symtab_lookup(&symtab, str, &parent);
    if (*pnode == NULL) {
        *pnode = mk_symbol(str);
        if (parent != NULL)
            gc_wb(parent, *pnode);
    }
    return *pnode;
}
Пример #12
0
static jl_sym_t *_jl_symbol(const char *str, size_t len)
{
    jl_sym_t **pnode;
    jl_sym_t *parent;
    pnode = symtab_lookup(&symtab, str, len, &parent);
    if (*pnode == NULL) {
        *pnode = mk_symbol(str, len);
        if (parent != NULL)
            jl_gc_wb(parent, *pnode);
    }
    return *pnode;
}
Пример #13
0
/**
 * Transform a namespace URI into its prefix.
 */
static const char *
xfmt_uri_to_prefix(const struct xfmt_pass2 *xp2, const char *uri)
{
    const char *prefix;

    g_assert(uri != NULL);

    prefix = symtab_lookup(xp2->uris, uri);
    g_assert(prefix != NULL);

    return prefix;
}
Пример #14
0
char *new_nodename (char *eqname)
{
    static int maxindex = 0 ;
    static char name [MAXLINE] ;

    do
    {
	sprintf (name, "%s:%d", eqname, ++maxindex) ;
    } while (symtab_lookup (name) != NULL) ;

    return name ;
}
Пример #15
0
/*symtab_verify - verifica se a variável foi declarada*/
int
symtab_verify(char const *symbol)
{

int position = symtab_lookup(symbol);

	if (symtab[symtab_nextentry-1].valtype==1)
	{
		//printf( "variável declarada");
	}else
	{ 
		printf (" ATENCAO!, VARIAVEL %s ,NAO DECLARADA\n",symbol);
       	// exit(getch());
	}
}
Пример #16
0
static int
internal(int argc, char *argv[])
{
  char *name = argv[0];
  symbol_t *symbol = symtab_lookup(symtab, name);
  int status = -1;

  if (symbol && symbol->type == SYM_INTERNAL) {
    status = ((internal_t)symbol->value)(argc, argv);
  } else {
#if !defined(LSH_ENABLE_EXTERNAL)
    lsh_not_impl(argv[0]);
#endif
  }
  return status;
}
Пример #17
0
Файл: pb-xform.c Проект: mpw/p2
IDENT *
new_struct (char *name, BOOLEAN add_to_symtab)
{
  CTYPE *c = STRUCT_CTYPE;
  IDENT *i = new_ident(SUE, name, c, NULL, FALSE);
  c->ident = i;
  if (add_to_symtab)
  {
#ifndef NDEBUG
    ENTRY *e = symtab_lookup(symtab[SUE], name);
    if (e != NULL && e->ident->scope == scope)
      assertion_failed("struct %s already exists in scope", name);
#endif /* NDEBUG */
    add_ident_to_symtab1(symtab[SUE], i);
  }
  return(i);
}
Пример #18
0
void storage(char *varname) {

	int address;

	if (address = symtab_lookup(varname) == -1) {

		// assigns symtab_next_entry to address and add symtab_next_entry
		address = symtab_next_entry++;

		if (add_symbol(varname, address)) {

			memory[address] = stack[top];

		}

	}

}
Пример #19
0
/*fact parser:*/
void
fact (void)
{
  switch (lookahead)
    {
    case INTCTE://constante inteira
      match (INTCTE);
      break;
    case '('://parênteses
      match ('(');
      expr ();
      match (')');
      break;
    case ID://identificador
      {
            
      /*geração de código de máquina*/
      {printf("\tmov %s, %%eax\n", lexeme);}
      
	if (symtab_lookup (lexeme) == -1)
	  {
	    deupau ();
	  }
      }
      match (ID);
      if (lookahead == '(')
	{
	  match ('(');
	  exprlist ();
	  match (')');
	}
      else
	{
	  while (lookahead == '[')
	    {
	      idxsynt ();
	    }
	}
      break;
    default:
      ;
    }
}
Пример #20
0
int asmout_make_rom(struct SymTab **curSyms, char *out, char *data) {
  FILE *handle;
  int x, y, t, datasize;
  
  /* sanity check */
  if (symtab_lookup(curSyms, "$filesize", NULL, &datasize) != 0) {
    fprintf(stderr, "ERROR - Unknown file size\n");
    return -1;
  }

  /* open output */
  if ((handle = fopen(out, "w")) == NULL) {
    perror("ERROR - Could not open output file");
    return -1;
  }
  
  /* dump ROM header (none for now) */


  DEBUG(1) printf("Max Address %d\n", datasize);
  /* output each row */
  for (x=0; x<datasize; x+=8) {
    fprintf(handle, "0x%04X |", x);
    for (y=0; y<8; y++) {
      if ((x+y)<datasize) {
	t = (data[x+y] & 0xff);
	fprintf(handle, " %02X", t);
      }
      else {
	fprintf(handle, " 00");
      }
    }
    fprintf(handle, "\n");
  }
  
  /* dump ROM trailer (none for now) */
  
  /* done */
  fclose(handle);
  return 0;
}
Пример #21
0
static void
print_id_string(FILE *file, int id, bool print_long)
{
	switch (id) {
$$PRINT_IDS$$
	default: {
		symtab_entry_t *e = symtab_lookup(id);
		if (!e) {
			fprintf(file, "(UNKNOWN-SYM[%d])", id);
		} else {
			if (print_long) {
				fprintf(file, "(SYM[%d] ", id);
			}
			symtab_entry_name_dump(file, e);
			if (print_long) {
				fprintf(file, ")");
			}
		}
	}
	}
}
Пример #22
0
int
symtab_add(char const *newsymbol)
{
    int             i;
    if ((i = symtab_lookup(newsymbol)) < 0
        || symtab[i].lexlevel < lexlevel) {
        if (symtab_nextentry < MAXTBENTRIES) {
            strcpy(symtab[symtab_nextentry].symbol, newsymbol);
            symtab[symtab_nextentry].lexlevel = lexlevel;
            return ++symtab_nextentry;
        } else {
            fprintf(stderr,
                    "maximum symbol entries exceeded... exiting\n");
            exit(-4);
        }
    } else {
        fprintf(stderr,
                "%s already declared in the same lexical level... exiting\n",
                newsymbol);
        exit(-3);
    }
}
Пример #23
0
symbol_t *
make_symbol (const char *name, type_t *type, defspace_t *space,
			 storage_class_t storage)
{
	symbol_t   *sym;
	struct reloc_s *relocs = 0;

	if (storage != sc_extern && storage != sc_global && storage != sc_static)
		internal_error (0, "invalid storage class for %s", __FUNCTION__);
	if (storage != sc_extern && !space)
		internal_error (0, "null space for non-external storage");
	sym = symtab_lookup (pr.symtab, name);
	if (!sym) {
		sym = new_symbol_type (name, type);
	}
	if (sym->type != type) {
		if (is_array (sym->type) && is_array (type)
			&& !sym->type->t.array.size) {
			sym->type = type;
		} else {
			error (0, "%s redefined", name);
			sym = new_symbol_type (name, type);
		}
	}
	if (sym->s.def && sym->s.def->external && storage != sc_extern) {
		//FIXME this really is not the right way
		relocs = sym->s.def->relocs;
		free_def (sym->s.def);
		sym->s.def = 0;
	}
	if (!sym->s.def) {
		sym->s.def = new_def (name, type, space, storage);
		reloc_attach_relocs (relocs, &sym->s.def->relocs);
	}
	return sym;
}
Пример #24
0
/**
 * Emit namespace declarations.
 */
static void
xfmt_pass2_declare_ns(struct xfmt_pass2 *xp2, GSList *ns)
{
    GSList *sl;

    GM_SLIST_FOREACH(ns, sl) {
        const char *prefix = sl->data;
        const char *uri;
        int c;

        /*
         * Do not declare the "xml" namespace.
         */

        if (0 == strcmp(prefix, VXS_XML))
            continue;

        /*
         * We don't need to declare the default namespace though, unless
         * it is used in attributes (since there is no default namespace
         * for attributes).
         */

        uri = symtab_lookup(xp2->prefixes, prefix);

        if (
            xp2->default_ns != NULL && 0 == strcmp(uri, xp2->default_ns) &&
            !hset_contains(xp2->attr_uris, xp2->default_ns)
        )
            continue;

        c = xfmt_quoting_char(uri);
        g_assert(c != '\0');
        ostream_printf(xp2->os, " xmlns:%s=%c%s%c", prefix, c, uri, c);
    }
}
Пример #25
0
int asmgen_parse_value(struct ScanData *scanner,
		       struct SymTab **curSyms,
		       unsigned int *pResult) {
  struct Token curToken;
  unsigned int lval, rval;
  
  /* scan next token or expression */
  switch (get_token(&curToken, scanner)) {
    
  case TOK_INT:
    /* integer value, just pass it back */
    DEBUG(1) printf("Got an integer - %d\n", curToken.value);
    lval = curToken.value;
    if (curToken.limHigh - curToken.limLow < 8*sizeof(lval) - 1) {
      /* if token is specified with a bitslice, use only those bits */
      lval = GETBITS(curToken.limLow, curToken.limHigh, lval);
    }
    *pResult = lval;
    return 0;
    break;
    
  case TOK_IDENT:
    /* identifier, locate it in the symbol table */
    DEBUG(1) printf("Got a symbol lookup - '%s'\n", curToken.token);
    if (symtab_lookup(curSyms, curToken.token, NULL, (int*)&lval) == 0) {
      /* symbol table lookup success */
      if (curToken.limHigh - curToken.limLow < 8*sizeof(lval) - 1) {
	/* if token is specified with a bitslice, use only those bits */
	lval = GETBITS(curToken.limLow, curToken.limHigh, lval);
      }
      *pResult = lval;
      return 0;
    }
    printf("ERROR - Symbol '%s' Not Found\n", curToken.token);
    break;
    
  case TOK_LPAREN:
    /* left parentheses, beginning of an arithmetic expression */
    
    /* start by evaluating first term (may be another expression */
    if (asmgen_parse_value(scanner, curSyms, &lval) != 0) {
      /* error parsing sub-expression */
      printf("ERROR - Cannot Parse Arithmetic Expression\n");
      return -1;
    }
    
    /* inner loop to evalate left-to-right arithmetic expressions */
    while (1) {
      /* get next token */
      switch (get_token(&curToken, scanner)) {
	
      case TOK_RPAREN:
	/* close parentheses, end of sub-expression */
	*pResult = lval;
	return 0;
	break;
	
      case TOK_ARITHOP:
	/* arithmetic operation (+/-), get right hand value */
	if (asmgen_parse_value(scanner, curSyms, &rval) != 0) {
	  /* error parsing sub-expression */
	  printf("ERROR - Cannot Parse Arithmetic Expression\n");
	  return -1;
	}
	
	/* handle arithmetic operation */
	switch (curToken.token[0]) {
	case '+':
	  lval += rval;
	  break;
	case '-':
	  lval -= rval;
	  break;
	default:
	  /* unhandled */
	  printf("ERROR - Unknown Arithmetic operation '%s'\n", curToken.token);
	  return -1;
	  break;
	}
	break;
	
      default:
	printf("ERROR - Unexpected token '%s' while parsing subexpression\n",
	       curToken.token);
	return -1;
	break;
      }
    }
    break;
    
  default:
    /* unknown token */
    printf("Unhandled token \'%s\'\n", curToken.token);
    break;
  }
  return -1;
}
Пример #26
0
JL_DLLEXPORT jl_sym_t *jl_symbol_lookup(const char *str)
{
    return symtab_lookup(&symtab, str, strlen(str), NULL);
}
Пример #27
0
const char *
inifile_get(inifile_t *self, const char *sec, const char *key, const char *val)
{
  inisec_t *s = symtab_lookup(&self->if_sections, sec);
  return s ? inisec_get(s, key, val) : val;
}
Пример #28
0
inisec_t *
inifile_get_section(inifile_t *self, const char *sec)
{
  return symtab_lookup(&self->if_sections, sec);
}
Пример #29
0
jl_sym_t *jl_symbol_lookup(const char *str)
{
    return *symtab_lookup(&symtab, str);
}
Пример #30
0
int
inifile_has(inifile_t *self, const char *sec, const char *key)
{
  inisec_t *s = symtab_lookup(&self->if_sections, sec);
  return s ? inisec_has(s, key) : 0;
}