Rename and restructure bytecode functions to make this use clearer.
svn path=/trunk/yasm/; revision=164
-/* $Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $
+/* $Id: bytecode.c,v 1.21 2001/09/16 19:44:49 peter Exp $
* Bytecode utility functions
*
* Copyright (C) 2001 Peter Johnson
#include "bytecode.h"
-RCSID("$Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $");
+RCSID("$Id: bytecode.c,v 1.21 2001/09/16 19:44:49 peter Exp $");
/* Static structures for when NULL is passed to conversion functions. */
/* for Convert*ToEA() */
/* for Convert*ToBytes() */
unsigned char bytes_static[16];
-static void BuildBC_Common(bytecode *bc);
+static bytecode *bytecode_new_common(void);
effaddr *
ConvertRegToEA(effaddr *ptr, unsigned long reg)
*old_sel = new_sel;
}
-static void
-BuildBC_Common(bytecode *bc)
+static bytecode *
+bytecode_new_common(void)
{
+ bytecode *bc = malloc(sizeof(bytecode));
+
+ if (!bc)
+ Fatal(FATAL_NOMEM);
+
bc->len = 0;
bc->filename = strdup(filename);
bc->mode_bits = mode_bits;
}
-void
-BuildBC_Insn(bytecode *bc,
- unsigned char opersize,
- unsigned char opcode_len,
- unsigned char op0,
- unsigned char op1,
- unsigned char op2,
- effaddr *ea_ptr,
- unsigned char spare,
- immval *im_ptr,
- unsigned char im_len,
- unsigned char im_sign)
+bytecode *
+bytecode_new_insn(unsigned char opersize,
+ unsigned char opcode_len,
+ unsigned char op0,
+ unsigned char op1,
+ unsigned char op2,
+ effaddr *ea_ptr,
+ unsigned char spare,
+ immval *im_ptr,
+ unsigned char im_len,
+ unsigned char im_sign)
{
+ bytecode *bc = bytecode_new_common();
+
bc->type = BC_INSN;
if (ea_ptr) {
bc->data.insn.opersize = opersize;
bc->data.insn.lockrep_pre = 0;
- BuildBC_Common(bc);
+ return bc;
}
-void
-BuildBC_JmpRel(bytecode *bc,
- targetval *target,
- unsigned char short_valid,
- unsigned char short_opcode_len,
- unsigned char short_op0,
- unsigned char short_op1,
- unsigned char short_op2,
- unsigned char near_valid,
- unsigned char near_opcode_len,
- unsigned char near_op0,
- unsigned char near_op1,
- unsigned char near_op2,
- unsigned char addrsize)
+bytecode *
+bytecode_new_jmprel(targetval *target,
+ unsigned char short_valid,
+ unsigned char short_opcode_len,
+ unsigned char short_op0,
+ unsigned char short_op1,
+ unsigned char short_op2,
+ unsigned char near_valid,
+ unsigned char near_opcode_len,
+ unsigned char near_op0,
+ unsigned char near_op1,
+ unsigned char near_op2,
+ unsigned char addrsize)
{
+ bytecode *bc = bytecode_new_common();
+
bc->type = BC_JMPREL;
bc->data.jmprel.target = target->val;
bc->data.jmprel.opersize = 0;
bc->data.jmprel.lockrep_pre = 0;
- BuildBC_Common(bc);
+ return bc;
}
-void
-BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size)
+bytecode *
+bytecode_new_data(datavalhead *datahead, unsigned long size)
{
+ bytecode *bc;
dataval *cur;
/* First check to see if all the data elements are valid for the size
}
}
+ bc = bytecode_new_common();
+
bc->type = BC_DATA;
bc->data.data.datahead = *datahead;
bc->data.data.size = size;
- BuildBC_Common(bc);
+ return bc;
}
-void
-BuildBC_Reserve(bytecode *bc, expr *numitems, unsigned long itemsize)
+bytecode *
+bytecode_new_reserve(expr *numitems, unsigned long itemsize)
{
+ bytecode *bc = bytecode_new_common();
+
bc->type = BC_RESERVE;
bc->data.reserve.numitems = numitems;
bc->data.reserve.itemsize = itemsize;
- BuildBC_Common(bc);
+ return bc;
}
void
-DebugPrintBC(bytecode *bc)
+bytecode_print(bytecode *bc)
{
switch (bc->type) {
case BC_EMPTY:
-/* $Id: bytecode.h,v 1.18 2001/09/16 04:49:46 peter Exp $
+/* $Id: bytecode.h,v 1.19 2001/09/16 19:44:49 peter Exp $
* Bytecode utility functions header file
*
* Copyright (C) 2001 Peter Johnson
void SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel);
-void BuildBC_Insn(bytecode *bc,
- unsigned char opersize,
- unsigned char opcode_len,
- unsigned char op0,
- unsigned char op1,
- unsigned char op2,
- effaddr *ea_ptr,
- unsigned char spare,
- immval *im_ptr,
- unsigned char im_len,
- unsigned char im_sign);
-
-void BuildBC_JmpRel(bytecode *bc,
- targetval *target,
- unsigned char short_valid,
- unsigned char short_opcode_len,
- unsigned char short_op0,
- unsigned char short_op1,
- unsigned char short_op2,
- unsigned char near_valid,
- unsigned char near_opcode_len,
- unsigned char near_op0,
- unsigned char near_op1,
- unsigned char near_op2,
- unsigned char addrsize);
-
-void BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size);
-
-void BuildBC_Reserve(bytecode *bc,
- struct expr_s *numitems,
- unsigned long itemsize);
-
-void DebugPrintBC(bytecode *bc);
+bytecode *bytecode_new_insn(unsigned char opersize,
+ unsigned char opcode_len,
+ unsigned char op0,
+ unsigned char op1,
+ unsigned char op2,
+ effaddr *ea_ptr,
+ unsigned char spare,
+ immval *im_ptr,
+ unsigned char im_len,
+ unsigned char im_sign);
+
+bytecode *bytecode_new_jmprel(targetval *target,
+ unsigned char short_valid,
+ unsigned char short_opcode_len,
+ unsigned char short_op0,
+ unsigned char short_op1,
+ unsigned char short_op2,
+ unsigned char near_valid,
+ unsigned char near_opcode_len,
+ unsigned char near_op0,
+ unsigned char near_op1,
+ unsigned char near_op2,
+ unsigned char addrsize);
+
+bytecode *bytecode_new_data(datavalhead *datahead, unsigned long size);
+
+bytecode *bytecode_new_reserve(struct expr_s *numitems,
+ unsigned long itemsize);
+
+void bytecode_print(bytecode *bc);
dataval *dataval_new_expr(struct expr_s *exp);
dataval *dataval_new_float(double float_val);
-/* $Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $
+/* $Id: bison.y.in,v 1.30 2001/09/16 19:44:49 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
#include "bytecode.h"
#include "section.h"
-RCSID("$Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $");
+RCSID("$Id: bison.y.in,v 1.30 2001/09/16 19:44:49 peter Exp $");
#define YYDEBUG 1
extern section *nasm_parser_cur_section;
-static bytecode *new_bc;
-
%}
%union {
targetval tgt_val;
datavalhead datahead;
dataval *data;
- bytecode bc;
+ bytecode *bc;
}
%token <int_val> INTNUM
| input line {
OutputError();
OutputWarning();
- if ($2.type != BC_EMPTY) {
- new_bc = malloc(sizeof(bytecode));
- if(!new_bc)
- Fatal(FATAL_NOMEM);
- memcpy(new_bc, &$2, sizeof(bytecode));
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+ if ($2) {
+ if ($2->type != BC_EMPTY) {
+ STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
+ } else {
+ free($2);
+ }
}
line_number++;
}
;
-line: '\n' { $$.type = BC_EMPTY; }
+line: '\n' { $$ = (bytecode *)NULL; }
| exp '\n'
- | directive '\n' { $$.type = BC_EMPTY; }
+ | directive '\n' { $$ = (bytecode *)NULL; }
| error '\n' {
Error(_("label or instruction expected at start of line"));
- $$.type = BC_EMPTY;
+ $$ = (bytecode *)NULL;
yyerrok;
}
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
- | RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
+ | DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
+ | RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| label exp { $$ = $2; }
- | label { $$.type = BC_EMPTY; }
+ | label { $$ = (bytecode *)NULL; }
;
datavals: dataval {
explabel: ID | SPECIAL_ID | LOCAL_ID ;
instr: instrbase
- | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride(&$$, $1); }
- | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride(&$$, $1); }
- | REG_CS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x2E); }
- | REG_SS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x36); }
- | REG_DS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x3E); }
- | REG_ES instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x26); }
- | REG_FS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x64); }
- | REG_GS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x65); }
- | LOCK instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF0); }
- | REPNZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF2); }
- | REP instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF3); }
- | REPZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF4); }
+ | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride($$, $1); }
+ | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride($$, $1); }
+ | REG_CS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x2E); }
+ | REG_SS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x36); }
+ | REG_DS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x3E); }
+ | REG_ES instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x26); }
+ | REG_FS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x64); }
+ | REG_GS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x65); }
+ | LOCK instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF0); }
+ | REPNZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF2); }
+ | REP instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF3); }
+ | REPZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF4); }
;
/* instruction grammars (dynamically generated) */
#!/usr/bin/perl -w
-# $Id: gen_instr.pl,v 1.19 2001/08/30 03:45:26 peter Exp $
+# $Id: gen_instr.pl,v 1.20 2001/09/16 19:44:49 peter Exp $
# Generates bison.y and token.l from instrs.dat for YASM
#
# Copyright (C) 2001 Michael Urman
my ($rule, $tokens, $count, $regarg, $val, $func, $a_eax) = splice (@_);
return rule_header ($rule, $tokens, $count) . <<"EOF";
if (\$$regarg == $val) {
- $func(@$a_eax);
+ \$\$ = $func(@$a_eax);
}
EOF
}
my ($regarg, $val, $func, $a_eax) = splice (@_);
return <<"EOF";
else if (\$$regarg == $val) {
- $func(@$a_eax);
+ \$\$ = $func(@$a_eax);
}
EOF
}
my ($func, $a_args) = splice (@_);
return <<"EOF" . rule_footer;
else {
- $func (@$a_args);
+ \$\$ = $func (@$a_args);
}
EOF
}
{
my ($rule, $tokens, $func, $a_args, $count) = splice @_;
return rule_header ($rule, $tokens, $count)
- . " $func (@$a_args);\n"
+ . " \$\$ = $func (@$a_args);\n"
. rule_footer;
}
if $inst->[OPERANDS] ne 'nil';
$tokens =~ s/,/ ',' /g;
$tokens =~ s/:/ ':' /g;
- my $func = "BuildBC_JmpRel";
+ my $func = "bytecode_new_jmprel";
- # Create the argument list for BuildBC
+ # Create the argument list for bytecode_new
my @args;
- # First argument is always &$$
- push @args, '&$$,';
-
# Target argument: HACK: Always assumed to be arg 1.
push @args, '&$2,';
$tokens =~ s/:/ ':' /g;
# offset args
my $to = $tokens =~ m/\b(TO|WORD|DWORD)\b/ ? 1 : 0;
- my $func = "BuildBC_Insn";
+ my $func = "bytecode_new_insn";
- # Create the argument list for BuildBC
+ # Create the argument list for bytecode_new
my @args;
- # First argument is always &$$
- push @args, '&$$,';
-
# operand size
push @args, "$inst->[OPSIZE],";
$args[-1] =~ s/nil/0/;
-/* $Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $
+/* $Id: nasm-bison.y,v 1.30 2001/09/16 19:44:49 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
#include "bytecode.h"
#include "section.h"
-RCSID("$Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $");
+RCSID("$Id: nasm-bison.y,v 1.30 2001/09/16 19:44:49 peter Exp $");
#define YYDEBUG 1
extern section *nasm_parser_cur_section;
-static bytecode *new_bc;
-
%}
%union {
targetval tgt_val;
datavalhead datahead;
dataval *data;
- bytecode bc;
+ bytecode *bc;
}
%token <int_val> INTNUM
| input line {
OutputError();
OutputWarning();
- if ($2.type != BC_EMPTY) {
- new_bc = malloc(sizeof(bytecode));
- if(!new_bc)
- Fatal(FATAL_NOMEM);
- memcpy(new_bc, &$2, sizeof(bytecode));
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+ if ($2) {
+ if ($2->type != BC_EMPTY) {
+ STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
+ } else {
+ free($2);
+ }
}
line_number++;
}
;
-line: '\n' { $$.type = BC_EMPTY; }
+line: '\n' { $$ = (bytecode *)NULL; }
| exp '\n'
- | directive '\n' { $$.type = BC_EMPTY; }
+ | directive '\n' { $$ = (bytecode *)NULL; }
| error '\n' {
Error(_("label or instruction expected at start of line"));
- $$.type = BC_EMPTY;
+ $$ = (bytecode *)NULL;
yyerrok;
}
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
- | RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
+ | DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
+ | RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| label exp { $$ = $2; }
- | label { $$.type = BC_EMPTY; }
+ | label { $$ = (bytecode *)NULL; }
;
datavals: dataval {
explabel: ID | SPECIAL_ID | LOCAL_ID ;
instr: instrbase
- | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride(&$$, $1); }
- | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride(&$$, $1); }
- | REG_CS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x2E); }
- | REG_SS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x36); }
- | REG_DS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x3E); }
- | REG_ES instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x26); }
- | REG_FS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x64); }
- | REG_GS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x65); }
- | LOCK instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF0); }
- | REPNZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF2); }
- | REP instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF3); }
- | REPZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF4); }
+ | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride($$, $1); }
+ | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride($$, $1); }
+ | REG_CS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x2E); }
+ | REG_SS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x36); }
+ | REG_DS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x3E); }
+ | REG_ES instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x26); }
+ | REG_FS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x64); }
+ | REG_GS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x65); }
+ | LOCK instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF0); }
+ | REPNZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF2); }
+ | REP instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF3); }
+ | REPZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF4); }
;
/* instruction grammars (dynamically generated) */
-/* $Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $
+/* $Id: bytecode.c,v 1.21 2001/09/16 19:44:49 peter Exp $
* Bytecode utility functions
*
* Copyright (C) 2001 Peter Johnson
#include "bytecode.h"
-RCSID("$Id: bytecode.c,v 1.20 2001/08/30 03:45:26 peter Exp $");
+RCSID("$Id: bytecode.c,v 1.21 2001/09/16 19:44:49 peter Exp $");
/* Static structures for when NULL is passed to conversion functions. */
/* for Convert*ToEA() */
/* for Convert*ToBytes() */
unsigned char bytes_static[16];
-static void BuildBC_Common(bytecode *bc);
+static bytecode *bytecode_new_common(void);
effaddr *
ConvertRegToEA(effaddr *ptr, unsigned long reg)
*old_sel = new_sel;
}
-static void
-BuildBC_Common(bytecode *bc)
+static bytecode *
+bytecode_new_common(void)
{
+ bytecode *bc = malloc(sizeof(bytecode));
+
+ if (!bc)
+ Fatal(FATAL_NOMEM);
+
bc->len = 0;
bc->filename = strdup(filename);
bc->mode_bits = mode_bits;
}
-void
-BuildBC_Insn(bytecode *bc,
- unsigned char opersize,
- unsigned char opcode_len,
- unsigned char op0,
- unsigned char op1,
- unsigned char op2,
- effaddr *ea_ptr,
- unsigned char spare,
- immval *im_ptr,
- unsigned char im_len,
- unsigned char im_sign)
+bytecode *
+bytecode_new_insn(unsigned char opersize,
+ unsigned char opcode_len,
+ unsigned char op0,
+ unsigned char op1,
+ unsigned char op2,
+ effaddr *ea_ptr,
+ unsigned char spare,
+ immval *im_ptr,
+ unsigned char im_len,
+ unsigned char im_sign)
{
+ bytecode *bc = bytecode_new_common();
+
bc->type = BC_INSN;
if (ea_ptr) {
bc->data.insn.opersize = opersize;
bc->data.insn.lockrep_pre = 0;
- BuildBC_Common(bc);
+ return bc;
}
-void
-BuildBC_JmpRel(bytecode *bc,
- targetval *target,
- unsigned char short_valid,
- unsigned char short_opcode_len,
- unsigned char short_op0,
- unsigned char short_op1,
- unsigned char short_op2,
- unsigned char near_valid,
- unsigned char near_opcode_len,
- unsigned char near_op0,
- unsigned char near_op1,
- unsigned char near_op2,
- unsigned char addrsize)
+bytecode *
+bytecode_new_jmprel(targetval *target,
+ unsigned char short_valid,
+ unsigned char short_opcode_len,
+ unsigned char short_op0,
+ unsigned char short_op1,
+ unsigned char short_op2,
+ unsigned char near_valid,
+ unsigned char near_opcode_len,
+ unsigned char near_op0,
+ unsigned char near_op1,
+ unsigned char near_op2,
+ unsigned char addrsize)
{
+ bytecode *bc = bytecode_new_common();
+
bc->type = BC_JMPREL;
bc->data.jmprel.target = target->val;
bc->data.jmprel.opersize = 0;
bc->data.jmprel.lockrep_pre = 0;
- BuildBC_Common(bc);
+ return bc;
}
-void
-BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size)
+bytecode *
+bytecode_new_data(datavalhead *datahead, unsigned long size)
{
+ bytecode *bc;
dataval *cur;
/* First check to see if all the data elements are valid for the size
}
}
+ bc = bytecode_new_common();
+
bc->type = BC_DATA;
bc->data.data.datahead = *datahead;
bc->data.data.size = size;
- BuildBC_Common(bc);
+ return bc;
}
-void
-BuildBC_Reserve(bytecode *bc, expr *numitems, unsigned long itemsize)
+bytecode *
+bytecode_new_reserve(expr *numitems, unsigned long itemsize)
{
+ bytecode *bc = bytecode_new_common();
+
bc->type = BC_RESERVE;
bc->data.reserve.numitems = numitems;
bc->data.reserve.itemsize = itemsize;
- BuildBC_Common(bc);
+ return bc;
}
void
-DebugPrintBC(bytecode *bc)
+bytecode_print(bytecode *bc)
{
switch (bc->type) {
case BC_EMPTY:
-/* $Id: bytecode.h,v 1.18 2001/09/16 04:49:46 peter Exp $
+/* $Id: bytecode.h,v 1.19 2001/09/16 19:44:49 peter Exp $
* Bytecode utility functions header file
*
* Copyright (C) 2001 Peter Johnson
void SetOpcodeSel(jmprel_opcode_sel *old_sel, jmprel_opcode_sel new_sel);
-void BuildBC_Insn(bytecode *bc,
- unsigned char opersize,
- unsigned char opcode_len,
- unsigned char op0,
- unsigned char op1,
- unsigned char op2,
- effaddr *ea_ptr,
- unsigned char spare,
- immval *im_ptr,
- unsigned char im_len,
- unsigned char im_sign);
-
-void BuildBC_JmpRel(bytecode *bc,
- targetval *target,
- unsigned char short_valid,
- unsigned char short_opcode_len,
- unsigned char short_op0,
- unsigned char short_op1,
- unsigned char short_op2,
- unsigned char near_valid,
- unsigned char near_opcode_len,
- unsigned char near_op0,
- unsigned char near_op1,
- unsigned char near_op2,
- unsigned char addrsize);
-
-void BuildBC_Data(bytecode *bc, datavalhead *datahead, unsigned long size);
-
-void BuildBC_Reserve(bytecode *bc,
- struct expr_s *numitems,
- unsigned long itemsize);
-
-void DebugPrintBC(bytecode *bc);
+bytecode *bytecode_new_insn(unsigned char opersize,
+ unsigned char opcode_len,
+ unsigned char op0,
+ unsigned char op1,
+ unsigned char op2,
+ effaddr *ea_ptr,
+ unsigned char spare,
+ immval *im_ptr,
+ unsigned char im_len,
+ unsigned char im_sign);
+
+bytecode *bytecode_new_jmprel(targetval *target,
+ unsigned char short_valid,
+ unsigned char short_opcode_len,
+ unsigned char short_op0,
+ unsigned char short_op1,
+ unsigned char short_op2,
+ unsigned char near_valid,
+ unsigned char near_opcode_len,
+ unsigned char near_op0,
+ unsigned char near_op1,
+ unsigned char near_op2,
+ unsigned char addrsize);
+
+bytecode *bytecode_new_data(datavalhead *datahead, unsigned long size);
+
+bytecode *bytecode_new_reserve(struct expr_s *numitems,
+ unsigned long itemsize);
+
+void bytecode_print(bytecode *bc);
dataval *dataval_new_expr(struct expr_s *exp);
dataval *dataval_new_float(double float_val);
-/* $Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $
+/* $Id: bison.y.in,v 1.30 2001/09/16 19:44:49 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
#include "bytecode.h"
#include "section.h"
-RCSID("$Id: bison.y.in,v 1.29 2001/09/16 18:53:47 peter Exp $");
+RCSID("$Id: bison.y.in,v 1.30 2001/09/16 19:44:49 peter Exp $");
#define YYDEBUG 1
extern section *nasm_parser_cur_section;
-static bytecode *new_bc;
-
%}
%union {
targetval tgt_val;
datavalhead datahead;
dataval *data;
- bytecode bc;
+ bytecode *bc;
}
%token <int_val> INTNUM
| input line {
OutputError();
OutputWarning();
- if ($2.type != BC_EMPTY) {
- new_bc = malloc(sizeof(bytecode));
- if(!new_bc)
- Fatal(FATAL_NOMEM);
- memcpy(new_bc, &$2, sizeof(bytecode));
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+ if ($2) {
+ if ($2->type != BC_EMPTY) {
+ STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
+ } else {
+ free($2);
+ }
}
line_number++;
}
;
-line: '\n' { $$.type = BC_EMPTY; }
+line: '\n' { $$ = (bytecode *)NULL; }
| exp '\n'
- | directive '\n' { $$.type = BC_EMPTY; }
+ | directive '\n' { $$ = (bytecode *)NULL; }
| error '\n' {
Error(_("label or instruction expected at start of line"));
- $$.type = BC_EMPTY;
+ $$ = (bytecode *)NULL;
yyerrok;
}
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
- | RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
+ | DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
+ | RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| label exp { $$ = $2; }
- | label { $$.type = BC_EMPTY; }
+ | label { $$ = (bytecode *)NULL; }
;
datavals: dataval {
explabel: ID | SPECIAL_ID | LOCAL_ID ;
instr: instrbase
- | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride(&$$, $1); }
- | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride(&$$, $1); }
- | REG_CS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x2E); }
- | REG_SS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x36); }
- | REG_DS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x3E); }
- | REG_ES instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x26); }
- | REG_FS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x64); }
- | REG_GS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x65); }
- | LOCK instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF0); }
- | REPNZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF2); }
- | REP instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF3); }
- | REPZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF4); }
+ | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride($$, $1); }
+ | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride($$, $1); }
+ | REG_CS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x2E); }
+ | REG_SS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x36); }
+ | REG_DS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x3E); }
+ | REG_ES instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x26); }
+ | REG_FS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x64); }
+ | REG_GS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x65); }
+ | LOCK instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF0); }
+ | REPNZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF2); }
+ | REP instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF3); }
+ | REPZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF4); }
;
/* instruction grammars (dynamically generated) */
#!/usr/bin/perl -w
-# $Id: gen_instr.pl,v 1.19 2001/08/30 03:45:26 peter Exp $
+# $Id: gen_instr.pl,v 1.20 2001/09/16 19:44:49 peter Exp $
# Generates bison.y and token.l from instrs.dat for YASM
#
# Copyright (C) 2001 Michael Urman
my ($rule, $tokens, $count, $regarg, $val, $func, $a_eax) = splice (@_);
return rule_header ($rule, $tokens, $count) . <<"EOF";
if (\$$regarg == $val) {
- $func(@$a_eax);
+ \$\$ = $func(@$a_eax);
}
EOF
}
my ($regarg, $val, $func, $a_eax) = splice (@_);
return <<"EOF";
else if (\$$regarg == $val) {
- $func(@$a_eax);
+ \$\$ = $func(@$a_eax);
}
EOF
}
my ($func, $a_args) = splice (@_);
return <<"EOF" . rule_footer;
else {
- $func (@$a_args);
+ \$\$ = $func (@$a_args);
}
EOF
}
{
my ($rule, $tokens, $func, $a_args, $count) = splice @_;
return rule_header ($rule, $tokens, $count)
- . " $func (@$a_args);\n"
+ . " \$\$ = $func (@$a_args);\n"
. rule_footer;
}
if $inst->[OPERANDS] ne 'nil';
$tokens =~ s/,/ ',' /g;
$tokens =~ s/:/ ':' /g;
- my $func = "BuildBC_JmpRel";
+ my $func = "bytecode_new_jmprel";
- # Create the argument list for BuildBC
+ # Create the argument list for bytecode_new
my @args;
- # First argument is always &$$
- push @args, '&$$,';
-
# Target argument: HACK: Always assumed to be arg 1.
push @args, '&$2,';
$tokens =~ s/:/ ':' /g;
# offset args
my $to = $tokens =~ m/\b(TO|WORD|DWORD)\b/ ? 1 : 0;
- my $func = "BuildBC_Insn";
+ my $func = "bytecode_new_insn";
- # Create the argument list for BuildBC
+ # Create the argument list for bytecode_new
my @args;
- # First argument is always &$$
- push @args, '&$$,';
-
# operand size
push @args, "$inst->[OPSIZE],";
$args[-1] =~ s/nil/0/;
-/* $Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $
+/* $Id: nasm-bison.y,v 1.30 2001/09/16 19:44:49 peter Exp $
* Main bison parser
*
* Copyright (C) 2001 Peter Johnson, Michael Urman
#include "bytecode.h"
#include "section.h"
-RCSID("$Id: nasm-bison.y,v 1.29 2001/09/16 18:53:47 peter Exp $");
+RCSID("$Id: nasm-bison.y,v 1.30 2001/09/16 19:44:49 peter Exp $");
#define YYDEBUG 1
extern section *nasm_parser_cur_section;
-static bytecode *new_bc;
-
%}
%union {
targetval tgt_val;
datavalhead datahead;
dataval *data;
- bytecode bc;
+ bytecode *bc;
}
%token <int_val> INTNUM
| input line {
OutputError();
OutputWarning();
- if ($2.type != BC_EMPTY) {
- new_bc = malloc(sizeof(bytecode));
- if(!new_bc)
- Fatal(FATAL_NOMEM);
- memcpy(new_bc, &$2, sizeof(bytecode));
- STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, new_bc, link);
+ if ($2) {
+ if ($2->type != BC_EMPTY) {
+ STAILQ_INSERT_TAIL(&nasm_parser_cur_section->bc, $2, link);
+ } else {
+ free($2);
+ }
}
line_number++;
}
;
-line: '\n' { $$.type = BC_EMPTY; }
+line: '\n' { $$ = (bytecode *)NULL; }
| exp '\n'
- | directive '\n' { $$.type = BC_EMPTY; }
+ | directive '\n' { $$ = (bytecode *)NULL; }
| error '\n' {
Error(_("label or instruction expected at start of line"));
- $$.type = BC_EMPTY;
+ $$ = (bytecode *)NULL;
yyerrok;
}
;
exp: instr
- | DECLARE_DATA datavals { BuildBC_Data(&$$, &$2, $1); }
- | RESERVE_SPACE expr { BuildBC_Reserve(&$$, $2, $1); }
+ | DECLARE_DATA datavals { $$ = bytecode_new_data(&$2, $1); }
+ | RESERVE_SPACE expr { $$ = bytecode_new_reserve($2, $1); }
| label exp { $$ = $2; }
- | label { $$.type = BC_EMPTY; }
+ | label { $$ = (bytecode *)NULL; }
;
datavals: dataval {
explabel: ID | SPECIAL_ID | LOCAL_ID ;
instr: instrbase
- | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride(&$$, $1); }
- | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride(&$$, $1); }
- | REG_CS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x2E); }
- | REG_SS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x36); }
- | REG_DS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x3E); }
- | REG_ES instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x26); }
- | REG_FS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x64); }
- | REG_GS instr { $$ = $2; SetEASegment(&$$.data.insn.ea, 0x65); }
- | LOCK instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF0); }
- | REPNZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF2); }
- | REP instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF3); }
- | REPZ instr { $$ = $2; SetInsnLockRepPrefix(&$$, 0xF4); }
+ | OPERSIZE instr { $$ = $2; SetInsnOperSizeOverride($$, $1); }
+ | ADDRSIZE instr { $$ = $2; SetInsnAddrSizeOverride($$, $1); }
+ | REG_CS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x2E); }
+ | REG_SS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x36); }
+ | REG_DS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x3E); }
+ | REG_ES instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x26); }
+ | REG_FS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x64); }
+ | REG_GS instr { $$ = $2; SetEASegment(&$$->data.insn.ea, 0x65); }
+ | LOCK instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF0); }
+ | REPNZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF2); }
+ | REP instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF3); }
+ | REPZ instr { $$ = $2; SetInsnLockRepPrefix($$, 0xF4); }
;
/* instruction grammars (dynamically generated) */