diff options
author | Linus Torvalds <torvalds@penguin.transmeta.com> | 2003-04-03 12:09:50 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:00:07 -0700 |
commit | b5b3dfdd3989922b71a38e76c037aa30bb8f160a (patch) | |
tree | 5dabbcc8c172c964ee57ee11d6cd50eb4dcd301c /obfuscate.c | |
parent | Oops. Missed a place where we added pure symbol declarations (diff) | |
download | sparse-b5b3dfdd3989922b71a38e76c037aa30bb8f160a.tar.gz sparse-b5b3dfdd3989922b71a38e76c037aa30bb8f160a.tar.bz2 sparse-b5b3dfdd3989922b71a38e76c037aa30bb8f160a.zip |
Make the "obfuscate" backend actually generate a few
type descriptions. Nothing interesting yet, though.
Oh, well.
Diffstat (limited to 'obfuscate.c')
-rw-r--r-- | obfuscate.c | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/obfuscate.c b/obfuscate.c index a16d723..7201fac 100644 --- a/obfuscate.c +++ b/obfuscate.c @@ -21,11 +21,41 @@ static void emit_blob(struct symbol *sym) { - int bit_size = sym->bit_size; + int size = sym->bit_size; + int alignment = sym->ctype.alignment; + const char *name = show_ident(sym->ident); - if (bit_size & 7) - warn(sym->pos, "emitting symbol of size %d\n", bit_size); - printf("unsigned char %s[%d]\n", show_ident(sym->ident), bit_size >> 3); + if (size <= 0) { + warn(sym->pos, "emitting insized symbol"); + size = 8; + } + if (size & 7) + warn(sym->pos, "emitting symbol of size %d bits\n", size); + size = (size+7) >> 3; + if (alignment < 1) + alignment = 1; + if (!(size & (alignment-1))) { + switch (alignment) { + case 1: + printf("unsigned char %s[%d];\n", name, size); + return; + case 2: + printf("unsigned short %s[%d];\n", name, (size+1) >> 1); + return; + case 4: + printf("unsigned int %s[%d];\n", name, (size+3) >> 2); + return; + } + } + printf("unsigned char %s[%d] __attribute__((aligned(%d)));\n", + name, size, alignment); + return; +} + +static void emit_fn(struct symbol *sym) +{ + const char *name = show_ident(sym->ident); + printf("%s();\n", name); } void emit_symbol(struct symbol *sym, void *_parent, int flags) @@ -33,10 +63,16 @@ void emit_symbol(struct symbol *sym, void *_parent, int flags) struct symbol *ctype; evaluate_symbol(sym); + if (sym->type != SYM_NODE) { + warn(sym->pos, "I really want to emit nodes, not pure types!"); + return; + } + ctype = sym->ctype.base_type; if (!ctype) return; switch (ctype->type) { + case SYM_NODE: case SYM_PTR: case SYM_ARRAY: case SYM_STRUCT: @@ -44,7 +80,11 @@ void emit_symbol(struct symbol *sym, void *_parent, int flags) case SYM_BASETYPE: emit_blob(sym); return; + case SYM_FN: + emit_fn(sym); + return; default: + warn(sym->pos, "what kind of strange node do you want me to emit again?"); return; } } |