s502 assembler
A very simple assembler for the 6502 line of processors written in C
src
main.c
Go to the documentation of this file.
1
#define __USE_MINGW_ANSI_STDIO 1
2
3
#include "
logging.h
"
4
#include "
pass_twothree.h
"
5
#include "
state.h
"
6
#include "
loadfile.h
"
7
#include "
pass_one.h
"
8
#include "
tokenFunc.h
"
9
23
int
main
(
int
argc,
char
** argv) {
24
logging_level
(1);
25
State
* state =
state_new
();
26
if
(!state)
goto
ERR_INIT;
27
if
(
state_load_instr
(state,
"opcodes.csv"
) < 0)
goto
ERR_INIT;
28
if
(
state_parse_commandline
(state, argc, argv) < 0)
goto
ERR_INIT;
29
30
LOG
(2,
"Init done!\n"
);
31
32
state->
tokens
=
load_file
(state->
infile
);
33
if
(!state->
tokens
)
goto
ERR_COMP;
34
if
(
pass_one
(state) < 0)
goto
ERR_COMP;
35
if
(
pass_two
(state) < 0)
goto
ERR_COMP;
36
if
(
write_data
(state) < 0)
goto
ERR_COMP;
37
38
39
LOG
(2,
"Now dunping the file: \n"
);
40
LOGDO
(2,
tokenslist_debug_print
(state->
tokens
));
41
LOG
(2,
"Now the defined constants:\n"
);
42
LOGDO
(2,
map_debug_print
(state->
defines
));
43
LOG
(2,
"And the labels:\n"
);
44
LOGDO
(2,
map_debug_print
(state->
labels
));
45
LOG
(2,
"Cleaning up...\n"
);
46
state_free
(state);
47
48
return
0;
49
50
ERR_INIT:
51
FAIL
(
"Initialization failed!\n"
);
52
state_free
(state);
53
return
-1;
54
55
ERR_COMP:
56
FAIL
(
"Compilation failed!\n"
);
57
state_free
(state);
58
state = NULL;
59
return
-1;
60
}
State::labels
Map * labels
label locations
Definition:
state.h:36
load_file
TokensList * load_file(char *name)
load and parse one file
Definition:
loadfile.c:166
pass_two
int pass_two(State *s)
compilation pass 2
Definition:
pass_twothree.c:19
State::infile
char infile[STATE_MAX_STRING_LEN]
input file name
Definition:
state.h:44
loadfile.h
File reading step.
TokensList::tokenslist_debug_print
void tokenslist_debug_print(TokensList *list)
Pretty-print all tokens in a list.
Definition:
tokenslist.c:89
LOG
#define LOG(LVL,...)
logging macro - works like printf
Definition:
logging.h:28
pass_twothree.h
processing steps 2 and 3
logging_level
int logging_level(int level)
pseudo-global accessor
Definition:
logging.c:6
State::tokens
TokensList * tokens
tokens
Definition:
state.h:38
State
Compiler pseudo-global state.
Definition:
state.h:32
State::state_load_instr
int state_load_instr(State *s, char *fname)
load instructions from a file
Definition:
state.c:41
LOGDO
#define LOGDO(LVL, x)
Conditional macro. Wraps contents into a conditional based on log level.
Definition:
logging.h:35
Map::map_debug_print
void map_debug_print(Map *map)
Print all key-value pairs of the map.
Definition:
map.c:85
main
int main(int argc, char **argv)
standard libc main function
Definition:
main.c:23
pass_one.h
processing step one
pass_one
int pass_one(State *s)
Compilation pass 1.
Definition:
pass_one.c:19
State::defines
Map * defines
defined constants
Definition:
state.h:34
State::state_new
State * state_new()
Create a new State object.
Definition:
state.c:16
State::state_free
void state_free(State *s)
free a State object and all associated memory
Definition:
state.c:48
write_data
int write_data(State *s)
compilation pass 3
Definition:
pass_twothree.c:69
tokenFunc.h
Token type member methods.
State::state_parse_commandline
int state_parse_commandline(State *s, int argc, char **argv)
parse command line arguments and update state
Definition:
state.c:81
logging.h
logging and fancy-printing
state.h
implement State class
FAIL
#define FAIL(...)
Fancy-print a fail (failed step). Works like printf.
Definition:
logging.h:45
Generated by
1.8.20