X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcodegen.h;h=8d16c8948ba93395731142bf8908f1530fbcbfc9;hb=465d208b2b4ba80f41c6b7cfa673951a0218f61a;hp=33bad1d22472aba32e0898cf58bfb49ac101f550;hpb=53dd513176425872128ef26031d00952ef7a0628;p=cc65 diff --git a/src/cc65/codegen.h b/src/cc65/codegen.h index 33bad1d22..8d16c8948 100644 --- a/src/cc65/codegen.h +++ b/src/cc65/codegen.h @@ -1,8 +1,35 @@ -/* - * codegen.h - * - * Ullrich von Bassewitz, 04.06.1998 - */ +/*****************************************************************************/ +/* */ +/* codegen.h */ +/* */ +/* 6502 code generator */ +/* */ +/* */ +/* */ +/* (C) 1998-2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ @@ -11,8 +38,16 @@ +/* common */ +#include "coll.h" + +/* cc65 */ +#include "segments.h" + + + /*****************************************************************************/ -/* data */ +/* Data */ /*****************************************************************************/ @@ -23,19 +58,20 @@ */ #define CF_NONE 0x0000 /* No special flags */ -#define CF_TYPE 0x000F /* Mask for operand type */ +#define CF_TYPE 0x0007 /* Mask for operand type */ #define CF_CHAR 0x0003 /* Operation on characters */ #define CF_INT 0x0001 /* Operation on ints */ #define CF_PTR CF_INT /* Alias for readability */ #define CF_LONG 0x0000 /* Operation on longs */ +#define CF_NOKEEP 0x0008 /* Value may get destroyed when storing */ + #define CF_UNSIGNED 0x0010 /* Value is unsigned */ #define CF_CONST 0x0020 /* Constant value available */ #define CF_CONSTADDR 0x0040 /* Constant address value available */ #define CF_TEST 0x0080 /* Test value */ #define CF_FIXARGC 0x0100 /* Function has fixed arg count */ #define CF_FORCECHAR 0x0200 /* Handle chars as chars, not ints */ -#define CF_SHORT 0x0400 /* Use short addressing */ #define CF_REG 0x0800 /* Value is in primary register */ /* Type of static address */ @@ -51,10 +87,13 @@ /* Compiler relative stackpointer */ extern int oursp; +/* Forward */ +struct StrBuf; + /*****************************************************************************/ -/* Pre- and postamble */ +/* Files, pre- and postamble */ /*****************************************************************************/ @@ -62,8 +101,8 @@ extern int oursp; void g_preamble (void); /* Generate the assembler code preamble */ -void g_postamble (void); -/* Generate assembler code postamble */ +void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime); +/* If debug info is enabled, place a file info into the source */ @@ -73,9 +112,6 @@ void g_postamble (void); -void g_usecode (void); -/* Switch to the code segment */ - void g_userodata (void); /* Switch to the read only data segment */ @@ -85,28 +121,22 @@ void g_usedata (void); void g_usebss (void); /* Switch to the bss segment */ -void g_codename (const char* Name); -/* Set the name of the CODE segment */ - -void g_rodataname (const char* Name); -/* Set the name of the RODATA segment */ - -void g_dataname (const char* Name); -/* Set the name of the DATA segment */ - -void g_bssname (const char* Name); -/* Set the name of the BSS segment */ +void g_segname (segment_t Seg, const char* Name); +/* Set the name of a segment */ /*****************************************************************************/ -/* Functions handling local labels */ +/* Functions handling local labels */ /*****************************************************************************/ -void g_defloclabel (unsigned label); -/* Define a local label */ +void g_defcodelabel (unsigned label); +/* Define a local code label */ + +void g_defdatalabel (unsigned label); +/* Define a local data label */ @@ -185,10 +215,10 @@ void g_scale (unsigned flags, long val); -void g_enter (unsigned flags, const char* Name, unsigned argsize); +void g_enter (unsigned flags, unsigned argsize); /* Function prologue */ -void g_leave (int flags, int val); +void g_leave (void); /* Function epilogue */ @@ -213,11 +243,27 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes); -void g_getimmed (unsigned flags, unsigned long val, unsigned offs); -void g_getstatic (unsigned flags, unsigned long label, unsigned offs); -void g_getlocal (unsigned flags, int offs); -void g_getind (unsigned flags, unsigned offs); -void g_leasp (int offs); +void g_getimmed (unsigned Flags, unsigned long Val, long Offs); +/* Load a constant into the primary register */ + +void g_getstatic (unsigned Flags, unsigned long Label, long Offs); +/* Fetch an static memory cell into the primary register */ + +void g_getlocal (unsigned Flags, int Offs); +/* Fetch specified local object (local var). */ + +void g_getind (unsigned Flags, unsigned Offs); +/* Fetch the specified object type indirect through the primary register + * into the primary register + */ + +void g_leasp (int Offs); +/* Fetch the address of the specified symbol into the primary register */ + +void g_leavariadic (int Offs); +/* Fetch the address of a parameter in a variadic function into the primary + * register + */ @@ -227,10 +273,10 @@ void g_leasp (int offs); -void g_putstatic (unsigned flags, unsigned long label, unsigned offs); +void g_putstatic (unsigned flags, unsigned long label, long offs); /* Store the primary register into the specified static memory cell */ -void g_putlocal (unsigned flags, int offs); +void g_putlocal (unsigned Flags, int Offs, long Val); /* Put data into local object. */ void g_putind (unsigned flags, unsigned offs); @@ -249,32 +295,18 @@ void g_putind (unsigned flags, unsigned offs); void g_addlocal (unsigned flags, int offs); /* Add a local variable to ax */ -void g_addstatic (unsigned flags, unsigned long label, unsigned offs); +void g_addstatic (unsigned flags, unsigned long label, long offs); /* Add a static variable to ax */ -/*****************************************************************************/ -/* Compares of ax with a variable with fixed address */ -/*****************************************************************************/ - - - -void g_cmplocal (unsigned flags, int offs); -/* Compare a local variable to ax */ - -void g_cmpstatic (unsigned flags, unsigned label, unsigned offs); -/* Compare a static variable to ax */ - - - /*****************************************************************************/ /* Special op= functions */ /*****************************************************************************/ -void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs, +void g_addeqstatic (unsigned flags, unsigned long label, long offs, unsigned long val); /* Emit += for a static variable */ @@ -284,7 +316,7 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val); void g_addeqind (unsigned flags, unsigned offs, unsigned long val); /* Emit += for the location with address in ax */ -void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs, +void g_subeqstatic (unsigned flags, unsigned long label, long offs, unsigned long val); /* Emit -= for a static variable */ @@ -297,7 +329,7 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val); /*****************************************************************************/ -/* Add a variable address to the value in ax */ +/* Add a variable address to the value in ax */ /*****************************************************************************/ @@ -305,7 +337,7 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val); void g_addaddr_local (unsigned flags, int offs); /* Add the address of a local variable to ax */ -void g_addaddr_static (unsigned flags, unsigned long label, unsigned offs); +void g_addaddr_static (unsigned flags, unsigned long label, long offs); /* Add the address of a static variable to ax */ @@ -317,7 +349,10 @@ void g_addaddr_static (unsigned flags, unsigned long label, unsigned offs); void g_save (unsigned flags); +/* Copy primary register to hold register. */ + void g_restore (unsigned flags); +/* Copy hold register to primary. */ void g_cmp (unsigned flags, unsigned long val); /* Immidiate compare. The primary register will not be changed, Z flag @@ -325,15 +360,24 @@ void g_cmp (unsigned flags, unsigned long val); */ void g_test (unsigned flags); +/* Test the value in the primary and set the condition codes */ + void g_push (unsigned flags, unsigned long val); +/* Push the primary register or a constant value onto the stack */ + void g_swap (unsigned flags); -void g_call (unsigned flags, char *lbl, unsigned argsize); -void g_callind (unsigned flags, unsigned argsize); -void g_jump (unsigned label); -void g_switch (unsigned flags); +/* Swap the primary register and the top of the stack. flags give the type + * of *both* values (must have same size). + */ + +void g_call (unsigned Flags, const char* Label, unsigned ArgSize); +/* Call the specified subroutine name */ -void g_case (unsigned flags, unsigned label, unsigned long val); -/* Create table code for one case selector */ +void g_callind (unsigned Flags, unsigned ArgSize, int Offs); +/* Call subroutine indirect */ + +void g_jump (unsigned Label); +/* Jump to specified internal label number */ void g_truejump (unsigned flags, unsigned label); /* Jump to label if zero flag clear */ @@ -344,6 +388,12 @@ void g_falsejump (unsigned flags, unsigned label); void g_space (int space); /* Create or drop space on the stack */ +void g_cstackcheck (void); +/* Check for a C stack overflow */ + +void g_stackcheck (void); +/* Check for a stack overflow */ + void g_add (unsigned flags, unsigned long val); void g_sub (unsigned flags, unsigned long val); void g_rsub (unsigned flags, unsigned long val); @@ -366,15 +416,40 @@ void g_lt (unsigned flags, unsigned long val); void g_le (unsigned flags, unsigned long val); void g_gt (unsigned flags, unsigned long val); void g_ge (unsigned flags, unsigned long val); -void g_makebool (unsigned flags); -void outdat (int n); + void g_res (unsigned n); +/* Reserve static storage, n bytes */ -void g_defdata (unsigned flags, unsigned long val, unsigned offs); +void g_defdata (unsigned flags, unsigned long val, long offs); /* Define data with the size given in flags */ -void g_defbytes (const unsigned char *bytes, unsigned count); +void g_defbytes (const void* bytes, unsigned count); +/* Output a row of bytes as a constant */ + void g_zerobytes (unsigned n); +/* Output n bytes of data initialized with zero */ + + + +/*****************************************************************************/ +/* Switch statement */ +/*****************************************************************************/ + + + +void g_switch (Collection* Nodes, unsigned DefaultLabel, unsigned Depth); +/* Generate code for a switch statement */ + + + +/*****************************************************************************/ +/* User supplied assembler code */ +/*****************************************************************************/ + + + +void g_asmcode (struct StrBuf* B); +/* Output one line of assembler code. */ @@ -384,7 +459,7 @@ void g_zerobytes (unsigned n); -void g_strlen (unsigned flags, unsigned long val, unsigned offs); +void g_strlen (unsigned flags, unsigned long val, long offs); /* Inline the strlen() function */