T.I.M | Toolchain Documentation
|
Header file for data types and functions used by the assembler. More...
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "assert.h"
#include "common.h"
#include "asm_lex.h"
Go to the source code of this file.
Data Structures | |
struct | asm_args_reg_double |
Register arguments structure for opcodes with two register arguments. More... | |
struct | asm_args_reg_double_imm |
Register arguments structure for opcodes with two register arguments and an immediate. More... | |
struct | asm_args_reg_single |
Register arguments structure for opcodes with only a single register argument. More... | |
struct | asm_args_reg_single_imm |
Register arguments structure for opcodes with one register argument and an immediate. More... | |
struct | asm_args_reg_tripple |
Register arguments structure for opcodes with three register arguments. More... | |
struct | asm_args_single_imm |
Register arguments structure for opcodes with one immediate. More... | |
struct | asm_args_single_imm_label |
Register arguments structure for opcodes with one immediate who's value is a label. More... | |
struct | asm_context |
Contains all information for the program in a format that can be easily passed around. More... | |
struct | asm_hash_table |
Keeps a key,value pairing of elements. It's a hash table folks. More... | |
struct | asm_hash_table_bin |
Contains a single bin in the hashtable. More... | |
union | asm_opcode_args |
Union types for all different types of argument/operand combinations used. More... | |
struct | asm_statement |
Stores all information on a single ASM instruction. More... | |
#define | TIM_PRINT_PROMPT "\e[1;36masm>\e[0m " |
enum | asm_format { BINARY, ASCII } |
Describes whether to output the parsed asm code as binary or ascii code. More... | |
typedef int | asm_hash_key |
Typedef masking an integer to be the asm hash table key type. More... | |
int | asm_emit_instructions (asm_statement *statements, FILE *file, asm_format format) |
Responsible for writing all statements to the supplied file. More... | |
int | asm_calculate_addresses (asm_statement *statements, unsigned int base_address, asm_hash_table *labels) |
Assigns addresses to each statement so that jumps and calls can be calculated. 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... | |
int | asm_hash_table_insert (asm_hash_table *table, char *key, void *data) |
Inserts an element into the hash table associated with the provided key. More... | |
void | asm_hash_table_new (int initial_size, asm_hash_table *tr) |
Creates and returns a new pointer to a hash table. More... | |
void * | asm_hash_table_get (asm_hash_table *table, char *strkey) |
Returns a pointer to the data stored in a hash table with the given key or NULL if no such element exists. More... | |
Header file for data types and functions used by the assembler.
#define TIM_PRINT_PROMPT "\e[1;36masm>\e[0m " |
typedef int asm_hash_key |
Typedef masking an integer to be the asm hash table key type.
enum asm_format |
int asm_calculate_addresses | ( | asm_statement * | statements, |
unsigned int | base_address, | ||
asm_hash_table * | labels | ||
) |
Assigns addresses to each statement so that jumps and calls can be calculated.
statements | - head of a linked list of asm statements. |
base_address | - Where the addresses of the program should start. |
References asm_hash_table_get(), CALLI, error, JUMPI, log, NOT_EMITTED, opcode, and size.
Referenced by main().
int asm_emit_instructions | ( | asm_statement * | statements, |
FILE * | file, | ||
asm_format | format | ||
) |
Responsible for writing all statements to the supplied file.
statements | - Linked list of statements to emit binary code for. |
file | - The file to write the code too. |
format | - Whether to emit the code as raw bytes or ascii binary strings. This is used to feed the VHDL testbenches. |
References ANDI, ANDR, asm_emit_opcode_ANDI(), asm_emit_opcode_ANDR(), asm_emit_opcode_CALLI(), asm_emit_opcode_CALLR(), asm_emit_opcode_FADDI(), asm_emit_opcode_FADDR(), asm_emit_opcode_FASLI(), asm_emit_opcode_FASLR(), asm_emit_opcode_FASRI(), asm_emit_opcode_FASRR(), asm_emit_opcode_FDIVI(), asm_emit_opcode_FDIVR(), asm_emit_opcode_FMULI(), asm_emit_opcode_FMULR(), asm_emit_opcode_FSUBI(), asm_emit_opcode_FSUBR(), asm_emit_opcode_HALT(), asm_emit_opcode_IADDI(), asm_emit_opcode_IADDR(), asm_emit_opcode_IALSI(), asm_emit_opcode_IASLR(), asm_emit_opcode_IASRI(), asm_emit_opcode_IASRR(), asm_emit_opcode_IDIVI(), asm_emit_opcode_IDIVR(), asm_emit_opcode_IMULI(), asm_emit_opcode_IMULR(), asm_emit_opcode_ISUBI(), asm_emit_opcode_ISUBR(), asm_emit_opcode_JUMPI(), asm_emit_opcode_JUMPR(), asm_emit_opcode_LOADI(), asm_emit_opcode_LOADR(), asm_emit_opcode_LSLI(), asm_emit_opcode_LSLR(), asm_emit_opcode_LSRI(), asm_emit_opcode_LSRR(), asm_emit_opcode_MOVI(), asm_emit_opcode_MOVR(), asm_emit_opcode_NANDI(), asm_emit_opcode_NANDR(), asm_emit_opcode_NORI(), asm_emit_opcode_NORR(), asm_emit_opcode_NOT_EMITTED(), asm_emit_opcode_NOTR(), asm_emit_opcode_ORI(), asm_emit_opcode_ORR(), asm_emit_opcode_POP(), asm_emit_opcode_PUSH(), asm_emit_opcode_RETURN(), asm_emit_opcode_SLEEP(), asm_emit_opcode_STORI(), asm_emit_opcode_STORR(), asm_emit_opcode_TEST(), asm_emit_opcode_XORI(), asm_emit_opcode_XORR(), CALLI, CALLR, error, FADDI, FADDR, FASLI, FASLR, FASRI, FASRR, FDIVI, FDIVR, FMULI, FMULR, FSUBI, FSUBR, HALT, IADDI, IADDR, IALSI, IASLR, IASRI, IASRR, IDIVI, IDIVR, IMULI, IMULR, ISUBI, ISUBR, JUMPI, JUMPR, LOADI, LOADR, LSLI, LSLR, LSRI, LSRR, MOVI, MOVR, NANDI, NANDR, NORI, NORR, NOT_EMITTED, NOTR, opcode, ORI, ORR, POP, PUSH, RETURN, SLEEP, STORI, STORR, TEST, XORI, and XORR.
Referenced by main().
void* asm_hash_table_get | ( | asm_hash_table * | table, |
char * | strkey | ||
) |
Returns a pointer to the data stored in a hash table with the given key or NULL if no such element exists.
table | - The table to fetch the data from. |
strkey | - The key to the data to fetch. |
table | - The table to fetch the data from. |
strkey | - The key to the data to fetch. |
References asm_hash_key_string(), and asm_hash_table::current_size.
Referenced by asm_calculate_addresses().
int asm_hash_table_insert | ( | asm_hash_table * | table, |
char * | key, | ||
void * | data | ||
) |
Inserts an element into the hash table associated with the provided key.
table | - Pointer to the hash table to insert into. |
key | - The key to the data. |
data | - Pointer to the data the table will contain. |
table | - Pointer to the hash table to insert into. |
key | - The key to the data. |
data | - Pointer to the data the table will contain. |
References asm_hash_key_string().
Referenced by asm_parse_label_declaration().
void asm_hash_table_new | ( | int | initial_size, |
asm_hash_table * | tr | ||
) |
Creates and returns a new pointer to a hash table.
initial_size | - The initial size of the hash table's internal data structure. |
tr | - The newly initialised and returned hashtable. Memory space should already be declared. |
Referenced by main().
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.
[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 and after being called, all of the parsing was a success. |
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.
[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. |
References ALWAYS, asm_parse_label_declaration(), asm_parse_opcode(), CONDITION, error, LABEL, and OPCODE.
Referenced by main().