-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations.h
More file actions
86 lines (74 loc) · 2.59 KB
/
Copy pathoperations.h
File metadata and controls
86 lines (74 loc) · 2.59 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
#ifndef OPERATIONS_H
#define OPERATIONS_H
#define SOURCE 0
#define TARGET 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defs.h"
#include "errors.h"
#include "macrofunctions.h"
#include <ctype.h>
/*Types of addressing methods*/
typedef enum
{
NONE = -1,
IMMEDIATE,
DIRECT,
RELATIVE,
REGISTER
} OperandType;
/*Defines a code operation*/
typedef struct
{
char *name;
int opcode;
int funct;
OperandType allowed_source[MAX_OPERAND_TYPES]; /*Allowed addressing methods for source*/
OperandType allowed_target[MAX_OPERAND_TYPES]; /*Allowed addressing methods for target*/
} Operation;
/* checks if a string is one of the operation names */
int is_operation_name(char *name);
/* checks if a string is one of the register names */
int is_register_name(char *name);
/* get register index based on name */
int get_register_index(char *register_name);
/* get operation's pointer from the operations table based on the name */
Operation *get_operation(char *name);
OperandType *get_allowed_addressing_methods(char *name, int source_or_target);
/*Operation Type Detection*/
/*Detect data operation based on the name*/
int is_data_operation(char *word);
/*Detect extern operation based on the name*/
int is_extern_operation(char *word);
/*Detect entry operation based on the name*/
int is_entry_operation(char *word);
/*Detect code operation based on the name*/
int is_code_operation(char *word);
/*Detect if word is a label declaration*/
int is_label_dec(char *word_original, int line_number, ErrorObject *error, MacroNode *macro_list);
/*Detect if word is a reserved word*/
int is_reserved_word(char *word);
/*Validate line operands and format based on operation:*/
/*Validates format of .data instruction*/
ErrorCode validate_data(char *word);
/*Validates format of .string instruction*/
ErrorCode validate_string(char *word);
/*Validates format of .extern instruction*/
ErrorCode validate_extern(char *word, MacroNode *macro_list);
/*Validates format of .entry instruction*/
ErrorCode validate_entry(char *word);
/*Validates format of operands and allowed addressing methods based on operation name.*/
ErrorCode validate_code(char *operation, char *oprands);
/*Checks if a string is a valid integer*/
int is_integer(char *str, int len);
/*Checks if a string is a valid label name*/
ErrorCode validate_label_name(char *word, MacroNode *macro_list);
/*Addressing Method Validation*/
int is_immediate(char *word);
int is_direct(char *word);
int is_relative(char *word);
int is_register(char *word);
/*Returns the type of the operand based on the word*/
int get_operand_type(char *word);
#endif