-/* $Id: yasm.c,v 1.7 2001/08/19 03:52:58 peter Exp $
+/* $Id: yasm.c,v 1.8 2001/08/19 05:41:01 peter Exp $
* Program entry point, command line parsing
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "util.h"
#include "bytecode.h"
#include "section.h"
#include "outfmt.h"
-/* $Id: bytecode.c,v 1.16 2001/08/19 03:52:58 peter Exp $
+/* $Id: bytecode.c,v 1.17 2001/08/19 05:41:01 peter Exp $
* Bytecode utility functions
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "util.h"
#include "globals.h"
#include "bytecode.h"
#include "errwarn.h"
unsigned char im_len,
unsigned char im_sign)
{
- bc->next = (bytecode *)NULL;
bc->type = BC_INSN;
if (ea_ptr) {
unsigned char near_op2,
unsigned char addrsize)
{
- bc->next = (bytecode *)NULL;
bc->type = BC_JMPREL;
bc->data.jmprel.target = target->val;
}
void
-BuildBC_Data(bytecode *bc, dataval *data, unsigned long size)
+BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size)
{
- dataval *cur = data;
+ dataval *cur;
/* First check to see if all the data elements are valid for the size
* being set.
* constants (equ's) should always be legal, but labels should raise
* warnings when used in db or dq context at the minimum).
*/
- while (cur) {
+ STAILQ_FOREACH(cur, datahead, link) {
switch (cur->type) {
case DV_EMPTY:
case DV_STRING:
Error(ERR_DECLDATA_EXPR, (char *)NULL, "DT");
break;
}
- cur = cur->next;
}
- bc->next = (bytecode *)NULL;
bc->type = BC_DATA;
- bc->data.data.data = data;
+ bc->data.data.datahead = *datahead;
bc->data.data.size = size;
BuildBC_Common(bc);
void
BuildBC_Reserve(bytecode *bc, expr *numitems, unsigned long itemsize)
{
- bc->next = (bytecode *)NULL;
bc->type = BC_RESERVE;
bc->data.reserve.numitems = numitems;
printf("Final Element Size=%u\n",
(unsigned int)bc->data.data.size);
printf("Elements:\n");
- dataval_print(bc->data.data.data);
+ dataval_print(&bc->data.data.datahead);
break;
case BC_RESERVE:
printf("_Reserve_\n");
if (!retval)
Fatal(FATAL_NOMEM);
- retval->next = (dataval *)NULL;
- retval->last = retval;
retval->type = DV_EXPR;
retval->data.exp = exp;
if (!retval)
Fatal(FATAL_NOMEM);
- retval->next = (dataval *)NULL;
- retval->last = retval;
retval->type = DV_FLOAT;
retval->data.float_val = float_val;
if (!retval)
Fatal(FATAL_NOMEM);
- retval->next = (dataval *)NULL;
- retval->last = retval;
retval->type = DV_STRING;
retval->data.str_val = str_val;
return retval;
}
-dataval *
-dataval_append(dataval *list, dataval *item)
-{
- if (item)
- item->next = (dataval *)NULL;
-
- if (!list) {
- item->last = item;
- return item;
- } else {
- if (item) {
- list->last->next = item;
- list->last = item;
- item->last = (dataval *)NULL;
- }
- return list;
- }
-}
-
void
-dataval_print(dataval *start)
+dataval_print(datavalhead *head)
{
- dataval *cur = start;
+ dataval *cur;
- while (cur) {
+ STAILQ_FOREACH(cur, head, link) {
switch (cur->type) {
case DV_EMPTY:
printf(" Empty\n");
printf(" String=%s\n", cur->data.str_val);
break;
}
-
- cur = cur->next;
}
}
-/* $Id: bytecode.h,v 1.16 2001/08/19 03:52:58 peter Exp $
+/* $Id: bytecode.h,v 1.17 2001/08/19 05:41:01 peter Exp $
* Bytecode utility functions header file
*
* Copyright (C) 2001 Peter Johnson
unsigned char f_sign; /* 1 if final imm should be signed */
} immval;
+typedef STAILQ_HEAD(datavalhead_s, dataval_s) datavalhead;
+
typedef struct dataval_s {
- struct dataval_s *next, *last;
+ STAILQ_ENTRY(dataval_s) link;
enum { DV_EMPTY, DV_EXPR, DV_FLOAT, DV_STRING } type;
} targetval;
typedef struct bytecode_s {
- struct bytecode_s *next;
+ STAILQ_ENTRY(bytecode_s) link;
enum { BC_EMPTY, BC_INSN, BC_JMPREL, BC_DATA, BC_RESERVE } type;
unsigned char lockrep_pre; /* 0 indicates no prefix */
} jmprel;
struct {
- dataval *data; /* non-converted data (linked list) */
+ /* non-converted data (linked list) */
+ datavalhead datahead;
/* final (converted) size of each element (in bytes) */
unsigned char size;
unsigned char near_op2,
unsigned char addrsize);
-void BuildBC_Data(bytecode *bc, dataval *data, unsigned long size);
+void BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size);
void BuildBC_Reserve(bytecode *bc,
struct expr_s *numitems,
dataval *dataval_append(dataval *list, dataval *item);
-void dataval_print(dataval *start);
+void dataval_print(datavalhead *head);
#endif
-/* $Id: bison.y.in,v 1.23 2001/08/19 02:15:18 peter Exp $
+/* $Id: bison.y.in,v 1.24 2001/08/19 05:41:01 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%{
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <math.h>
#include <stdlib.h>
+#include "util.h"
#include "symrec.h"
#include "globals.h"
#include "bytecode.h"
expr *exp;
immval im_val;
targetval tgt_val;
+ datavalhead datahead;
dataval *data;
bytecode bc;
}
%type <syminfo> explabel
%type <sym> label_id
%type <tgt_val> target
-%type <data> dataval datavals
+%type <data> dataval
+%type <datahead> datavals
%left '|'
%left '^'
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, $2, $1); }
+ | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
| RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
;
-datavals: dataval
- | datavals ',' dataval { $$ = dataval_append($1, $3); }
+datavals: dataval {
+ STAILQ_INIT(&$$);
+ STAILQ_INSERT_TAIL(&$$, $1, link);
+ }
+ | datavals ',' dataval {
+ STAILQ_INSERT_TAIL(&$1, $3, link);
+ $$ = $1;
+ }
;
dataval: expr_no_string { $$ = dataval_new_expr($1); }
-/* $Id: nasm-bison.y,v 1.23 2001/08/19 02:15:18 peter Exp $
+/* $Id: nasm-bison.y,v 1.24 2001/08/19 05:41:01 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%{
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <math.h>
#include <stdlib.h>
+#include "util.h"
#include "symrec.h"
#include "globals.h"
#include "bytecode.h"
expr *exp;
immval im_val;
targetval tgt_val;
+ datavalhead datahead;
dataval *data;
bytecode bc;
}
%type <syminfo> explabel
%type <sym> label_id
%type <tgt_val> target
-%type <data> dataval datavals
+%type <data> dataval
+%type <datahead> datavals
%left '|'
%left '^'
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, $2, $1); }
+ | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
| RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
;
-datavals: dataval
- | datavals ',' dataval { $$ = dataval_append($1, $3); }
+datavals: dataval {
+ STAILQ_INIT(&$$);
+ STAILQ_INSERT_TAIL(&$$, $1, link);
+ }
+ | datavals ',' dataval {
+ STAILQ_INSERT_TAIL(&$1, $3, link);
+ $$ = $1;
+ }
;
dataval: expr_no_string { $$ = dataval_new_expr($1); }
-/* $Id: nasm-parser.c,v 1.3 2001/08/19 02:57:02 peter Exp $
+/* $Id: nasm-parser.c,v 1.4 2001/08/19 05:41:01 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
+#include "util.h"
#include "bytecode.h"
#include "section.h"
#include "outfmt.h"
-/* $Id: parser.c,v 1.3 2001/08/19 02:57:02 peter Exp $
+/* $Id: parser.c,v 1.4 2001/08/19 05:41:01 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
+#include "util.h"
#include "bytecode.h"
#include "section.h"
#include "outfmt.h"
-/* $Id: bytecode.c,v 1.16 2001/08/19 03:52:58 peter Exp $
+/* $Id: bytecode.c,v 1.17 2001/08/19 05:41:01 peter Exp $
* Bytecode utility functions
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "util.h"
#include "globals.h"
#include "bytecode.h"
#include "errwarn.h"
unsigned char im_len,
unsigned char im_sign)
{
- bc->next = (bytecode *)NULL;
bc->type = BC_INSN;
if (ea_ptr) {
unsigned char near_op2,
unsigned char addrsize)
{
- bc->next = (bytecode *)NULL;
bc->type = BC_JMPREL;
bc->data.jmprel.target = target->val;
}
void
-BuildBC_Data(bytecode *bc, dataval *data, unsigned long size)
+BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size)
{
- dataval *cur = data;
+ dataval *cur;
/* First check to see if all the data elements are valid for the size
* being set.
* constants (equ's) should always be legal, but labels should raise
* warnings when used in db or dq context at the minimum).
*/
- while (cur) {
+ STAILQ_FOREACH(cur, datahead, link) {
switch (cur->type) {
case DV_EMPTY:
case DV_STRING:
Error(ERR_DECLDATA_EXPR, (char *)NULL, "DT");
break;
}
- cur = cur->next;
}
- bc->next = (bytecode *)NULL;
bc->type = BC_DATA;
- bc->data.data.data = data;
+ bc->data.data.datahead = *datahead;
bc->data.data.size = size;
BuildBC_Common(bc);
void
BuildBC_Reserve(bytecode *bc, expr *numitems, unsigned long itemsize)
{
- bc->next = (bytecode *)NULL;
bc->type = BC_RESERVE;
bc->data.reserve.numitems = numitems;
printf("Final Element Size=%u\n",
(unsigned int)bc->data.data.size);
printf("Elements:\n");
- dataval_print(bc->data.data.data);
+ dataval_print(&bc->data.data.datahead);
break;
case BC_RESERVE:
printf("_Reserve_\n");
if (!retval)
Fatal(FATAL_NOMEM);
- retval->next = (dataval *)NULL;
- retval->last = retval;
retval->type = DV_EXPR;
retval->data.exp = exp;
if (!retval)
Fatal(FATAL_NOMEM);
- retval->next = (dataval *)NULL;
- retval->last = retval;
retval->type = DV_FLOAT;
retval->data.float_val = float_val;
if (!retval)
Fatal(FATAL_NOMEM);
- retval->next = (dataval *)NULL;
- retval->last = retval;
retval->type = DV_STRING;
retval->data.str_val = str_val;
return retval;
}
-dataval *
-dataval_append(dataval *list, dataval *item)
-{
- if (item)
- item->next = (dataval *)NULL;
-
- if (!list) {
- item->last = item;
- return item;
- } else {
- if (item) {
- list->last->next = item;
- list->last = item;
- item->last = (dataval *)NULL;
- }
- return list;
- }
-}
-
void
-dataval_print(dataval *start)
+dataval_print(datavalhead *head)
{
- dataval *cur = start;
+ dataval *cur;
- while (cur) {
+ STAILQ_FOREACH(cur, head, link) {
switch (cur->type) {
case DV_EMPTY:
printf(" Empty\n");
printf(" String=%s\n", cur->data.str_val);
break;
}
-
- cur = cur->next;
}
}
-/* $Id: bytecode.h,v 1.16 2001/08/19 03:52:58 peter Exp $
+/* $Id: bytecode.h,v 1.17 2001/08/19 05:41:01 peter Exp $
* Bytecode utility functions header file
*
* Copyright (C) 2001 Peter Johnson
unsigned char f_sign; /* 1 if final imm should be signed */
} immval;
+typedef STAILQ_HEAD(datavalhead_s, dataval_s) datavalhead;
+
typedef struct dataval_s {
- struct dataval_s *next, *last;
+ STAILQ_ENTRY(dataval_s) link;
enum { DV_EMPTY, DV_EXPR, DV_FLOAT, DV_STRING } type;
} targetval;
typedef struct bytecode_s {
- struct bytecode_s *next;
+ STAILQ_ENTRY(bytecode_s) link;
enum { BC_EMPTY, BC_INSN, BC_JMPREL, BC_DATA, BC_RESERVE } type;
unsigned char lockrep_pre; /* 0 indicates no prefix */
} jmprel;
struct {
- dataval *data; /* non-converted data (linked list) */
+ /* non-converted data (linked list) */
+ datavalhead datahead;
/* final (converted) size of each element (in bytes) */
unsigned char size;
unsigned char near_op2,
unsigned char addrsize);
-void BuildBC_Data(bytecode *bc, dataval *data, unsigned long size);
+void BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size);
void BuildBC_Reserve(bytecode *bc,
struct expr_s *numitems,
dataval *dataval_append(dataval *list, dataval *item);
-void dataval_print(dataval *start);
+void dataval_print(datavalhead *head);
#endif
-/* $Id: main.c,v 1.7 2001/08/19 03:52:58 peter Exp $
+/* $Id: main.c,v 1.8 2001/08/19 05:41:01 peter Exp $
* Program entry point, command line parsing
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "util.h"
#include "bytecode.h"
#include "section.h"
#include "outfmt.h"
-/* $Id: bison.y.in,v 1.23 2001/08/19 02:15:18 peter Exp $
+/* $Id: bison.y.in,v 1.24 2001/08/19 05:41:01 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%{
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <math.h>
#include <stdlib.h>
+#include "util.h"
#include "symrec.h"
#include "globals.h"
#include "bytecode.h"
expr *exp;
immval im_val;
targetval tgt_val;
+ datavalhead datahead;
dataval *data;
bytecode bc;
}
%type <syminfo> explabel
%type <sym> label_id
%type <tgt_val> target
-%type <data> dataval datavals
+%type <data> dataval
+%type <datahead> datavals
%left '|'
%left '^'
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, $2, $1); }
+ | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
| RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
;
-datavals: dataval
- | datavals ',' dataval { $$ = dataval_append($1, $3); }
+datavals: dataval {
+ STAILQ_INIT(&$$);
+ STAILQ_INSERT_TAIL(&$$, $1, link);
+ }
+ | datavals ',' dataval {
+ STAILQ_INSERT_TAIL(&$1, $3, link);
+ $$ = $1;
+ }
;
dataval: expr_no_string { $$ = dataval_new_expr($1); }
-/* $Id: nasm-bison.y,v 1.23 2001/08/19 02:15:18 peter Exp $
+/* $Id: nasm-bison.y,v 1.24 2001/08/19 05:41:01 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%{
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <math.h>
#include <stdlib.h>
+#include "util.h"
#include "symrec.h"
#include "globals.h"
#include "bytecode.h"
expr *exp;
immval im_val;
targetval tgt_val;
+ datavalhead datahead;
dataval *data;
bytecode bc;
}
%type <syminfo> explabel
%type <sym> label_id
%type <tgt_val> target
-%type <data> dataval datavals
+%type <data> dataval
+%type <datahead> datavals
%left '|'
%left '^'
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, $2, $1); }
+ | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
| RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
;
-datavals: dataval
- | datavals ',' dataval { $$ = dataval_append($1, $3); }
+datavals: dataval {
+ STAILQ_INIT(&$$);
+ STAILQ_INSERT_TAIL(&$$, $1, link);
+ }
+ | datavals ',' dataval {
+ STAILQ_INSERT_TAIL(&$1, $3, link);
+ $$ = $1;
+ }
;
dataval: expr_no_string { $$ = dataval_new_expr($1); }
-/* $Id: nasm-parser.c,v 1.3 2001/08/19 02:57:02 peter Exp $
+/* $Id: nasm-parser.c,v 1.4 2001/08/19 05:41:01 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
+#include "util.h"
#include "bytecode.h"
#include "section.h"
#include "outfmt.h"
-/* $Id: parser.c,v 1.3 2001/08/19 02:57:02 peter Exp $
+/* $Id: parser.c,v 1.4 2001/08/19 05:41:01 peter Exp $
* NASM-compatible parser
*
* Copyright (C) 2001 Peter Johnson
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <stdio.h>
+#include "util.h"
#include "bytecode.h"
#include "section.h"
#include "outfmt.h"