s502 assembler
A very simple assembler for the 6502 line of processors written in C
|
Implement pass 1 and pass 3 (compile) processing for directive tokens. More...
#include "debugmalloc.h"
#include <string.h>
#include <stdlib.h>
#include "state.h"
#include "token_t.h"
#include "tokenFunc.h"
#include "logging.h"
#include "directive.h"
#include "util.h"
#include "number.h"
#include "loadfile.h"
#include "istack.h"
Go to the source code of this file.
Typedefs | |
typedef enum DIRCommand(* | tokenprocessor) (State *, TokensListElement *ptr) |
Token processor function. More... | |
Functions | |
enum DIRCommand | process_define (State *s, TokensListElement *ptr) |
Process an ifbeq directive. More... | |
enum DIRCommand | process_ifbeq (State *s, TokensListElement *ptr) |
Process an ifbeq directive. More... | |
enum DIRCommand | process_endif (State *s, TokensListElement *ptr) |
"Process" an endif directive More... | |
enum DIRCommand | process_print (State *s, TokensListElement *ptr) |
Process a print directive. More... | |
enum DIRCommand | process_printc (State *s, TokensListElement *ptr) |
Process a printc directive. More... | |
enum DIRCommand | process_include (State *s, TokensListElement *ptr) |
Process an include directive. More... | |
enum DIRCommand | process_ifdef (State *s, TokensListElement *ptr) |
Process an ifdef directive. More... | |
enum DIRCommand | process_ifndef (State *s, TokensListElement *ptr) |
Process an ifndef directive. More... | |
enum DIRCommand | process_org (State *s, TokensListElement *ptr) |
Process an org directive. More... | |
enum DIRCommand | process_data (State *s, TokensListElement *ptr) |
Process a data directive. More... | |
enum DIRCommand | process_pad (State *s, TokensListElement *ptr) |
Process a pad directive. More... | |
enum DIRCommand | do_directive_token (State *s, TokensListElement *ptr, int skip) |
process a directive token More... | |
int | compile_data (State *s, Token *t, char **dataptr) |
Compile a .data directive into binary data. More... | |
int | compile_pad (State *s, Token *t, char **dataptr) |
Compile a .pad directive into binary data. More... | |
int | directive_compile (State *s, Token *t, char **dataptr) |
Compile a directive into binary data. More... | |
Variables | |
struct { | |
tokenprocessor | p |
char * | name |
} | processors [] |
The list of all processor functions and their tokens. More... | |
struct { | |
enum DIRCommand | ret |
char * | name |
} | skipProcessors [] |
List of tokens to "process" when skipping tokens due to a falsy if. More... | |
Implement pass 1 and pass 3 (compile) processing for directive tokens.
Pass 1 processing is complex processing, exact method depens on the current directive.
For this, I used an array to link directive names to different processing functions.
(also another array for disabled compilation)
Directives control conditional compilation and can modify the list of currently loaded tokens.
For this reason the common interface for processing functions receives state and full list along the current token, and returns a DIRCommand
Definition in file directive.c.
typedef enum DIRCommand(* tokenprocessor) (State *, TokensListElement *ptr) |
Token processor function.
Should process one token and return a DIRCommand
The reason why it takes a TokensListElemnt* and not just a Token* is that we need to do an insert to it's position (in require)
Definition at line 1 of file directive.c.
Compile a .data directive into binary data.
dataptr | return buffer for data |
s | state object |
t | token to compile |
Definition at line 396 of file directive.c.
References Token::binSize, ERROR, LOG, number_get_number(), NUMBER_LABEL_NODEF, Token::stripped, Token::token_print(), and util_split_string().
Referenced by directive_compile().
Compile a .pad directive into binary data.
dataptr | return buffer for data |
s | state object |
t | token to compile |
Definition at line 469 of file directive.c.
References Token::binSize, ERROR, number_get_number(), Token::stripped, Token::token_print(), and util_split_string().
Referenced by directive_compile().
Compile a directive into binary data.
dataptr | return buffer for data |
s | assembler state |
t | token to compile |
Simply relays it to compile_pad or compile_data
Definition at line 498 of file directive.c.
References compile_data(), compile_pad(), Token::stripped, and util_match_string().
Referenced by token_compile().
enum DIRCommand do_directive_token | ( | State * | s, |
TokensListElement * | ptr, | ||
int | skip | ||
) |
process a directive token
s | state of the compiler |
ptr | ptr to the current token in the list |
skip | disable compilation flag (1=disabled) |
Identifies directive type, and runs a processor function on it.
Definition at line 1 of file directive.c.
Referenced by pass_one().
enum DIRCommand process_data | ( | State * | s, |
TokensListElement * | ptr | ||
) |
Process a data directive.
Only counts size, generating binary will be done if all labels are defined (pass 3)
Definition at line 1 of file directive.c.
enum DIRCommand process_define | ( | State * | s, |
TokensListElement * | ptr | ||
) |
Process an ifbeq directive.
s | current state |
ptr | pointer to element to process |
Definition at line 1 of file directive.c.
enum DIRCommand process_endif | ( | State * | s, |
TokensListElement * | ptr | ||
) |
enum DIRCommand process_ifbeq | ( | State * | s, |
TokensListElement * | ptr | ||
) |
Process an ifbeq directive.
Definition at line 1 of file directive.c.
enum DIRCommand process_ifdef | ( | State * | s, |
TokensListElement * | ptr | ||
) |
Process an ifdef directive.
Definition at line 1 of file directive.c.
enum DIRCommand process_ifndef | ( | State * | s, |
TokensListElement * | ptr | ||
) |
Process an ifndef directive.
Uses process_ifdef internally
Definition at line 1 of file directive.c.
enum DIRCommand process_include | ( | State * | s, |
TokensListElement * | ptr | ||
) |
Process an include directive.
Reads another file and inserts the tokens into the list.
This modifies the tokenslist directly!
Definition at line 1 of file directive.c.
enum DIRCommand process_org | ( | State * | s, |
TokensListElement * | ptr | ||
) |
Process an org directive.
Modifies state PC
Definition at line 1 of file directive.c.
enum DIRCommand process_pad | ( | State * | s, |
TokensListElement * | ptr | ||
) |
enum DIRCommand process_print | ( | State * | s, |
TokensListElement * | ptr | ||
) |
enum DIRCommand process_printc | ( | State * | s, |
TokensListElement * | ptr | ||
) |
struct { ... } processors[] |
The list of all processor functions and their tokens.
Their order DOES matter as comparision can not check end of strings as tokens do not end after directive names.
(namely printc must come before print or will get falsely reconized as a print)
struct { ... } skipProcessors[] |
List of tokens to "process" when skipping tokens due to a falsy if.