/* */
/* */
/* */
-/* (C) 1998-2004 Ullrich von Bassewitz */
-/* Römerstraße 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 1998-2009, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#include "cmdline.h"
#include "mmodel.h"
#include "print.h"
+#include "strbuf.h"
#include "target.h"
#include "tgttrans.h"
#include "version.h"
#include "istack.h"
#include "lineinfo.h"
#include "listing.h"
+#include "macpack.h"
#include "macro.h"
#include "nexttok.h"
#include "objfile.h"
" --cpu type\t\tSet cpu type\n"
" --debug-info\t\tAdd debug info to object file\n"
" --feature name\tSet an emulation feature\n"
+ " --forget-inc-paths\tForget include search paths\n"
" --help\t\tHelp (this text)\n"
" --ignore-case\t\tIgnore case of symbols\n"
" --include-dir dir\tSet an include directory search path\n"
" --listing\t\tCreate a listing if assembly was ok\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"
" --pagelength n\tSet the page length for the listing\n"
" --smart\t\tEnable smart mode\n"
static void SetOptions (void)
/* Set the option for the translator */
{
- char Buf [256];
+ StrBuf Buf = STATIC_STRBUF_INITIALIZER;
/* Set the translator */
- sprintf (Buf, "ca65 V%u.%u.%u", VER_MAJOR, VER_MINOR, VER_PATCH);
- OptTranslator (Buf);
+ SB_Printf (&Buf, "ca65 V%u.%u.%u", VER_MAJOR, VER_MINOR, VER_PATCH);
+ OptTranslator (&Buf);
/* Set date and time */
OptDateTime ((unsigned long) time(0));
+
+ /* Release memory for the string */
+ SB_Done (&Buf);
}
/* Define a symbol with a fixed numeric value in the current scope */
{
ExprNode* Expr;
+ SymEntry* Sym;
+
+ /* Convert the name to a string buffer */
+ StrBuf SymBuf = STATIC_STRBUF_INITIALIZER;
+ SB_CopyStr (&SymBuf, SymName);
/* Search for the symbol, allocate a new one if it doesn't exist */
- SymEntry* Sym = SymFind (CurrentScope, SymName, SYM_ALLOC_NEW);
+ Sym = SymFind (CurrentScope, &SymBuf, SYM_ALLOC_NEW);
/* Check if have already a symbol with this name */
if (SymIsDef (Sym)) {
/* Mark the symbol as defined */
SymDef (Sym, Expr, ADDR_SIZE_DEFAULT, SF_NONE);
+
+ /* Free string buffer memory */
+ SB_Done (&SymBuf);
}
CBMSystem ("__C128__");
break;
- case TGT_ACE:
- CBMSystem ("__ACE__");
- break;
-
case TGT_PLUS4:
CBMSystem ("__PLUS4__");
break;
const char* P;
unsigned I;
long Val;
- char SymName [MAX_STR_LEN+1];
+ StrBuf SymName = AUTO_STRBUF_INITIALIZER;
/* The symbol must start with a character or underline */
- if (Def [0] != '_' && !IsAlpha (Def [0])) {
+ if (!IsIdStart (Def [0])) {
InvDef (Def);
}
P = Def;
/* Copy the symbol, checking the rest */
I = 0;
- while (IsAlNum (*P) || *P == '_') {
- if (I <= MAX_STR_LEN) {
- SymName [I++] = *P;
- }
- ++P;
+ while (IsIdChar (*P)) {
+ SB_AppendChar (&SymName, *P++);
}
- SymName [I] = '\0';
+ SB_Terminate (&SymName);
/* Do we have a value given? */
if (*P != '=') {
}
/* Define the new symbol */
- NewSymbol (SymName, Val);
+ NewSymbol (SB_GetConstBuf (&SymName), Val);
+
+ /* Release string memory */
+ SB_Done (&SymName);
}
static void OptFeature (const char* Opt attribute ((unused)), const char* Arg)
/* Set an emulation feature */
{
+ /* Make a string buffer from Arg */
+ StrBuf Feature;
+
/* Set the feature, check for errors */
- if (SetFeature (Arg) == FEAT_UNKNOWN) {
+ if (SetFeature (SB_InitFromString (&Feature, Arg)) == FEAT_UNKNOWN) {
AbEnd ("Illegal emulation feature: `%s'", Arg);
}
}
+static void OptForgetIncPaths (const char* Opt attribute ((unused)),
+ const char* Arg attribute ((unused)))
+/* Forget all currently defined include paths */
+{
+ ForgetAllIncludePaths ();
+}
+
+
+
static void OptHelp (const char* Opt attribute ((unused)),
const char* Arg attribute ((unused)))
/* Print usage information and exit */
+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 */
{
if (PC < 0 || PC > 0xFFFFFF) {
Error ("Range error");
} else {
- SetAbsPC (PC);
+ EnterAbsoluteMode (PC);
}
}
if (Tok == TOK_IDENT) {
if (!UbiquitousIdents) {
/* Macros and symbols cannot use instruction names */
- Instr = FindInstruction (SVal);
+ Instr = FindInstruction (&SVal);
if (Instr < 0) {
- Macro = IsMacro (SVal);
+ Macro = IsMacro (&SVal);
}
} else {
/* Macros and symbols may use the names of instructions */
- Macro = IsMacro (SVal);
+ Macro = IsMacro (&SVal);
}
}
/* Generate the symbol table entry, then skip the name */
if (Tok == TOK_IDENT) {
- Sym = SymFind (CurrentScope, SVal, SYM_ALLOC_NEW);
+ Sym = SymFind (CurrentScope, &SVal, SYM_ALLOC_NEW);
} else {
- Sym = SymFindLocal (SymLast, SVal, SYM_ALLOC_NEW);
+ Sym = SymFindLocal (SymLast, &SVal, SYM_ALLOC_NEW);
}
NextTok ();
if (Tok == TOK_IDENT) {
if (!UbiquitousIdents) {
/* Macros and symbols cannot use instruction names */
- Instr = FindInstruction (SVal);
+ Instr = FindInstruction (&SVal);
if (Instr < 0) {
- Macro = IsMacro (SVal);
+ Macro = IsMacro (&SVal);
}
} else {
/* Macros and symbols may use the names of instructions */
- Macro = IsMacro (SVal);
+ Macro = IsMacro (&SVal);
}
}
}
/* A macro expansion */
MacExpandStart ();
} else if (Instr >= 0 ||
- (UbiquitousIdents && ((Instr = FindInstruction (SVal)) >= 0))) {
+ (UbiquitousIdents && ((Instr = FindInstruction (&SVal)) >= 0))) {
/* A mnemonic - assemble one instruction */
HandleInstruction (Instr);
} else if (PCAssignment && (Tok == TOK_STAR || Tok == TOK_PC)) {
{ "--cpu", 1, OptCPU },
{ "--debug-info", 0, OptDebugInfo },
{ "--feature", 1, OptFeature },
+ { "--forget-inc-paths", 0, OptForgetIncPaths },
{ "--help", 0, OptHelp },
{ "--ignore-case", 0, OptIgnoreCase },
{ "--include-dir", 1, OptIncludeDir },
{ "--list-bytes", 1, OptListBytes },
{ "--listing", 0, OptListing },
+ { "--macpack-dir", 1, OptMacPackDir },
{ "--memory-model", 1, OptMemoryModel },
{ "--pagelength", 1, OptPageLength },
{ "--smart", 0, OptSmart },
{ "--version", 0, OptVersion },
};
+ /* Name of the global name space */
+ static const StrBuf GlobalNameSpace = STATIC_STRBUF_INITIALIZER;
+
unsigned I;
/* Initialize the cmdline module */
InitCmdLine (&argc, &argv, "ca65");
+ /* Initialize the include search paths */
+ InitIncludePaths ();
+
/* Enter the base lexical level. We must do that here, since we may
* define symbols using -D.
*/
- SymEnterLevel ("", ST_GLOBAL, ADDR_SIZE_DEFAULT);
+ SymEnterLevel (&GlobalNameSpace, ST_GLOBAL, ADDR_SIZE_DEFAULT);
/* Check the parameters */
I = 1;