diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-05-23 15:55:30 -0400 |
---|---|---|
committer | GHC GitLab CI <ghc-ci@gitlab-haskell.org> | 2022-05-23 23:05:26 -0400 |
commit | f390cfc51ca93ef883a454308942ca3f8497ae31 (patch) | |
tree | afbe6f3d48d7facd80a47b388a90066d4ddcb91b /rts/linker/BufferBuilder.c | |
parent | 1ca1efdc8758458a28414f6d00c679b8f9a6bd0a (diff) | |
download | haskell-wip/gdb-jit-object.tar.gz |
(cherry picked from commit 07c9532947a623a065d43ef5f69e530ca762f986)
Diffstat (limited to 'rts/linker/BufferBuilder.c')
-rw-r--r-- | rts/linker/BufferBuilder.c | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/rts/linker/BufferBuilder.c b/rts/linker/BufferBuilder.c deleted file mode 100644 index 9f6ff04277..0000000000 --- a/rts/linker/BufferBuilder.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "Rts.h" -#include "RtsUtils.h" -#include "BufferBuilder.h" -#include <string.h> - -struct BufferBuilder buffer_builder_new(size_t initial_sz) -{ - uint8_t *buffer = stgMallocBytes(initial_sz, "new_buffer_builder"); - return (struct BufferBuilder) { - .buffer = buffer, - .head = buffer, - .end = buffer + initial_sz, - }; -} - -void buffer_builder_free(struct BufferBuilder *bb) -{ - stgFree(bb->buffer); - bb->buffer = NULL; - bb->head = NULL; - bb->end = NULL; -} - -size_t buffer_builder_filled_size(struct BufferBuilder *bb) -{ - return bb->head - bb->buffer; -} - -size_t buffer_builder_reserved_size(struct BufferBuilder *bb) -{ - return bb->end - bb->buffer; -} - -void buffer_builder_realloc(struct BufferBuilder *bb, size_t new_sz) -{ - size_t filled_sz = buffer_builder_filled_size(bb); - ASSERT(filled_sz <= new_sz); - uint8_t *buffer = stgReallocBytes(bb->buffer, new_sz, "new_buffer_builder"); - bb->buffer = buffer; - bb->head = buffer + filled_sz; - bb->end = buffer + new_sz; -} - -uint8_t *buffer_builder_push(struct BufferBuilder *bb, uint8_t *x, size_t sz) -{ - if (bb->head + sz > bb->end) { - buffer_builder_realloc(bb, 2*buffer_builder_reserved_size(bb)); - } - - memcpy(bb->head, x, sz); - uint8_t *ret = bb->head; - bb->head += sz; - return ret; -} - -void buffer_builder_append(struct BufferBuilder *bb, struct BufferBuilder *src) -{ - size_t sz = buffer_builder_filled_size(src); - buffer_builder_push(bb, bb->buffer, sz); -} - |