/******************************************************************************* Interface functions. *******************************************************************************/ static yasm_preproc * cpp_preproc_create(const char *in, yasm_symtab *symtab, yasm_linemap *lm, yasm_errwarns *errwarns) { yasm_preproc_cpp *pp = yasm_xmalloc(sizeof(yasm_preproc_cpp)); void * iter; const char * inc_dir; pp->preproc.module = &yasm_cpp_LTX_preproc; pp->f = pp->f_deps = NULL; pp->cur_lm = lm; pp->errwarns = errwarns; pp->flags = 0; pp->filename = yasm__xstrdup(in); TAILQ_INIT(&pp->cpp_args); /* Iterate through the list of include dirs. */ iter = NULL; while ((inc_dir = yasm_get_include_dir(&iter)) != NULL) { cpp_arg_entry *arg = yasm_xmalloc(sizeof(cpp_arg_entry)); arg->op = "-I"; arg->param = yasm__xstrdup(inc_dir); TAILQ_INSERT_TAIL(&pp->cpp_args, arg, entry); } return (yasm_preproc *)pp; }
void yasm_linemap_set(yasm_linemap *linemap, const char *filename, unsigned long virtual_line, unsigned long file_line, unsigned long line_inc) { char *copy; unsigned long i; int replace = 0; line_mapping *mapping = NULL; if (virtual_line == 0) { virtual_line = linemap->current; } /* Replace all existing mappings that have line numbers >= this one. */ for (i = linemap->map_size; i > 0; i--) { if (linemap->map_vector[i-1].line < virtual_line) { if (i < linemap->map_size) { mapping = &linemap->map_vector[i]; linemap->map_size = i + 1; } break; } } if (mapping == NULL) { /* Create a new mapping in the map */ if (linemap->map_size >= linemap->map_allocated) { /* allocate another size bins when full for 2x space */ linemap->map_vector = yasm_xrealloc(linemap->map_vector, 2*linemap->map_allocated*sizeof(line_mapping)); linemap->map_allocated *= 2; } mapping = &linemap->map_vector[linemap->map_size]; linemap->map_size++; } /* Fill it */ if (!filename) { if (linemap->map_size >= 2) mapping->filename = linemap->map_vector[linemap->map_size-2].filename; else filename = "unknown"; } if (filename) { /* Copy the filename (via shared storage) */ copy = yasm__xstrdup(filename); /*@-aliasunique@*/ mapping->filename = HAMT_insert(linemap->filenames, copy, copy, &replace, filename_delete_one); /*@=aliasunique@*/ } mapping->line = virtual_line; mapping->file_line = file_line; mapping->line_inc = line_inc; }
/* strtab functions */ elf_strtab_entry * elf_strtab_entry_create(const char *str) { elf_strtab_entry *entry = yasm_xmalloc(sizeof(elf_strtab_entry)); entry->str = yasm__xstrdup(str); entry->index = 0; return entry; }
static void cpp_preproc_undefine_macro(yasm_preproc *preproc, const char *macroname) { yasm_preproc_cpp *pp = (yasm_preproc_cpp *)preproc; cpp_arg_entry *arg = yasm_xmalloc(sizeof(cpp_arg_entry)); arg->op = "-U"; arg->param = yasm__xstrdup(macroname); TAILQ_INSERT_TAIL(&pp->cpp_args, arg, entry); }
static void cpp_preproc_add_include_file(yasm_preproc *preproc, const char *filename) { yasm_preproc_cpp *pp = (yasm_preproc_cpp *)preproc; cpp_arg_entry *arg = yasm_xmalloc(sizeof(cpp_arg_entry)); arg->op = "-include"; arg->param = yasm__xstrdup(filename); TAILQ_INSERT_TAIL(&pp->cpp_args, arg, entry); }
elf_strtab_head * elf_strtab_create() { elf_strtab_head *strtab = yasm_xmalloc(sizeof(elf_strtab_head)); elf_strtab_entry *entry = yasm_xmalloc(sizeof(elf_strtab_entry)); STAILQ_INIT(strtab); entry->index = 0; entry->str = yasm__xstrdup(""); STAILQ_INSERT_TAIL(strtab, entry, qlink); return strtab; }
static int run_output_test(Test_Entry *test) { char *valstr = yasm__xstrdup(test->input); yasm_intnum *intn = yasm_intnum_create_hex(valstr); unsigned long size, i; unsigned char out[100]; int bad; yasm_xfree(valstr); if (test->negate) yasm_intnum_calc(intn, YASM_EXPR_NEG, NULL); size = yasm_intnum_size_leb128(intn, test->sign); if (size != test->outsize) { yasm_intnum_destroy(intn); sprintf(failmsg, "%ssigned %s%s size() bad size: expected %lu, got %lu!", test->sign?"":"un", test->negate?"-":"", test->input, test->outsize, size); return 1; } for (i=0; i<sizeof(out); i++) out[i] = 0xFF; size = yasm_intnum_get_leb128(intn, out, test->sign); if (size != test->outsize) { yasm_intnum_destroy(intn); sprintf(failmsg, "%ssigned %s%s get() bad size: expected %lu, got %lu!", test->sign?"":"un", test->negate?"-":"", test->input, test->outsize, size); return 1; } bad = 0; for (i=0; i<test->outsize && !bad; i++) { if (out[i] != test->result[i]) bad = 1; } if (bad) { yasm_intnum_destroy(intn); sprintf(failmsg, "%ssigned %s%s get() bad output!", test->sign?"":"un", test->negate?"-":"", test->input); return 1; } yasm_intnum_destroy(intn); return 0; }
void elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str) { elf_strtab_entry *last; if (entry->str) yasm_xfree(entry->str); entry->str = yasm__xstrdup(str); /* Update all following indices since string length probably changes */ last = entry; entry = STAILQ_NEXT(last, qlink); while (entry) { entry->index = last->index + (unsigned long)strlen(last->str) + 1; last = entry; entry = STAILQ_NEXT(last, qlink); } }
int yasm_dir_helper_string(void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg) { /*@dependent@*/ /*@null@*/ const char *local; char **s = (char **)data; if (*s) yasm_xfree(*s); if (!(local = yasm_vp_string(vp))) { yasm_error_set(YASM_ERROR_VALUE, N_("argument to `%s' is not a string or identifier"), vp->val); return -1; } *s = yasm__xstrdup(local); return 0; }
static int run_input_test(Test_Entry *test) { char *valstr = yasm__xstrdup(test->input); yasm_intnum *intn = yasm_intnum_create_hex(valstr); yasm_intnum *testn; unsigned long size; yasm_xfree(valstr); if (test->negate) yasm_intnum_calc(intn, YASM_EXPR_NEG, NULL); testn = yasm_intnum_create_leb128(test->result, test->sign, &size); if (size != test->outsize) { yasm_intnum_destroy(testn); yasm_intnum_destroy(intn); sprintf(failmsg, "%ssigned %s%s create() bad size: expected %lu, got %lu!", test->sign?"":"un", test->negate?"-":"", test->input, test->outsize, size); return 1; } yasm_intnum_calc(intn, YASM_EXPR_EQ, testn); if (!yasm_intnum_is_pos1(intn)) { yasm_intnum_destroy(testn); yasm_intnum_destroy(intn); sprintf(failmsg, "%ssigned %s%s create() bad output!", test->sign?"":"un", test->negate?"-":"", test->input); return 1; } yasm_intnum_destroy(testn); yasm_intnum_destroy(intn); return 0; }
void yasm_linemap_add_source(yasm_linemap *linemap, yasm_bytecode *bc, const char *source) { size_t i; while (linemap->current > linemap->source_info_size) { /* allocate another size bins when full for 2x space */ linemap->source_info = yasm_xrealloc(linemap->source_info, 2*linemap->source_info_size*sizeof(line_source_info)); for (i=linemap->source_info_size; i<linemap->source_info_size*2; i++) { linemap->source_info[i].bc = NULL; linemap->source_info[i].source = NULL; } linemap->source_info_size *= 2; } /* Delete existing info for that line (if any) */ if (linemap->source_info[linemap->current-1].source) yasm_xfree(linemap->source_info[linemap->current-1].source); linemap->source_info[linemap->current-1].bc = bc; linemap->source_info[linemap->current-1].source = yasm__xstrdup(source); }