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 */
17 * This lot manages the current set of sync points by means of a
18 * heap (priority queue) structure.
24 } synx
[SYNC_MAX
+1]; /* synx[0] never used - who cares :) */
27 void init_sync(void) {
31 void add_sync(unsigned long pos
, unsigned long length
) {
34 if (nsynx
== SYNC_MAX
)
35 return; /* can't do anything - overflow */
38 synx
[nsynx
].pos
= pos
;
39 synx
[nsynx
].length
= length
;
41 for (i
= nsynx
; i
> 1; i
/= 2) {
42 if (synx
[i
/2].pos
> synx
[i
].pos
) {
44 t
= synx
[i
/2]; /* structure copy */
45 synx
[i
/2] = synx
[i
]; /* structure copy again */
46 synx
[i
] = t
; /* another structure copy */
51 unsigned long next_sync(unsigned long position
, unsigned long *length
) {
52 while (nsynx
> 0 && synx
[1].pos
+ synx
[1].length
<= position
) {
55 t
= synx
[nsynx
]; /* structure copy */
56 synx
[nsynx
] = synx
[1]; /* structure copy */
57 synx
[1] = t
; /* ditto */
62 while (i
*2 <= nsynx
) {
64 if (synx
[j
].pos
< synx
[i
].pos
&&
65 (j
+1 > nsynx
|| synx
[j
+1].pos
> synx
[j
].pos
)) {
66 t
= synx
[j
]; /* structure copy */
67 synx
[j
] = synx
[i
]; /* lots of these... */
68 synx
[i
] = t
; /* ...aren't there? */
70 } else if (j
+1 <= nsynx
&& synx
[j
+1].pos
< synx
[i
].pos
) {
71 t
= synx
[j
+1]; /* structure copy */
72 synx
[j
+1] = synx
[i
]; /* structure <yawn> copy */
73 synx
[i
] = t
; /* structure copy <zzzz....> */
82 *length
= synx
[1].length
;