1 /* sync.c the Netwide Disassembler synchronisation processing module
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
14 #define SYNC_MAX 4096 /* max # of sync points */
22 void init_sync(void) {
26 void add_sync(unsigned long pos
, unsigned long length
) {
29 if (nsynx
== SYNC_MAX
)
30 return; /* can't do anything - overflow */
33 synx
[nsynx
].pos
= pos
;
34 synx
[nsynx
].length
= length
;
36 for (i
= nsynx
; i
> 1; i
/= 2) {
37 if (synx
[i
/2].pos
> synx
[i
].pos
) {
39 t
= synx
[i
/2]; /* structure copy */
40 synx
[i
/2] = synx
[i
]; /* structure copy again */
41 synx
[i
] = t
; /* another structure copy */
46 unsigned long next_sync(unsigned long position
, unsigned long *length
) {
47 while (nsynx
> 0 && synx
[1].pos
+ synx
[1].length
<= position
) {
50 t
= synx
[nsynx
]; /* structure copy */
51 synx
[nsynx
] = synx
[1]; /* structure copy */
52 synx
[1] = t
; /* ditto */
57 while (i
*2 <= nsynx
) {
59 if (synx
[j
].pos
< synx
[i
].pos
&&
60 (j
+1 > nsynx
|| synx
[j
+1].pos
> synx
[j
].pos
)) {
61 t
= synx
[j
]; /* structure copy */
62 synx
[j
] = synx
[i
]; /* lots of these... */
63 synx
[i
] = t
; /* ...aren't there? */
65 } else if (j
+1 <= nsynx
&& synx
[j
+1].pos
< synx
[i
].pos
) {
66 t
= synx
[j
+1]; /* structure copy */
67 synx
[j
+1] = synx
[i
]; /* structure <yawn> copy */
68 synx
[i
] = t
; /* structure copy <zzzz....> */
77 *length
= synx
[1].length
;