Replaced builtin macro packages with .mac files that are included like ordinary .inc files.

The benefits are:
- Independency of ca65 build from perl
- More transparent behaviour
This commit is contained in:
Oliver Schmidt 2013-04-07 22:10:30 +02:00
parent 414a59ce65
commit 54299fae5a
11 changed files with 9 additions and 420 deletions

View File

@ -1,173 +0,0 @@
/*****************************************************************************/
/* */
/* macpack.c */
/* */
/* Predefined macro packages for the ca65 macroassembler */
/* */
/* */
/* */
/* (C) 1998-2008, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* 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. */
/* */
/*****************************************************************************/
/* common */
#include "check.h"
#include "strbuf.h"
#include "strutil.h"
/* ca65 */
#include "error.h"
#include "scanner.h"
#include "macpack.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Predefined macro packages converted into C strings by a perl script */
#include "atari.inc"
#include "cbm.inc"
#include "cpu.inc"
#include "generic.inc"
#include "longbranch.inc"
/* Table with pointers to the different packages */
static struct {
const char* Name;
char* Package;
} MacPackages[MAC_COUNT] = {
/* Packages sorted by id */
{ "atari", MacAtari },
{ "cbm", MacCBM },
{ "cpu", MacCPU },
{ "generic", MacGeneric },
{ "longbranch", MacLongBranch },
};
/* Directory that contains standard macro package files */
static StrBuf MacPackDir = STATIC_STRBUF_INITIALIZER;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
int MacPackFind (const StrBuf* Name)
/* Find a macro package by name. The function will either return the id or
* -1 if the package name was not found.
*/
{
int I;
for (I = 0; I < MAC_COUNT; ++I) {
if (SB_CompareStr (Name, MacPackages[I].Name) == 0) {
/* Found */
return I;
}
}
/* Not found */
return -1;
}
int MacPackInsert (int Id)
/* Insert the macro package with the given id in the input stream. Returns
* true if the macro package was found and successfully inserted. Returns
* false otherwise.
*/
{
int RetCode;
/* 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);
/* Always successful */
RetCode = 1;
} 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 */
RetCode = NewInputFile (SB_GetConstBuf (&Filename));
/* Destroy the contents of Filename */
SB_Done (&Filename);
}
/* Return the success code */
return RetCode;
}
void MacPackSetDir (const StrBuf* 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_Copy (&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);
}

View File

@ -1,96 +0,0 @@
/*****************************************************************************/
/* */
/* macpack.h */
/* */
/* Predefined macro packages for the ca65 macroassembler */
/* */
/* */
/* */
/* (C) 1998-2008, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* 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. */
/* */
/*****************************************************************************/
#ifndef MACPACK_H
#define MACPACK_H
/* common */
#include "strbuf.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Constants for the predefined packages */
enum {
MAC_ATARI,
MAC_CBM,
MAC_CPU,
MAC_GENERIC,
MAC_LONGBRANCH,
/* Number of known packages */
MAC_COUNT
};
/*****************************************************************************/
/* Code */
/*****************************************************************************/
int MacPackFind (const StrBuf* Name);
/* Find a macro package by name. The function will either return the id or
* -1 if the package name was not found.
*/
int MacPackInsert (int Id);
/* Insert the macro package with the given id in the input stream. Returns
* true if the macro package was found and successfully inserted. Returns
* false otherwise.
*/
void MacPackSetDir (const StrBuf* 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 */
#endif

View File

@ -1,75 +0,0 @@
#!/usr/bin/perl
# Check number of params
die "Usage: cvt-cfg.pl input output varname\n" unless ($#ARGV == 2);
# Get the parameters
$InputName = shift (@ARGV);
$OutputName = shift (@ARGV);
$VarName = shift (@ARGV);
# Open both files
open (IN, "<$InputName") or die "Cannot open $InputName\n";
open (OUT, ">$OutputName") or die "Cannot open $OutputName\n";
# Print the header to the output file
print OUT "static char $VarName" . "[] = \n";
# Read from input, print to output
while ($Line = <IN>) {
# Remove the newline
chomp $Line;
# Separate an existing comment. No need to be overly clever, just ignore
# semicolons in strings.
if ($Line =~ /(.*?)(\s*)(;\s*)(.*?)\s*$/) {
$Line = $1;
$CommentSpace = $2;
$Comment = $4;
} else {
$CommentSpace = "";
$Comment = "";
}
# Remove leading and trailing spaces
$Line =~ s/^\s*|\s*$//g;
# Ignore empty lines
if ($Line eq "") {
if ($Comment ne "") {
print OUT "/* $Comment */\n";
}
next;
}
# Replace control chars
$Line =~ s/\\/\\\\/g;
$Line =~ s/\"/\\\"/g;
$Line =~ s/\'/\\\'/g;
# Print to output
print OUT "\"$Line\\n\"";
# Add a comment if we have one
if ($Comment ne "") {
print OUT "$CommentSpace/* $Comment */";
}
# Terminate the line
print OUT "\n";
}
# Terminate the variable declaration
print OUT ";\n";
# Close the files
close IN;
close OUT;
# Done
exit 0;

View File

@ -65,7 +65,6 @@
#include "istack.h"
#include "lineinfo.h"
#include "listing.h"
#include "macpack.h"
#include "macro.h"
#include "nexttok.h"
#include "objfile.h"
@ -526,18 +525,6 @@ static void OptListing (const char* Opt, const char* Arg)
static void OptMacPackDir (const char* Opt attribute ((unused)), const char* Arg)
/* Set a macro package directory */
{
/* Make a string buffer from Arg */
StrBuf Dir;
/* Use the directory */
MacPackSetDir (SB_InitFromString (&Dir, Arg));
}
static void OptMemoryModel (const char* Opt, const char* Arg)
/* Set the memory model */
{
@ -891,7 +878,6 @@ int main (int argc, char* argv [])
{ "--large-alignment", 0, OptLargeAlignment },
{ "--list-bytes", 1, OptListBytes },
{ "--listing", 1, OptListing },
{ "--macpack-dir", 1, OptMacPackDir },
{ "--memory-model", 1, OptMemoryModel },
{ "--pagelength", 1, OptPageLength },
{ "--relax-checks", 0, OptRelaxChecks },

View File

@ -21,9 +21,6 @@ override CFLAGS += -DCA65_INC=$(CA65_INC)
EBIND = emxbind
LDFLAGS =
# Perl script for macro file conversion
CVT=macpack/cvt-mac.pl
# -----------------------------------------------------------------------------
# List of all object files
@ -45,7 +42,6 @@ OBJS = anonname.o \
istack.o \
lineinfo.o \
listing.o \
macpack.o \
macro.o \
main.o \
nexttok.o \
@ -72,12 +68,6 @@ OBJS = anonname.o \
# -----------------------------------------------------------------------------
# List of all macro files
INCS = atari.inc \
cbm.inc \
cpu.inc \
generic.inc \
longbranch.inc
LIBS = $(COMMON)/common.a
# ------------------------------------------------------------------------------
@ -93,17 +83,15 @@ all: depend
@$(MAKE) -f make/gcc.mak all
endif
$(EXE): $(INCS) $(OBJS) $(LIBS)
$(EXE): $(OBJS) $(LIBS)
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
@if [ $(OS2_SHELL) ] ; then $(EBIND) $(EXE) ; fi
inc: $(INCS)
clean:
$(RM) *~ core.* *.map
zap: clean
$(RM) *.o $(EXE) $(INCS) .depend
$(RM) *.o $(EXE) .depend
# ------------------------------------------------------------------------------
# Make the dependencies
@ -112,31 +100,3 @@ zap: clean
depend dep: $(INCS) $(OBJS:.o=.c)
@echo "Creating dependency information"
$(CC) $(CFLAGS) -MM $(OBJS:.o=.c) > .depend
# -----------------------------------------------------------------------------
# Rules to make config includes
atari.inc: macpack/atari.mac
@$(CVT) $< $@ MacAtari
cbm.inc: macpack/cbm.mac
@$(CVT) $< $@ MacCBM
cpu.inc: macpack/cpu.mac
@$(CVT) $< $@ MacCPU
generic.inc: macpack/generic.mac
@$(CVT) $< $@ MacGeneric
longbranch.inc: macpack/longbranch.mac
@$(CVT) $< $@ MacLongBranch

View File

@ -67,7 +67,6 @@
#include "incpath.h"
#include "instr.h"
#include "listing.h"
#include "macpack.h"
#include "macro.h"
#include "nexttok.h"
#include "objcode.h"
@ -1444,28 +1443,16 @@ static void DoLocalChar (void)
static void DoMacPack (void)
/* Insert a macro package */
{
int Package;
/* We expect an identifier */
if (CurTok.Tok != TOK_IDENT) {
ErrorSkip ("Identifier expected");
return;
}
/* Search for the macro package name */
LocaseSVal ();
Package = MacPackFind (&CurTok.SVal);
if (Package < 0) {
/* Not found */
ErrorSkip ("Invalid macro package");
return;
}
/* Insert the package. If this fails, skip the remainder of the line to
* avoid additional error messages.
*/
if (MacPackInsert (Package) == 0) {
SkipUntilSep ();
} else {
SB_AppendStr (&CurTok.SVal, ".mac");
SB_Terminate (&CurTok.SVal);
if (NewInputFile (SB_GetConstBuf (&CurTok.SVal)) == 0) {
/* Error opening the file, skip remainder of line */
SkipUntilSep ();
}
}
}