Commit 86d7f2db by Jan Brittenson

Initial revision

From-SVN: r5378
parent e72498e1
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
/* Typecode definitions for Bytecode Interpreter.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef TYPECODE_H
#define TYPECODE_H
enum typecode
{
#define DEFTYPECODE(CODE, NAME, MACHMODE, TYPE) CODE,
#include "bc-typecd.def"
#undef DEFTYPECODE
LAST_AND_UNUSED_TYPECODE
};
/* Determine if a given type is integer. */
#define TYPECODE_INTEGER_P(TYPECODE) ((TYPECODE) < SFcode)
/* Determine if a given type is unsigned. */
#define TYPECODE_UNSIGNED_P(TYPECODE) \
(TYPECODE_INTEGER_P(TYPECODE) && (TYPECODE) & 1)
/* Determine if a given type is signed. */
#define TYPECODE_SIGNED_P(TYPECODE) \
(TYPECODE_INTEGER_P(TYPECODE) && !((TYPECODE) & 1))
/* Determine if a given type is floating. */
#define TYPECODE_FLOAT_P(TYPECODE) \
((TYPECODE) < Pcode && !TYPECODE_INTEGER_P(TYPECODE))
/* Determine if the given type is arithmetic. */
#define TYPECODE_ARITH_P(TYPECODE) \
(TYPECODE_INTEGER_P(TYPECODE) || TYPECODE_FLOAT_P(TYPECODE))
#define NUM_TYPECODES ((int) LAST_AND_UNUSED_TYPECODE)
#endif
/* Utility to generate opcode list from bytecode definition.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include "bi-defs.h"
int
main(argc, argv)
int argc;
char **argv;
{
struct def *d;
struct variation *v;
int i;
yyparse();
reverse();
puts ("/* This file is automatically generated from bytecode.def, do not make\n\
any changes here. Instead edit bytecode.def and type ``make''. */\n\
enum bytecode_opcode\n{");
i = 0;
for (d = defs; d; d = d->next)
for (v = d->variations; v; v = v->next)
printf (" %s%s,\n", d->basename, v->name, i++);
puts (" LAST_AND_UNUSED_OPCODE\n};");
if (i > 256)
fprintf (stderr, "%s: warning, number of opcodes is %d\n", *argv, i);
else
fprintf (stderr, "(Number of opcodes is %d)\n", i);
return 0;
}
/* Bytecode definition file parser.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
%{
#include <stdio.h>
#include "bi-defs.h"
extern char yytext[];
extern int yyleng;
extern char *malloc();
/* Chain of all defs built by the parser. */
struct def *defs;
int ndefs;
static struct node *makenode();
static struct variation *makevar();
static struct def *makedef();
%}
%union{
char *string;
struct def *def;
struct variation *variation;
struct node *node;
}
%token <string> DEFOP STRING
%type <string> opt_string
%type <def> defs def
%type <variation> variations variation
%type <node> list items item
%%
top:
defs
{ defs = $1; }
;
defs:
def
| defs def
{ $2->next = $1; $$ = $2; }
;
def:
DEFOP '(' STRING ',' opt_string ',' '(' variations ')' ')'
{ $$ = makedef($3, $5, $8); }
;
variations:
variation
| variations ',' variation
{ $3->next = $1; $$ = $3; }
;
variation:
'(' opt_string ')'
{ $$ = makevar($2, (struct node *) NULL, (struct node *) NULL, (struct node *) NULL); }
| '(' opt_string ',' list ')'
{ $$ = makevar($2, $4, (struct node *) NULL, (struct node *) NULL); }
| '(' opt_string ',' list ',' list ')'
{ $$ = makevar($2, $4, $6, (struct node *) NULL); }
| '(' opt_string ',' list ',' list ',' list ')'
{ $$ = makevar($2, $4, $6, $8); }
;
opt_string:
/* empty */ { $$ = ""; }
| STRING { $$ = $1; }
;
list:
'(' items ')'
{ $$ = $2; }
| /* empty */
{ $$ = NULL; }
;
items:
item
/* Note right recursion. */
| item ',' items
{ $1->next = $3; $$ = $1; }
;
item:
STRING
{ $$ = makenode($1); }
;
%%
static struct node *
makenode(s)
char *s;
{
struct node *n;
n = (struct node *) malloc(sizeof (struct node));
n->text = s;
n->next = NULL;
return n;
}
static struct variation *
makevar(name, inputs, outputs, literals)
char *name;
struct node *inputs, *outputs, *literals;
{
struct variation *v;
v = (struct variation *) malloc(sizeof (struct variation));
v->name = name;
v->code = ndefs++;
v->inputs = inputs;
v->outputs = outputs;
v->literals = literals;
v->next = NULL;
return v;
}
static struct def *
makedef(name, template, vars)
char *name, *template;
struct variation *vars;
{
struct def *d;
d = (struct def *) malloc(sizeof (struct def));
d->basename = name;
d->template = template;
d->variations = vars;
d->next = NULL;
return d;
}
void
yyerror(s)
char *s;
{
extern int yylineno;
fprintf(stderr, "syntax error in line %d\n", yylineno);
exit(1);
}
/* Definitions for Bytecode Interpreter.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
typedef union stacktype
{
QItype QIval;
QUtype QUval;
HItype HIval;
HUtype HUval;
SItype SIval;
SUtype SUval;
DItype DIval;
DUtype DUval;
SFtype SFval;
DFtype DFval;
XFtype XFval;
Ptype Pval;
Ttype Tval;
} stacktype;
#define MAXLITERALS 5
struct arityvec
{
char ninputs;
char noutputs;
char nliterals;
char literals[MAXLITERALS];
};
struct argtype
{
int modealign; /* Argument mode:alignment */
int size; /* Argument size, in bytes */
};
struct callinfo
{
int nargs; /* Number of arguments in call */
struct argtype retvaltype; /* Type of return value */
struct argtype argtypes[1]; /* Argument types */
};
/* Structure describing a bytecode function. If this changes, we also
need to change expand_function_end () in bc-trans.c */
struct bytecode
{
int stacksize; /* Depth required of evaluation stack. */
int localsize; /* Size in bytes of local variables. */
unsigned char *pc0; /* Initial program counter. */
void **ptrlit; /* Vector of (relocatable) pointer literals. */
struct callinfo *callinfo; /* Vector of procedure call type info. */
};
#define INTERP_BPC 8 /* Bits per char */
#define INTERP_BPI \
(sizeof (int) * INTERP_BPC) /* Bits per int */
#ifndef min
#define min(L, R) ((L) < (R) ? (L) : (R))
#endif
/* bit field operations. */
/* Low (high) mask: int with low (high) N bits set */
#define LM(N) ((1 << (N)) - 1)
#define HM(N) ((~LM (INTERP_BPI - (N))))
/* Sign-extend SIZE low bits of VALUE to integer (typeof VALUE)
Signed bitfields are loaded from memory by the sxloadBI instruction,
which first retrieves the bitfield with XFIELD and then sign extends
it to an SItype. */
#define EXTEND(SIZE, VALUE) \
({ SUtype value = (SUtype) (VALUE); \
(value & (1 << ((SIZE) - 1)) ? value | ~LM (SIZE) : value); })
/* Given OFFSET:SIZE for a bitfield, calculate:
[1] BYTE_OFFSET = the byte offset of the bit field.
[2] BIT_OFFSET = the bit offset of the bit field (less than INTERP_BPC).
[3] NBYTES = the number of integral bytes in the bit field.
[4] TRAILING_BITS= the number of trailing bits (less than INTERP_BPC).
, , , , , (memory bytes)
---------------- (bitfield)
| | || | | (divisions)
^ ^ ^ ^
| | | |__ [4] (bits)
| | |_________ [3] (bytes)
| |_________________ [2] (bits)
|___________________________ [1] (bytes)
The above applies to BYTE_LOW_ENDIAN machines. In BYTE_BIG_ENDIAN machines, the
bit numbering is reversed (i.e. bit 0 is the sign bit).
(Alright, so I drew this to keep my tongue in cheek while writing the code below,
not because I'm into ASCII art.) */
#define BI_PARAMS(OFFSET, SIZE, BYTE_OFFSET, \
BIT_OFFSET, NBYTES, TRAILING_BITS ) \
\
{ BYTE_OFFSET = (OFFSET) / (INTERP_BPC); \
BIT_OFFSET = (OFFSET) % (INTERP_BPC); \
NBYTES = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) / INTERP_BPC; \
if ((NBYTES) < 0 || ((NBYTES) > 64)) \
NBYTES = 0; \
if ((SIZE) + (BIT_OFFSET) <= INTERP_BPC) \
TRAILING_BITS = 0; \
else \
TRAILING_BITS = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) % INTERP_BPC; }
/* SHIFT_IN_BITS retrieves NBITS bits from SOURCE and shifts into
DEST. The bit field starts OFFSET bits into SOURCE.
OR_IN_BITS copies the NBITS low bits from VALUE into a the bitfield in
DEST offset by OFFSET bits. */
#ifdef BYTES_BIG_ENDIAN
#define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS) \
(DEST = ((DEST) << (NBITS)) \
| (LM ((NBITS)) \
& ((SOURCE) >> (INTERP_BPC - (OFFSET) - (NBITS)))))
#define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS) \
(DEST = ((DEST) & ~(LM ((NBITS)) << (INTERP_BPC - (OFFSET) - (NBITS)))) \
| (((VALUE) & LM ((NBITS))) << (INTERP_BPC - (OFFSET) - (NBITS))))
#else
#define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS) \
(DEST = ((DEST) << (NBITS)) \
| (LM ((NBITS)) \
& ((SOURCE) >> (OFFSET))))
#define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS) \
(DEST = ((DEST) & ~(LM ((NBITS)) << (OFFSET))) \
| (((VALUE) & LM ((NBITS))) << (OFFSET)))
#endif
/* Procedure call; arguments are a pointer to the function to be called,
a pointer to a place to store the return value, a pointer to a vector
describing the type of procedure call, and the interpreter's stack pointer,
which will point to the first of the arguments at this point. */
#define CALL(FUNC, CALLDESC, RETVAL, SP) __call(FUNC, CALLDESC, RETVAL, SP)
/* Procedure return; arguments are a pointer to the calldesc for this
function, and a pointer to the place where the value to be returned
may be found. Generally the MACHARGS above contain a machine dependent
cookie that is used to determine where to jump to. */
#define PROCRET(CALLDESC, RETVAL) return
/* Bytecode definitions for GNU C-compiler.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* These should come from genemit */
typedef signed char QItype;
typedef unsigned char QUtype;
typedef signed short int HItype;
typedef unsigned short int HUtype;
typedef signed long int SItype;
typedef unsigned long int SUtype;
typedef signed long long int DItype;
typedef unsigned long long int DUtype;
typedef float SFtype;
typedef double DFtype;
typedef long double XFtype;
typedef char *Ptype;
typedef int Ttype;
extern int output_bytecode;
extern int stack_depth;
extern int max_stack_depth;
/* Emit DI constant according to target machine word ordering */
#ifdef WORD_HIGH_ENDIAN
#define bc_emit_bytecode_DI_const(CST) \
{ int opcode; \
opcode = TREE_INT_CST_HIGH (CST); \
bc_emit_bytecode_const ((char *) &opcode, sizeof opcode); \
opcode = TREE_INT_CST_LOW (CST); \
bc_emit_bytecode_const ((char *) &opcode, sizeof opcode); \
}
#else
#define bc_emit_bytecode_DI_const(CST) \
{ int opcode; \
opcode = TREE_INT_CST_LOW (CST); \
bc_emit_bytecode_const ((char *) &opcode, sizeof opcode); \
opcode = TREE_INT_CST_HIGH (CST); \
bc_emit_bytecode_const ((char *) &opcode, sizeof opcode); \
}
#endif
extern void bc_expand_expr ();
extern void bc_output_data_constructor ();
extern void bc_store_field ();
extern void bc_load_bit_field ();
extern void bc_store_bit_field ();
extern void bc_push_offset_and_size ();
extern void bc_init_mode_to_code_map ();
/* These are just stubs, so the compiler will compile for targets
that aren't yet supported by the bytecode generator. */
#ifndef TARGET_SUPPORTS_BYTECODE
#define MACHINE_SEG_ALIGN 1
#define INT_ALIGN 1
#define PTR_ALIGN 1
#define NAMES_HAVE_UNDERSCORES
#define BC_NOP (0)
#define BC_GLOBALIZE_LABEL(FP, NAME) BC_NOP
#define BC_OUTPUT_COMMON(FP, NAME, SIZE, ROUNDED) BC_NOP
#define BC_OUTPUT_LOCAL(FP, NAME, SIZE, ROUNDED) BC_NOP
#define BC_OUTPUT_ALIGN(FP, ALIGN) BC_NOP
#define BC_OUTPUT_LABEL(FP, NAME) BC_NOP
#define BC_OUTPUT_SKIP(FP, SIZE) BC_NOP
#define BC_OUTPUT_LABELREF(FP, NAME) BC_NOP
#define BC_OUTPUT_FLOAT(FP, VAL) BC_NOP
#define BC_OUTPUT_DOUBLE(FP, VAL) BC_NOP
#define BC_OUTPUT_BYTE(FP, VAL) BC_NOP
#define BC_OUTPUT_FILE ASM_OUTPUT_FILE
#define BC_OUTPUT_ASCII ASM_OUTPUT_ASCII
#define BC_OUTPUT_IDENT ASM_OUTPUT_IDENT
#define BCXSTR(RTX) ((RTX)->bc_label)
#define BC_WRITE_FILE(FP) BC_NOP
#define BC_WRITE_SEGSYM(SEGSYM, FP) BC_NOP
#define BC_WRITE_RELOC_ENTRY(SEGRELOC, FP, OFFSET) BC_NOP
#define BC_START_BYTECODE_LINE(FP) BC_NOP
#define BC_WRITE_BYTECODE(SEP, VAL, FP) BC_NOP
#define BC_WRITE_RTL(R, FP) BC_NOP
#define BC_EMIT_TRAMPOLINE(TRAMPSEG, CALLINFO) BC_NOP
#define VALIDATE_STACK BC_NOP
#endif /* !TARGET_SUPPORTS_BYTECODE */
/* Bytecode specific machine mode info for GNU C-compiler.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Map mode to signed, unsigned typecodes, bytecode to push const,
to load, to store */
DEF_MODEMAP(QImode, QIcode, QUcode, constQI, loadQI, storeQI)
DEF_MODEMAP(HImode, HIcode, HUcode, constHI, loadHI, storeHI)
DEF_MODEMAP(VOIDmode, SIcode, SUcode, constSI, loadSI, storeSI)
DEF_MODEMAP(SImode, SIcode, SUcode, constSI, loadSI, storeSI)
DEF_MODEMAP(DImode, DIcode, DUcode, constDI, loadDI, storeDI)
DEF_MODEMAP(PSImode, Pcode, Pcode, constP, loadP, storeP)
DEF_MODEMAP(BLKmode, Pcode, Pcode, constP, loadP, neverneverland)
DEF_MODEMAP(SFmode, SFcode, SFcode, constSF, loadSF, storeSF)
DEF_MODEMAP(DFmode, DFcode, DFcode, constDF, loadDF, storeDF)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment