From 827930b5a4a73a2d302a9169b105dd59d05853db Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 28 Oct 2006 22:06:01 +0000 Subject: [PATCH] Have incbin search include paths (long-missing feature). svn path=/trunk/yasm/; revision=1673 --- libyasm/bc-incbin.c | 19 ++++++++++++------- libyasm/bytecode.h | 6 ++++-- modules/parsers/nasm/nasm-bison.y | 15 ++++++++++----- tools/python-yasm/bytecode.pxi | 3 ++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/libyasm/bc-incbin.c b/libyasm/bc-incbin.c index cf8dc278..6137db7c 100644 --- a/libyasm/bc-incbin.c +++ b/libyasm/bc-incbin.c @@ -30,6 +30,8 @@ #include "coretype.h" +#include "linemgr.h" + #include "errwarn.h" #include "intnum.h" #include "expr.h" @@ -37,11 +39,14 @@ #include "bytecode.h" +#include "file.h" + #include "bc-int.h" typedef struct bytecode_incbin { /*@only@*/ char *filename; /* file to include data from */ + const char *from; /* filename of what contained incbin */ /* starting offset to read from (NULL=0) */ /*@only@*/ /*@null@*/ yasm_expr *start; @@ -158,12 +163,8 @@ bc_incbin_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span, } } - /* FIXME: Search include path for filename. Save full path back into - * filename if save is true. - */ - /* Open file and determine its length */ - f = fopen(incbin->filename, "rb"); + f = yasm_fopen_include(incbin->filename, incbin->from, "rb", NULL); if (!f) { yasm_error_set(YASM_ERROR_IO, N_("`incbin': unable to open file `%s'"), @@ -214,7 +215,7 @@ bc_incbin_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, } /* Open file */ - f = fopen(incbin->filename, "rb"); + f = yasm_fopen_include(incbin->filename, incbin->from, "rb", NULL); if (!f) { yasm_error_set(YASM_ERROR_IO, N_("`incbin': unable to open file `%s'"), incbin->filename); @@ -246,9 +247,13 @@ bc_incbin_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d, yasm_bytecode * yasm_bc_create_incbin(char *filename, yasm_expr *start, yasm_expr *maxlen, - unsigned long line) + yasm_linemap *linemap, unsigned long line) { bytecode_incbin *incbin = yasm_xmalloc(sizeof(bytecode_incbin)); + unsigned long xline; + + /* Find from filename based on line number */ + yasm_linemap_lookup(linemap, line, &incbin->from, &xline); /*@-mustfree@*/ incbin->filename = filename; diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index d5262611..7d277192 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -190,17 +190,19 @@ void yasm_bc_set_multiple(yasm_bytecode *bc, /*@keep@*/ yasm_expr *e); unsigned long line); /** Create a bytecode that includes a binary file verbatim. - * \param filename full path to binary file (kept, do not free) + * \param filename path to binary file (kept, do not free) * \param start starting location in file (in bytes) to read data from * (kept, do not free); may be NULL to indicate 0 * \param maxlen maximum number of bytes to read from the file (kept, do * do not free); may be NULL to indicate no maximum + * \param linemap line mapping repository * \param line virtual line (from yasm_linemap) for the bytecode * \return Newly allocated bytecode. */ /*@only@*/ yasm_bytecode *yasm_bc_create_incbin (/*@only@*/ char *filename, /*@only@*/ /*@null@*/ yasm_expr *start, - /*@only@*/ /*@null@*/ yasm_expr *maxlen, unsigned long line); + /*@only@*/ /*@null@*/ yasm_expr *maxlen, yasm_linemap *linemap, + unsigned long line); /** Create a bytecode that aligns the following bytecode to a boundary. * \param boundary byte alignment (must be a power of two) diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index a006e507..60a33bbc 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -204,19 +204,24 @@ exp: instr $$ = yasm_bc_create_reserve($2, $1/8, cur_line); } | INCBIN string { - $$ = yasm_bc_create_incbin($2.contents, NULL, NULL, cur_line); + $$ = yasm_bc_create_incbin($2.contents, NULL, NULL, + parser_nasm->linemap, cur_line); } | INCBIN string ',' { - $$ = yasm_bc_create_incbin($2.contents, NULL, NULL, cur_line); + $$ = yasm_bc_create_incbin($2.contents, NULL, NULL, + parser_nasm->linemap, cur_line); } | INCBIN string ',' expr { - $$ = yasm_bc_create_incbin($2.contents, $4, NULL, cur_line); + $$ = yasm_bc_create_incbin($2.contents, $4, NULL, + parser_nasm->linemap, cur_line); } | INCBIN string ',' expr ',' { - $$ = yasm_bc_create_incbin($2.contents, $4, NULL, cur_line); + $$ = yasm_bc_create_incbin($2.contents, $4, NULL, + parser_nasm->linemap, cur_line); } | INCBIN string ',' expr ',' expr { - $$ = yasm_bc_create_incbin($2.contents, $4, $6, cur_line); + $$ = yasm_bc_create_incbin($2.contents, $4, $6, parser_nasm->linemap, + cur_line); } ; diff --git a/tools/python-yasm/bytecode.pxi b/tools/python-yasm/bytecode.pxi index 57c181a9..913a4081 100644 --- a/tools/python-yasm/bytecode.pxi +++ b/tools/python-yasm/bytecode.pxi @@ -64,7 +64,8 @@ cdef extern from "libyasm/bytecode.h": cdef yasm_bytecode* yasm_bc_create_reserve(yasm_expr *numitems, unsigned int itemsize, unsigned long line) cdef yasm_bytecode* yasm_bc_create_incbin(char *filename, - yasm_expr *start, yasm_expr *maxlen, unsigned long line) + yasm_expr *start, yasm_expr *maxlen, yasm_linemap *linemap, + unsigned long line) cdef yasm_bytecode* yasm_bc_create_align(yasm_expr *boundary, yasm_expr *fill, yasm_expr *maxskip, unsigned char **code_fill, unsigned long line) -- 2.49.0