D Paste by Anonymous
Description: None
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | template __body__ (char[] name, char[] backing, char[] typectx) { const char[] __body__ = " struct "~name~" { union { "~backing~" void* address; void* __R3FL3CTtyp31d__; } short type; extern(C) void* function(void* dst, void* src, size_t n) copy; "~typectx~" uint64_t opIndex(in int i) in { assert(address != null); } body { uint64_t val; copy(&val, address + offset[type][i], size[type][i]); return val; } void opIndexAssign(in uint64_t val, in int i) in { assert(address != null); } body { copy(address + offset[type][i], &val, size[type][i]); } ushort tsize(){ return t_size[type]; } }"; } char[] __backing__(char[][] types) { char[] text; foreach (type; types) text ~= type ~ "* __" ~ type ~ "__;"; return text; } char[] __members__(char[][] types, char[][] t) { char[] text = "enum { "; foreach (s; t) text ~= s ~ ","; text ~= "};"; text ~= "static const ushort[] t_size = ["; foreach (type; types) text ~= type ~ ".sizeof,"; text ~= "];"; text ~= "static const ushort[][] offset = [ "; foreach (type; types) { text ~= "["; foreach (s; t) text ~= type ~ "." ~ s ~ ".offsetof,"; text ~= "],"; } text ~= "];"; text ~= "static const ushort[][] size = [ "; foreach (type; types) { text ~= "["; foreach (s; t) text ~= type ~ "." ~ s ~ ".sizeof,"; text ~= "],"; } text ~= "];"; return text; } template proxy(t...) { const char[] proxy = __body__!(t[0], __backing__(t[1]), __members__(t[1], [t[2..$]])); } mixin (proxy!("Sym", ["Elf32_Sym", "Elf64_Sym"], "st_name", "st_value", "st_size", "st_info", "st_other", "st_shndx")); |