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

Contains all functions relating to parsing the source code into IR data structure. More...

#include "asm.h"

Functions

asm_lex_token * asm_parse_call_jump (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing Jump and call instructions. More...
 
asm_lex_token * asm_parse_three_register_operands (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing instructions with three register operands. More...
 
asm_lex_token * asm_parse_two_register_one_immediate (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing instructions with two register operands and one immediate operand. More...
 
asm_lex_token * asm_parse_three_operand (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing instructions with three operands.. More...
 
asm_lex_token * asm_parse_two_operand (asm_statement *statement, asm_lex_token *token, int *errors)
 Parses instructions that take two operands. NOT, TEST, MOV. More...
 
asm_lex_token * asm_parse_data (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing DATA elements. More...
 
asm_lex_token * asm_parse_sleep (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing SLEEP instructions. More...
 
asm_lex_token * asm_parse_nop (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing NOP instructions. More...
 
asm_lex_token * asm_parse_push_pop (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for parsing PUSH and POP instructions. More...
 
asm_lex_token * asm_parse_opcode (asm_statement *statement, asm_lex_token *token, int *errors)
 Responsible for selecting which function should parse the next few tokens.:w. More...
 
asm_lex_token * asm_parse_label_declaration (asm_lex_token *token, asm_hash_table *labels, int *errors, asm_statement *statement)
 Responsible for adding a label declaration and associated statement to the symbol table. More...
 
asm_statement * asm_parse_token_stream (asm_lex_token *tokens, asm_hash_table *labels, int *errors)
 Top function to trigger the parsing of an input source file. More...
 

Detailed Description

Contains all functions relating to parsing the source code into IR data structure.

Function Documentation

asm_lex_token* asm_parse_call_jump ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing Jump and call instructions.

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References CALLI, CALLR, error, IMMEDIATE, JUMPI, JUMPR, LABEL, LEX_CALL, LEX_JUMP, opcode, REGISTER, size, and TRUE.

Referenced by asm_parse_opcode().

asm_lex_token* asm_parse_data ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing DATA elements.

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References error, FALSE, IMMEDIATE, LABEL, NOT_EMITTED, opcode, size, and TRUE.

Referenced by asm_parse_opcode().

asm_lex_token* asm_parse_label_declaration ( asm_lex_token *  token,
asm_hash_table labels,
int *  errors,
asm_statement *  statement 
)

Responsible for adding a label declaration and associated statement to the symbol table.

Parameters
token- The token containing the label value
labels- The symbol table.
errors- Pointer to an error counter.
Returns
the next token to be parsed.

References asm_hash_table_insert(), and LABEL.

Referenced by asm_parse_token_stream().

asm_lex_token* asm_parse_nop ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing NOP instructions.

NOP is actually a pseudo instruction which assembles into ANDR $R0 $R0 $R0

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References ANDR, opcode, R0, and size.

Referenced by asm_parse_opcode().

asm_lex_token* asm_parse_opcode ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for selecting which function should parse the next few tokens.:w.

Parameters
token- The token containing the label value
statement- The statement to parse the tokens into.
errors- Pointer to an error counter.
Returns
the next token to be parsed.

References asm_parse_call_jump(), asm_parse_data(), asm_parse_nop(), asm_parse_push_pop(), asm_parse_sleep(), asm_parse_three_operand(), asm_parse_two_operand(), error, HALT, 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_XOR, OPCODE, opcode, RETURN, size, and warning.

Referenced by asm_parse_token_stream().

asm_lex_token* asm_parse_push_pop ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing PUSH and POP instructions.

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References error, LEX_POP, LEX_PUSH, opcode, POP, PUSH, and size.

Referenced by asm_parse_opcode().

asm_lex_token* asm_parse_sleep ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing SLEEP instructions.

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References opcode, size, and SLEEP.

Referenced by asm_parse_opcode().

asm_lex_token* asm_parse_three_operand ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing instructions with three operands..

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References asm_parse_three_register_operands(), asm_parse_two_register_one_immediate(), error, IMMEDIATE, opcode, and REGISTER.

Referenced by asm_parse_opcode().

asm_lex_token* asm_parse_three_register_operands ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing instructions with three register operands.

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References ANDR, error, FADDR, FASRR, FDIVR, FMULR, FSUBR, IADDR, IASRR, IDIVR, IMULR, ISUBR, LEX_AND, LEX_ERROR, LEX_FADD, LEX_FASR, LEX_FDIV, LEX_FMUL, LEX_FSUB, LEX_IADD, LEX_IASR, LEX_IDIV, LEX_IMUL, LEX_ISUB, LEX_LOAD, LEX_LSL, LEX_LSR, LEX_NAND, LEX_NOR, LEX_OR, LEX_STORE, LEX_XOR, LOADR, LSLR, LSRR, NANDR, NORR, OPCODE, opcode, ORR, REGISTER, size, STORR, and XORR.

Referenced by asm_parse_three_operand().

asm_statement* asm_parse_token_stream ( asm_lex_token *  tokens,
asm_hash_table labels,
int *  errors 
)

Top function to trigger the parsing of an input source file.

Takes an opened for reading text file and parses it into a series of asm statements, filling out their arguments and parameters as it goes. It also populates the hash-table of labels used for calculating jump target addresses.

See Also
The ISA Specification contains more information on the grammar of the assembly language.
Parameters
[in,out]labels- Hashtable which is apopulated with any encountered labels.
[in,out]errors- Pointer to a error counter. If the counter has the same value before
tokens- Linked list of tokens to parse into a program IR. and after being called, all of the parsing was a success.
Returns
The parsed statements as a doublely linked list.

References ALWAYS, asm_parse_label_declaration(), asm_parse_opcode(), CONDITION, error, LABEL, and OPCODE.

Referenced by main().

asm_lex_token* asm_parse_two_operand ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Parses instructions that take two operands. NOT, TEST, MOV.

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References error, IMMEDIATE, LEX_MOV, LEX_NOT, LEX_TEST, MOVR, NOTR, opcode, size, and TEST.

Referenced by asm_parse_opcode().

asm_lex_token* asm_parse_two_register_one_immediate ( asm_statement *  statement,
asm_lex_token *  token,
int *  errors 
)

Responsible for parsing instructions with two register operands and one immediate operand.

Parameters
[in,out]statement- Resulting statment to set members of.
[in]token- The token which to parse into a statement. Several subsequent tokens may also be eaten.
errors- Error counter pointer.
Returns
The next token that should be parsed, i.e. the one following the last token eaten by this function.

References ANDI, error, FADDI, FASRI, FDIVI, FMULI, FSUBI, IADDI, IASRI, IDIVI, IMMEDIATE, IMULI, ISUBI, LEX_AND, LEX_ERROR, LEX_FADD, LEX_FASR, LEX_FDIV, LEX_FMUL, LEX_FSUB, LEX_IADD, LEX_IASR, LEX_IDIV, LEX_IMUL, LEX_ISUB, LEX_LOAD, LEX_LSL, LEX_LSR, LEX_NAND, LEX_NOR, LEX_OR, LEX_STORE, LEX_XOR, LOADI, LSLI, LSRI, NANDI, NORI, OPCODE, opcode, ORI, REGISTER, size, STORI, and XORI.

Referenced by asm_parse_three_operand().