-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.h
84 lines (70 loc) · 2.55 KB
/
utils.h
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
/* Contains general-purposed functions, for both passes and many usages */
#ifndef _UTILS_H
#define _UTILS_H
#include "globals.h"
/** moves the index to the next place in string where the char isn't white */
#define MOVE_TO_NOT_WHITE(string, index) \
for (;string[(index)] && (string[(index)] == '\t' || string[(index)] == ' '); (++(index)))\
;
/**
* Concatenates both string to a new allocated memory
* @param s0 The first string
* @param s1 The second string
* @return A pointer to the new, allocated string
*/
char *strallocat(char *s0, char* s1);
/**
* Finds the defined label in the code if exists, and saves it into the buffer.
* Returns whether syntax error found.
* @param line The source line to find in
* @param symbol_dest The buffer for copying the found label in
* @return Whether syntax error found
*/
bool find_label(line_info line, char *symbol_dest);
/**
* Returns the instruction enum by the instruction's name, without the opening '.'
* @param name The instruction name, without the '.'
* @return The instruction enum if found, NONE_INST if not found.
*/
instruction find_instruction_by_name(char *name);
/**
* Returns whether the string is a valid 21-bit integer
* @param string The number string
* @return Whether a valid 21-bit signed integer.
*/
bool is_int(char* string);
/**
* Allocates memory in the required size. Exits the program if failed.
* @param size The size to allocate in bytes
* @return A generic pointer to the allocated memory if succeeded
*/
void *malloc_with_check(long size);
/**
* Returns whether a label can be defined with the specified name.
* @param name The label name
* @return Whether the specified name is valid,
*/
bool is_valid_label_name(char* name);
/**
* Returns whether a string is alphanumeric.
* @param string The string
* @return Whether it's alphanumeric
*/
bool is_alphanumeric_str(char *string);
/*Returns TRUE if name is saved word*/
bool is_reserved_word(char *name);
/**
* Prints a detailed error message, including file name and line number by the specified message,
* formatted as specified in App. B of "The C Programming language" for printf.
* @param message The error message
* @param ... The arguments to format into the message
* @return printf result of the message
*/
int printf_line_error(line_info line, char *message, ...);
/**
* Frees all the dynamically-allocated memory for the code image.
* @param code_image A pointer to the code images buffer
* @param fic The final instruction counter value
*/
void free_code_image(machine_word **code_image, long fic);
#endif