Menu

[r61]: / trunk / src / Main.cpp  Maximize  Restore  History

Download this file

202 lines (164 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
///////////////////////////////////////////////////////////////////////////////
//
// main.cpp
//
// $Id$
//
// Main program, options, etc etc etc
//
// Copyright (C) Simon Collis 2000-2018
//
//-----------------------------------------------------------------------------
//
// This file is part of The A6 Cross-Assembler.
//
// a6 is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// a6 is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License
// along with a6. If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Assembler.h"
#include "Conditional.h"
#include "Config.h"
#include "Cpu.h"
#include "Error.h"
#include "Label.h"
#include "OutputFactory.h"
#include "String.h"
#include "SymbolTable.h"
#include "Text.h"
#include "Main.h"
// *** ProcessCommandLine
void ProcessCommandLine(Assembler *asm, int argc, char **argv)
{
}
/*===========================================================================*
* MAIN *
*===========================================================================*/
int main(int argc, char **argv)
{
// Process command line arguments
AsmOptions* opts = ProcessCommandLine(asm, argc, argv);
// Setup for pass 2
if (opts->OutputFileName() == null)
{
// Build output filename
}
/* char *s;*/
size_t i;
int freeoutname = 0;
/* char *outname = NULL;*/
FILE *infile = NULL;
/* TODO -- add code to get a6_homedir */
/* Defaults before command line */
g_listout = stdout;
ctx->ProcessCommandLine(argc, argv);
/* If no input name, show usage and exit */
if(inname == 0)
{
usage();
exit(EXIT_FAILURE);
}
/* If no output name, generate it */
if(g_outname == NULL)
{
g_outname = (char *)a6malloc(strlen(inname) + 5);
freeoutname = 1;
strcpy(g_outname, inname);
i = strlen(g_outname);
while(i > 0 && g_outname[i] != '.') i--;
if(i == 0)
i = strlen(g_outname);
g_outname[i++] = '.';
g_outname[i++] = outf_extension[g_outf_format][0];
g_outname[i++] = outf_extension[g_outf_format][1];
g_outname[i++] = outf_extension[g_outf_format][2];
g_outname[i] = '\0';
}
/* Check that main file exists */
infile = fopen(inname, "r");
if(infile == NULL)
{
printf("file not found: '%s'\n", inname);
exit(EXIT_FAILURE);
}
/* CALL ALL ASSEMBLY ROUTINES HERE */
//----------------------------------------------------------------------------
/* Pass 1 */
if (ctx->IsVerbose())
{
printf("\npass 1\n\n");
}
g_undocopsflag = 0; /* Undoc. ops OFF by default */
pstext_setcset(CSET_PETSCII); /* Default = PET ASCII */
lbl_init(); /* Set up label indexing */
/* Actual pass */
af_open(inname, infile);
while(af_parseline());
//----------------------------------------------------------------------------
// Pass 2
ctx->BeginPass2();
if (ctx->IsVerbose())
{
printf("\npass 2\n\n");
}
// Reset conditional assembly stack
Conditional::Clear();
// Clear up asmfiles (This has to be the last cleanup!)
af_reset(); /* Reset af_postotal */
while(af_close() != 0);
/* ------------------------------------------------------- */
/* Pass 2 */
g_undocopsflag = 0; /* Undoc. ops OFF by default */
lbl_reset(); /* Reset local labels */
pstext_setcset(CSET_PETSCII); /* Default = PET ASCII */
outf_setpc(0); /* Reset PC counter */
outf_open(g_outname); /* Open output file */
/* Actual pass */
af_open(inname, 0);
while(af_parseline());
//----------------------------------------------------------------------------
// End of pass 2
// Warning if conditional stack not empty
if(Conditional::OpenItems() > 0)
{
ErrorHandler::RaiseError(Warning, UnclosedCond);
}
/* Cleanup input files */
while(af_close() != 0);
/* List symbol table if required */
if(symflag != 0)
{
if(verbose)
printf("\n\n");
lbl_dumpsym();
}
/* Tidy everything up */
af_cleanup(); /* Clean up assembly files */
lbl_destroy(); /* Delete all allocated labels */
outf_close();
if(freeoutname)
free(g_outname);
/* ------------------------------------------------------- */
/* Final message */
if(ErrorHandler::ErrorCount() > 0)
{
printf("\n %u errors; assembly failed.\n", ErrorHandler::ErrorCount());
exit(EXIT_FAILURE);
}
if(verbose)
printf("\n assembly successful; no errors.\n");
return(EXIT_SUCCESS);
}
MongoDB Logo MongoDB