diff options
| author | Nick Barnes | 2001-10-31 14:40:56 +0000 |
|---|---|---|
| committer | Nick Barnes | 2001-10-31 14:40:56 +0000 |
| commit | 7acfca905d76140f4cc0b09c9a12de237de364cd (patch) | |
| tree | 3ed8babfa3a73d30f29e08ca5d5adcda4ca4e826 /mps/code/format.c | |
| parent | b7ce4893f9902d57cd67ac9a92fa6c3d5a8fc833 (diff) | |
| download | emacs-7acfca905d76140f4cc0b09c9a12de237de364cd.tar.gz emacs-7acfca905d76140f4cc0b09c9a12de237de364cd.zip | |
Branch imports for masters.
Copied from Perforce
Change: 23678
ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code/format.c')
| -rw-r--r-- | mps/code/format.c | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/mps/code/format.c b/mps/code/format.c new file mode 100644 index 00000000000..c5403e15c5e --- /dev/null +++ b/mps/code/format.c | |||
| @@ -0,0 +1,154 @@ | |||
| 1 | /* impl.c.format: OBJECT FORMATS | ||
| 2 | * | ||
| 3 | * $HopeName: MMsrc!format.c(trunk.20) $ | ||
| 4 | * Copyright (C) 2000 Harlequin Limited. All rights reserved. | ||
| 5 | * | ||
| 6 | * DESIGN | ||
| 7 | * | ||
| 8 | * See protocol.mps.format. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include "mpm.h" | ||
| 12 | |||
| 13 | SRCID(format, "$HopeName: MMsrc!format.c(trunk.20) $"); | ||
| 14 | |||
| 15 | |||
| 16 | /* FormatCheck -- check a format */ | ||
| 17 | |||
| 18 | Bool FormatCheck(Format format) | ||
| 19 | { | ||
| 20 | CHECKS(Format, format); | ||
| 21 | CHECKU(Arena, format->arena); | ||
| 22 | CHECKL(format->serial < format->arena->formatSerial); | ||
| 23 | CHECKL(format->variety == FormatVarietyA | ||
| 24 | || format->variety == FormatVarietyB | ||
| 25 | || format->variety == FormatVarietyAutoHeader); | ||
| 26 | CHECKL(RingCheck(&format->arenaRing)); | ||
| 27 | CHECKL(AlignCheck(format->alignment)); | ||
| 28 | /* @@@@ alignment should be less than maximum allowed */ | ||
| 29 | CHECKL(FUNCHECK(format->scan)); | ||
| 30 | CHECKL(FUNCHECK(format->skip)); | ||
| 31 | CHECKL(FUNCHECK(format->move)); | ||
| 32 | CHECKL(FUNCHECK(format->isMoved)); | ||
| 33 | /* Ignore unused copy field. */ | ||
| 34 | CHECKL(FUNCHECK(format->pad)); | ||
| 35 | CHECKL(FUNCHECK(format->class)); | ||
| 36 | |||
| 37 | return TRUE; | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | static Addr FormatDefaultClass(Addr object) | ||
| 42 | { | ||
| 43 | AVER(object != NULL); | ||
| 44 | |||
| 45 | return ((Addr *)object)[0]; | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | /* FormatCreate -- create a format */ | ||
| 50 | |||
| 51 | Res FormatCreate(Format *formatReturn, Arena arena, | ||
| 52 | Align alignment, | ||
| 53 | FormatVariety variety, | ||
| 54 | FormatScanMethod scan, | ||
| 55 | FormatSkipMethod skip, | ||
| 56 | FormatMoveMethod move, | ||
| 57 | FormatIsMovedMethod isMoved, | ||
| 58 | FormatCopyMethod copy, | ||
| 59 | FormatPadMethod pad, | ||
| 60 | FormatClassMethod class, | ||
| 61 | Size headerSize) | ||
| 62 | { | ||
| 63 | Format format; | ||
| 64 | Res res; | ||
| 65 | void *p; | ||
| 66 | |||
| 67 | AVER(formatReturn != NULL); | ||
| 68 | |||
| 69 | res = ControlAlloc(&p, arena, sizeof(FormatStruct), | ||
| 70 | /* withReservoirPermit */ FALSE); | ||
| 71 | if(res != ResOK) | ||
| 72 | return res; | ||
| 73 | format = (Format)p; /* avoid pun */ | ||
| 74 | |||
| 75 | format->arena = arena; | ||
| 76 | RingInit(&format->arenaRing); | ||
| 77 | format->alignment = alignment; | ||
| 78 | format->variety = variety; | ||
| 79 | format->scan = scan; | ||
| 80 | format->skip = skip; | ||
| 81 | format->move = move; | ||
| 82 | format->isMoved = isMoved; | ||
| 83 | format->copy = copy; | ||
| 84 | format->pad = pad; | ||
| 85 | if(class == NULL) { | ||
| 86 | format->class = &FormatDefaultClass; | ||
| 87 | } else { | ||
| 88 | AVER(variety == FormatVarietyB); | ||
| 89 | format->class = class; | ||
| 90 | } | ||
| 91 | if(headerSize != 0) { | ||
| 92 | AVER(variety == FormatVarietyAutoHeader); | ||
| 93 | format->headerSize = headerSize; | ||
| 94 | } else { | ||
| 95 | format->headerSize = 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | format->sig = FormatSig; | ||
| 99 | format->serial = arena->formatSerial; | ||
| 100 | ++arena->formatSerial; | ||
| 101 | |||
| 102 | AVERT(Format, format); | ||
| 103 | |||
| 104 | RingAppend(&arena->formatRing, &format->arenaRing); | ||
| 105 | |||
| 106 | *formatReturn = format; | ||
| 107 | return ResOK; | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | void FormatDestroy(Format format) | ||
| 112 | { | ||
| 113 | AVERT(Format, format); | ||
| 114 | |||
| 115 | RingRemove(&format->arenaRing); | ||
| 116 | |||
| 117 | format->sig = SigInvalid; | ||
| 118 | |||
| 119 | RingFinish(&format->arenaRing); | ||
| 120 | |||
| 121 | ControlFree(format->arena, format, sizeof(FormatStruct)); | ||
| 122 | } | ||
| 123 | |||
| 124 | |||
| 125 | /* Must be thread safe. See design.mps.interface.c.thread-safety. */ | ||
| 126 | Arena FormatArena(Format format) | ||
| 127 | { | ||
| 128 | /* Can't AVER format as that would not be thread-safe */ | ||
| 129 | /* AVERT(Format, format); */ | ||
| 130 | return format->arena; | ||
| 131 | } | ||
| 132 | |||
| 133 | |||
| 134 | Res FormatDescribe(Format format, mps_lib_FILE *stream) | ||
| 135 | { | ||
| 136 | Res res; | ||
| 137 | |||
| 138 | res = WriteF(stream, | ||
| 139 | "Format $P ($U) {\n", (WriteFP)format, (WriteFU)format->serial, | ||
| 140 | " arena $P ($U)\n", | ||
| 141 | (WriteFP)format->arena, (WriteFU)format->arena->serial, | ||
| 142 | " alignment $W\n", (WriteFW)format->alignment, | ||
| 143 | " scan $F\n", (WriteFF)format->scan, | ||
| 144 | " skip $F\n", (WriteFF)format->skip, | ||
| 145 | " move $F\n", (WriteFF)format->move, | ||
| 146 | " isMoved $F\n", (WriteFF)format->isMoved, | ||
| 147 | " copy $F\n", (WriteFF)format->copy, | ||
| 148 | " pad $F\n", (WriteFF)format->pad, | ||
| 149 | "} Format $P ($U)\n", (WriteFP)format, (WriteFU)format->serial, | ||
| 150 | NULL); | ||
| 151 | if(res != ResOK) return res; | ||
| 152 | |||
| 153 | return ResOK; | ||
| 154 | } | ||