diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | symbol.c | 55 | ||||
| -rw-r--r-- | target.c | 49 | ||||
| -rw-r--r-- | target.h | 34 |
4 files changed, 95 insertions, 45 deletions
@@ -8,7 +8,7 @@ PROGRAMS=test-lexing test-parsing obfuscate check compile test-linearize LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h linearize.h -LIB_OBJS= parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \ +LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \ expression.o show-parse.o evaluate.o expand.o inline.o linearize.o LIB_FILE= sparse.a @@ -466,32 +466,32 @@ struct symbol bool_ctype, void_ctype, type_ctype, struct ctype_declare { struct symbol *ptr; unsigned long modifiers; - unsigned long bit_size; - unsigned long maxalign; + int *bit_size; + int *maxalign; struct symbol *base_type; } ctype_declaration[] = { - { &bool_ctype, 0, BITS_IN_INT, MAX_INT_ALIGNMENT, &int_type }, - { &void_ctype, 0, -1, 0, NULL }, - { &type_ctype, MOD_TYPE, -1, 0, NULL }, - { &label_ctype, MOD_LABEL | MOD_UNSIGNED, BITS_IN_POINTER, MAX_INT_ALIGNMENT, &label_type }, - - { &char_ctype, MOD_SIGNED | MOD_CHAR, BITS_IN_CHAR, MAX_INT_ALIGNMENT, &int_type }, - { &uchar_ctype, MOD_UNSIGNED | MOD_CHAR, BITS_IN_CHAR, MAX_INT_ALIGNMENT, &int_type }, - { &short_ctype, MOD_SIGNED | MOD_SHORT, BITS_IN_SHORT, MAX_INT_ALIGNMENT, &int_type }, - { &ushort_ctype, MOD_UNSIGNED | MOD_SHORT, BITS_IN_SHORT, MAX_INT_ALIGNMENT, &int_type }, - { &int_ctype, MOD_SIGNED, BITS_IN_INT, MAX_INT_ALIGNMENT, &int_type }, - { &uint_ctype, MOD_UNSIGNED, BITS_IN_INT, MAX_INT_ALIGNMENT, &int_type }, - { &long_ctype, MOD_SIGNED | MOD_LONG, BITS_IN_LONG, MAX_INT_ALIGNMENT, &int_type }, - { &ulong_ctype, MOD_UNSIGNED | MOD_LONG, BITS_IN_LONG, MAX_INT_ALIGNMENT, &int_type }, - { &llong_ctype, MOD_SIGNED | MOD_LONG | MOD_LONGLONG, BITS_IN_LONGLONG, MAX_INT_ALIGNMENT, &int_type }, - { &ullong_ctype, MOD_UNSIGNED | MOD_LONG | MOD_LONGLONG, BITS_IN_LONGLONG, MAX_INT_ALIGNMENT, &int_type }, - - { &float_ctype, 0, BITS_IN_FLOAT, MAX_FP_ALIGNMENT, &fp_type }, - { &double_ctype, MOD_LONG, BITS_IN_DOUBLE, MAX_FP_ALIGNMENT, &fp_type }, - { &ldouble_ctype,MOD_LONG | MOD_LONGLONG, BITS_IN_LONGDOUBLE,MAX_FP_ALIGNMENT, &fp_type }, - - { &string_ctype, 0, BITS_IN_POINTER, POINTER_ALIGNMENT, &char_ctype }, - { &ptr_ctype, 0, BITS_IN_POINTER, POINTER_ALIGNMENT, &void_ctype }, + { &bool_ctype, 0, &BITS_IN_INT, &MAX_INT_ALIGNMENT, &int_type }, + { &void_ctype, 0, NULL, NULL, NULL }, + { &type_ctype, MOD_TYPE, NULL, NULL, NULL }, + { &label_ctype, MOD_LABEL | MOD_UNSIGNED, &BITS_IN_POINTER, &MAX_INT_ALIGNMENT, &label_type }, + + { &char_ctype, MOD_SIGNED | MOD_CHAR, &BITS_IN_CHAR, &MAX_INT_ALIGNMENT, &int_type }, + { &uchar_ctype, MOD_UNSIGNED | MOD_CHAR, &BITS_IN_CHAR, &MAX_INT_ALIGNMENT, &int_type }, + { &short_ctype, MOD_SIGNED | MOD_SHORT, &BITS_IN_SHORT, &MAX_INT_ALIGNMENT, &int_type }, + { &ushort_ctype, MOD_UNSIGNED | MOD_SHORT, &BITS_IN_SHORT, &MAX_INT_ALIGNMENT, &int_type }, + { &int_ctype, MOD_SIGNED, &BITS_IN_INT, &MAX_INT_ALIGNMENT, &int_type }, + { &uint_ctype, MOD_UNSIGNED, &BITS_IN_INT, &MAX_INT_ALIGNMENT, &int_type }, + { &long_ctype, MOD_SIGNED | MOD_LONG, &BITS_IN_LONG, &MAX_INT_ALIGNMENT, &int_type }, + { &ulong_ctype, MOD_UNSIGNED | MOD_LONG, &BITS_IN_LONG, &MAX_INT_ALIGNMENT, &int_type }, + { &llong_ctype, MOD_SIGNED | MOD_LONG | MOD_LONGLONG, &BITS_IN_LONGLONG, &MAX_INT_ALIGNMENT, &int_type }, + { &ullong_ctype, MOD_UNSIGNED | MOD_LONG | MOD_LONGLONG, &BITS_IN_LONGLONG, &MAX_INT_ALIGNMENT, &int_type }, + + { &float_ctype, 0, &BITS_IN_FLOAT, &MAX_FP_ALIGNMENT, &fp_type }, + { &double_ctype, MOD_LONG, &BITS_IN_DOUBLE, &MAX_FP_ALIGNMENT, &fp_type }, + { &ldouble_ctype,MOD_LONG | MOD_LONGLONG, &BITS_IN_LONGDOUBLE, &MAX_FP_ALIGNMENT, &fp_type }, + + { &string_ctype, 0, &BITS_IN_POINTER, &POINTER_ALIGNMENT, &char_ctype }, + { &ptr_ctype, 0, &BITS_IN_POINTER, &POINTER_ALIGNMENT, &void_ctype }, { NULL, } }; @@ -575,11 +575,12 @@ void init_symbols(void) string_ctype.type = SYM_PTR; for (ctype = ctype_declaration ; ctype->ptr; ctype++) { struct symbol *sym = ctype->ptr; - unsigned long bit_size = ctype->bit_size; + unsigned long bit_size = ctype->bit_size ? *ctype->bit_size : -1; + unsigned long maxalign = ctype->maxalign ? *ctype->maxalign : 0; unsigned long alignment = bit_size >> 3; - if (alignment > ctype->maxalign) - alignment = ctype->maxalign; + if (alignment > maxalign) + alignment = maxalign; sym->bit_size = bit_size; sym->ctype.alignment = alignment; sym->ctype.base_type = ctype->base_type; diff --git a/target.c b/target.c new file mode 100644 index 00000000..6aece3bd --- /dev/null +++ b/target.c @@ -0,0 +1,49 @@ +#ifndef TARGET_H +#define TARGET_H + +#include <stdio.h> + +#include "symbol.h" +#include "target.h" + +struct symbol *size_t_ctype = &ulong_ctype; +struct symbol *ssize_t_ctype = &long_ctype; + +/* + * For "__attribute__((aligned))" + */ +int MAX_ALIGNMENT = 16; + +/* + * Integer data types + */ +int BITS_IN_CHAR = 8; +int BITS_IN_SHORT = 16; +int BITS_IN_INT = 32; +int BITS_IN_LONG = 32; +int BITS_IN_LONGLONG = 64; + +int MAX_INT_ALIGNMENT = 4; + +/* + * Floating point data types + */ +int BITS_IN_FLOAT = 32; +int BITS_IN_DOUBLE = 64; +int BITS_IN_LONGDOUBLE = 80; + +int MAX_FP_ALIGNMENT = 8; + +/* + * Pointer data type + */ +int BITS_IN_POINTER = 32; +int POINTER_ALIGNMENT = 4; + +/* + * Enum data types + */ +int BITS_IN_ENUM = 32; +int ENUM_ALIGNMENT = 4; + +#endif @@ -1,44 +1,44 @@ #ifndef TARGET_H #define TARGET_H -#define size_t_ctype (&ulong_ctype) -#define ssize_t_ctype (&long_ctype) +extern struct symbol *size_t_ctype; +extern struct symbol *ssize_t_ctype; /* * For "__attribute__((aligned))" */ -#define MAX_ALIGNMENT 16 +extern int MAX_ALIGNMENT; /* * Integer data types */ -#define BITS_IN_CHAR 8 -#define BITS_IN_SHORT 16 -#define BITS_IN_INT 32 -#define BITS_IN_LONG 32 -#define BITS_IN_LONGLONG 64 +extern int BITS_IN_CHAR; +extern int BITS_IN_SHORT; +extern int BITS_IN_INT; +extern int BITS_IN_LONG; +extern int BITS_IN_LONGLONG; -#define MAX_INT_ALIGNMENT 4 +extern int MAX_INT_ALIGNMENT; /* * Floating point data types */ -#define BITS_IN_FLOAT 32 -#define BITS_IN_DOUBLE 64 -#define BITS_IN_LONGDOUBLE 80 +extern int BITS_IN_FLOAT; +extern int BITS_IN_DOUBLE; +extern int BITS_IN_LONGDOUBLE; -#define MAX_FP_ALIGNMENT 8 +extern int MAX_FP_ALIGNMENT; /* * Pointer data type */ -#define BITS_IN_POINTER 32 -#define POINTER_ALIGNMENT 4 +extern int BITS_IN_POINTER; +extern int POINTER_ALIGNMENT; /* * Enum data types */ -#define BITS_IN_ENUM 32 -#define ENUM_ALIGNMENT 4 +extern int BITS_IN_ENUM; +extern int ENUM_ALIGNMENT; #endif |
