Mercurial > projects > ldc
view dmd/mem.c @ 986:a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Note: For a backward compatible interface, use the new bin/ldmd script. It
supports all old options while passing on anything it doesn't recognize.
Some changes caused by this:
* -debug and -version are now -d-debug and -d-version due to a conflict with
standard LLVM options.
* All "flag" options now allow an optional =true/=1/=false/=0 suffix.
* Some "hidden debug switches" starting with "--" were renamed because LLVM
doesn't care about the number of dashes, so they were conflicting with other
options (such as -c).
The new versions start with "-hidden-debug-" instead of "--"
* --help works, but has a non-zero exit code. This breaks some Tango scripts
which use it to test for compiler existence. See tango.patch.
Some changes not (directly) caused by this;
* (-enable/-disable)-FOO options are now available for pre- and postconditions.
* -march is used instead of -m (like other LLVM programs), but -m is an alias
for it.
* -defaultlib, -debuglib, -d-debug and -d-version allow comma-separated values.
The effect should be identical to specifying the same option multiple times.
I decided against allowing these for some other options because paths might
contain commas on some systems.
* -fPIC is removed in favor of the standard LLVM option -relocation-model=pic
Bug:
* If -run is specified as the last argument in DFLAGS, no error is generated.
(Not very serious IMHO)
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Wed, 25 Feb 2009 17:34:51 +0100 |
parents | 967178e31a13 |
children | b30fe7e1dbb9 |
line wrap: on
line source
/* Copyright (c) 2000 Digital Mars */ /* All Rights Reserved */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include "mem.h" #if USE_BOEHM_GC // I needed to perfix the dir after upgrading to gc 7.0 #include "gc/gc.h" #endif /* This implementation of the storage allocator uses the standard C allocation package. */ Mem mem; #if USE_BOEHM_GC static bool gc_was_init = false; void Mem::init() { GC_init(); gc_was_init = true; } char *Mem::strdup(const char *s) { char *p; if (s) { p = GC_strdup(s); if (p) return p; error(); } return NULL; } void *Mem::malloc(size_t size) { void *p; if (!size) p = NULL; else { p = GC_malloc(size); if (!p) error(); } return p; } void *Mem::calloc(size_t size, size_t n) { void *p; if (!size || !n) p = NULL; else { p = GC_malloc(size * n); if (!p) error(); memset(p, 0, size * n); } return p; } void *Mem::realloc(void *p, size_t size) { if (!size) { if (p) { GC_free(p); p = NULL; } } else if (!p) { p = GC_malloc(size); if (!p) error(); } else { p = GC_realloc(p, size); if (!p) error(); } return p; } void Mem::free(void *p) { if (p) GC_free(p); } void *Mem::mallocdup(void *o, size_t size) { void *p; if (!size) p = NULL; else { p = GC_malloc(size); if (!p) error(); else memcpy(p,o,size); } return p; } void Mem::error() { printf("Error: out of memory\n"); exit(EXIT_FAILURE); } void Mem::fullcollect() { GC_gcollect(); } void Mem::mark(void *pointer) { (void) pointer; // necessary for VC /W4 } /* =================================================== */ void * operator new(size_t m_size) { // without this we segfault with gc 7.0 if (!gc_was_init) { mem.init(); } void *p = GC_malloc(m_size); if (p) return p; printf("Error: out of memory\n"); exit(EXIT_FAILURE); return p; } void operator delete(void *p) { GC_free(p); } #elif !USE_BOEHM_GC void Mem::init() { } char *Mem::strdup(const char *s) { char *p; if (s) { p = ::strdup(s); if (p) return p; error(); } return NULL; } void *Mem::malloc(size_t size) { void *p; if (!size) p = NULL; else { p = ::malloc(size); if (!p) error(); } return p; } void *Mem::calloc(size_t size, size_t n) { void *p; if (!size || !n) p = NULL; else { p = ::malloc(size * n); if (!p) error(); memset(p, 0, size * n); } return p; } void *Mem::realloc(void *p, size_t size) { if (!size) { if (p) { ::free(p); p = NULL; } } else if (!p) { p = ::malloc(size); if (!p) error(); } else { p = ::realloc(p, size); if (!p) error(); } return p; } void Mem::free(void *p) { if (p) ::free(p); } void *Mem::mallocdup(void *o, size_t size) { void *p; if (!size) p = NULL; else { p = ::malloc(size); if (!p) error(); else memcpy(p,o,size); } return p; } void Mem::error() { printf("Error: out of memory\n"); exit(EXIT_FAILURE); } void Mem::fullcollect() { } void Mem::mark(void *pointer) { } #endif // USE_BOEHM_GC