Repository navigation
Expand file tree
/
Copy pathreplace_labels.c
More file actions
52 lines (45 loc) · 1.6 KB
/
Copy pathreplace_labels.c
File metadata and controls
52 lines (45 loc) · 1.6 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* replace_labels.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eblackbu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/03 14:01:15 by eblackbu #+# #+# */
/* Updated: 2020/05/03 14:01:17 by eblackbu ### ########.fr */
/* */
/* ************************************************************************** */
#include "asm.h"
int get_indirent_value(t_champion **champ, t_instr *instr, int arg_num)
{
t_label *tmp;
tmp = (*champ)->labels;
while (tmp && !ft_strequ(tmp->name, instr->args[arg_num].label_name))
tmp = tmp->next;
if (!tmp)
error_args(ERR_UNKNOWN_LABEL, arg_num);
return (tmp->first_byte - instr->first_byte);
}
t_instr *check_labels(t_champion **champ, t_instr *instr)
{
int i;
i = 0;
while (i < instr->type.count_args)
{
if (instr->args[i].label_name)
instr->args[i].value = get_indirent_value(champ, instr, i);
i++;
}
return (instr);
}
void replace_labels(t_champion **champ)
{
t_instr *tmp;
g_current_string = 0;
tmp = (*champ)->code;
while (tmp)
{
tmp = check_labels(champ, tmp);
tmp = tmp->next;
}
}