summaryrefslogtreecommitdiffstats
path: root/src/compiler/blob.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/blob.c')
-rw-r--r--src/compiler/blob.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/compiler/blob.c b/src/compiler/blob.c
index 65c450ee979..5375c647b02 100644
--- a/src/compiler/blob.c
+++ b/src/compiler/blob.c
@@ -172,6 +172,20 @@ blob_reserve_bytes(struct blob *blob, size_t to_write)
return ret;
}
+ssize_t
+blob_reserve_uint32(struct blob *blob)
+{
+ align_blob(blob, sizeof(uint32_t));
+ return blob_reserve_bytes(blob, sizeof(uint32_t));
+}
+
+ssize_t
+blob_reserve_intptr(struct blob *blob)
+{
+ align_blob(blob, sizeof(intptr_t));
+ return blob_reserve_bytes(blob, sizeof(intptr_t));
+}
+
bool
blob_write_uint32(struct blob *blob, uint32_t value)
{
@@ -180,11 +194,15 @@ blob_write_uint32(struct blob *blob, uint32_t value)
return blob_write_bytes(blob, &value, sizeof(value));
}
+#define ASSERT_ALIGNED(_offset, _align) \
+ assert(ALIGN((_offset), (_align)) == (_offset))
+
bool
blob_overwrite_uint32 (struct blob *blob,
size_t offset,
uint32_t value)
{
+ ASSERT_ALIGNED(offset, sizeof(value));
return blob_overwrite_bytes(blob, offset, &value, sizeof(value));
}
@@ -205,6 +223,15 @@ blob_write_intptr(struct blob *blob, intptr_t value)
}
bool
+blob_overwrite_intptr (struct blob *blob,
+ size_t offset,
+ intptr_t value)
+{
+ ASSERT_ALIGNED(offset, sizeof(value));
+ return blob_overwrite_bytes(blob, offset, &value, sizeof(value));
+}
+
+bool
blob_write_string(struct blob *blob, const char *str)
{
return blob_write_bytes(blob, str, strlen(str) + 1);