1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-28 10:55:43 +00:00

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 };
/* Variables controlling the steps we're doing */
static int DontLink = 0;
static int DontAssemble = 0;
static int DoLink = 1;
static int DoAssemble = 1;
/* The name of the output file, NULL if none given */
static const char* OutputName = 0;
@ -448,19 +448,20 @@ static void AssembleFile (const char* File, unsigned ArgCount)
/* Set the target system */
CmdSetTarget (&CA65, Target);
/* If we won't link, this is the final step. In this case, set the
* output name.
*/
if (DontLink && OutputName) {
CmdSetOutput (&CA65, OutputName);
} 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.
*/
/* Check if this is the last processing step */
if (DoLink) {
/* We're linking later. Add the output file of the assembly
* the the file list of the linker. The name of the output
* file is that of the input file with ".s" replaced by ".o".
*/
char* ObjName = MakeFilename (File, ".o");
CmdAddFile (&LD65, 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 */
@ -478,19 +479,28 @@ static void AssembleFile (const char* File, unsigned ArgCount)
static void AssembleIntermediate (const char* File)
/* Assemble an intermediate file. The -dep options won't be added and
* the file is removed after assembly.
static void AssembleIntermediate (const char* SourceFile)
/* Assemble an intermediate file which was generated by a previous processing
* step with SourceFile as input. The -dep options won't be added and
* the intermediate assembler file is removed after assembly.
*/
{
/* Use common routine */
AssembleFile (File, CA65.ArgCount);
/* Generate the name of the assembler output file from the source file
* name. It's the same name with the extension replaced by ".s"
*/
char* AsmName = MakeFilename (SourceFile, ".s");
/* Remove the generated file */
if (remove (File) < 0) {
/* Assemble the intermediate assembler file */
AssembleFile (AsmName, CA65.ArgCount);
/* Remove the input file */
if (remove (AsmName) < 0) {
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)
/* Compile the given file */
{
char* AsmName = 0;
/* Remember the current compiler argument count */
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
* output name.
*/
if (DontAssemble && OutputName) {
if (!DoAssemble && 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 */
@ -556,12 +559,10 @@ static void Compile (const char* File)
/* If this is not the final step, assemble the generated file, then
* remove it
*/
if (!DontAssemble) {
AssembleIntermediate (AsmName);
if (DoAssemble) {
/* 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)
/* Compile the given geos resource file */
{
char* AsmName = 0;
/* Remember the current assembler argument count */
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 */
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
* remove it
*/
if (!DontAssemble) {
AssembleIntermediate (AsmName);
if (DoAssemble) {
/* 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)
/* Convert an o65 object file into an assembler file */
{
char* AsmName = 0;
/* Remember the current converter argument count */
unsigned ArgCount = CO65.ArgCount;
/* If we won't assemble, this is the final step. In this case, set the
* output name.
*/
if (DontAssemble && 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");
if (!DoAssemble && OutputName) {
CmdSetOutput (&CO65, OutputName);
}
/* 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
* remove it
*/
if (!DontAssemble) {
AssembleIntermediate (AsmName);
if (DoAssemble) {
/* 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':
/* Dont assemble and link the created files */
DontLink = DontAssemble = 1;
DoAssemble = 0;
DoLink = 0;
break;
case 'T':
@ -1362,7 +1346,7 @@ int main (int argc, char* argv [])
case 'c':
/* Don't link the resulting files */
DontLink = 1;
DoLink = 0;
break;
case 'd':
@ -1446,7 +1430,7 @@ int main (int argc, char* argv [])
case FILETYPE_ASM:
/* Assemble the file */
if (!DontAssemble) {
if (DoAssemble) {
Assemble (Arg);
}
break;
@ -1484,7 +1468,7 @@ int main (int argc, char* argv [])
}
/* Link the given files if requested and if we have any */
if (DontLink == 0 && LD65.FileCount > 0) {
if (DoLink && LD65.FileCount > 0) {
Link ();
}