aboutsummaryrefslogtreecommitdiffstats
path: root/symbol.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@home.transmeta.com>2003-03-24 22:28:54 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 20:59:44 -0700
commitef62291202fc1cdb05d12ea6605340cf80032028 (patch)
tree5c99cb2431a59cc1f4ae918bd90d83e2eb925a54 /symbol.c
parentda7f6d4fe8d6321f692651a423ad37586e100f63 (diff)
downloadsparse-ef62291202fc1cdb05d12ea6605340cf80032028.tar.gz
Add building of the normal built-in C types (as opposed to the
abstract types that type parser already knows about). Make constant string expressions have some almost-proper type.
Diffstat (limited to 'symbol.c')
-rw-r--r--symbol.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/symbol.c b/symbol.c
index 80760d5e..67e36cfa 100644
--- a/symbol.c
+++ b/symbol.c
@@ -267,12 +267,37 @@ struct sym_init {
{ NULL, NULL, 0 }
};
+/*
+ * Abstract types
+ */
struct symbol void_type,
int_type,
fp_type,
vector_type,
bad_type;
+/*
+ * C types (ie actual instances that the abstract types
+ * can map onto)
+ */
+struct symbol char_ctype,
+ int_ctype,
+ string_ctype;
+
+struct ctype_declare {
+ struct symbol *ptr;
+ unsigned long modifiers;
+ unsigned long bit_size;
+ unsigned long maxalign;
+ struct symbol *base_type;
+} ctype_declaration[] = {
+ { &char_ctype, MOD_SIGNED | MOD_CHAR, BITS_IN_CHAR, MAX_INT_ALIGNMENT, &int_type },
+ { &int_ctype, 0, BITS_IN_INT, MAX_INT_ALIGNMENT, &int_type },
+ { &string_ctype, 0, BITS_IN_POINTER, POINTER_ALIGNMENT, &char_ctype },
+ { NULL, }
+};
+
+
#define __IDENT(n,str) \
struct ident n ## _ident = { len: sizeof(str)-1, name: str }
#define IDENT(n) __IDENT(n, #n)
@@ -293,6 +318,7 @@ void init_symbols(void)
{
int stream = init_stream("builtin", -1);
struct sym_init *ptr;
+ struct ctype_declare *ctype;
hash_ident(&sizeof_ident);
hash_ident(&alignof_ident);
@@ -324,4 +350,18 @@ void init_symbols(void)
sym->ctype.base_type = ptr->base_type;
sym->ctype.modifiers = ptr->modifiers;
}
+
+ 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 alignment = bit_size >> 3;
+
+ if (alignment > ctype->maxalign)
+ alignment = ctype->maxalign;
+ sym->bit_size = bit_size;
+ sym->alignment = alignment;
+ sym->ctype.base_type = ctype->base_type;
+ sym->ctype.modifiers = ctype->modifiers;
+ }
}