s502 assembler
A very simple assembler for the 6502 line of processors written in C
Macros | Functions
main.c File Reference

Entry point. More...

#include "logging.h"
#include "pass_twothree.h"
#include "state.h"
#include "loadfile.h"
#include "pass_one.h"
#include "tokenFunc.h"

Go to the source code of this file.

Macros

#define __USE_MINGW_ANSI_STDIO   1
 

Functions

int main (int argc, char **argv)
 standard libc main function More...
 

Detailed Description

Entry point.

Entry point of the application tying all the steps together

Definition in file main.c.

Macro Definition Documentation

◆ __USE_MINGW_ANSI_STDIO

#define __USE_MINGW_ANSI_STDIO   1

Definition at line 1 of file main.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

standard libc main function

Parameters
argccommandline arg count
argvcommandline arguments
Returns
exit code (0 on success, -1 on error)

Definition at line 23 of file main.c.

23  {
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");
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 }

References State::defines, FAIL, State::infile, State::labels, load_file(), LOG, LOGDO, logging_level(), Map::map_debug_print(), pass_one(), pass_two(), State::state_free(), State::state_load_instr(), State::state_new(), State::state_parse_commandline(), State::tokens, TokensList::tokenslist_debug_print(), and write_data().

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
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
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
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
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
FAIL
#define FAIL(...)
Fancy-print a fail (failed step). Works like printf.
Definition: logging.h:45