mirror of
https://github.com/cc65/cc65.git
synced 2025-01-15 22:30:04 +00:00
Added a new option --macpack-dir that allows to load the macro packages
from files instead of using the builtin ones. git-svn-id: svn://svn.cc65.org/cc65/trunk@3587 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
4759eaebfb
commit
1f6276d21e
@ -78,7 +78,7 @@ unsigned char MissingCharTerm = 0; /* Allow lda #'a (no closing term) */
|
|||||||
unsigned char UbiquitousIdents = 0; /* Allow ubiquitous identifiers */
|
unsigned char UbiquitousIdents = 0; /* Allow ubiquitous identifiers */
|
||||||
|
|
||||||
/* Misc stuff */
|
/* Misc stuff */
|
||||||
const char Copyright[] = "(C) Copyright 1998-2004 Ullrich von Bassewitz";
|
const char Copyright[] = "(C) Copyright 1998-2005 Ullrich von Bassewitz";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
#include "strbuf.h"
|
||||||
|
#include "strutil.h"
|
||||||
|
|
||||||
/* ca65 */
|
/* ca65 */
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
@ -56,13 +58,20 @@
|
|||||||
#include "longbranch.inc"
|
#include "longbranch.inc"
|
||||||
|
|
||||||
/* Table with pointers to the different packages */
|
/* Table with pointers to the different packages */
|
||||||
static char* MacPackages [] = {
|
static struct {
|
||||||
MacGeneric,
|
const char* Name;
|
||||||
MacLongBranch,
|
char* Package;
|
||||||
MacCBM,
|
} MacPackages[MAC_COUNT] = {
|
||||||
MacCPU
|
/* Packages sorted by id */
|
||||||
|
{ "cbm", MacCBM },
|
||||||
|
{ "cpu", MacCPU },
|
||||||
|
{ "generic", MacGeneric },
|
||||||
|
{ "longbranch", MacLongBranch },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Directory that contains standard macro package files */
|
||||||
|
static StrBuf MacPackDir = STATIC_STRBUF_INITIALIZER;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@ -71,14 +80,80 @@ static char* MacPackages [] = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InsertMacPack (unsigned Id)
|
int MacPackFind (const char* Name)
|
||||||
/* Insert the macro package with the given id in the input stream */
|
/* Find a macro package by name. The function will either return the id or
|
||||||
|
* -1 if the package name was not found.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
/* Check the parameter */
|
int I;
|
||||||
CHECK (Id < sizeof (MacPackages) / sizeof (MacPackages [0]));
|
|
||||||
|
|
||||||
/* Insert the package */
|
for (I = 0; I < MAC_COUNT; ++I) {
|
||||||
NewInputData (MacPackages[Id], 0);
|
if (StrCaseCmp (Name, MacPackages[I].Name) == 0) {
|
||||||
|
/* Found */
|
||||||
|
return I;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not found */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void MacPackInsert (int Id)
|
||||||
|
/* Insert the macro package with the given id in the input stream */
|
||||||
|
{
|
||||||
|
/* Check the parameter */
|
||||||
|
CHECK (Id >= 0 && Id < MAC_COUNT);
|
||||||
|
|
||||||
|
/* If we have a macro package directory given, load a file from the
|
||||||
|
* directory, otherwise use the builtin stuff.
|
||||||
|
*/
|
||||||
|
if (SB_IsEmpty (&MacPackDir)) {
|
||||||
|
|
||||||
|
/* Insert the builtin package */
|
||||||
|
NewInputData (MacPackages[Id].Package, 0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
StrBuf Filename = AUTO_STRBUF_INITIALIZER;
|
||||||
|
|
||||||
|
/* Build the complete file name */
|
||||||
|
SB_Copy (&Filename, &MacPackDir);
|
||||||
|
SB_AppendStr (&Filename, MacPackages[Id].Name);
|
||||||
|
SB_AppendStr (&Filename, ".mac");
|
||||||
|
SB_Terminate (&Filename);
|
||||||
|
|
||||||
|
/* Open the macro package as include file */
|
||||||
|
NewInputFile (SB_GetConstBuf (&Filename));
|
||||||
|
|
||||||
|
/* Destroy the contents of Filename */
|
||||||
|
DoneStrBuf (&Filename);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void MacPackSetDir (const char* Dir)
|
||||||
|
/* Set a directory where files for macro packages can be found. Standard is
|
||||||
|
* to use the builtin packages. For debugging macro packages, external files
|
||||||
|
* can be used.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Copy the directory name to the buffer */
|
||||||
|
SB_CopyStr (&MacPackDir, Dir);
|
||||||
|
|
||||||
|
/* Make sure that the last character is a path delimiter */
|
||||||
|
if (SB_NotEmpty (&MacPackDir)) {
|
||||||
|
char C = SB_LookAtLast (&MacPackDir);
|
||||||
|
if (C != '\\' && C != '/') {
|
||||||
|
SB_AppendChar (&MacPackDir, '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Terminate the buffer so it's usable as a C string */
|
||||||
|
SB_Terminate (&MacPackDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2003 Ullrich von Bassewitz */
|
/* (C) 1998-2005, Ullrich von Bassewitz */
|
||||||
/* Römerstrasse 52 */
|
/* Römerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@ -45,10 +45,15 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Constants for the predefined packages */
|
/* Constants for the predefined packages */
|
||||||
#define MAC_GENERIC 0
|
enum {
|
||||||
#define MAC_LONGBRANCH 1
|
MAC_CBM,
|
||||||
#define MAC_CBM 2
|
MAC_CPU,
|
||||||
#define MAC_CPU 3
|
MAC_GENERIC,
|
||||||
|
MAC_LONGBRANCH,
|
||||||
|
|
||||||
|
/* Number of known packages */
|
||||||
|
MAC_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -58,9 +63,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InsertMacPack (unsigned Id);
|
int MacPackFind (const char* Name);
|
||||||
|
/* Find a macro package by name. The function will either return the id or
|
||||||
|
* -1 if the package name was not found.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void MacPackInsert (int Id);
|
||||||
/* Insert the macro package with the given id in the input stream */
|
/* Insert the macro package with the given id in the input stream */
|
||||||
|
|
||||||
|
void MacPackSetDir (const char* Dir);
|
||||||
|
/* Set a directory where files for macro packages can be found. Standard is
|
||||||
|
* to use the builtin packages. For debugging macro packages, external files
|
||||||
|
* can be used.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of macpack.h */
|
/* End of macpack.h */
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2004 Ullrich von Bassewitz */
|
/* (C) 1998-2005, Ullrich von Bassewitz */
|
||||||
/* Römerstraße 52 */
|
/* Römerstraße 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* This software is provided 'as-is', without any expressed or implied */
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
@ -61,6 +61,7 @@
|
|||||||
#include "istack.h"
|
#include "istack.h"
|
||||||
#include "lineinfo.h"
|
#include "lineinfo.h"
|
||||||
#include "listing.h"
|
#include "listing.h"
|
||||||
|
#include "macpack.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "nexttok.h"
|
#include "nexttok.h"
|
||||||
#include "objfile.h"
|
#include "objfile.h"
|
||||||
@ -111,6 +112,7 @@ static void Usage (void)
|
|||||||
" --include-dir dir\tSet an include directory search path\n"
|
" --include-dir dir\tSet an include directory search path\n"
|
||||||
" --listing\t\tCreate a listing if assembly was ok\n"
|
" --listing\t\tCreate a listing if assembly was ok\n"
|
||||||
" --list-bytes n\tMaximum number of bytes per listing line\n"
|
" --list-bytes n\tMaximum number of bytes per listing line\n"
|
||||||
|
" --macpack-dir dir\tSet a macro package directory\n"
|
||||||
" --memory-model model\tSet the memory model\n"
|
" --memory-model model\tSet the memory model\n"
|
||||||
" --pagelength n\tSet the page length for the listing\n"
|
" --pagelength n\tSet the page length for the listing\n"
|
||||||
" --smart\t\tEnable smart mode\n"
|
" --smart\t\tEnable smart mode\n"
|
||||||
@ -420,6 +422,15 @@ static void OptListing (const char* Opt attribute ((unused)),
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void OptMacPackDir (const char* Opt attribute ((unused)), const char* Arg)
|
||||||
|
/* Set a macro package directory */
|
||||||
|
{
|
||||||
|
/* Use the directory */
|
||||||
|
MacPackSetDir (Arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void OptMemoryModel (const char* Opt, const char* Arg)
|
static void OptMemoryModel (const char* Opt, const char* Arg)
|
||||||
/* Set the memory model */
|
/* Set the memory model */
|
||||||
{
|
{
|
||||||
@ -754,6 +765,7 @@ int main (int argc, char* argv [])
|
|||||||
{ "--include-dir", 1, OptIncludeDir },
|
{ "--include-dir", 1, OptIncludeDir },
|
||||||
{ "--list-bytes", 1, OptListBytes },
|
{ "--list-bytes", 1, OptListBytes },
|
||||||
{ "--listing", 0, OptListing },
|
{ "--listing", 0, OptListing },
|
||||||
|
{ "--macpack-dir", 1, OptMacPackDir },
|
||||||
{ "--memory-model", 1, OptMemoryModel },
|
{ "--memory-model", 1, OptMemoryModel },
|
||||||
{ "--pagelength", 1, OptPageLength },
|
{ "--pagelength", 1, OptPageLength },
|
||||||
{ "--smart", 0, OptSmart },
|
{ "--smart", 0, OptSmart },
|
||||||
|
@ -1206,14 +1206,6 @@ static void DoLocalChar (void)
|
|||||||
static void DoMacPack (void)
|
static void DoMacPack (void)
|
||||||
/* Insert a macro package */
|
/* Insert a macro package */
|
||||||
{
|
{
|
||||||
/* Macro package names */
|
|
||||||
static const char* Keys [] = {
|
|
||||||
"GENERIC",
|
|
||||||
"LONGBRANCH",
|
|
||||||
"CBM",
|
|
||||||
"CPU"
|
|
||||||
};
|
|
||||||
|
|
||||||
int Package;
|
int Package;
|
||||||
|
|
||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
@ -1222,8 +1214,8 @@ static void DoMacPack (void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map the keyword to a number */
|
/* Search for the macro package name */
|
||||||
Package = GetSubKey (Keys, sizeof (Keys) / sizeof (Keys [0]));
|
Package = MacPackFind (SVal);
|
||||||
if (Package < 0) {
|
if (Package < 0) {
|
||||||
/* Not found */
|
/* Not found */
|
||||||
ErrorSkip ("Invalid macro package");
|
ErrorSkip ("Invalid macro package");
|
||||||
@ -1234,7 +1226,7 @@ static void DoMacPack (void)
|
|||||||
NextTok ();
|
NextTok ();
|
||||||
|
|
||||||
/* Insert the package */
|
/* Insert the package */
|
||||||
InsertMacPack (Package);
|
MacPackInsert (Package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user