| 
    s502 assembler
    
   A very simple assembler for the 6502 line of processors written in C 
   | 
 
 
 
 
implement token member methods  
More...
#include "debugmalloc.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "tokenFunc.h"
#include "util.h"
#include "number.h"
#include "state.h"
#include "logging.h"
#include "directive.h"
 
Go to the source code of this file.
implement token member methods 
- See also
 - tokenFunc.h 
 
Definition in file tokenFunc.c.
 
◆ token_analyze_instruction()
      
        
          | int token_analyze_instruction  | 
          ( | 
          State *  | 
          s,  | 
        
        
           | 
           | 
          Token *  | 
          t  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
 
◆ token_compile()
      
        
          | int token_compile  | 
          ( | 
          State *  | 
          s,  | 
        
        
           | 
           | 
          Token *  | 
          t,  | 
        
        
           | 
           | 
          char **  | 
          dataptr  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Definition at line 318 of file tokenFunc.c.
  324         ERROR(
"Something went terribly wrong!\n");
 
  325         ERROR(
"A LABEL in last pass!\n");
 
  329     char* data = malloc(size);
 
  332         int n = t->
instr.number - t->
instr.address - 2;
 
  334         if (-128 > n || 127 < n) {
 
  335             ERROR(
"Relative addressing jump too far!\n");
 
  336             printf(
"Target: $%x, from: $%x (diff: $%x)\n", t->
instr.number, t->
instr.address, n);
 
  344     data[0] = t->
instr.inst->opcs[t->
instr.addressmode];
 
  346         data[1] = t->
instr.number & 0xff;
 
  349         data[2] = (t->
instr.number >> 8) & 0xff;
 
 
References ADRM_REL, Token::binSize, directive_compile(), ERROR, Token::instr, Token::token_print(), TT_DIRECTIVE, TT_INSTR, and Token::type.
 
 
◆ token_get_operand()
Definition at line 287 of file tokenFunc.c.
  296     for (; *begin != 0 && (*begin == 
' ' || *begin == 
'*' || *begin == 
'(' || *begin == 
'#'); begin++);
 
  297     for (end = begin; *end != 0 && *end != 
')' && *end != 
',' && *end != 
' '; end++);
 
  299     char* buff = malloc(end - begin + 1);
 
  300     strncpy(buff, begin, end - begin + 1);
 
  301     buff[end - begin] = 0;
 
  308         FAIL(
"Opcode operand parsing failed!\n");
 
 
References Token::binSize, FAIL, Token::instr, NUMBER_ERROR, number_get_number(), NUMBER_LABEL_NODEF, Token::stripped, Token::token_print(), TT_INSTR, and Token::type.
 
 
◆ token_print()
      
        
          | void token_print  | 
          ( | 
          Token *  | 
          token | ) | 
           | 
        
      
 
 
◆ token_recognize()
      
        
          | int token_recognize  | 
          ( | 
          Token *  | 
          t | ) | 
           | 
        
      
 
Definition at line 251 of file tokenFunc.c.
  270         t->
instr.number = -1;
 
  276         ERROR(
"Can not recognize token:\n");
 
  281     LOG(4, 
"Recognized token as %d:\n", t->
type);
 
 
References ERROR, Token::instr, Token::len, LOG, LOGDO, Token::stripped, Token::token_print(), TT_DIRECTIVE, TT_INSTR, TT_LABEL, and Token::type.
 
 
 
@ 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
 
@ ADRM_REL
Relative (8bit, signed 2's complement)
 
int token_link_instruction(State *s, Token *token)
find and link the instruction entry for a token
 
int token_get_addressmode(Token *t)
Determine the address mode of a token.
 
#define LOG(LVL,...)
logging macro - works like printf
 
#define LOGDO(LVL, x)
Conditional macro. Wraps contents into a conditional based on log level.
 
int ADRM_SIZES[ADRM_COUNT+1]
operand sizes of addressmodes
 
int binSize
number of bytes this token will generate
 
@ 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.
 
int directive_compile(State *s, Token *t, char **dataptr)
Compile a directive into binary data.
 
struct Token::@2 source
source of this token
 
int len
length of stripped text
 
@ NUMBER_ERROR
Could not parse a number or constant is undefined.
 
int number_get_number(State *s, char *str)
interpret a string as a constant, label or number
 
@ OPC_INVALID
An invalid opcode to signal invalid / non-existent variations.
 
#define FAIL(...)
Fancy-print a fail (failed step). Works like printf.
 
#define ERROR(...)
Fancy-print an error (cause of faliure). Works like printf.
 
@ NUMBER_LABEL_NODEF
Undefined label.