|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
review, pull requestHi Peter,
please consider pulling from my repo the following changes. Also I would like the changes to be reviewed so I put the whole diff as well. Comments are welcome! -- Cyrill --- The following changes since commit 4ea846623aa7633ac010504b013cc1c73a5fc09a: Keith Kanios (1): changes.src: document preprocessor directives added since 2.07 nasmdoc.src: document %exitmacro are available in the git repository at: git://repo.or.cz/nasm-cyr.git idata Cyrill Gorcunov (2): nasmlib: Introduce idata_bytes helper stdscan: switch to stdscan_get/set routines assemble.c | 58 ++++------------------------------------------- nasm.c | 4 +- nasmlib.c | 39 +++++++++++++++++++++++++++++++ nasmlib.h | 2 + output/outaout.c | 8 +++--- output/outbin.c | 6 +--- output/outelf32.c | 8 +++--- output/outelf64.c | 8 +++--- output/outobj.c | 4 +- parser.c | 65 ++++++++++++++++++---------------------------------- stdscan.c | 12 +++++++++- stdscan.h | 8 +++--- 12 files changed, 102 insertions(+), 120 deletions(-) diff --git a/assemble.c b/assemble.c index ca2b909..5fceea3 100644 --- a/assemble.c +++ b/assemble.c @@ -344,40 +344,16 @@ int64_t assemble(int32_t segment, int64_t offset, int bits, uint32_t cp, int64_t insn_end; int32_t itimes; int64_t start = offset; - int64_t wsize = 0; /* size for DB etc. */ + int64_t wsize; /* size for DB etc. */ errfunc = error; /* to pass to other functions */ cpu = cp; outfmt = output; /* likewise */ list = listgen; /* and again */ - switch (instruction->opcode) { - case -1: + wsize = idata_bytes(instruction->opcode); + if (wsize == -1) return 0; - case I_DB: - wsize = 1; - break; - case I_DW: - wsize = 2; - break; - case I_DD: - wsize = 4; - break; - case I_DQ: - wsize = 8; - break; - case I_DT: - wsize = 10; - break; - case I_DO: - wsize = 16; - break; - case I_DY: - wsize = 32; - break; - default: - break; - } if (wsize) { extop *e; @@ -684,34 +660,10 @@ int64_t insn_size(int32_t segment, int64_t offset, int bits, uint32_t cp, instruction->opcode == I_DT || instruction->opcode == I_DO || instruction->opcode == I_DY) { extop *e; - int32_t isize, osize, wsize = 0; /* placate gcc */ + int32_t isize, osize, wsize; isize = 0; - switch (instruction->opcode) { - case I_DB: - wsize = 1; - break; - case I_DW: - wsize = 2; - break; - case I_DD: - wsize = 4; - break; - case I_DQ: - wsize = 8; - break; - case I_DT: - wsize = 10; - break; - case I_DO: - wsize = 16; - break; - case I_DY: - wsize = 32; - break; - default: - break; - } + wsize = idata_bytes(instruction->opcode); list_for_each(e, instruction->eops) { int32_t align; diff --git a/nasm.c b/nasm.c index d955660..ac2adde 100644 --- a/nasm.c +++ b/nasm.c @@ -1365,7 +1365,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) } case D_ABSOLUTE: /* [ABSOLUTE address] */ stdscan_reset(); - stdscan_bufptr = value; + stdscan_set(value); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, pass2, nasm_error, NULL); @@ -1470,7 +1470,7 @@ static void assemble_file(char *fname, StrList **depend_ptr) break; case D_DEFAULT: /* [DEFAULT] */ stdscan_reset(); - stdscan_bufptr = value; + stdscan_set(value); tokval.t_type = TOKEN_INVALID; if (stdscan(NULL, &tokval) == TOKEN_SPECIAL) { switch ((int)tokval.t_integer) { diff --git a/nasmlib.c b/nasmlib.c index 0dea39e..fe39281 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -689,3 +689,42 @@ char *nasm_zap_spaces_rev(char *p) *p-- = 0x0; return p; } + +/* + * initialized data bytes from opcode + */ +int idata_bytes(int opcode) +{ + unsigned int ret; + + switch (opcode) { + case I_DB: + ret = 1; + break; + case I_DW: + ret = 2; + break; + case I_DD: + ret = 4; + break; + case I_DQ: + ret = 8; + break; + case I_DT: + ret = 10; + break; + case I_DO: + ret = 16; + break; + case I_DY: + ret = 32; + break; + case I_none: + ret = -1; + break; + default: + ret = 0; + break; + } + return ret; +} diff --git a/nasmlib.h b/nasmlib.h index 2b30ef4..9d39117 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -415,4 +415,6 @@ static inline bool overflow_unsigned(int64_t value, int bytes) return value < vmin || value > vmax; } +int idata_bytes(int opcode); + #endif diff --git a/output/outaout.c b/output/outaout.c index f0a86ec..113eafe 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -299,7 +299,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, while (*p && nasm_isspace(*p)) p++; stdscan_reset(); - stdscan_bufptr = p; + stdscan_set(p); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { @@ -379,7 +379,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, struct tokenval tokval; expr *e; int fwd = false; - char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */ + char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */ if (!bsd) { nasm_error(ERR_NONFATAL, "Linux a.out does not support" @@ -393,7 +393,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, */ sym->type |= SYM_WITH_SIZE; stdscan_reset(); - stdscan_bufptr = special + n; + stdscan_set(special + n); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, NULL); @@ -409,7 +409,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, sym->size = reloc_value(e); } } - stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ + stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ } special_used = true; } diff --git a/output/outbin.c b/output/outbin.c index ba9947d..41c28f3 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -152,8 +152,6 @@ static struct Reloc { struct Section *target; } *relocs, **reloctail; -extern char *stdscan_bufptr; - static uint8_t format_mode; /* 0 = original bin, 1 = extended bin */ static int32_t current_section; /* only really needed if format_mode = 0 */ static uint64_t origin; @@ -985,7 +983,7 @@ static int bin_read_attribute(char **line, int *attribute, /* Read and evaluate the expression. */ stdscan_reset(); - stdscan_bufptr = exp; + stdscan_set(exp); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { @@ -1292,7 +1290,7 @@ static int bin_directive(enum directives directive, char *args, int pass) expr *e; stdscan_reset(); - stdscan_bufptr = args; + stdscan_set(args); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { diff --git a/output/outelf32.c b/output/outelf32.c index 47c9d10..8cb01de 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -495,7 +495,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, while (*p && nasm_isspace(*p)) p++; stdscan_reset(); - stdscan_bufptr = p; + stdscan_set(p); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { @@ -630,7 +630,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, struct tokenval tokval; expr *e; int fwd = 0; - char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */ + char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */ while (special[n] && nasm_isspace(special[n])) n++; @@ -639,7 +639,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, * evaluate it. */ stdscan_reset(); - stdscan_bufptr = special + n; + stdscan_set(special + n); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, NULL); @@ -654,7 +654,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else sym->size = reloc_value(e); } - stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ + stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ } special_used = true; } diff --git a/output/outelf64.c b/output/outelf64.c index b005693..3b9fae1 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -499,7 +499,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, while (*p && nasm_isspace(*p)) p++; stdscan_reset(); - stdscan_bufptr = p; + stdscan_set(p); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { @@ -635,7 +635,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, struct tokenval tokval; expr *e; int fwd = 0; - char *saveme = stdscan_bufptr; /* bugfix? fbk 8/10/00 */ + char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */ while (special[n] && nasm_isspace(special[n])) n++; @@ -644,7 +644,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, * evaluate it. */ stdscan_reset(); - stdscan_bufptr = special + n; + stdscan_set(special + n); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, &fwd, 0, nasm_error, NULL); @@ -659,7 +659,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else sym->size = reloc_value(e); } - stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ + stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ } special_used = true; } diff --git a/output/outobj.c b/output/outobj.c index 87846fb..804ff52 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -966,7 +966,7 @@ static void obj_deflabel(char *name, int32_t segment, struct tokenval tokval; stdscan_reset(); - stdscan_bufptr = special; + stdscan_set(special); tokval.t_type = TOKEN_INVALID; e = evaluate(stdscan, NULL, &tokval, NULL, 1, nasm_error, NULL); if (e) { @@ -976,7 +976,7 @@ static void obj_deflabel(char *name, int32_t segment, else ext->commonelem = reloc_value(e); } - special = stdscan_bufptr; + special = stdscan_get(); } else { nasm_error(ERR_NONFATAL, "`%s': element-size specifications only" diff --git a/parser.c b/parser.c index d0d660b..f597013 100644 --- a/parser.c +++ b/parser.c @@ -205,7 +205,7 @@ restart_parse: result->forw_ref = false; stdscan_reset(); - stdscan_bufptr = buffer; + stdscan_set(buffer); i = stdscan(NULL, &tokval); result->label = NULL; /* Assume no label */ @@ -417,56 +417,37 @@ restart_parse: if (i && i != ',') i = stdscan(NULL, &tokval); } else if (i == '-' || i == '+') { - char *save = stdscan_bufptr; + char *save = stdscan_get(); int token = i; sign = (i == '-') ? -1 : 1; i = stdscan(NULL, &tokval); if (i != TOKEN_FLOAT) { - stdscan_bufptr = save; + stdscan_set(save); i = tokval.t_type = token; goto is_expression; } else { goto is_float; } } else if (i == TOKEN_FLOAT) { - is_float: +is_float: eop->type = EOT_DB_STRING; result->eops_float = true; - switch (result->opcode) { - case I_DB: - eop->stringlen = 1; - break; - case I_DW: - eop->stringlen = 2; - break; - case I_DD: - eop->stringlen = 4; - break; - case I_DQ: - eop->stringlen = 8; - break; - case I_DT: - eop->stringlen = 10; - break; - case I_DO: - eop->stringlen = 16; - break; - case I_DY: - nasm_error(ERR_NONFATAL, "floating-point constant" - " encountered in DY instruction"); - eop->stringlen = 0; - break; - default: - nasm_error(ERR_NONFATAL, "floating-point constant" - " encountered in unknown instruction"); - /* - * fix suggested by Pedro Gimeno... original line - * was: - * eop->type = EOT_NOTHING; - */ - eop->stringlen = 0; - break; - } + + eop->stringlen = idata_bytes(result->opcode); + if (eop->stringlen > 16) { + nasm_error(ERR_NONFATAL, "floating-point constant" + " encountered in DY instruction"); + eop->stringlen = 0; + } else if (eop->stringlen < 1) { + nasm_error(ERR_NONFATAL, "floating-point constant" + " encountered in unknown instruction"); + /* + * fix suggested by Pedro Gimeno... original line was: + * eop->type = EOT_NOTHING; + */ + eop->stringlen = 0; + } + eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen); tail = &eop->next; *fixptr = eop; @@ -481,7 +462,7 @@ restart_parse: /* anything else, assume it is an expression */ expr *value; - is_expression: +is_expression: value = evaluate(stdscan, NULL, &tokval, NULL, critical, nasm_error, NULL); i = tokval.t_type; @@ -970,9 +951,9 @@ static int is_comma_next(void) int i; struct tokenval tv; - p = stdscan_bufptr; + p = stdscan_get(); i = stdscan(NULL, &tv); - stdscan_bufptr = p; + stdscan_set(p); return (i == ',' || i == ';' || !i); } diff --git a/stdscan.c b/stdscan.c index 0f7b3bd..f50dd85 100644 --- a/stdscan.c +++ b/stdscan.c @@ -50,10 +50,21 @@ * formats. It keeps a succession of temporary-storage strings in * stdscan_tempstorage, which can be cleared using stdscan_reset. */ +static char *stdscan_bufptr = NULL; static char **stdscan_tempstorage = NULL; static int stdscan_tempsize = 0, stdscan_templen = 0; #define STDSCAN_TEMP_DELTA 256 +void stdscan_set(char *str) +{ + stdscan_bufptr = str; +} + +char *stdscan_get(void) +{ + return stdscan_bufptr; +} + static void stdscan_pop(void) { nasm_free(stdscan_tempstorage[--stdscan_templen]); @@ -94,7 +105,6 @@ static char *stdscan_copy(char *p, int len) return text; } -char *stdscan_bufptr = NULL; int stdscan(void *private_data, struct tokenval *tv) { char ourcopy[MAX_KEYWORD + 1], *r, *s; diff --git a/stdscan.h b/stdscan.h index 0546ef2..8dbc2d0 100644 --- a/stdscan.h +++ b/stdscan.h @@ -37,10 +37,10 @@ #ifndef NASM_STDSCAN_H #define NASM_STDSCAN_H -/* - * Standard scanner. - */ -extern char *stdscan_bufptr; + +/* Standard scanner */ +void stdscan_set(char *str); +char *stdscan_get(void); void stdscan_reset(void); int stdscan(void *private_data, struct tokenval *tv); int nasm_token_hash(const char *token, struct tokenval *tv); ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Nasm-devel mailing list Nasm-devel@... https://lists.sourceforge.net/lists/listinfo/nasm-devel |
|
|
Re: review, pull requestCyrill Gorcunov wrote:
... > - stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ > + stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ While you're at it, you could remove my comment(s - it seems to have reproduced). It *is* a bugfix (apparently). "saveme" might have a better name, too... Nice cleanup, Cyrill. Thanks! Best, Frank ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Nasm-devel mailing list Nasm-devel@... https://lists.sourceforge.net/lists/listinfo/nasm-devel |
|
|
Re: review, pull request[Frank Kotler - Thu, Oct 29, 2009 at 04:54:23PM -0400]
| Cyrill Gorcunov wrote: | | ... | > - stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ | > + stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ | | While you're at it, you could remove my comment(s - it seems to have | reproduced). It *is* a bugfix (apparently). "saveme" might have a better | name, too... | | Nice cleanup, Cyrill. Thanks! | | Best, | Frank | Thanks Frank! Will do and push new pull-request. -- Cyrill ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Nasm-devel mailing list Nasm-devel@... https://lists.sourceforge.net/lists/listinfo/nasm-devel |
|
|
Re: review, pull request[Cyrill Gorcunov - Fri, Oct 30, 2009 at 12:10:16AM +0300]
| [Frank Kotler - Thu, Oct 29, 2009 at 04:54:23PM -0400] | | Cyrill Gorcunov wrote: | | | | ... | | > - stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ | | > + stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ | | | | While you're at it, you could remove my comment(s - it seems to have | | reproduced). It *is* a bugfix (apparently). "saveme" might have a better | | name, too... | | | | Nice cleanup, Cyrill. Thanks! | | | | Best, | | Frank | | | | Thanks Frank! Will do and push new pull-request. | | -- Cyrill Frank, I made it this way (patch below). Pushed it into my repo upon last -idata commit. Ie request pull includes this commit too. Ping me if you find something inconvenient with commit log text. I didn't change "saveme" name since I have some idea about this (ie perhaps we could switch to some other interface here as well). Need to think a bit more. But not now (I'm out of time at moment) :) -- Cyrill --- From: Cyrill Gorcunov <gorcunov@...> Date: Fri, 30 Oct 2009 00:23:48 +0300 Subject: [PATCH] Remove outdated comments >From Frank Kotler: | ... | > - stdscan_bufptr = saveme; /* bugfix? fbk 8/10/00 */ | > + stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ | | While you're at it, you could remove my comment(s - it seems to have | reproduced). It *is* a bugfix (apparently). "saveme" might have a better | name, too... So get rid of them. Reported-by: Frank Kotler <fbkotler@...> Signed-off-by: Cyrill Gorcunov <gorcunov@...> --- output/outaout.c | 4 ++-- output/outelf32.c | 4 ++-- output/outelf64.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/output/outaout.c b/output/outaout.c index 113eafe..e2a9075 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -379,7 +379,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, struct tokenval tokval; expr *e; int fwd = false; - char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */ + char *saveme = stdscan_get(); if (!bsd) { nasm_error(ERR_NONFATAL, "Linux a.out does not support" @@ -409,7 +409,7 @@ static void aout_deflabel(char *name, int32_t segment, int64_t offset, sym->size = reloc_value(e); } } - stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ + stdscan_set(saveme); } special_used = true; } diff --git a/output/outelf32.c b/output/outelf32.c index 8cb01de..32e7d09 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -630,7 +630,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, struct tokenval tokval; expr *e; int fwd = 0; - char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */ + char *saveme = stdscan_get(); while (special[n] && nasm_isspace(special[n])) n++; @@ -654,7 +654,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else sym->size = reloc_value(e); } - stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ + stdscan_set(saveme); } special_used = true; } diff --git a/output/outelf64.c b/output/outelf64.c index 3b9fae1..3c42484 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -635,7 +635,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, struct tokenval tokval; expr *e; int fwd = 0; - char *saveme = stdscan_get(); /* bugfix? fbk 8/10/00 */ + char *saveme = stdscan_get(); while (special[n] && nasm_isspace(special[n])) n++; @@ -659,7 +659,7 @@ static void elf_deflabel(char *name, int32_t segment, int64_t offset, else sym->size = reloc_value(e); } - stdscan_set(saveme); /* bugfix? fbk 8/10/00 */ + stdscan_set(saveme); } special_used = true; } -- 1.6.5 ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Nasm-devel mailing list Nasm-devel@... https://lists.sourceforge.net/lists/listinfo/nasm-devel |
| Free embeddable forum powered by Nabble | Forum Help |