forked from simonpichette/tomasulo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstruction.h
More file actions
115 lines (102 loc) · 3.75 KB
/
instruction.h
File metadata and controls
115 lines (102 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/****** instruction.h ********************************************************
* Description
* Instruction data model for Tomasulo's algorithm simulator
*
* Author : Simon Pichette
* Creation date : Thu Jul 16 16:38:42 2020
*****************************************************************************
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef INSTRUCTION_H
#define INSTRUCTION_H
#include <stdlib.h>
#include <stdbool.h>
enum opclasses {addsub, muldiv, loadstore};
enum opcode {ld, sw, addd, subd, muld, divd};
struct instruction {
char* text;
int issue;
int execute;
int writeback;
int retired;
int remaining;
enum opcode op;
enum opclasses opclass;
int rs1;
int rs2;
int rd;
char* name;
};
struct ilist {
size_t size;
size_t occupied;
struct instruction *data;
bool complete;
};
/****** create_instruction_list *********************************************
* Create a dynamic array of instructions
*
* Parameters :
* int initial_size : size of array after creation
*
* Return : pointer to the newly allocated ilist if successful
* NULL if memory allocation fails
*
* Side effects :
* memory for an ilist including initial_size new instructions is
* allocated.
*****************************************************************************/
struct ilist* create_inst_list(int initial_size);
/****** add_inst ************************************************************
* Add an instruction to an ilist
*
* Parameters :
* struct ilist* list : target ilist
* char* text : source text of the instruction, to be decoded
*
* Return : 0 if succesfull, non-zero otherwise
*
* Side effects :
* if there is space on the list, an instruction struct is modified.
* if the list is full, enough memory for doubling the size of the
* list is allocated.
*****************************************************************************/
int add_inst(struct ilist* list, char* text);
/****** print_isnt **********************************************************
* Display information about an instruction in a format that is compatible with
* then following header :
* "| Instruction | Issue | Execute | Writeback | Retired |"
*
* Parameters :
* struct instruction* inst : the instruction to display
*
* Return : none
*
* Side effects :
* a line of output is sent to the terminal
*****************************************************************************/
void print_inst(struct instruction* inst);
/****** inst_details ********************************************************
* Display complete information about an instruction for debugging
*
* Parameters :
* struct instruction* inst : the instruction to display
*
* Return : none
*
* Side effects :
* 5 lines of output are sent to the terminal
*****************************************************************************/
void inst_details(struct instruction* inst);
#endif