Commit Diff


commit - 9be3f8306dc92152ec1af230d2a54cbf3415a976
commit + e3104fa570bd763e4e49bfad1762926f304adfdb
blob - 593c0f5e809e181c9ee6f36b3e883793c144170f
blob + b1d8661c78a168e1b189e6def88102d7c214197f
--- Makefile
+++ Makefile
@@ -5,6 +5,7 @@ all: destruct
 run: destruct
 	./destruct -H test.h -o test.c test.txt
 	cat test.h test.c
+	cc -c -o /dev/null test.c
 
 clean:
 	rm -f destruct destruct.inc y.tab.h test.[ch] *.o *.core
blob - 4e1153c2c0c8857bed664e941eeb7e86f0952791
blob + 09086c3949efb6e01a4e1a4faa20800c8580fed8
--- destruct.h
+++ destruct.h
@@ -11,7 +11,7 @@ static uint16_t dst_read16 (const uint8_t *ptr)
 	const uint16_t b0 = ptr[0];
 	const uint16_t b1 = ptr[1];
 
-#ifdef DST_FROM_ENDIAN == DST_LITTLE_ENDIAN
+#if DST_FROM_ENDIAN == DST_LITTLE_ENDIAN
 	return b0 | (b1 << 8);
 #elif DST_FROM_ENDIAN == DST_BIG_ENDIAN
 	return b1 | (b0 << 8);
@@ -25,7 +25,7 @@ static uint32_t dst_read32 (const uint8_t *ptr)
 	const uint32_t b2 = ptr[2];
 	const uint32_t b3 = ptr[3];
 
-#ifdef DST_FROM_ENDIAN == DST_LITTLE_ENDIAN
+#if DST_FROM_ENDIAN == DST_LITTLE_ENDIAN
 	return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
 #elif DST_FROM_ENDIAN == DST_BIG_ENDIAN
 	return b3 | (b2 << 8) | (b1 << 16) | (b0 << 24);
@@ -43,7 +43,7 @@ static uint64_t dst_read64 (const uint8_t *ptr)
 	const uint64_t b6 = ptr[6];
 	const uint64_t b7 = ptr[7];
 
-#ifdef DST_FROM_ENDIAN == DST_LITTLE_ENDIAN
+#if DST_FROM_ENDIAN == DST_LITTLE_ENDIAN
 	return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24) | (b4 << 32) | (b5 << 40) | (b6 << 48) | (b7 << 56);
 #elif DST_FROM_ENDIAN == DST_BIG_ENDIAN
 	return b7 | (b6 << 8) | (b5 << 16) | (b4 << 24) | (b3 << 32) | (b2 << 40) | (b1 << 48) | (b0 << 56);
@@ -60,7 +60,7 @@ static void dst_write16 (uint8_t *ptr, uint16_t x)
 	const uint8_t b0 = x & 0xff;
 	const uint8_t b1 = x >> 8;
 
-#ifdef DST_TO_ENDIAN == DST_LITTLE_ENDIAN
+#if DST_TO_ENDIAN == DST_LITTLE_ENDIAN
 	ptr[0] = b0;
 	ptr[1] = b1;
 #else
@@ -76,7 +76,7 @@ static void dst_write32 (uint8_t *ptr, uint32_t x)
 	const uint8_t b2 = (x >> 16) & 0xff;
 	const uint8_t b3 = (x >> 24) & 0xff;
 
-#ifdef DST_TO_ENDIAN == DST_LITTLE_ENDIAN
+#if DST_TO_ENDIAN == DST_LITTLE_ENDIAN
 	ptr[0] = b0;
 	ptr[1] = b1;
 	ptr[2] = b2;
@@ -100,7 +100,7 @@ static void dst_write64 (uint8_t *ptr, uint64_t x)
 	const uint8_t b6 = (x >> 48) & 0xff;
 	const uint8_t b7 = (x >> 56) & 0xff;
 
-#ifdef DST_TO_ENDIAN == DST_LITTLE_ENDIAN
+#if DST_TO_ENDIAN == DST_LITTLE_ENDIAN
 	ptr[0] = b0;
 	ptr[1] = b1;
 	ptr[2] = b2;
blob - f91f8a2a73220dc687f44ec3b53363be1801755e
blob + 4003962fddca5513a4d4795ca1a95dfd053b4b63
--- gen.c
+++ gen.c
@@ -255,7 +255,7 @@ void encode (FILE *out, size_t *offset, struct type *t
 	case T_U32:
 	case T_U64:
 		prindent (out, indent);
-		fprintf (out, "write%zu (out + %zu, %s);\n", sz * 8, *offset, from);
+		fprintf (out, "dst_write%zu (out + %zu, %s);\n", sz * 8, *offset, from);
 		*offset += sz;
 		break;
 	case T_ARRAY:
@@ -339,7 +339,7 @@ void decode (FILE *out, size_t *offset, struct type *t
 	case T_U32:
 	case T_U64:
 		prindent (out, indent);
-		fprintf (out, "%s = read%zu (in + %zu);\n", into, sz * 8, *offset);
+		fprintf (out, "%s = dst_read%zu (in + %zu);\n", into, sz * 8, *offset);
 		*offset += sz;
 		break;
 	case T_ARRAY:
blob - 03a1ee5bbe7953382aa7c52d8d258a0d0c5df460
blob + 760e41b4e6ab1b6d20a42d91c8ecae5427516311
--- test.txt
+++ test.txt
@@ -9,7 +9,7 @@ struct asdf {
 	z: u64,
 	a: [u64; 4],
 	t: struct test,
-	x: struct {
+	k: struct {
 		a: u8,
 		arr: [struct test; 3],
 		u: union {
@@ -21,7 +21,7 @@ struct asdf {
 		a: u8 if x == 0,
 		b: u8 if x == 1,
 	},
-	z: i8,
+	d: i8,
 };
 
 struct elf64_ehdr {