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

Header file for all common code shared across the tim toolchain. More...

#include "stdio.h"

Go to the source code of this file.

#define TIM_PRINT_PROMPT   "\e[1;36mtim>\e[0m "
 The prefix for all stdout/stderr messages. More...
 
#define TIM_PROMPT   printf(TIM_PRINT_PROMPT)
 Prints the prompt to stdout. More...
 
#define tprintf(...)   {TIM_PROMPT; printf(__VA_ARGS__);}
 Masking print macro that places the prompt in front of the message. More...
 
#define log(...)   {TIM_PROMPT; printf(__VA_ARGS__);}
 Alias for the tprintf macro. More...
 
#define debug(...)   ;
 Alternative debug macro that is evaluated to NOP when we are not in a debug build. More...
 
#define warning(...)
 Warning macro that spits out line number and function. More...
 
#define error(...)
 Error macro that spits out the line number and function. More...
 
#define fatal(...)
 Fatal error macro that behaves the same as error() but also exits the program. More...
 
#define TRUE   1
 
#define FALSE   0
 
enum  tim_register {
  R0 = 0, R1 = 1, R2 = 2, R3 = 3,
  R4 = 4, R5 = 5, R6 = 6, R7 = 7,
  R8 = 8, R9 = 9, R10 = 10, R11 = 11,
  R12 = 12, R13 = 13, R14 = 14, R15 = 15,
  PC = 16, SP = 17, LR = 18, TR = 19,
  SR = 20, IR = 21, IS = 22, REG_RESERVED_1 = 23,
  T0 = 24, T1 = 25, T2 = 26, T3 = 27,
  T4 = 28, T5 = 29, T6 = 30, T7 = 31,
  REG_ERROR =32, REG_NOT_USED = 33
}
 Encodes the address of the registers. More...
 
enum  tim_instruction_opcode {
  LOADR, LOADI, STORI, STORR,
  PUSH, POP, MOVR, MOVI,
  JUMPR, JUMPI, CALLR, CALLI,
  RETURN, TEST, HALT, ANDR,
  NANDR, ORR, NORR, XORR,
  LSLR, LSRR, NOTR, ANDI,
  NANDI, ORI, NORI, XORI,
  LSLI, LSRI, IADDI, ISUBI,
  IMULI, IDIVI, IALSI, IASRI,
  IADDR, ISUBR, IMULR, IDIVR,
  IASLR, IASRR, FADDI, FSUBI,
  FMULI, FDIVI, FASLI, FASRI,
  FADDR, FSUBR, FMULR, FDIVR,
  FASLR, FASRR, SLEEP, NOT_EMITTED
}
 Encodes all of the valid instruction opcodes and their bit values. More...
 
enum  tim_condition { ALWAYS = 0, IFTRUE = 1, IFFALSE = 2, IFZERO = 3 }
 A condition code for conditional execution. More...
 
typedef unsigned char BOOL
 Boolean type. More...
 
typedef int tim_immediate
 typedef for tim immediate values as operands to instructions. More...
 
typedef unsigned char tim_instruction_size
 Encodes the size in bytes of an instruction in memory. More...
 
tim_instruction_opcode opcode
 The opcode of the instruction. More...
 
tim_instruction_size size
 The number of bytes the instruction occupies in memory. More...
 
BOOL tim_is_general_register (tim_register reg)
 Checks if the supplied register is a general purpose register or not. More...
 
BOOL tim_is_temp_register (tim_register reg)
 Checks if the supplied register is a temporary register or not. More...
 
BOOL tim_is_special_register (tim_register reg)
 Checks if the supplied register is a special register or not. More...
 

Detailed Description

Header file for all common code shared across the tim toolchain.

Macro Definition Documentation

#define debug (   ...)    ;

Alternative debug macro that is evaluated to NOP when we are not in a debug build.

#define error (   ...)
Value:
printf("\e[1;31m[Error] \e[0m"); \
printf("line %d of %s in %s\n", __LINE__, __FUNCTION__, __FILE__); \
printf("\e[1;31m[Error] \e[0m"); \
printf(__VA_ARGS__); \
TIM_PROMPT; printf("\n"); }
#define TIM_PROMPT
Prints the prompt to stdout.
Definition: common.h:20

Error macro that spits out the line number and function.

Referenced by asm_calculate_addresses(), asm_emit_instructions(), asm_lex_immediate(), asm_lex_input_file(), asm_lex_register(), asm_parse_call_jump(), asm_parse_data(), asm_parse_opcode(), asm_parse_push_pop(), asm_parse_three_operand(), asm_parse_three_register_operands(), asm_parse_token_stream(), asm_parse_two_operand(), asm_parse_two_register_one_immediate(), and main().

#define fatal (   ...)
Value:
{error(__VA_ARGS__); \
printf("\e[1;31m[ FATAL ERROR ] \e[0m\n"); \
exit(1);}
#define error(...)
Error macro that spits out the line number and function.
Definition: common.h:53
#define TIM_PROMPT
Prints the prompt to stdout.
Definition: common.h:20

Fatal error macro that behaves the same as error() but also exits the program.

Referenced by main(), and parse_cmd_args().

#define log (   ...)    {TIM_PROMPT; printf(__VA_ARGS__);}

Alias for the tprintf macro.

Referenced by asm_calculate_addresses(), and main().

#define TIM_PRINT_PROMPT   "\e[1;36mtim>\e[0m "

The prefix for all stdout/stderr messages.

#define TIM_PROMPT   printf(TIM_PRINT_PROMPT)

Prints the prompt to stdout.

#define tprintf (   ...)    {TIM_PROMPT; printf(__VA_ARGS__);}

Masking print macro that places the prompt in front of the message.

Referenced by usage().

#define warning (   ...)
Value:
printf("\e[1;33m[Warning] \e[0m"); \
printf("line %d of %s in %s\n", __LINE__, __FUNCTION__, __FILE__); \
printf("\e[1;33m[Warning] \e[0m"); \
printf(__VA_ARGS__); \
TIM_PROMPT; printf("\n"); }
#define TIM_PROMPT
Prints the prompt to stdout.
Definition: common.h:20

Warning macro that spits out line number and function.

Referenced by asm_hash_table_expand(), asm_parse_opcode(), and parse_cmd_args().

Typedef Documentation

typedef unsigned char BOOL

Boolean type.

typedef int tim_immediate

typedef for tim immediate values as operands to instructions.

typedef unsigned char tim_instruction_size

Encodes the size in bytes of an instruction in memory.

Enumeration Type Documentation

A condition code for conditional execution.

Enumerator
ALWAYS 
IFTRUE 
IFFALSE 
IFZERO 

Encodes all of the valid instruction opcodes and their bit values.

Enumerator
LOADR 

Load to register X from address in register Y with offset in register Z.

LOADI 

Load to register X from address in register Y with immediate offset.

STORI 

Store register X to address in register Y with offset in register Z.

STORR 

Store register X to address in register Y with immediate offset.

PUSH 

Push register X onto the top of the stack and decrement the stack pointer.

POP 

Pop element at top of stack into register X and increment the stack pointer.

MOVR 

Move the content of register X into register Y.

MOVI 

Move immediate I into register X.

JUMPR 

Jump to address contained within register X.

JUMPI 

Jump to address contained within instruction immediate.

CALLR 

Call to function who's address is contained within register X.

CALLI 

Call to function who's address is contained within instruction immediate.

RETURN 

Return from the last function call.

TEST 

Test two general or special registers and set comparison bits.

HALT 

Stop processing and wait to be reset.

ANDR 

Bitwise AND two registers together.

NANDR 

Bitwise NAND two registers together.

ORR 

Bitwise OR two registers together.

NORR 

Bitwise NOR two registers together.

XORR 

Bitwise XOR two registers together.

LSLR 

Logical shift left the bits in register X by the value in register Y.

LSRR 

Logical shift right the bits in register X by the value in register Y.

NOTR 

Bitwise invert the specificed register.

ANDI 

Bitwise AND two registers together.

NANDI 

Bitwise NAND two registers together.

ORI 

Bitwise OR two registers together.

NORI 

Bitwise NOR two registers together.

XORI 

Bitwise XOR two registers together.

LSLI 

Logical shift left the bits in register X by the immediate value.

LSRI 

Logical shift right the bits in register X by the immediate value.

IADDI 

Integer Add register X to immediate value.

ISUBI 

Integer Subtract immediate value from register X.

IMULI 

Integer Multiply register X by immediate value.

IDIVI 

Integer Divide register X by immediate value.

IALSI 

Integer Arithmetic shift register X left by immediate value.

IASRI 

Integer Arithmetic shift register X right immediate value.

IADDR 

Integer Add register X to register Y.

ISUBR 

Integer Subtract register X from register Y.

IMULR 

Integer Multiply register X by register Y.

IDIVR 

Integer Divide register X by register Y.

IASLR 

Integer Arithmetic shift register X left by value in register Y.

IASRR 

Integer Arithmetic shift register X right value in register Y.

FADDI 

Floating point Add register X to immediate value.

FSUBI 

Floating point Subtract immediate value from register X.

FMULI 

Floating point Multiply register X by immediate value.

FDIVI 

Floating point Divide register X by immediate value.

FASLI 

Floating point Arithmetic shift register X left by immediate value.

FASRI 

Floating point Arithmetic shift register X right immediate value.

FADDR 

Floating point Add register X to register Y.

FSUBR 

Floating point Subtract register X from register Y.

FMULR 

Floating point Multiply register X by register Y.

FDIVR 

Floating point Divide register X by register Y.

FASLR 

Floating point Arithmetic shift register X left by value in register Y.

FASRR 

Floating point Arithmetic shift register X right value in register Y.

SLEEP 

Sleeps the core for a certain number of cycles.

NOT_EMITTED 

Used in the parse tree for instruction like DATA that are not emitted.

Encodes the address of the registers.

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

Function Documentation

BOOL tim_is_general_register ( tim_register  reg)

Checks if the supplied register is a general purpose register or not.

Parameters
[in]reg- the register to test.
Returns
TRUE if the register is a gp reg, otherwise false.

References FALSE, R0, R15, and TRUE.

BOOL tim_is_special_register ( tim_register  reg)

Checks if the supplied register is a special register or not.

Parameters
[in]reg- the register to test.
Returns
TRUE if the register is a special reg, otherwise false.

References FALSE, IS, PC, and TRUE.

BOOL tim_is_temp_register ( tim_register  reg)

Checks if the supplied register is a temporary register or not.

Parameters
[in]reg- the register to test.
Returns
TRUE if the register is a temporary reg, otherwise false.

References FALSE, T0, T7, and TRUE.

Variable Documentation

The opcode of the instruction.

Referenced by asm_calculate_addresses(), asm_emit_instructions(), 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_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(), asm_parse_call_jump(), asm_parse_data(), asm_parse_nop(), asm_parse_opcode(), asm_parse_push_pop(), asm_parse_sleep(), asm_parse_three_operand(), asm_parse_three_register_operands(), asm_parse_two_operand(), and asm_parse_two_register_one_immediate().