s502 assembler
A very simple assembler for the 6502 line of processors written in C
|
Go to the documentation of this file.
36 int seen_whitespace = 1, eol = 0;
45 if (c == EOF || c ==
'\n') {
49 if (c ==
'\r')
continue;
56 if (c ==
'\t' || c ==
' ') {
57 if (!seen_whitespace) {
96 LOG(5,
"READ TOKEN:\n");
122 FILE* f = fopen(name,
"r");
124 ERROR(
"An error occured opening the file %s!\n", name);
125 ERROR(
"Error opening file: %s\n", strerror(errno));
130 if (tokenslist == NULL)
goto ERR_MEM;
141 tok.
source.lineno = lineno;
151 ERROR(
"line is too long!\n");
159 FAIL(
"read_file() failed!\n");
167 LOG(3,
"Reading file...\n");
173 LOG(3,
"Running first analysis...\n");
180 FAIL(
"Failed to load file contents: '%s'\n", name);
void tokenslist_free(TokensList *list)
free ALL memory associated with the TokensList object
TokensList * read_file(char *name)
read all tokens from a file
struct Token::@1 instr
instruction data. Not used if token type is not TT_INSTR
char stripped[TOKEN_BUFFER_SIZE]
stripped text from source file
TokensList * load_file(char *name)
load and parse one file
int tokenslist_add(TokensList *list, Token t)
Append a token to the list.
@ TOKEN_SOURCE_FILE_SIZE
source filename max length. Longer strings will get truncated.
#define LOG(LVL,...)
logging macro - works like printf
@ TOKEN_BUFFER_SIZE
Token max length.
#define LOGDO(LVL, x)
Conditional macro. Wraps contents into a conditional based on log level.
Token type to store token information.
int binSize
number of bytes this token will generate
int tokenslist_recognize(TokensList *t)
Do token recognition on all tokens in a list.
Token type member methods.
A doubly-linked list for storing Tokens.
void token_print(Token *token)
Pretty-print one token, with its source and length.
logging and fancy-printing
struct Token::@2 source
source of this token
int len
length of stripped text
int read_token(FILE *f, Token *t)
magic token reader function
TokensList * tokenslist_new()
Create a new (empty) TokensList object.
#define FAIL(...)
Fancy-print a fail (failed step). Works like printf.
#define ERROR(...)
Fancy-print an error (cause of faliure). Works like printf.