Restructured the code for better reada- and maintainability.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4659 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2010-05-02 09:32:42 +00:00
parent 84b1e343b5
commit e61bf7094c

View File

@@ -98,8 +98,8 @@ static CmdDesc LD65 = { 0, 0, 0, 0, 0, 0, 0 };
static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 }; static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 };
/* Variables controlling the steps we're doing */ /* Variables controlling the steps we're doing */
static int DontLink = 0; static int DoLink = 1;
static int DontAssemble = 0; static int DoAssemble = 1;
/* The name of the output file, NULL if none given */ /* The name of the output file, NULL if none given */
static const char* OutputName = 0; static const char* OutputName = 0;
@@ -448,19 +448,20 @@ static void AssembleFile (const char* File, unsigned ArgCount)
/* Set the target system */ /* Set the target system */
CmdSetTarget (&CA65, Target); CmdSetTarget (&CA65, Target);
/* If we won't link, this is the final step. In this case, set the /* Check if this is the last processing step */
* output name. if (DoLink) {
*/ /* We're linking later. Add the output file of the assembly
if (DontLink && OutputName) { * the the file list of the linker. The name of the output
CmdSetOutput (&CA65, OutputName); * file is that of the input file with ".s" replaced by ".o".
} else { */
/* The object file name will be the name of the source file
* with .s replaced by ".o". Add this file to the list of
* linker files.
*/
char* ObjName = MakeFilename (File, ".o"); char* ObjName = MakeFilename (File, ".o");
CmdAddFile (&LD65, ObjName); CmdAddFile (&LD65, ObjName);
xfree (ObjName); xfree (ObjName);
} else {
/* This is the final step. If an output name is given, set it */
if (OutputName) {
CmdSetOutput (&CA65, OutputName);
}
} }
/* Add the file as argument for the assembler */ /* Add the file as argument for the assembler */
@@ -478,19 +479,28 @@ static void AssembleFile (const char* File, unsigned ArgCount)
static void AssembleIntermediate (const char* File) static void AssembleIntermediate (const char* SourceFile)
/* Assemble an intermediate file. The -dep options won't be added and /* Assemble an intermediate file which was generated by a previous processing
* the file is removed after assembly. * step with SourceFile as input. The -dep options won't be added and
* the intermediate assembler file is removed after assembly.
*/ */
{ {
/* Use common routine */ /* Generate the name of the assembler output file from the source file
AssembleFile (File, CA65.ArgCount); * name. It's the same name with the extension replaced by ".s"
*/
char* AsmName = MakeFilename (SourceFile, ".s");
/* Remove the generated file */ /* Assemble the intermediate assembler file */
if (remove (File) < 0) { AssembleFile (AsmName, CA65.ArgCount);
/* Remove the input file */
if (remove (AsmName) < 0) {
Warning ("Cannot remove temporary file `%s': %s", Warning ("Cannot remove temporary file `%s': %s",
File, strerror (errno)); AsmName, strerror (errno));
} }
/* Free the assembler file name which was allocated from the heap */
xfree (AsmName);
} }
@@ -521,8 +531,6 @@ static void Assemble (const char* File)
static void Compile (const char* File) static void Compile (const char* File)
/* Compile the given file */ /* Compile the given file */
{ {
char* AsmName = 0;
/* Remember the current compiler argument count */ /* Remember the current compiler argument count */
unsigned ArgCount = CC65.ArgCount; unsigned ArgCount = CC65.ArgCount;
@@ -532,13 +540,8 @@ static void Compile (const char* File)
/* If we won't assemble, this is the final step. In this case, set the /* If we won't assemble, this is the final step. In this case, set the
* output name. * output name.
*/ */
if (DontAssemble && OutputName) { if (!DoAssemble && OutputName) {
CmdSetOutput (&CC65, OutputName); CmdSetOutput (&CC65, OutputName);
} else {
/* The assembler file name will be the name of the source file
* with .c replaced by ".s".
*/
AsmName = MakeFilename (File, ".s");
} }
/* Add the file as argument for the compiler */ /* Add the file as argument for the compiler */
@@ -556,12 +559,10 @@ static void Compile (const char* File)
/* If this is not the final step, assemble the generated file, then /* If this is not the final step, assemble the generated file, then
* remove it * remove it
*/ */
if (!DontAssemble) { if (DoAssemble) {
AssembleIntermediate (AsmName); /* Assemble the intermediate file and remove it */
AssembleIntermediate (File);
} }
/* Free the assembler file name which was allocated from the heap */
xfree (AsmName);
} }
@@ -569,16 +570,9 @@ static void Compile (const char* File)
static void CompileRes (const char* File) static void CompileRes (const char* File)
/* Compile the given geos resource file */ /* Compile the given geos resource file */
{ {
char* AsmName = 0;
/* Remember the current assembler argument count */ /* Remember the current assembler argument count */
unsigned ArgCount = GRC.ArgCount; unsigned ArgCount = GRC.ArgCount;
/* The assembler file name will be the name of the source file
* with .grc replaced by ".s".
*/
AsmName = MakeFilename (File, ".s");
/* Add the file as argument for the resource compiler */ /* Add the file as argument for the resource compiler */
CmdAddArg (&GRC, File); CmdAddArg (&GRC, File);
@@ -594,12 +588,10 @@ static void CompileRes (const char* File)
/* If this is not the final step, assemble the generated file, then /* If this is not the final step, assemble the generated file, then
* remove it * remove it
*/ */
if (!DontAssemble) { if (DoAssemble) {
AssembleIntermediate (AsmName); /* Assemble the intermediate file and remove it */
AssembleIntermediate (File);
} }
/* Free the assembler file name which was allocated from the heap */
xfree (AsmName);
} }
@@ -607,21 +599,14 @@ static void CompileRes (const char* File)
static void ConvertO65 (const char* File) static void ConvertO65 (const char* File)
/* Convert an o65 object file into an assembler file */ /* Convert an o65 object file into an assembler file */
{ {
char* AsmName = 0;
/* Remember the current converter argument count */ /* Remember the current converter argument count */
unsigned ArgCount = CO65.ArgCount; unsigned ArgCount = CO65.ArgCount;
/* If we won't assemble, this is the final step. In this case, set the /* If we won't assemble, this is the final step. In this case, set the
* output name. * output name.
*/ */
if (DontAssemble && OutputName) { if (!DoAssemble && OutputName) {
CmdSetOutput (&CO65, OutputName); CmdSetOutput (&CO65, OutputName);
} else {
/* The assembler file name will be the name of the source file
* with .c replaced by ".s".
*/
AsmName = MakeFilename (File, ".s");
} }
/* Add the file as argument for the object file converter */ /* Add the file as argument for the object file converter */
@@ -639,12 +624,10 @@ static void ConvertO65 (const char* File)
/* If this is not the final step, assemble the generated file, then /* If this is not the final step, assemble the generated file, then
* remove it * remove it
*/ */
if (!DontAssemble) { if (DoAssemble) {
AssembleIntermediate (AsmName); /* Assemble the intermediate file and remove it */
AssembleIntermediate (File);
} }
/* Free the assembler file name which was allocated from the heap */
xfree (AsmName);
} }
@@ -1324,7 +1307,8 @@ int main (int argc, char* argv [])
case 'S': case 'S':
/* Dont assemble and link the created files */ /* Dont assemble and link the created files */
DontLink = DontAssemble = 1; DoAssemble = 0;
DoLink = 0;
break; break;
case 'T': case 'T':
@@ -1362,7 +1346,7 @@ int main (int argc, char* argv [])
case 'c': case 'c':
/* Don't link the resulting files */ /* Don't link the resulting files */
DontLink = 1; DoLink = 0;
break; break;
case 'd': case 'd':
@@ -1446,7 +1430,7 @@ int main (int argc, char* argv [])
case FILETYPE_ASM: case FILETYPE_ASM:
/* Assemble the file */ /* Assemble the file */
if (!DontAssemble) { if (DoAssemble) {
Assemble (Arg); Assemble (Arg);
} }
break; break;
@@ -1484,7 +1468,7 @@ int main (int argc, char* argv [])
} }
/* Link the given files if requested and if we have any */ /* Link the given files if requested and if we have any */
if (DontLink == 0 && LD65.FileCount > 0) { if (DoLink && LD65.FileCount > 0) {
Link (); Link ();
} }