forked from StarWolf3000/vasm-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cond.c
99 lines (77 loc) · 1.78 KB
/
cond.c
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
/* cond.c - conditional assembly support routines */
/* (c) in 2015,2023 by Frank Wille */
#include "vasm.h"
int clev; /* conditional level */
static signed char cond[MAXCONDLEV+1];
static char *condsrc[MAXCONDLEV+1];
static int condline[MAXCONDLEV+1];
static int ifnesting;
/* initialize conditional assembly */
void cond_init(void)
{
cond[0] = 1;
clev = ifnesting = 0;
}
/* return true, when current level allows assembling */
int cond_state(void)
{
return cond[clev] > 0;
}
/* ensures that all conditional block are closed at the end of the source */
void cond_check(void)
{
if (clev > 0)
general_error(66,condsrc[clev],condline[clev]); /* "endc/endif missing */
}
/* establish a new level of conditional assembly */
void cond_if(char flag)
{
if (++clev >= MAXCONDLEV)
general_error(65,clev); /* nesting depth exceeded */
cond[clev] = flag!=0;
condsrc[clev] = cur_src->name;
condline[clev] = cur_src->line;
}
/* handle skipped if statement */
void cond_skipif(void)
{
ifnesting++;
}
/* handle else statement after skipped if-branch */
void cond_else(void)
{
if (ifnesting == 0)
cond[clev] = cond[clev] ? -1 : 1;
}
/* handle else statement after assembled if-branch */
void cond_skipelse(void)
{
if (clev > 0)
cond[clev] = -1;
else
general_error(63); /* else without if */
}
/* handle else-if statement */
void cond_elseif(char flag)
{
if (clev > 0) {
if (!cond[clev])
cond[clev] = flag!=0;
else
cond[clev] = -1;
}
else
general_error(63); /* else without if */
}
/* handle end-if statement */
void cond_endif(void)
{
if (ifnesting == 0) {
if (clev > 0)
clev--;
else
general_error(64); /* unexpected endif without if */
}
else /* the whole conditional block was ignored */
ifnesting--;
}