static void collect_arguments (symbol *sym, struct obstack *argptr, struct obstack *arguments) { token_data td; token_data *tdp; bool more_args; bool groks_macro_args = SYMBOL_MACRO_ARGS (sym); TOKEN_DATA_TYPE (&td) = TOKEN_TEXT; TOKEN_DATA_TEXT (&td) = SYMBOL_NAME (sym); tdp = (token_data *) obstack_copy (arguments, &td, sizeof td); obstack_ptr_grow (argptr, tdp); if (peek_token () == TOKEN_OPEN) { next_token (&td, NULL); /* gobble parenthesis */ do { more_args = expand_argument (arguments, &td); if (!groks_macro_args && TOKEN_DATA_TYPE (&td) == TOKEN_FUNC) { TOKEN_DATA_TYPE (&td) = TOKEN_TEXT; TOKEN_DATA_TEXT (&td) = (char *) ""; } tdp = (token_data *) obstack_copy (arguments, &td, sizeof td); obstack_ptr_grow (argptr, tdp); } while (more_args); } }
static char * copy_string_to_obstack (struct obstack *obstack, const char *string, long *len) { *len = strlen (string); return obstack_copy (obstack, string, *len); }
void s_if (int arg) { expressionS operand; struct conditional_frame cframe; int t; char *stop = NULL; char stopc; if (flag_mri) stop = mri_comment_field (&stopc); /* Leading whitespace is part of operand. */ SKIP_WHITESPACE (); if (current_cframe != NULL && current_cframe->ignoring) { operand.X_add_number = 0; while (! is_end_of_line[(unsigned char) *input_line_pointer]) ++input_line_pointer; } else { expression (&operand); if (operand.X_op != O_constant) as_bad (_("non-constant expression in \".if\" statement")); } switch ((operatorT) arg) { case O_eq: t = operand.X_add_number == 0; break; case O_ne: t = operand.X_add_number != 0; break; case O_lt: t = operand.X_add_number < 0; break; case O_le: t = operand.X_add_number <= 0; break; case O_ge: t = operand.X_add_number >= 0; break; case O_gt: t = operand.X_add_number > 0; break; default: abort (); return; } /* If the above error is signaled, this will dispatch using an undefined result. No big deal. */ initialize_cframe (&cframe); cframe.ignoring = cframe.dead_tree || ! t; current_cframe = ((struct conditional_frame *) obstack_copy (&cond_obstack, &cframe, sizeof (cframe))); if (LISTING_SKIP_COND () && cframe.ignoring && (cframe.previous_cframe == NULL || ! cframe.previous_cframe->ignoring)) listing_list (2); if (flag_mri) mri_comment_end (stop, stopc); demand_empty_rest_of_line (); }
type_t *duplicate_type(const type_t *type) { size_t size = get_type_struct_size(type->kind); type_t *const copy = obstack_copy(&type_obst, type, size); copy->base.firm_type = NULL; return copy; }
void s_ifdef (int test_defined) { /* Points to name of symbol. */ char *name; /* Points to symbol. */ symbolS *symbolP; struct conditional_frame cframe; char c; /* Leading whitespace is part of operand. */ SKIP_WHITESPACE (); name = input_line_pointer; if (!is_name_beginner (*name)) { as_bad (_("invalid identifier for \".ifdef\"")); obstack_1grow (&cond_obstack, 0); ignore_rest_of_line (); return; } c = get_symbol_end (); symbolP = symbol_find (name); *input_line_pointer = c; initialize_cframe (&cframe); if (cframe.dead_tree) cframe.ignoring = 1; else { int is_defined; /* Use the same definition of 'defined' as .equiv so that a symbol which has been referenced but not yet given a value/address is considered to be undefined. */ is_defined = symbolP != NULL && S_IS_DEFINED (symbolP) && S_GET_SEGMENT (symbolP) != reg_section; cframe.ignoring = ! (test_defined ^ is_defined); } current_cframe = ((struct conditional_frame *) obstack_copy (&cond_obstack, &cframe, sizeof (cframe))); if (LISTING_SKIP_COND () && cframe.ignoring && (cframe.previous_cframe == NULL || ! cframe.previous_cframe->ignoring)) listing_list (2); demand_empty_rest_of_line (); }
void hidrd_ttbl_set(hidrd_ttbl *tbl, size_t col, size_t line, const char *text) { hidrd_ttbl_seta(tbl, col, line, (text == NULL) ? NULL : obstack_copy(&tbl->obstack, text, strlen(text) + 1)); }
int insert_entry (hash_table *htab, const void *key, size_t keylen, void *data) { unsigned long int hval = compute_hashval (key, keylen); hash_entry *table = (hash_entry *) htab->table; size_t idx = lookup (htab, key, keylen, hval); if (table[idx].used) /* We don't want to overwrite the old value. */ return -1; else { /* An empty bucket has been found. */ insert_entry_2 (htab, obstack_copy (&htab->mem_pool, key, keylen), keylen, hval, idx, data); return 0; } }
void s_ifc (int arg) { char *stop = NULL; char stopc; char *s1, *s2; int len1, len2; int res; struct conditional_frame cframe; if (flag_mri) stop = mri_comment_field (&stopc); s1 = get_mri_string (',', &len1); if (*input_line_pointer != ',') as_bad (_("bad format for ifc or ifnc")); else ++input_line_pointer; s2 = get_mri_string (';', &len2); res = len1 == len2 && strncmp (s1, s2, len1) == 0; initialize_cframe (&cframe); cframe.ignoring = cframe.dead_tree || ! (res ^ arg); current_cframe = ((struct conditional_frame *) obstack_copy (&cond_obstack, &cframe, sizeof (cframe))); if (LISTING_SKIP_COND () && cframe.ignoring && (cframe.previous_cframe == NULL || ! cframe.previous_cframe->ignoring)) listing_list (2); if (flag_mri) mri_comment_end (stop, stopc); demand_empty_rest_of_line (); }
void s_ifeqs (int arg) { char *s1, *s2; int len1, len2; int res; struct conditional_frame cframe; s1 = demand_copy_C_string (&len1); SKIP_WHITESPACE (); if (*input_line_pointer != ',') { as_bad (_(".ifeqs syntax error")); ignore_rest_of_line (); return; } ++input_line_pointer; s2 = demand_copy_C_string (&len2); res = len1 == len2 && strncmp (s1, s2, len1) == 0; initialize_cframe (&cframe); cframe.ignoring = cframe.dead_tree || ! (res ^ arg); current_cframe = ((struct conditional_frame *) obstack_copy (&cond_obstack, &cframe, sizeof (cframe))); if (LISTING_SKIP_COND () && cframe.ignoring && (cframe.previous_cframe == NULL || ! cframe.previous_cframe->ignoring)) listing_list (2); demand_empty_rest_of_line (); }
/* * Build node. Buf contains an the description of this node (without the * enclosing brackets and without any child nodes). */ static mol_device_node_t * build_node( char *buf ) { char tmpbuf[100], tmpbuf2[40]; p_property_t **prop_ptr; mol_device_node_t *dn; char *start, *end; union { void * v; int * i; } node_num; dn = obstack_alloc( &oftree.stack, sizeof(mol_device_node_t) ); memset( dn, 0, sizeof(mol_device_node_t) ); /* unit_string */ tmpbuf[0] = 0; if( findkey( buf, "unit_string", &start, NULL )) { sscanf( start, "%99s", tmpbuf ); dn->unit_string = obstack_copy( &oftree.stack, tmpbuf, strlen(tmpbuf)+1 ); } /* phandle field -- used internally by MOL as node identifier */ if( findkey( buf, "mol_phandle", &start, NULL )) { node_num.v = &dn->node; sscanf( start, "%x", node_num.i); if( (ulong)dn->node < PHANDLE_BASE ) { printm("-----> molrc: mol_phandle field 0x%lX < 0x%x\n", (ulong)dn->node, PHANDLE_BASE ); dn->node = 0; } } if( !dn->node ) dn->node = (p_phandle_t)oftree.next_phandle++; /* properties */ prop_ptr = &dn->properties; while( findkey(buf,"property", &start, &end) ) { p_property_t *pr; format_entry *fe; /* prepare for next property */ buf = end; /* read name and data format */ tmpbuf[0] = tmpbuf2[0]=0; sscanf( start, "%99s %39s", tmpbuf, tmpbuf2 ); /* allocate and insert property */ pr = obstack_alloc( &oftree.stack,sizeof( p_property_t ) ); memset(pr, 0, sizeof(p_property_t) ); *prop_ptr = pr; prop_ptr = &pr->next; pr->name = obstack_copy( &oftree.stack, tmpbuf, strlen(tmpbuf)+1 ); for( fe = format_table; fe->key ; fe++ ) { if( strcmp( tmpbuf2, fe->key ) ) continue; start = strchr( start, '>' ) + 1; *end = 0; pr->value = (unsigned char *)((*fe->proc)( start, &pr->length, fe->refcon )); *end = ')'; break; } if( !fe->key ) printm("WARNING: Data format %s unimplemented\n", tmpbuf2 ); } return dn; }