struct symbol *quad_get_label(quad *q) { char *labelname; struct symbol *sym; struct type t; if (q->label != NULL) return q->label; labelname = malloc(16 * sizeof(char)); if (!labelname) { perror("malloc"); exit(EXIT_FAILURE); } snprintf(labelname, 14 * sizeof(char), "label_%d", next_label_id); next_label_id++; t.is_scalar = TRUE; t.stype = STYPE_ADDR; t.size = 0; sym = symbol_create(labelname, t, FALSE, 0); q->label = sym; return q->label; }
void itbl_init (void) { struct itbl_entry *e, **es; e_processor procn; e_type type; if (!itbl_have_entries) return; /* Since register names don't have a prefix, put them in the symbol table so they can't be used as symbols. This simplifies argument parsing as we can let gas parse registers for us. */ /* Use symbol_create instead of symbol_new so we don't try to output registers into the object file's symbol table. */ for (type = e_regtype0; type < e_nregtypes; type++) for (procn = e_p0; procn < e_nprocs; procn++) { es = get_entries (procn, type); for (e = *es; e; e = e->next) { symbol_table_insert (symbol_create (e->name, reg_section, e->value, &zero_address_frag)); } } append_insns_as_macros (); }
void cgen_asm_record_register (char *name, int number) { /* Use symbol_create here instead of symbol_new so we don't try to output registers into the object file's symbol table. */ symbol_table_insert (symbol_create (name, reg_section, number, &zero_address_frag)); }
symbolS * make_expr_symbol (expressionS *expressionP) { #ifdef NOTYET expressionS zero; #endif symbolS *symbolP; #ifdef NOTYET struct expr_symbol_line *n; #endif if (expressionP->X_op == O_symbol && expressionP->X_add_number == 0) return expressionP->X_add_symbol; #ifndef NOTYET abort (); #else if (expressionP->X_op == O_big) { /* This won't work, because the actual value is stored in generic_floating_point_number or generic_bignum, and we are going to lose it if we haven't already. */ if (expressionP->X_add_number > 0) as_bad (_("bignum invalid")); else as_bad (_("floating point number invalid")); zero.X_op = O_constant; zero.X_add_number = 0; zero.X_unsigned = 0; clean_up_expression (&zero); expressionP = &zero; } /* Putting constant symbols in absolute_section rather than expr_section is convenient for the old a.out code, for which S_GET_SEGMENT does not always retrieve the value put in by S_SET_SEGMENT. */ symbolP = symbol_create (FAKE_LABEL_NAME, (expressionP->X_op == O_constant ? absolute_section : expr_section), 0, &zero_address_frag); symbol_set_value_expression (symbolP, expressionP); if (expressionP->X_op == O_constant) resolve_symbol_value (symbolP); n = (struct expr_symbol_line *) xmalloc (sizeof *n); n->sym = symbolP; as_where (&n->file, &n->line); n->next = expr_symbol_lines; expr_symbol_lines = n; #endif return symbolP; }
void decl_resolve(struct decl* d,int x) { if(!d)return; if(scope_lookup_local(d->name)!=NULL && d->type->kind!=TYPE_FUNCTION) { if(x == 1)printf("Resolve error: %s already declared\n",d->name); get_incrementError(1); } else{ if(scope_level() == 1){ struct symbol *sym = symbol_create(SYMBOL_GLOBAL,d->type,d->name,0,0); d->symbol = sym; scope_bind(d->name,sym); } else { params_local_varibles++; local_variables_cont++; struct symbol *sym = symbol_create(SYMBOL_LOCAL,d->type,d->name,0,0); d->symbol = sym; scope_bind(d->name,sym); } expr_resolve(d->value,x); if(d->type->kind == TYPE_FUNCTION){ param_list_resolve(d->type->params,0); if(!parametro)parametro = hash_table_create(0,0); hash_table_insert(parametro,d->name,d->type); } if(d->code){ scope_enter(); stmt_resolve(d->code,x); d->symbol->total_locals = local_variables_cont; local_variables_cont = 0; params_local_varibles = 0; scope_leave(); } if(d->next){ decl_resolve(d->next,x); } } }
void param_list_resolve(struct param_list *p){ if (p == NULL) { return; } struct symbol *sym = symbol_create(SYMBOL_PARAM, p->type, p->name); if (scope_lookup_local(p->name) != NULL) { fprintf(stderr,"No redeclarations allowed: %s\n",p->name); return; } scope_bind(p->name,sym); param_list_resolve(p->next); }
struct param_list * param_list_resolve( struct param_list *a ) { //struct param_list * params = a; while (a) { if (scope_lookup_local(a->name)) { printf("resolve error: %s is already declared\n", a->name); exit(1); //return; } struct symbol *sym = symbol_create(SYMBOL_PARAM, a->type, a->name); scope_bind(a->name, sym); a = a->next; } return a; }
static int keywords_scope_init () { if (st_create_scope(tableSymbole) == -1) return -1 ; keywords_scope = st_current_scope(tableSymbole); int cpt = 0; char *key = keywords[cpt] ; Symbol *sym; int *val; while(key != NULL) { val = malloc (sizeof(int)); assert(val); switch (cpt) { case 0: /*class*/ *val = CLASS; break ; case 1: /*case*/ *val = CASE; break ; case 2: /*else*/ *val = ELSE; break ; case 3: /*esac*/ *val = ESAC; break ; case 4: /*false*/ *val = FALSE; break ; case 5: /*fi*/ *val = FI; break ; case 6: /*if*/ *val = IF; break ; case 7: /*in*/ *val = IN; break ; case 8: /*inherits*/ *val = INHERITS; break ; case 9: /*isvoid*/ *val = ISVOID; break ; case 10: /*let*/ *val = LET; break ; case 11: /*loop*/ *val = LOOP; break ; case 12: /*new*/ *val = NEW; break ; case 13: /*not*/ *val = NOT; break ; case 14: /*pool*/ *val = POOL; break ; case 15: /*then*/ *val = THEN; break ; case 16: /*true*/ *val = TRUE; break ; case 17: /*while*/ *val = WHILE; break ; } // create and init symbole sym = symbol_create(); symbol_init(sym, free); sym -> id = key; sym -> val = val; sym -> scope = keywords_scope; if (st_add_symbol(tableSymbole, sym) == -1) return -1; key = keywords[++cpt]; } }
symbolS * section_symbol (segT sec) { segment_info_type *seginfo = seg_info (sec); symbolS *s; if (seginfo == 0) abort (); if (seginfo->sym) return seginfo->sym; #ifndef EMIT_SECTION_SYMBOLS #define EMIT_SECTION_SYMBOLS 1 #endif if (! EMIT_SECTION_SYMBOLS || symbol_table_frozen) { /* Here we know it won't be going into the symbol table. */ s = symbol_create (sec->symbol->name, sec, 0, &zero_address_frag); } else { segT seg; s = symbol_find (sec->symbol->name); /* We have to make sure it is the right symbol when we have multiple sections with the same section name. */ if (s == NULL || ((seg = S_GET_SEGMENT (s)) != sec && seg != undefined_section)) s = symbol_new (sec->symbol->name, sec, 0, &zero_address_frag); else if (seg == undefined_section) { S_SET_SEGMENT (s, sec); symbol_set_frag (s, &zero_address_frag); } } S_CLEAR_EXTERNAL (s); /* Use the BFD section symbol, if possible. */ if (obj_sec_sym_ok_for_reloc (sec)) symbol_set_bfdsym (s, sec->symbol); else symbol_get_bfdsym (s)->flags |= BSF_SECTION_SYM; seginfo->sym = s; return s; }
symbol_p stem_create(void) { symbol_p y = symbol_create(t_current); stem_p s = &y->symbol.stem; y->type = SYM_STEM; mpq_init(s->t); mpq_set(s->t, t_current); s->tuplet = NO_ID; s->beam = NO_ID; s->slur_start = NO_ID; s->slur_end = NO_ID; s->articulations = NULL; return y; }
static symbol_p clef_create(niffClef *p) { symbol_p s = symbol_create(t_current); clef_p c = &s->symbol.clef; s->type = SYM_CLEF; c->shape = p->shape; c->step = p->staffStep; c->octave = p->octaveNumber; switch (c->shape) { case 1: /* G clef */ c->offset = c->step + OCTAVE_DIATON; break; case 2: /* F clef */ c->offset = c->step + 5 - 2 * OCTAVE_DIATON; break; case 3: /* C clef */ c->offset = c->step - 1; if (c->step == 4) { c->offset += 0; /* alto */ } else if (c->step == 6) { c->offset += -OCTAVE_DIATON + 3; /* tenor */ } else if (c->step == 0) { c->offset += OCTAVE_DIATON + 1; /* soprano */ } else if (c->step == 2) { c->offset += OCTAVE_DIATON; /* mezzo-soprano */ } else if (c->step == 8) { c->offset += -2 * OCTAVE_DIATON; /* baritone */ } break; case 4: /* percussion "clef" */ case 5: /* Double G clef (C'est quoi????) */ case 6: /* TAB for guitar tabulature */ default: break; } VPRINTF("Insert a clef shape %d offset %d\n", c->shape, c->offset); return s; }
void decl_resolve( struct decl *d, symbol_t sym_type ) { if (!d) return; if (scope_lookup_local(d->name)) { printf("resolve error: %s is already declared\n", d->name); exit(1); } struct symbol *sym = symbol_create(sym_type, d->type, d->name); scope_bind(d->name, sym); // resolve type num_subtype for arrays struct type *temp_t = d->type; while (temp_t) { expr_resolve(temp_t->num_subtype); temp_t = temp_t->subtype; } if (d->code) { scope_enter(); if (d->type->params) { sym->params = d->type->params; param_list_resolve(d->type->params); } stmt_resolve(d->code); scope_exit(); } else if (d->value) { expr_resolve(d->value); } // function prototype if ((!d->code) && d->type->params ) { scope_enter(); sym->params = d->type->params; param_list_resolve(d->type->params); scope_exit(); } if (d->next) decl_resolve(d->next, sym_type); }
static symbol_p rest_create(niffRest *p) { symbol_p s = symbol_create(t_current); note_p n = &s->symbol.note; mpq_init(n->duration); rat2mpq(n->duration, &p->duration); stem_p stem = stem_current; if (mpq_cmp(n->duration, time_sig_current->duration) >= 0 && ! mpq_equal(t_current, t_measure_start)) { fprintf(stderr, "Meet SharpEye rest(measure) bug. Replace start time "); mpq_out_str(stderr, 10, t_current); fprintf(stderr, " with measure start time "); mpq_out_str(stderr, 10, t_measure_start); fprintf(stderr, "\n"); mpq_set(s->start, t_measure_start); stem = NULL; // don't share a stem when the time is incorrect } s->type = SYM_NOTE; n->value = p->staffStep; n->flags |= FLAG_REST; if (stem == NULL) { #if VERBOSE VPRINTF("\n ****** Get a Rest chunk without stem chunk??"); #else fprintf(stderr, "Warning: ****** Get a Rest chunk without stem chunk??\n"); #endif stem = &stem_create()->symbol.stem; } n->tie_start = NO_ID; n->tie_end = NO_ID; n->stem = stem; n->tuplet = stem->tuplet; return s; }
/* * The semantics of get is to return an uninitialized symbol entry * if a lookup fails. */ symbol_t * symtable_get(char *name) { symbol_t *stored_ptr; DBT key; DBT data; int retval; key.data = (void *)name; key.size = strlen(name); if ((retval = symtable->get(symtable, &key, &data, /*flags*/0)) != 0) { if (retval == -1) { perror("Symbol table get operation failed"); exit(EX_SOFTWARE); /* NOTREACHED */ } else if (retval == 1) { /* Symbol wasn't found, so create a new one */ symbol_t *new_symbol; new_symbol = symbol_create(name); data.data = &new_symbol; data.size = sizeof(new_symbol); if (symtable->put(symtable, &key, &data, /*flags*/0) !=0) { perror("Symtable put failed"); exit(EX_SOFTWARE); } return (new_symbol); } else { perror("Unexpected return value from db get routine"); exit(EX_SOFTWARE); /* NOTREACHED */ } } memcpy(&stored_ptr, data.data, sizeof(stored_ptr)); return (stored_ptr); }
// have to store params in a place where they can be resolved in block. void param_list_resolve(struct param_list *p){ if(!p) return; if(scope_lookup_single(p->name)){ printf("resolve error: %s already defined in this scope\n", p->name); error_count++; }else{ int *which = hash_table_lookup(h,"0params"); // which grabs the number of locals from the hash table if(*which >6){ printf("resolve error: too many parameters"); error_count++; printf("Error count: %d\n", error_count); exit(1); } struct symbol *sym = symbol_create(SYMBOL_PARAM, p->type, p->name); sym->which = *which; *which += 1; scope_bind(p->name, sym); p->symbol = sym; //printf("%s resolves to param %d\n", p->name, sym->which); } param_list_resolve(p->next); }
static int bar_number(mpq_t *now, mpq_t remain) { int n = 0; symbol_p scan; mpq_t t; mpq_t t2; mpq_t start; mpq_t end; mpq_t num; mpq_init(t); mpq_init(t2); mpq_init(start); mpq_init(end); mpq_init(num); mpq_set_si(start, 0, 1); if (time_line == NULL) { time_line = symbol_create(start); time_line->type = SYM_TIME_SIGNATURE; mpq_init(time_line->symbol.time_signature.duration); mpq_set_si(time_line->symbol.time_signature.duration, 1, 1); time_line->next = NULL; } scan = time_line; if (scan->next == NULL) { mpq_set(end, *now); } else { mpq_set(end, scan->next->start); } mpq_set(remain, *now); mpq_sub(remain, remain, xly_t_partial); VPRINTF("now = "); VPRINT_MPQ(*now); VPRINTF("\n start = "); VPRINT_MPQ(start); VPRINTF("\n end = "); VPRINT_MPQ(end); VPRINTF("\n remain = "); VPRINT_MPQ(remain); VPRINTF("\n"); while (scan != NULL && mpq_cmp(*now, end) >= 0) { int nu; int de; VPRINTF("\n now = "); VPRINT_MPQ(*now); VPRINTF("\n end = "); VPRINT_MPQ(end); mpq_sub(t, end, start); VPRINTF("\n t = "); VPRINT_MPQ(t); mpq_set(t2, t); mpq_div(t, t2, scan->symbol.time_signature.duration); VPRINTF("\n t = "); VPRINT_MPQ(t); mpq2rat(t, &nu, &de); VPRINTF("\n t = "); VPRINT_MPQ(t); n += nu / de; /* Discount partial bars */ mpq_set_si(num, n, 1); mpq_mul(t, scan->symbol.time_signature.duration, num); mpq_sub(remain, remain, t); VPRINTF("\n remain = "); VPRINT_MPQ(remain); VPRINTF("\n"); mpq_set(start, end); if (scan->next == NULL || scan->next->next == NULL) { mpq_set(end, *now); } else { mpq_set(end, scan->next->next->start); } scan = scan->next; } mpq_clear(t); mpq_clear(start); mpq_clear(end); mpq_clear(num); return n; }
const char * gas_cgen_parse_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, enum cgen_parse_operand_type want, const char **strP, int opindex, int opinfo, enum cgen_parse_operand_result *resultP, bfd_vma *valueP) { #ifdef __STDC__ /* These are volatile to survive the setjmp. */ char * volatile hold; enum cgen_parse_operand_result * volatile resultP_1; volatile int opinfo_1; #else static char *hold; static enum cgen_parse_operand_result *resultP_1; int opinfo_1; #endif const char *errmsg; expressionS exp; #ifdef OBJ_COMPLEX_RELC volatile int signed_p = 0; symbolS * stmp = NULL; bfd_reloc_code_real_type reloc_type; const CGEN_OPERAND * operand; fixS dummy_fixup; #endif if (want == CGEN_PARSE_OPERAND_INIT) { gas_cgen_init_parse (); return NULL; } resultP_1 = resultP; hold = input_line_pointer; input_line_pointer = (char *) *strP; opinfo_1 = opinfo; /* We rely on md_operand to longjmp back to us. This is done via gas_cgen_md_operand. */ if (setjmp (expr_jmp_buf) != 0) { expr_jmp_buf_p = 0; input_line_pointer = (char *) hold; *resultP_1 = CGEN_PARSE_OPERAND_RESULT_ERROR; return _("illegal operand"); } expr_jmp_buf_p = 1; expression (&exp); expr_jmp_buf_p = 0; errmsg = NULL; *strP = input_line_pointer; input_line_pointer = hold; #ifdef TC_CGEN_PARSE_FIX_EXP opinfo_1 = TC_CGEN_PARSE_FIX_EXP (opinfo_1, & exp); #endif /* FIXME: Need to check `want'. */ switch (exp.X_op) { case O_illegal: errmsg = _("illegal operand"); *resultP = CGEN_PARSE_OPERAND_RESULT_ERROR; break; case O_absent: errmsg = _("missing operand"); *resultP = CGEN_PARSE_OPERAND_RESULT_ERROR; break; case O_constant: if (want == CGEN_PARSE_OPERAND_SYMBOLIC) goto de_fault; *valueP = exp.X_add_number; *resultP = CGEN_PARSE_OPERAND_RESULT_NUMBER; break; case O_register: *valueP = exp.X_add_number; *resultP = CGEN_PARSE_OPERAND_RESULT_REGISTER; break; de_fault: default: #ifdef OBJ_COMPLEX_RELC /* Look up operand, check to see if there's an obvious overflow (this helps disambiguate some insn parses). */ operand = cgen_operand_lookup_by_num (cd, opindex); errmsg = weak_operand_overflow_check (& exp, operand); if (! errmsg) { /* Fragment the expression as necessary, and queue a reloc. */ memset (& dummy_fixup, 0, sizeof (fixS)); reloc_type = md_cgen_lookup_reloc (0, operand, & dummy_fixup); if (exp.X_op == O_symbol && reloc_type == BFD_RELOC_RELC && exp.X_add_symbol->sy_value.X_op == O_constant && (!exp.X_add_symbol->bsym || (exp.X_add_symbol->bsym->section != expr_section && exp.X_add_symbol->bsym->section != absolute_section && exp.X_add_symbol->bsym->section != undefined_section))) { /* Local labels will have been (eagerly) turned into constants by now, due to the inappropriately deep insight of the expression parser. Unfortunately make_expr_symbol prematurely dives into the symbol evaluator, and in this case it gets a bad answer, so we manually create the expression symbol we want here. */ stmp = symbol_create (FAKE_LABEL_NAME, expr_section, 0, & zero_address_frag); symbol_set_value_expression (stmp, & exp); } else stmp = make_expr_symbol (& exp); /* If this is a pc-relative RELC operand, we need to subtract "." from the expression. */ if (reloc_type == BFD_RELOC_RELC && CGEN_OPERAND_ATTR_VALUE (operand, CGEN_OPERAND_PCREL_ADDR)) stmp = expr_build_binary (O_subtract, stmp, expr_build_dot ()); /* FIXME: this is not a perfect heuristic for figuring out whether an operand is signed: it only works when the operand is an immediate. it's not terribly likely that any other values will be signed relocs, but it's possible. */ if (operand && (operand->hw_type == HW_H_SINT)) signed_p = 1; if (stmp->bsym && (stmp->bsym->section == expr_section) && ! S_IS_LOCAL (stmp)) { if (signed_p) stmp->bsym->flags |= BSF_SRELC; else stmp->bsym->flags |= BSF_RELC; } /* Now package it all up for the fixup emitter. */ exp.X_op = O_symbol; exp.X_op_symbol = 0; exp.X_add_symbol = stmp; exp.X_add_number = 0; /* Re-init rightshift quantity, just in case. */ rightshift = operand->length; queue_fixup_recursively (opindex, opinfo_1, & exp, (reloc_type == BFD_RELOC_RELC) ? & (operand->index_fields) : 0, signed_p, -1); } * resultP = errmsg ? CGEN_PARSE_OPERAND_RESULT_ERROR : CGEN_PARSE_OPERAND_RESULT_QUEUED; *valueP = 0; #else queue_fixup (opindex, opinfo_1, &exp); *valueP = 0; *resultP = CGEN_PARSE_OPERAND_RESULT_QUEUED; #endif break; } return errmsg; }