T.I.M | Toolchain Documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
asm_lex.c File Reference

Contains all functions for turning an input text file into a token stream. More...

#include "asm.h"
#include "asm_lex.h"

Functions

char * asm_lex_file_readline (FILE *source)
 reads and returns the rest of the current line in the file from the current cursor position. More...
 
tim_register asm_lex_register (char *str, int *errors, unsigned int line_number)
 Takes a three letter string and returns either an assembly register code or NO_REG if the character code is invalid. More...
 
tim_immediate asm_lex_immediate (char *immediate, int *errors, int line_num)
 Parses a character array into an asm_immediate and returns it as a 32 bit integer. More...
 
asm_lex_opcode asm_lex_instruction (char *instruction, int *errors, int line_num)
 parses a string instruction into its token typed declaration. More...
 
asm_lex_token * asm_lex_input_file (FILE *input, int *errors)
 Parses an entire input file into a single lexical token stream. More...
 

Detailed Description

Contains all functions for turning an input text file into a token stream.

Function Documentation

char* asm_lex_file_readline ( FILE *  source)

reads and returns the rest of the current line in the file from the current cursor position.

Parameters
[in]source- The opened source code file.
Returns
The read line or NULL if the end of the file is reached.

Referenced by asm_lex_input_file().

tim_immediate asm_lex_immediate ( char *  immediate,
int *  errors,
int  line_num 
)

Parses a character array into an asm_immediate and returns it as a 32 bit integer.

Note
The value returned is not nessecerily correct. It simply has the right bits set to represent the immediate in memory.
Parameters
[in]immediate- The character representation of the immediate value.
[in,out]errors- pointer to an error counter for syntax errors.
[in]line_num- The line number of the instruction, used for error reporting.
Returns
A tim_immediate representing the passed char array.

References error.

Referenced by asm_lex_input_file().

asm_lex_token* asm_lex_input_file ( FILE *  input,
int *  errors 
)

Parses an entire input file into a single lexical token stream.

Parameters
input- The input file with the seeker at the beginning of the file.
errors- pointer to an error counter.
Returns
The head of a linked list of lexer tokens representing the parsed file.

References ALWAYS, asm_lex_file_readline(), asm_lex_immediate(), asm_lex_instruction(), asm_lex_register(), CONDITION, error, IFFALSE, IFTRUE, IFZERO, IMMEDIATE, LABEL, LEX_ERROR, OPCODE, and REGISTER.

Referenced by main().

asm_lex_opcode asm_lex_instruction ( char *  instruction,
int *  errors,
int  line_num 
)

parses a string instruction into its token typed declaration.

Parameters
instruction- head of the string containing the token
errors- Pointer to an error counter.
line_num- The line number of the token being parsed. Helps with error reporting.
Returns
A parsed asm_lex_opcode or LEX_ERROR if no such opcode exists.

References LEX_AND, LEX_CALL, LEX_DATA, LEX_ERROR, LEX_FADD, LEX_FASR, LEX_FDIV, LEX_FMUL, LEX_FSUB, LEX_HALT, LEX_IADD, LEX_IASR, LEX_IDIV, LEX_IMUL, LEX_ISUB, LEX_JUMP, LEX_LOAD, LEX_LSL, LEX_LSR, LEX_MOV, LEX_NAND, LEX_NOP, LEX_NOR, LEX_NOT, LEX_OR, LEX_POP, LEX_PUSH, LEX_RETURN, LEX_SLEEP, LEX_STORE, LEX_TEST, lex_tok_AND, lex_tok_CALL, lex_tok_DATA, lex_tok_FADD, lex_tok_FASR, lex_tok_FDIV, lex_tok_FMUL, lex_tok_FSUB, lex_tok_HALT, lex_tok_IADD, lex_tok_IASR, lex_tok_IDIV, lex_tok_IMUL, lex_tok_ISUB, lex_tok_JUMP, lex_tok_LOAD, lex_tok_LSL, lex_tok_LSR, lex_tok_MOV, lex_tok_NAND, lex_tok_NOP, lex_tok_NOR, lex_tok_NOT, lex_tok_OR, lex_tok_POP, lex_tok_PUSH, lex_tok_RETURN, lex_tok_SLEEP, lex_tok_STORE, lex_tok_TEST, lex_tok_XOR, and LEX_XOR.

Referenced by asm_lex_input_file().

tim_register asm_lex_register ( char *  str,
int *  errors,
unsigned int  line_number 
)

Takes a three letter string and returns either an assembly register code or NO_REG if the character code is invalid.

Parameters
str- Pointer to the head of a string to check.
Returns
an asm_register representing the passed two letter code. If the input code is invalid then REG__ERROR is returned.

References error, IR, IS, LR, PC, R0, R1, R10, R11, R12, R13, R14, R15, R2, R3, R4, R5, R6, R7, R8, R9, REG_ERROR, SP, SR, T0, T1, T2, T3, T4, T5, T6, T7, and TR.

Referenced by asm_lex_input_file().