s502 assembler
A very simple assembler for the 6502 line of processors written in C
|
Go to the documentation of this file. 1 #include "debugmalloc.h"
22 if (ret < 0 || (ptr->token->type ==
TT_INSTR && (ptr->token->instr.number < 0))) {
24 ERROR(
"Undefined label reference!\n");
27 FAIL(
"Pass two failed!\n");
49 char* data = malloc(len);
61 for (
int i = 0; i < ptr->token->binSize; i++) data[j + i] = tdata[i];
62 j += ptr->token->binSize;
75 FAIL(
"Could not compile data!\n");
79 FILE* f = fopen(s->
outfile,
"wb");
81 ERROR(
"An error occured opening the file %s!\n", s->
outfile);
82 ERROR(
"Error opening file: %s\n", strerror(errno));
86 fwrite(data, 1, l, f);
@ TT_INSTR
instruction token
int pass_two(State *s)
compilation pass 2
TokensList * tokens
tokens
Compiler pseudo-global state.
struct TokensListElement * next
next element in list or NULL
char outfile[STATE_MAX_STRING_LEN]
output file name
TokensListElement * head
head (first element) of the list
An element of a TokensList.
char * concat_bin(State *s, int *n)
compile tokens and concat binary data
int write_data(State *s)
compilation pass 3
Token type member methods.
void token_print(Token *token)
Pretty-print one token, with its source and length.
int token_compile(State *s, Token *t, char **dataptr)
compile token into binary data
logging and fancy-printing
int token_get_operand(State *s, Token *t)
parse the operand of the instruction as a number
#define FAIL(...)
Fancy-print a fail (failed step). Works like printf.
#define ERROR(...)
Fancy-print an error (cause of faliure). Works like printf.