s502 assembler
A very simple assembler for the 6502 line of processors written in C
|
processing step one
More...
#include "tokenslist.h"
#include "state.h"
Go to the source code of this file.
processing step one
See documentation on steps for further info!
Definition in file pass_one.h.
◆ pass_one()
int pass_one |
( |
State * |
s | ) |
|
Compilation pass 1.
- Parameters
-
- Returns
- 0 on success, -1 on error
First pass processing for directives, instructions and labels
See documentation on steps for further info!
Definition at line 19 of file pass_one.c.
31 FAIL(
"Pass 1 init failed!\n");
40 LOG(4,
"Processing token:\n");
61 ERROR(
"More endif's than if's!\n");
82 LOG(3,
"Instruction: \n");
94 ERROR(
"Label is too long!");
104 #pragma GCC diagnostic push
105 #pragma GCC diagnostic ignored "-Wstringop-truncation"
108 #pragma GCC diagnostic pop
109 LOG(5,
"Label: %s\n", labelname);
112 ERROR(
"Can not re-define label '%s'\n", labelname);
119 LOG(3,
"Set label: '%s' to %d\n", labelname, s->
PC);
140 FAIL(
"Pass 1 failed!\n");
References ADRM_NAMES, Token::binSize, DIR_ENDIF, DIR_IF_FALSE, DIR_IF_TRUE, DIR_STOP, do_directive_token(), ERROR, FAIL, TokensList::head, Token::instr, Instruction::instruction_print(), istack_el::istack_free(), istack_el::istack_new(), istack_el::istack_pop(), istack_el::istack_push(), istack_el::istack_top(), State::labels, Token::len, LOG, LOGDO, Map::map_get(), MAP_MAX_KEY_LEN, Map::map_set(), TokensListElement::next, State::PC, Token::stripped, TokensListElement::token, Token::token_analyze_instruction(), Token::token_get_operand(), Token::token_print(), State::tokens, TokensList::tokenslist_remove(), TT_DIRECTIVE, TT_INSTR, TT_LABEL, and Token::type.
Referenced by main().
Map * labels
label locations
@ TT_INSTR
instruction token
struct Token::@1 instr
instruction data. Not used if token type is not TT_INSTR
const char * ADRM_NAMES[]
Human-readable names of address modes.
char stripped[TOKEN_BUFFER_SIZE]
stripped text from source file
@ DIR_STOP
An error occured, stop compilation.
int map_set(Map *map, char *name, int value)
Sets a key in the map.
Token * token
Token value.
#define LOG(LVL,...)
logging macro - works like printf
int istack_push(istack_ptr istack, int val)
push one element to the istack
TokensList * tokens
tokens
#define LOGDO(LVL, x)
Conditional macro. Wraps contents into a conditional based on log level.
@ DIR_ENDIF
An endif was encountered, should pop from state stack.
int token_analyze_instruction(State *s, Token *t)
analyze instruction token (instruction, addressmode & operand)
void istack_free(istack_ptr istack)
free all memory associated with a istack
struct TokensListElement * next
next element in list or NULL
int binSize
number of bytes this token will generate
void instruction_print(Instruction *instr)
fancy-print one instruction data
int istack_pop(istack_ptr istack)
pop the top of the istack
TokensListElement * head
head (first element) of the list
An element of a TokensList.
enum DIRCommand do_directive_token(State *s, TokensListElement *ptr, int skip)
process a directive token
DIRCommand
Internal command type for directives.
@ DIR_IF_FALSE
A conditional evaluated to false.
@ TT_DIRECTIVE
directive token
enum tokenType type
type of this token
void token_print(Token *token)
Pretty-print one token, with its source and length.
@ DIR_IF_TRUE
A conditional evaluated to true.
int map_get(Map *map, char *name)
Get the value of a key.
int len
length of stripped text
@ MAP_MAX_KEY_LEN
Key buffer size for Map.
int token_get_operand(State *s, Token *t)
parse the operand of the instruction as a number
int istack_top(istack_ptr istack, int def)
get the top element of the istack
istack_ptr istack_new()
create an empty istack
TokensListElement * tokenslist_remove(TokensList *list, TokensListElement *el)
remove a token from the list
#define FAIL(...)
Fancy-print a fail (failed step). Works like printf.
#define ERROR(...)
Fancy-print an error (cause of faliure). Works like printf.