aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorGareth Rees2013-05-20 20:45:52 +0100
committerGareth Rees2013-05-20 20:45:52 +0100
commit082f12d68ec69cbdedb159493fa2f634412f5a39 (patch)
tree572c49ff6fa11bf34f043fae9b2a8d2a70c74b0b /mps/code
parent2849a0bd33b8aa80910cb31cbdc25b9177fa9b8b (diff)
downloademacs-082f12d68ec69cbdedb159493fa2f634412f5a39.tar.gz
emacs-082f12d68ec69cbdedb159493fa2f634412f5a39.zip
New module range handles common operations on address ranges.
Copied from Perforce Change: 182015 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/range.c112
-rw-r--r--mps/code/range.h85
2 files changed, 197 insertions, 0 deletions
diff --git a/mps/code/range.c b/mps/code/range.c
new file mode 100644
index 00000000000..a714b515cd6
--- /dev/null
+++ b/mps/code/range.c
@@ -0,0 +1,112 @@
1/* range.c: ADDRESS RANGE IMPLEMENTATION
2 *
3 * $Id$
4 * Copyright (c) 2013 Ravenbrook Limited. See end of file for license.
5 */
6
7#include "range.h"
8
9SRCID(range, "$Id$");
10
11
12Bool RangeCheck(Range range)
13{
14 CHECKS(Range, range);
15 CHECKL(range != NULL);
16 CHECKL(RangeBase(range) != NULL);
17 CHECKL(RangeBase(range) <= RangeLimit(range));
18
19 return TRUE;
20}
21
22Res RangeInit(Range range, Addr base, Addr limit)
23{
24 AVER(range != NULL);
25 AVER(base != NULL);
26 AVER(base <= limit);
27
28 range->sig = RangeSig;
29 range->base = base;
30 range->limit = limit;
31
32 AVERT(Range, range);
33 return ResOK;
34}
35
36void RangeFinish(Range range)
37{
38 AVERT(Range, range);
39
40 range->base = range->limit = NULL;
41 range->sig = SigInvalid;
42}
43
44Res RangeDescribe(Range range, mps_lib_FILE *stream)
45{
46 Res res;
47
48 AVERT(Range, range);
49 AVER(stream != NULL);
50
51 res = WriteF(stream,
52 "Range $P\n{\n", (WriteFP)range,
53 " base: $P \n", (WriteFP)RangeBase(range),
54 " limit: $P \n", (WriteFP)RangeLimit(range),
55 "}\n", NULL);
56 if (res != ResOK) {
57 return res;
58 }
59
60 return ResOK;
61}
62
63Bool RangeOverlap(Range range1, Range range2)
64{
65 AVERT(Range, range1);
66 AVERT(Range, range2);
67
68 return RangeBase(range1) < RangeLimit(range2)
69 && RangeBase(range2) < RangeLimit(range1);
70}
71
72
73/* C. COPYRIGHT AND LICENSE
74 *
75 * Copyright (C) 2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
76 * All rights reserved. This is an open source license. Contact
77 * Ravenbrook for commercial licensing options.
78 *
79 * Redistribution and use in source and binary forms, with or without
80 * modification, are permitted provided that the following conditions are
81 * met:
82 *
83 * 1. Redistributions of source code must retain the above copyright
84 * notice, this list of conditions and the following disclaimer.
85 *
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in the
88 * documentation and/or other materials provided with the distribution.
89 *
90 * 3. Redistributions in any form must be accompanied by information on how
91 * to obtain complete source code for this software and any accompanying
92 * software that uses this software. The source code must either be
93 * included in the distribution or be available for no more than the cost
94 * of distribution plus a nominal fee, and must be freely redistributable
95 * under reasonable conditions. For an executable file, complete source
96 * code means the source code for all modules it contains. It does not
97 * include source code for modules or files that typically accompany the
98 * major components of the operating system on which the executable file
99 * runs.
100 *
101 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
102 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
103 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
104 * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE
105 * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
106 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
107 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
108 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
109 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
110 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
111 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112 */
diff --git a/mps/code/range.h b/mps/code/range.h
new file mode 100644
index 00000000000..24c1ca39e2d
--- /dev/null
+++ b/mps/code/range.h
@@ -0,0 +1,85 @@
1/* range.h: ADDRESS RANGE INTERFACE
2 *
3 * $Id$
4 * Copyright (c) 2013 Ravenbrook Limited. See end of file for license.
5 *
6 * .purpose: Representation of address ranges.
7 */
8
9#ifndef range_h
10#define range_h
11
12#include "mpmtypes.h"
13
14
15/* Signatures */
16
17#define RangeSig ((Sig)0x5196A493) /* SIGnature RANGE */
18
19
20/* Prototypes */
21
22typedef struct RangeStruct *Range;
23
24#define RangeBase(range) ((range)->base)
25#define RangeLimit(range) ((range)->limit)
26#define RangeSize(range) (AddrOffset(RangeBase(range), RangeLimit(range)))
27
28extern Res RangeInit(Range range, Addr base, Addr limit);
29extern void RangeFinish(Range range);
30extern Res RangeDescribe(Range range, mps_lib_FILE *stream);
31extern Bool RangeCheck(Range range);
32extern Bool RangeOverlap(Range range1, Range range2);
33
34
35/* Types */
36
37typedef struct RangeStruct {
38 Sig sig;
39 Addr base;
40 Addr limit;
41} RangeStruct;
42
43#endif /* range_h */
44
45
46/* C. COPYRIGHT AND LICENSE
47 *
48 * Copyright (C) 2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
49 * All rights reserved. This is an open source license. Contact
50 * Ravenbrook for commercial licensing options.
51 *
52 * Redistribution and use in source and binary forms, with or without
53 * modification, are permitted provided that the following conditions are
54 * met:
55 *
56 * 1. Redistributions of source code must retain the above copyright
57 * notice, this list of conditions and the following disclaimer.
58 *
59 * 2. Redistributions in binary form must reproduce the above copyright
60 * notice, this list of conditions and the following disclaimer in the
61 * documentation and/or other materials provided with the distribution.
62 *
63 * 3. Redistributions in any form must be accompanied by information on how
64 * to obtain complete source code for this software and any accompanying
65 * software that uses this software. The source code must either be
66 * included in the distribution or be available for no more than the cost
67 * of distribution plus a nominal fee, and must be freely redistributable
68 * under reasonable conditions. For an executable file, complete source
69 * code means the source code for all modules it contains. It does not
70 * include source code for modules or files that typically accompany the
71 * major components of the operating system on which the executable file
72 * runs.
73 *
74 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
75 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
76 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
77 * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE
78 * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
79 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
80 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
81 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
82 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
83 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
84 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85 */