T.I.M | Toolchain Documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
common.h
Go to the documentation of this file.
1 
8 #include "stdio.h"
9 
10 #ifndef COMMON_H
11 #define COMMON_H
12 
13 
14 // --------------------------- IO Macros ----------------------------------------------
15 
17 #define TIM_PRINT_PROMPT "\e[1;36mtim>\e[0m "
18 
20 #define TIM_PROMPT printf(TIM_PRINT_PROMPT)
21 
23 #define tprintf(...) {TIM_PROMPT; printf(__VA_ARGS__);}
24 
26 #define log(...) {TIM_PROMPT; printf(__VA_ARGS__);}
27 
28 #ifdef DEBUG
29 
31  #define debug(...) {TIM_PROMPT; \
32  printf("line %d of %s in %s\n", __LINE__, __FUNCTION__, __FILE__); \
33  TIM_PROMPT; \
34  printf(__VA_ARGS__);}
35 #endif
36 #ifndef DEBUG
37 
39  #define debug(...) ;
40 
41 #endif
42 
44 #define warning(...) {TIM_PROMPT; \
45  printf("\e[1;33m[Warning] \e[0m"); \
46  printf("line %d of %s in %s\n", __LINE__, __FUNCTION__, __FILE__); \
47  TIM_PROMPT; \
48  printf("\e[1;33m[Warning] \e[0m"); \
49  printf(__VA_ARGS__); \
50  TIM_PROMPT; printf("\n"); }
51 
53 #define error(...) {TIM_PROMPT; \
54  printf("\e[1;31m[Error] \e[0m"); \
55  printf("line %d of %s in %s\n", __LINE__, __FUNCTION__, __FILE__); \
56  TIM_PROMPT; \
57  printf("\e[1;31m[Error] \e[0m"); \
58  printf(__VA_ARGS__); \
59  TIM_PROMPT; printf("\n"); }
60 
62 #define fatal(...) {error(__VA_ARGS__); \
63  TIM_PROMPT; \
64  printf("\e[1;31m[ FATAL ERROR ] \e[0m\n"); \
65  exit(1);}
66 
67 // --------------------------- TIM Instructions and opcodes ---------------------------
68 
70 typedef unsigned char BOOL;
71 
72 #define TRUE 1
73 #define FALSE 0
74 
76 typedef int tim_immediate;
77 
79 typedef enum tim_register_e{
80  R0 = 0,
81  R1 = 1,
82  R2 = 2,
83  R3 = 3,
84  R4 = 4,
85  R5 = 5,
86  R6 = 6,
87  R7 = 7,
88  R8 = 8,
89  R9 = 9,
90  R10= 10,
91  R11= 11,
92  R12= 12,
93  R13= 13,
94  R14= 14,
95  R15= 15,
96  PC = 16,
97  SP = 17,
98  LR = 18,
99  TR = 19,
100  SR = 20,
101  IR = 21,
102  IS = 22,
104  T0 = 24,
105  T1 = 25,
106  T2 = 26,
107  T3 = 27,
108  T4 = 28,
109  T5 = 29,
110  T6 = 30,
111  T7 = 31,
114 } tim_register;
115 
117 typedef unsigned char tim_instruction_size;
118 
120 typedef enum tim_instruction_opcode_e {
121  LOADR ,
122  LOADI ,
123  STORI ,
124  STORR ,
125  PUSH ,
126  POP ,
127  MOVR ,
128  MOVI ,
129  JUMPR ,
130  JUMPI ,
131  CALLR ,
132  CALLI ,
134  TEST ,
135  HALT ,
136  ANDR ,
137  NANDR ,
138  ORR ,
139  NORR ,
140  XORR ,
141  LSLR ,
142  LSRR ,
143  NOTR ,
144  ANDI ,
145  NANDI ,
146  ORI ,
147  NORI ,
148  XORI ,
149  LSLI ,
150  LSRI ,
151  IADDI ,
152  ISUBI ,
153  IMULI ,
154  IDIVI ,
155  IALSI ,
156  IASRI ,
157  IADDR ,
158  ISUBR ,
159  IMULR ,
160  IDIVR ,
161  IASLR ,
162  IASRR ,
163  FADDI ,
164  FSUBI ,
165  FMULI ,
166  FDIVI ,
167  FASLI ,
168  FASRI ,
169  FADDR ,
170  FSUBR ,
171  FMULR ,
172  FDIVR ,
173  FASLR ,
174  FASRR ,
175  SLEEP ,
178 
179 
182 
185 
187 typedef enum tim_condition_e{
188  ALWAYS = 0,
189  IFTRUE = 1,
190  IFFALSE = 2,
191  IFZERO = 3
192 } tim_condition;
193 
200 
207 
214 
215 #endif
216 
Store register X to address in register Y with offset in register Z.
Definition: common.h:123
Definition: common.h:93
Definition: common.h:111
Bitwise NOR two registers together.
Definition: common.h:139
Floating point Subtract immediate value from register X.
Definition: common.h:164
Floating point Multiply register X by register Y.
Definition: common.h:171
Definition: common.h:88
Definition: common.h:104
Definition: common.h:90
Definition: common.h:108
Logical shift left the bits in register X by the value in register Y.
Definition: common.h:141
Call to function who's address is contained within register X.
Definition: common.h:131
Definition: common.h:94
int tim_immediate
typedef for tim immediate values as operands to instructions.
Definition: common.h:76
tim_condition
A condition code for conditional execution.
Definition: common.h:187
Definition: common.h:84
Definition: common.h:81
tim_instruction_size size
The number of bytes the instruction occupies in memory.
Definition: common.h:184
Floating point Add register X to immediate value.
Definition: common.h:163
BOOL tim_is_special_register(tim_register reg)
Checks if the supplied register is a special register or not.
Definition: common.c:76
Definition: common.h:106
Floating point Add register X to register Y.
Definition: common.h:169
tim_instruction_opcode
Encodes all of the valid instruction opcodes and their bit values.
Definition: common.h:120
Definition: common.h:102
Definition: common.h:96
Definition: common.h:83
Floating point Divide register X by register Y.
Definition: common.h:172
Move the content of register X into register Y.
Definition: common.h:127
Definition: common.h:190
Floating point Multiply register X by immediate value.
Definition: common.h:165
Definition: common.h:95
tim_register
Encodes the address of the registers.
Definition: common.h:79
Bitwise AND two registers together.
Definition: common.h:144
Integer Subtract immediate value from register X.
Definition: common.h:152
Store register X to address in register Y with immediate offset.
Definition: common.h:124
Load to register X from address in register Y with immediate offset.
Definition: common.h:122
unsigned char tim_instruction_size
Encodes the size in bytes of an instruction in memory.
Definition: common.h:117
Return from the last function call.
Definition: common.h:133
Definition: common.h:92
Floating point Arithmetic shift register X right value in register Y.
Definition: common.h:174
Definition: common.h:85
BOOL tim_is_temp_register(tim_register reg)
Checks if the supplied register is a temporary register or not.
Definition: common.c:62
Integer Add register X to immediate value.
Definition: common.h:151
Integer Divide register X by immediate value.
Definition: common.h:154
Integer Arithmetic shift register X left by immediate value.
Definition: common.h:155
Integer Multiply register X by immediate value.
Definition: common.h:153
Pop element at top of stack into register X and increment the stack pointer.
Definition: common.h:126
BOOL tim_is_general_register(tim_register reg)
Checks if the supplied register is a general purpose register or not.
Definition: common.c:48
Jump to address contained within instruction immediate.
Definition: common.h:130
Bitwise OR two registers together.
Definition: common.h:146
Floating point Arithmetic shift register X left by value in register Y.
Definition: common.h:173
Sleeps the core for a certain number of cycles.
Definition: common.h:175
Definition: common.h:189
Load to register X from address in register Y with offset in register Z.
Definition: common.h:121
Floating point Arithmetic shift register X right immediate value.
Definition: common.h:168
Integer Subtract register X from register Y.
Definition: common.h:158
Definition: common.h:98
Jump to address contained within register X.
Definition: common.h:129
Stop processing and wait to be reset.
Definition: common.h:135
Integer Arithmetic shift register X right immediate value.
Definition: common.h:156
Definition: common.h:82
Definition: common.h:103
Integer Divide register X by register Y.
Definition: common.h:160
Floating point Arithmetic shift register X left by immediate value.
Definition: common.h:167
Definition: common.h:97
Bitwise NAND two registers together.
Definition: common.h:145
Definition: common.h:188
Definition: common.h:87
Integer Arithmetic shift register X right value in register Y.
Definition: common.h:162
Definition: common.h:113
Floating point Divide register X by immediate value.
Definition: common.h:166
Bitwise AND two registers together.
Definition: common.h:136
Move immediate I into register X.
Definition: common.h:128
Definition: common.h:100
Bitwise invert the specificed register.
Definition: common.h:143
Push register X onto the top of the stack and decrement the stack pointer.
Definition: common.h:125
Definition: common.h:86
Definition: common.h:101
Bitwise XOR two registers together.
Definition: common.h:148
unsigned char BOOL
Boolean type.
Definition: common.h:70
Definition: common.h:105
Bitwise NOR two registers together.
Definition: common.h:147
Definition: common.h:99
Integer Multiply register X by register Y.
Definition: common.h:159
Definition: common.h:89
Integer Add register X to register Y.
Definition: common.h:157
Test two general or special registers and set comparison bits.
Definition: common.h:134
Logical shift left the bits in register X by the immediate value.
Definition: common.h:149
Definition: common.h:91
Definition: common.h:109
Floating point Subtract register X from register Y.
Definition: common.h:170
Bitwise OR two registers together.
Definition: common.h:138
Definition: common.h:80
Definition: common.h:107
Used in the parse tree for instruction like DATA that are not emitted.
Definition: common.h:176
Definition: common.h:191
Bitwise XOR two registers together.
Definition: common.h:140
Bitwise NAND two registers together.
Definition: common.h:137
Logical shift right the bits in register X by the value in register Y.
Definition: common.h:142
Definition: common.h:112
Definition: common.h:110
tim_instruction_opcode opcode
The opcode of the instruction.
Definition: common.h:181
Integer Arithmetic shift register X left by value in register Y.
Definition: common.h:161
Logical shift right the bits in register X by the immediate value.
Definition: common.h:150
Call to function who's address is contained within instruction immediate.
Definition: common.h:132