Commit efbeaff5 authored by Christian Schäfer's avatar Christian Schäfer
Browse files

Initial revision

[r4]
parents
# Hey, emacs, this is a -*- makefile -*-
#
# Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
# All rights reserved.
# Author: Goetz Lindenmaier
#
# Main Makefile
# This makefile makes firm and/or the testprograms.
SUBDIRS = ir testprograms
MAKE = /usr/bin/make -k
SHELL = /bin/sh
.PHONY: default all clean realclean install depend ir testprograms
ir:
$(MAKE) -C ir
all: TAGS ir testprograms
testprograms:
$(MAKE) -C testprograms
clean:
for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
realclean:
for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
rm -f libfirm.a core
TAGFILES = $(shell find . -name '*.c' -o -name '*.h')
TAGS: $(TAGFILES)
etags -C $(TAGFILES)
# Hey, emacs, this is a -*- makefile -*-
#
# Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
# All rights reserved.
# Author: Goetz Lindenmaier
#
# Makefile for IR library.
# This makefile descends to all directories listed in INCLUDES and to
# testprograms and calls make with the corresponding target there.
# After returning it builds a library out of the firm files.
# Further it updates the TAGS file with each recompilation
SUBDIRS = adt common debug ident ir tr tv
INCLUDES = -I../adt -I../common -I../debug -I../ident -I../include \
-I../ir -I../tr -I../tv
OFILES =
AR = ar rcs
MAKE = /usr/bin/make -k
SHELL = /bin/sh
CXX = gcc
CFLAGS = -pipe -Wall #-ansi -pedantic # -g
COPTFLAGS = -O3 -ffast-math # -fno-caller-saves
TARGET = libfirm.a
.PHONY: default all clean realclean install depend $(TARGET)
$(TARGET):
# mkdir objects
for i in $(SUBDIRS); do $(MAKE) "INCLUDES=$(INCLUDES)" -C $$i; done
$(AR) $(TARGET) objects/*.o
mv $(TARGET) ..
debug:
for i in $(SUBDIRS); do $(MAKE) "CFLAGS=$(CFLAGS) -g INCLUDES=$(INCLUDES)" -C $$i; done
all: TAGS $(TARGET)
#testprograms:
# $(MAKE) -C testprograms
clean:
for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
realclean:
for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
$(MAKE) -C testprograms realclean
rm -f $(TARGET) core
profile: realclean
for i in $(SUBDIRS); do \
$(MAKE) \
"CXX=$(CXX)" \
"CFLAGS=-g -pg" \
"INCLUDES=$(INCLUDES)" -C $$i; \
done
TAGFILES = $(shell find . -name '*.c' -o -name '*.h')
TAGS: $(TAGFILES)
etags -C $(TAGFILES)
# Hey, emacs, this is a -*- makefile -*-
## Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
# All rights reserved.
# Author: Goetz Lindenmaier
#
# Makefile for adt -- abstract data types
CXX = gcc
CFLAGS = -pipe -Wall # -ansi -pedantic
CXXFLAGS = # -g
COPTFLAGS = -O3
LDFLAGS =
DEPENDFLAGS = -M
LIBPATH =
LIBS =
X_LIBS =
INCLUDES = -I../adt -I../common -I../debug
X_INCLUDES =
SHELL = /bin/sh
MAKE = /usr/bin/make
MEMBERS = array.m pdeq.m set.m
CFILES = $(MEMBERS:.m=.c)
CFIMES += xmalloc.c
HFILES = $(MEMBERS:.m=.h)
HFILES += cookies.h host.h obst.h pset.h
HFILES += misc.h tune.h debug.h
OFILES = $(MEMBERS:%.m=../objects/%.o)
OFILES += ../objects/xmalloc.o ../objects/pset.o
DFILES = $(MEMBERS:.m=.d)
TARGET = all
.PHONY: default all clean realclean install depend
.SUFFIXES: .d .h .c .o
.DEFAULT: $(TARGET)
.SILENT: $(DFILES) clean # hides output
$(TARGET): $(DFILES) $(OFILES)
%.d: %.c
$(SHELL) -ec '$(CXX) $(DEPENDFLAGS) $(INCLUDES) $(X_INCLUDES) $< | sed '\''s/\($*\)\.o[ :]*/\.\.\/objects\/\1.o $@ : /g'\'' > $@'
../objects/%.o: %.c
$(CXX) $(CFLAGS) $(CXXFLAGS) $(COPTFLAGS) $(INCLUDES) $(X_INCLUDES) -c $< -o $@
# a hack to force recompilation
../objects/pset.o : set.c pset.h ../objects/set.o
$(COMPILE.c) $(INCLUDES) -DPSET -o $@ $<
# $(CXX) $(CFLAGS) $(CXXFLAGS) $(COPTFLAGS) $(INCLUDES) $(X_INCLUDES) -c $< -o $@
clean:
rm -f $(OFILES) $(DFILES)
realclean: clean
rm -f $(TARGET) *.flc TAGS
-include $(DFILES)
/* Array --- dynamic & flexible arrays.
Copyright (C) 1995, 1996 Markus Armbruster
All rights reserved. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "array.h"
/* Undefine the macros to get the functions instead, cf tmalloc.c. */
#undef xmalloc
#undef xrealloc
#undef xstrdup
#undef xfree
_arr_descr arr_mt_descr
#ifndef NDEBUG
= { ARR_D_MAGIC }
#endif
;
void *
_new_arr_d (struct obstack *obstack, int nelts, size_t elts_size)
{
_arr_descr *new;
assert (obstack && (nelts >= 0));
new = obstack_alloc (obstack, _ARR_ELTS_OFFS+elts_size);
_ARR_SET_DBGINF (new, ARR_D_MAGIC, elts_size/nelts);
new->u.obstack = obstack;
new->nelts = nelts;
return new->v.elts;
}
void *
_new_arr_f (int nelts, size_t elts_size)
{
_arr_descr *new;
assert (nelts >= 0);
new = xmalloc (_ARR_ELTS_OFFS+elts_size);
_ARR_SET_DBGINF (new, ARR_F_MAGIC, nelts ? elts_size/nelts : 0);
new->u.allocated = new->nelts = nelts;
return new->v.elts;
}
void
_del_arr_f (void *elts)
{
_arr_descr *dp = _ARR_DESCR (elts);
ARR_VRFY (elts);
assert (dp->cookie == ARR_F_MAGIC);
#ifndef NDEBUG
dp->cookie = 0xdeadbeef;
#endif
free (dp);
}
void *
_arr_setlen (void *elts, int nelts, size_t elts_size)
{
_arr_descr *dp = _ARR_DESCR (elts);
assert ((dp->cookie == ARR_F_MAGIC) && (nelts >= 0));
ARR_VRFY (elts);
assert (!dp->eltsize || !nelts || (dp->eltsize == elts_size/nelts));
dp = xrealloc (dp, _ARR_ELTS_OFFS+elts_size);
dp->u.allocated = dp->nelts = nelts;
return dp->v.elts;
}
void *
_arr_resize (void *elts, int nelts, size_t eltsize)
{
_arr_descr *dp = _ARR_DESCR (elts);
int n;
assert ((dp->cookie == ARR_F_MAGIC) && (nelts >= 0));
ARR_VRFY (elts);
assert (dp->eltsize ? dp->eltsize == eltsize : (dp->eltsize = eltsize, 1));
/* @@@ lots of resizes for small nelts */
n = MAX (1, dp->u.allocated);
while (nelts > n) n <<= 1;
while (3*nelts < n) n >>= 1;
assert (n >= nelts);
if (n != dp->u.allocated) {
dp = xrealloc (dp, _ARR_ELTS_OFFS+eltsize*n);
dp->u.allocated = n;
#if defined(DEBUG) && defined(HAVE_GNU_MALLOC)
} else {
tmalloc_tag = NULL;
#endif
}
dp->nelts = nelts;
return dp->v.elts;
}
/* Declarations for Array.
Copyright (C) 1995, 1996 Markus Armbruster
All rights reserved. */
/* @@@ growing a dynamic on an obstack */
#ifndef _ARRAY_H
#define _ARRAY_H
#include <assert.h>
#include <stddef.h>
#include <obstack.h>
#include "cookies.h"
#include "misc.h"
/* Flexible create / delete */
#define NEW_ARR_F(type, nelts) \
(XMALLOC_TRACE (type *)_new_arr_f ((nelts), sizeof(type) * (nelts)))
#define CLONE_ARR_F(type, arr) \
NEW_ARR_F (type, ARR_LEN ((arr)))
#define DUP_ARR_F(type, arr) \
memcpy (CLONE_ARR_F (type, (arr)), (arr), sizeof(type) * ARR_LEN((arr)))
#define DEL_ARR_F(arr) (XMALLOC_TRACE _del_arr_f ((arr)))
/* Dynamic create on obstacks */
#define NEW_ARR_D(type, obstack, nelts) \
( nelts \
? (type *)_new_arr_d ((obstack), (nelts), sizeof(type) * (nelts)) \
: (type *)arr_mt_descr.v.elts)
#define CLONE_ARR_D(type, obstack, arr) \
NEW_ARR_D (type, (obstack), ARR_LEN ((arr)))
#define DUP_ARR_D(type, obstack, arr) \
memcpy (CLONE_ARR_D (type, (obstack), (arr)), (arr), sizeof(type) * ARR_LEN ((arr)))
/* Automatic create; delete is automatic at return from function */
/* Quick'n'dirty! */
#define NEW_ARR_A(type, var, n) \
do { \
int _nelts = (n); \
assert (_nelts >= 0); \
(var) = (void *)((_arr_descr *)alloca (_ARR_ELTS_OFFS + sizeof(type) * _nelts))->v.elts; \
_ARR_SET_DBGINF (_ARR_DESCR ((var)), ARR_A_MAGIC, sizeof (type)); \
(void)(_ARR_DESCR ((var))->nelts = _nelts); \
} while (0)
#define CLONE_ARR_A(type, var, arr) \
NEW_ARR_A (type, (var), ARR_LEN ((arr)))
#define DUP_ARR_A(type, var, arr) \
do { CLONE_ARR_A(type, (var), (arr)); \
memcpy ((var), (arr), sizeof (type) * ARR_LEN ((arr))); } \
while (0)
/* Declare an initialized array of fixed size */
#define DECL_ARR_S(type, var, _nelts) \
ARR_STRUCT(type, (_nelts) ? (_nelts) : 1) _##var; \
type *var = (_ARR_SET_DBGINF (&_##var, ARR_A_MAGIC, sizeof (type)), \
_##var.nelts = _nelts, \
_##var.v.elts)
/* Length */
#define ARR_LEN(arr) (ARR_VRFY ((arr)), _ARR_DESCR((arr))->nelts)
/* Resize
Applicable to flexibles only, change arr which must be an lvalue. */
/* resize arr to hold n elts */
#define ARR_RESIZE(type, arr, n) \
(XMALLOC_TRACE (arr) = _arr_resize ((arr), (n), sizeof(type)))
/* resize arr to hold exactly n elts */
#define ARR_SETLEN(type, arr, n) \
(XMALLOC_TRACE (arr) = _arr_setlen ((arr), (n), sizeof(type) * (n)))
/* resize arr by delta elts */
#define ARR_EXTEND(type, arr, delta) \
ARR_RESIZE (type, (arr), ARR_LEN ((arr)) + (delta))
/* resize arr to hold n elts only if it is currently shorter */
#define ARR_EXTO(type, arr, n) \
((n) >= ARR_LEN ((arr)) ? ARR_RESIZE (type, (arr), (n)+1) : (arr))
/* append one elt to arr */
#define ARR_APP1(type, arr, elt) \
(ARR_EXTEND (type, (arr), 1), (arr)[ARR_LEN ((arr))-1] = (elt))
#ifdef NDEBUG
# define ARR_VRFY(arr) ((void)0)
# define ARR_IDX_VRFY(arr, idx) ((void)0)
#else
# define ARR_VRFY(arr) \
assert ( ( (_ARR_DESCR((arr))->cookie == ARR_D_MAGIC) \
|| (_ARR_DESCR((arr))->cookie == ARR_A_MAGIC) \
|| (_ARR_DESCR((arr))->cookie == ARR_F_MAGIC)) \
&& ( (_ARR_DESCR((arr))->cookie != ARR_F_MAGIC) \
|| (_ARR_DESCR((arr))->u.allocated >= _ARR_DESCR((arr))->nelts)) \
&& (_ARR_DESCR((arr))->nelts >= 0))
# define ARR_IDX_VRFY(arr, idx) \
assert ((0 <= (idx)) && ((idx) < ARR_LEN ((arr))))
#endif
/* Private */
/* Don't try this at home, kids, we're trained professionals ;-> */
// ... or at the IPD, either.
#ifdef NDEBUG
# define _ARR_DBGINF_DECL
# define _ARR_SET_DBGINF(descr, co, es) ((co), (es))
#else
# define _ARR_DBGINF_DECL int cookie; size_t eltsize;
# define _ARR_SET_DBGINF(descr, co, es) \
((descr)->cookie = (co), (descr)->eltsize = (es))
#endif
#define ARR_STRUCT(type, _nelts) \
struct { \
_ARR_DBGINF_DECL \
union { \
struct obstack *obstack; /* dynamic: allocated on this obstack */ \
int allocated; /* flexible: #slots allocated */ \
} u; \
int nelts; \
union { \
type elts[(_nelts)]; \
aligned_type align[1]; \
} v; \
}
typedef ARR_STRUCT (aligned_type, 1) _arr_descr;
extern _arr_descr arr_mt_descr;
void *_new_arr_f (int, size_t);
void _del_arr_f (void *);
void *_new_arr_d (struct obstack *, int, size_t);
void *_arr_resize (void *, int, size_t);
void *_arr_setlen (void *, int, size_t);
#define _ARR_ELTS_OFFS offsetof (_arr_descr, v.elts)
#define _ARR_DESCR(elts) ((_arr_descr *)(void *)((char *)(elts) - _ARR_ELTS_OFFS))
#endif
/* Magic cookies for dynamic data structures
Copyright (C) 1995, 1996 Christian von Roques & Markus Armbruster
All rights reserved. */
#ifndef _COOKIES_H
#define _COOKIES_H
/* Arrays */
#define ARR_D_MAGIC 0xD138A4
#define ARR_A_MAGIC 0xA138A4
#define ARR_F_MAGIC 0xF138A4
/* Pointer Double Ended Queue */
#define PDEQ_COOKIE1 0xC00B8A
#define PDEQ_COOKIE2 0x8A771E
/* Small Pointer DICTionary */
#define SPDICT_COOKIE1 0xB0031E7
#define SPDICT_COOKIE2 0xBA17B003
/* Line N_o_mbers ToDo: Warum o? */
#define LINO_COOKIE 0x71b83bd5
#endif
/* Declarations describing the host machine and C compiler.
Copyright (C) 1995, 1996 Markus Armbruster
All rights reserved.*/
#ifndef _HOST_H
#define _HOST_H
#include <stddef.h>
/* A size handled efficiently by malloc(), at least 1K. */
#define PREF_MALLOC_SIZE 2048
/* GNU C's __attribute__ */
/* According to the documentation, the attributes we are interested in
work with 2.5, but we encountered trouble before 2.7. */
#if defined (__GNUC__) && __GNUC__ >= 2 && __GNUC_MINOR__ >= 7
# define HAVE_ATTRIBUTE 1
# define ATTRIBUTE(attrs) __attribute__ (attrs)
#else
# define ATTRIBUTE(attrs)
#endif
/* Alignment */
/* A type that has most constrained alignment. */
typedef union {
long double d;
void *p;
long l;
} aligned_type ATTRIBUTE ((aligned));
/* Inquiring about the alignment. */
#ifdef __GNUC__
# define ALIGNOF(type) __alignof__ (type)
#else
# define ALIGNOF(type) offsetof (struct { char c; type d; }, d)
#endif
/* Maximal alignment required for any type. */
#define MAX_ALIGN ALIGNOF (aligned_type)
#endif
/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Martin Trapp, Christian Schaefer
**
*/
# include <obstack.h>
# include <malloc.h>
# define obstack_chunk_alloc xmalloc
# define obstack_chunk_free free
/* Pdeq --- double ended queue of generic pointers.
Copyright (C) 1995, 1996 Christian von Roques */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
# ifdef HAVE_STRING_H
# include <string.h>
# endif
#include "tune.h"
#include "cookies.h"
#include "debug.h"
#include "malloc.h"
#include "pdeq.h"
/* # of data items in block */
#define NDATA ((int)((PREF_MALLOC_SIZE - offsetof (pdeq, data)) / sizeof (void *)))
#ifdef NDEBUG
# define VRFY(dq) ((void)0)
#else
# define VRFY(dq) \
(d_(df_vrfy_level,1) ? _pdeq_vrfy ((dq)) : assert ((dq) && ((dq)->cookie == PDEQ_COOKIE1)))
#endif
struct pdeq {
#ifndef NDEBUG
unsigned cookie;
#endif
pdeq *l_end, *r_end; /* left and right ends of the deque */
pdeq *l, *r; /* left and right neighbour */
int n, p;
const void *data[1];
};
/* cache of unused, pdeq blocks to speed up new_pdeq and del_pdeq. */
/* +1 for compilers that can't grok empty arrays */
pdeq *pdeq_block_cache[TUNE_NSAVED_PDEQS+1];
unsigned pdeqs_cached; /* # pdeqs in pdeq_store */
static inline void
free_pdeq_block (pdeq *p)
{
#ifndef NDEBUG
p->cookie = 0xbadf00d1;
#endif
if (pdeqs_cached < TUNE_NSAVED_PDEQS) {
if (d_ (df_pdeq, 2)) printf ("[%p ==> pdeq_block_cache] ", p);
pdeq_block_cache[pdeqs_cached++] = p;
} else {
if (d_ (df_pdeq, 2)) printf ("[%p ==> free] ", p);
xfree (p);
}
}
static inline pdeq *
alloc_pdeq_block (void)
{
pdeq *p;
if (TUNE_NSAVED_PDEQS && pdeqs_cached) {
p = pdeq_block_cache[--pdeqs_cached];
if (d_ (df_pdeq, 2)) printf ("[pdeq_block_cache ==> %p] ", p);
} else {
p = xmalloc (PREF_MALLOC_SIZE);
if (d_ (df_pdeq, 2)) printf ("[malloc ==> %p] ", p);
}
return p;
}
#ifndef NDEBUG
void
_pdeq_vrfy (pdeq *dq)
{
pdeq *q;
if (d_ (df_pdeq, 5)) printf ("[pdeq_vrfy %p] ", dq);
assert ( dq
&& (dq->cookie == PDEQ_COOKIE1)
&& (dq->l_end && dq->r_end));
q = dq->l_end;
while (q) {
assert ( ((q == dq) || (q->cookie == PDEQ_COOKIE2))
&& ((q == dq->l_end) ^ (q->l!=0))
&& ((q == dq->r_end) ^ (q->r!=0))
&& (!q->l || (q == q->l->r))
&& ((q->n>=0) && (q->n<=NDATA))
&& ((q == dq->l_end) || (q == dq->r_end) || (q->n == NDATA))
&& ((q->p>=0) && (q->p<NDATA)));
q = q->r;
}
}
#endif
pdeq *
new_pdeq (void)
{
pdeq *dq;
dq = alloc_pdeq_block();
#ifndef NDEBUG
dq->cookie = PDEQ_COOKIE1;
#endif
dq->l_end = dq->r_end = dq;
dq->l = dq->r = NULL;
dq->n = dq->p = 0;
VRFY (dq);
if (d_ (df_pdeq, 1)) printf ("(new_pdeq ==> %p)\n", dq);
return dq;
}
pdeq *
new_pdeq1 (const void *x)
{
return