diff --git a/src/dmd/backend/aa.c b/src/dmd/backend/aa.c deleted file mode 100644 index f06510d954b9..000000000000 --- a/src/dmd/backend/aa.c +++ /dev/null @@ -1,509 +0,0 @@ -/** - * Compiler implementation of the - * $(LINK2 http://www.dlang.org, D programming language). - * - * Copyright: Copyright (C) 2000-2018 by The D Language Foundation, All Rights Reserved - * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) - * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) - * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/aa.c, backend/aa.c) - */ - - -#include -#include -#include -#include - -#include "tinfo.h" -#include "aa.h" - -// Implementation of associative array -// Auto-rehash and pre-allocate - Dave Fladebo - -static unsigned long prime_list[] = -{ - 97UL, 389UL, - 1543UL, 6151UL, - 24593UL, 98317UL, - 393241UL, 1572869UL, - 6291469UL, 25165843UL, - 100663319UL, 402653189UL, - 1610612741UL, 4294967291UL -}; - - -/********************************** - * Align to next pointer boundary, so value - * will be aligned. - */ - -size_t aligntsize(size_t tsize) -{ - // Is pointer alignment on the x64 4 bytes or 8? - return (tsize + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1); -} - -static int hashCmp(hash_t lhs, hash_t rhs) -{ - if (lhs == rhs) - return 0; - else if (lhs < rhs) - return -1; - return 1; -} - -/********************************** - * Constructor. - */ - -AArray::AArray(TypeInfo *keyti, size_t valuesize) -{ - this->keyti = keyti; - this->valuesize = valuesize; - this->nodes = 0; - this->buckets = NULL; - this->buckets_length = 0; -} - - -/********************************** - * Destructor. - */ - -void delnodes(aaA* e) -{ aaA* en; - - do - { - if (e->left) - { if (!e->right) - { en = e; - e = e->left; - delete [] en; - continue; - } - delnodes(e->left); - } - en = e; - e = e->right; - delete [] en; - } while (e != NULL); -} - -AArray::~AArray() -{ - if (buckets) - { - for (size_t i = 0; i < buckets_length; i++) - { aaA* e = buckets[i]; - - if (e) - delnodes(e); // recursively free all nodes - } - delete [] buckets; - } -} - - -/************************************************* - * Get pointer to value in associative array indexed by key. - * Add entry for key if it is not already there. - */ - -void* AArray::get(void *pkey) -{ - //printf("AArray::get()\n"); - size_t i; - aaA* e; - const size_t keysize = keyti->tsize(); - const size_t aligned_keysize = aligntsize(keysize); - - if (!buckets_length) - { - typedef aaA* aaAp; - buckets_length = prime_list[0]; - buckets = new aaAp[buckets_length]; - memset(buckets, 0, buckets_length * sizeof(buckets[0])); - } - - hash_t key_hash = keyti->getHash(pkey); - i = key_hash % buckets_length; - //printf("key_hash = %x, buckets_length = %d, i = %d\n", key_hash, buckets_length, i); - aaA** pe = &buckets[i]; - while ((e = *pe) != NULL) - { int c; - - c = hashCmp(key_hash, e->hash); - if (c == 0) - { - c = keyti->compare(pkey, e + 1); - if (c == 0) - goto Lret; - } - - if (c < 0) - pe = &e->left; - else - pe = &e->right; - } - - // Not found, create new elem - //printf("create new one\n"); - e = (aaA *) new char[sizeof(aaA) + aligned_keysize + valuesize]; - memcpy(e + 1, pkey, keysize); - memset((unsigned char *)(e + 1) + aligned_keysize, 0, valuesize); - e->hash = key_hash; - e->left = NULL; - e->right = NULL; - *pe = e; - - ++nodes; - //printf("length = %d, nodes = %d\n", buckets_length, nodes); - if (nodes > buckets_length * 4) - { - //printf("rehash()\n"); - rehash(); - } - -Lret: - return (void *)((char *)(e + 1) + aligned_keysize); -} - - -/************************************************* - * Determine if key is in aa. - * Returns: - * NULL not in aa - * !=NULL in aa, return pointer to value - */ - -void* AArray::in(void *pkey) -{ - //printf("_aaIn(), .length = %d, .ptr = %x\n", aa.a.length, cast(uint)aa.a.ptr); - size_t len = buckets_length; - - if (len) - { - hash_t key_hash = keyti->getHash(pkey); - //printf("hash = %d\n", key_hash); - size_t i = key_hash % len; - aaA *e = buckets[i]; - while (e != NULL) - { int c; - - c = hashCmp(key_hash, e->hash); - if (c == 0) - { - c = keyti->compare(pkey, e + 1); - if (c == 0) - return (char *)(e + 1) + aligntsize(keyti->tsize()); - } - - if (c < 0) - e = e->left; - else - e = e->right; - } - } - - // Not found - return NULL; -} - - -/************************************************* - * Delete key entry in aa[]. - * If key is not in aa[], do nothing. - */ - -void AArray::del(void *pkey) -{ - aaA* e; - - if (buckets_length) - { - hash_t key_hash = keyti->getHash(pkey); - //printf("hash = %d\n", key_hash); - size_t i = key_hash % buckets_length; - aaA** pe = &buckets[i]; - while ((e = *pe) != NULL) // NULL means not found - { int c; - - c = hashCmp(key_hash, e->hash); - if (c == 0) - { - c = keyti->compare(pkey, e + 1); - if (c == 0) - { - if (!e->left && !e->right) - { - *pe = NULL; - } - else if (e->left && !e->right) - { - *pe = e->left; - e->left = NULL; - } - else if (!e->left && e->right) - { - *pe = e->right; - e->right = NULL; - } - else - { - *pe = e->left; - e->left = NULL; - do - pe = &(*pe)->right; - while (*pe); - *pe = e->right; - e->right = NULL; - } - - nodes--; - - delete[] e; - break; - } - } - - if (c < 0) - pe = &e->left; - else - pe = &e->right; - } - } -} - - -/******************************************** - * Produce array of keys from aa. - */ - -void *AArray::keys() -{ - void *p = NULL; - - if (nodes) - { - size_t keysize = keyti->tsize(); - - typedef char* charp; - p = (void *)new charp[nodes * keysize]; - void *q = p; - for (size_t i = 0; i < buckets_length; i++) - { aaA* e = buckets[i]; - - if (e) - q = keys_x(e, q, keysize); - } - } - return p; -} - -void *AArray::keys_x(aaA* e, void *p, size_t keysize) -{ - do - { - memcpy(p, e + 1, keysize); - if (e->left) - { if (!e->right) - { e = e->left; - continue; - } - p = keys_x(e->left, p, keysize); - } - e = e->right; - } while (e != NULL); - return p; -} - -/******************************************** - * Produce array of values from aa. - */ - -void *AArray::values() -{ - void *p = NULL; - - if (nodes) - { - p = (void *)new char[nodes * valuesize]; - void *q = p; - for (size_t i = 0; i < buckets_length; i++) - { aaA *e = buckets[i]; - - if (e) - q = values_x(e, q); - } - } - return p; -} - -void *AArray::values_x(aaA *e, void *p) -{ - const size_t keysize = keyti->tsize(); - const size_t aligned_keysize = aligntsize(keysize); - do - { - memcpy(p, - (char *)(e + 1) + aligned_keysize, - valuesize); - p = (void *)((char *)p + valuesize); - if (e->left) - { if (!e->right) - { e = e->left; - continue; - } - p = values_x(e->left, p); - } - e = e->right; - } while (e != NULL); - return p; -} - - -/******************************************** - * Rehash an array. - */ - -void AArray::rehash() -{ - //printf("Rehash\n"); - if (buckets_length) - { - size_t len = nodes; - - if (len) - { size_t i; - aaA** newbuckets; - size_t newbuckets_length; - - for (i = 0; i < sizeof(prime_list)/sizeof(prime_list[0]) - 1; i++) - { - if (len <= prime_list[i]) - break; - } - newbuckets_length = prime_list[i]; - typedef aaA* aaAp; - newbuckets = new aaAp[newbuckets_length]; - memset(newbuckets, 0, newbuckets_length * sizeof(newbuckets[0])); - - for (i = 0; i < buckets_length; i++) - { aaA *e = buckets[i]; - - if (e) - rehash_x(e, newbuckets, newbuckets_length); - } - - delete[] buckets; - buckets = newbuckets; - buckets_length = newbuckets_length; - } - } -} - -void AArray::rehash_x(aaA* olde, aaA** newbuckets, size_t newbuckets_length) -{ - while (1) - { - aaA* left = olde->left; - aaA* right = olde->right; - olde->left = NULL; - olde->right = NULL; - - aaA* e; - - //printf("rehash %p\n", olde); - hash_t key_hash = olde->hash; - size_t i = key_hash % newbuckets_length; - aaA** pe = &newbuckets[i]; - while ((e = *pe) != NULL) - { int c; - - //printf("\te = %p, e->left = %p, e->right = %p\n", e, e->left, e->right); - assert(e->left != e); - assert(e->right != e); - c = hashCmp(key_hash, e->hash); - if (c == 0) - c = keyti->compare(olde + 1, e + 1); - if (c < 0) - pe = &e->left; - else if (c > 0) - pe = &e->right; - else - assert(0); - } - *pe = olde; - - if (right) - { - if (!left) - { olde = right; - continue; - } - rehash_x(right, newbuckets, newbuckets_length); - } - if (!left) - break; - olde = left; - } -} - - -/********************************************* - * For each element in the AArray, - * call dg(void *parameter, void *pkey, void *pvalue) - * If dg returns !=0, stop and return that value. - */ - -typedef int (*dg2_t)(void *, void *, void *); - -int AArray::apply(void *parameter, dg2_t dg) -{ int result = 0; - - //printf("_aaApply(aa = %p, keysize = %d, dg = %p)\n", this, keyti->tsize(), dg); - - if (nodes) - { - const size_t keysize = keyti->tsize(); - const size_t aligned_keysize = aligntsize(keysize); - - for (size_t i = 0; i < buckets_length; i++) - { aaA* e = buckets[i]; - - if (e) - { - result = apply_x(e, dg, aligned_keysize, parameter); - if (result) - break; - } - } - } - return result; -} - -int AArray::apply_x(aaA* e, dg2_t dg, size_t aligned_keysize, void *parameter) -{ int result; - - do - { - //printf("apply_x(e = %p, dg = %p)\n", e, dg); - result = (*dg)(parameter, e + 1, (char *)(e + 1) + aligned_keysize); - if (result) - break; - if (e->right) - { if (!e->left) - { - e = e->right; - continue; - } - result = apply_x(e->right, dg, aligned_keysize, parameter); - if (result) - break; - } - e = e->left; - } while (e); - - return result; -} diff --git a/src/dmd/backend/aa.h b/src/dmd/backend/aa.h index f20e77ce4ed1..09f811bce4eb 100644 --- a/src/dmd/backend/aa.h +++ b/src/dmd/backend/aa.h @@ -12,97 +12,22 @@ #ifndef AA_H #define AA_H -#include +typedef size_t hash_t; -#include "tinfo.h" - -struct aaA +struct AAchars { - aaA *left; - aaA *right; - hash_t hash; - /* key */ - /* value */ + static AAchars* create(); + static void destroy(AAchars*); + uint* get(const char *s, unsigned len); + uint length(); }; -struct AArray +struct AApair { - TypeInfo *keyti; - size_t valuesize; - size_t nodes; - - aaA** buckets; - size_t buckets_length; - - AArray(TypeInfo *keyti, size_t valuesize); - - ~AArray(); - - size_t length() - { - return nodes; - } - - /************************************************* - * Get pointer to value in associative array indexed by key. - * Add entry for key if it is not already there. - */ - - void* get(void *pkey); - - void* get(char *string) { return get(&string); } - - /************************************************* - * Determine if key is in aa. - * Returns: - * null not in aa - * !=null in aa, return pointer to value - */ - - void* in(void *pkey); - - void* in(char *string) { return in(&string); } - - /************************************************* - * Delete key entry in aa[]. - * If key is not in aa[], do nothing. - */ - - void del(void *pkey); - - /******************************************** - * Produce array of keys from aa. - */ - - void *keys(); - - /******************************************** - * Produce array of values from aa. - */ - - void *values(); - - /******************************************** - * Rehash an array. - */ - - void rehash(); - - /********************************************* - * For each element in the AArray, - * call dg(void *parameter, void *pkey, void *pvalue) - * If dg returns !=0, stop and return that value. - */ - - typedef int (*dg2_t)(void *, void *, void *); - - int apply(void *parameter, dg2_t dg); - - private: - void *keys_x(aaA* e, void *p, size_t keysize); - void *values_x(aaA *e, void *p); - void rehash_x(aaA* olde, aaA** newbuckets, size_t newbuckets_length); - int apply_x(aaA* e, dg2_t dg, size_t keysize, void *parameter); + static AApair* create(unsigned char** pbase); + static void destroy(AApair*); + uint* get(uint start, uint end); + uint length(); }; #endif diff --git a/src/dmd/backend/aarray.d b/src/dmd/backend/aarray.d new file mode 100644 index 000000000000..c003e27bd354 --- /dev/null +++ b/src/dmd/backend/aarray.d @@ -0,0 +1,587 @@ +/** + * Compiler implementation of the + * $(LINK2 http://www.dlang.org, D programming language). + * + * Copyright: Copyright (c) 2000-2018 by Digital Mars, All Rights Reserved + * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright), Dave Fladebo + * License: Distributed under the Boost Software License, Version 1.0. + * http://www.boost.org/LICENSE_1_0.txt + * Source: https://github.com/dlang/dmd/blob/master/src/dmd/backend/aarray.d + */ + +module dmd.backend.aarray; + +import core.stdc.stdio; +import core.stdc.stdlib; +import core.stdc.string; + +alias hash_t = size_t; + +/********************* + * This is the "bucket" used by the AArray. + */ +private struct aaA +{ + aaA *next; + hash_t hash; // hash of the key + /* key */ // key value goes here + /* value */ // value value goes here +} + +/************************** + * Associative Array type. + * Params: + * TKey = type that has members Key, getHash(), and equals() + * Value = value type + */ + +struct AArray(TKey, Value) +{ + alias Key = TKey.Key; // key type + + ~this() + { + destroy(); + } + + /**** + * Frees all the data used by AArray + */ + void destroy() + { + if (buckets) + { + foreach (e; buckets) + { + while (e) + { + auto en = e; + e = e.next; + free(en); + } + } + free(buckets.ptr); + buckets = null; + nodes = 0; + } + } + + /******** + * Returns: + * Number of entries in the AArray + */ + size_t length() + { + return nodes; + } + + /************************************************* + * Get pointer to value in associative array indexed by key. + * Add entry for key if it is not already there. + * Params: + * pKey = pointer to key + * Returns: + * pointer to Value + */ + + Value* get(Key* pkey) + { + //printf("AArray::get()\n"); + const aligned_keysize = aligntsize(Key.sizeof); + + if (!buckets.length) + { + alias aaAp = aaA*; + const len = prime_list[0]; + auto p = cast(aaAp*)calloc(len, aaAp.sizeof); + assert(p); + buckets = p[0 .. len]; + } + + hash_t key_hash = tkey.getHash(pkey); + const i = key_hash % buckets.length; + //printf("key_hash = %x, buckets.length = %d, i = %d\n", key_hash, buckets.length, i); + aaA* e; + auto pe = &buckets[i]; + while ((e = *pe) != null) + { + if (key_hash == e.hash && + tkey.equals(pkey, cast(Key*)(e + 1))) + { + goto Lret; + } + pe = &e.next; + } + + // Not found, create new elem + //printf("create new one\n"); + e = cast(aaA *) malloc(aaA.sizeof + aligned_keysize + Value.sizeof); + assert(e); + memcpy(e + 1, pkey, Key.sizeof); + memset(cast(void *)(e + 1) + aligned_keysize, 0, Value.sizeof); + e.hash = key_hash; + e.next = null; + *pe = e; + + ++nodes; + //printf("length = %d, nodes = %d\n", buckets_length, nodes); + if (nodes > buckets.length * 4) + { + //printf("rehash()\n"); + rehash(); + } + + Lret: + return cast(Value*)(cast(void*)(e + 1) + aligned_keysize); + } + + /************************************************* + * Determine if key is in aa. + * Params: + * pKey = pointer to key + * Returns: + * null not in aa + * !=null in aa, return pointer to value + */ + + Value* isIn(Key* pkey) + { + //printf("AArray.isIn(), .length = %d, .ptr = %p\n", nodes, buckets.ptr); + if (!nodes) + return null; + + const key_hash = tkey.getHash(pkey); + //printf("hash = %d\n", key_hash); + const i = key_hash % buckets.length; + auto e = buckets[i]; + while (e != null) + { + if (key_hash == e.hash && + tkey.equals(pkey, cast(Key*)(e + 1))) + { + return cast(Value*)(cast(void*)(e + 1) + aligntsize(Key.sizeof)); + } + + e = e.next; + } + + // Not found + return null; + } + + + /************************************************* + * Delete key entry in aa[]. + * If key is not in aa[], do nothing. + * Params: + * pKey = pointer to key + */ + + void del(Key *pkey) + { + if (!nodes) + return; + + const key_hash = tkey.getHash(pkey); + //printf("hash = %d\n", key_hash); + const i = key_hash % buckets.length; + auto pe = &buckets[i]; + aaA* e; + while ((e = *pe) != null) // null means not found + { + if (key_hash == e.hash && + tkey.equals(pkey, cast(Key*)(e + 1))) + { + *pe = e.next; + --nodes; + free(e); + break; + } + pe = &e.next; + } + } + + + /******************************************** + * Produce array of keys from aa. + * Returns: + * malloc'd array of keys + */ + + Key[] keys() + { + if (!nodes) + return null; + + auto p = cast(Key *)malloc(nodes * Key.sizeof); + assert(p); + auto q = p; + foreach (e; buckets) + { + while (e) + { + memcpy(q, e + 1, Key.sizeof); + ++q; + e = e.next; + } + } + return p[0 .. nodes]; + } + + /******************************************** + * Produce array of values from aa. + * Returns: + * malloc'd array of values + */ + + Value[] values() + { + if (!nodes) + return null; + + const aligned_keysize = aligntsize(Key.sizeof); + auto p = cast(Value *)malloc(nodes * Value.sizeof); + assert(p); + auto q = p; + foreach (e; buckets) + { + while (e) + { + memcpy(q, cast(void*)(e + 1) + aligned_keysize, Value.sizeof); + ++q; + e = e.next; + } + } + return p[0 .. nodes]; + } + + /******************************************** + * Rehash an array. + */ + + void rehash() + { + //printf("Rehash\n"); + if (!nodes) + return; + + size_t newbuckets_length = prime_list[$ - 1]; + + foreach (prime; prime_list[0 .. $ - 1]) + { + if (nodes <= prime) + { + newbuckets_length = prime; + break; + } + } + auto newbuckets = cast(aaA**)calloc(newbuckets_length, (aaA*).sizeof); + assert(newbuckets); + + foreach (e; buckets) + { + while (e) + { + auto en = e.next; + auto b = &newbuckets[e.hash % newbuckets_length]; + e.next = *b; + *b = e; + e = en; + } + } + + free(buckets.ptr); + buckets = null; + buckets = newbuckets[0 .. newbuckets_length]; + } + + + /********************************************* + * For each element in the AArray, + * call dg(Key* pkey, Value* pvalue) + * If dg returns !=0, stop and return that value. + * Params: + * dg = delegate to call for each key/value pair + * Returns: + * !=0 : value returned by first dg() call that returned non-zero + * 0 : no entries in aa, or all dg() calls returned 0 + */ + + int apply(int delegate(Key*, Value*) dg) + { + if (!nodes) + return 0; + + //printf("AArray.apply(aa = %p, keysize = %d, dg = %p)\n", &this, Key.sizeof, dg); + + const aligned_keysize = aligntsize(Key.sizeof); + + foreach (e; buckets) + { + while (e) + { + auto result = dg(cast(Key*)(e + 1), cast(Value*)(e + 1) + aligned_keysize); + if (result) + return result; + e = e.next; + } + } + + return 0; + } + + private: + + aaA*[] buckets; + size_t nodes; // number of nodes + TKey tkey; +} + +private: + +/********************************** + * Align to next pointer boundary, so value + * will be aligned. + * Params: + * tsize = offset to be aligned + * Returns: + * aligned offset + */ + +size_t aligntsize(size_t tsize) +{ + // Is pointer alignment on the x64 4 bytes or 8? + return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); +} + +immutable uint[14] prime_list = +[ + 97U, 389U, + 1543U, 6151U, + 24593U, 98317U, + 393241U, 1572869U, + 6291469U, 25165843U, + 100663319U, 402653189U, + 1610612741U, 4294967291U +]; + +/***************************************************************/ + +/*** + * A TKey for basic types + * Params: + * K = a basic type + */ +public struct Tinfo(K) +{ + alias Key = K; + + static hash_t getHash(Key* pk) + { + return cast(hash_t)*pk; + } + + static bool equals(Key* pk1, Key* pk2) + { + return *pk1 == *pk2; + } +} + +/***************************************************************/ + +/**** + * A TKey that is a string + */ +public struct TinfoChars +{ + alias Key = const(char)[]; + + static hash_t getHash(Key* pk) + { + auto buf = *pk; + hash_t hash = 0; + foreach (v; buf) + hash = hash * 11 + v; + return hash; + } + + static bool equals(Key* pk1, Key* pk2) + { + auto buf1 = *pk1; + auto buf2 = *pk2; + return buf1.length == buf2.length && + memcmp(buf1.ptr, buf2.ptr, buf1.length) == 0; + } +} + +// Interface for C++ code +extern (C++) struct AAchars +{ + alias AA = AArray!(TinfoChars, uint); + AA aa; + + static AAchars* create() + { + auto a = cast(AAchars*)calloc(1, AAchars.sizeof); + assert(a); + return a; + } + + static void destroy(AAchars* aac) + { + aac.aa.destroy(); + free(aac); + } + + uint* get(const(char)* s, uint len) + { + auto buf = s[0 .. len]; + return aa.get(&buf); + } + + uint length() + { + return cast(uint)aa.length(); + } +} + +/***************************************************************/ + +// Key is the slice specified by (*TinfoPair.pbase)[Pair.start .. Pair.end] + +struct Pair { uint start, end; } + +public struct TinfoPair +{ + alias Key = Pair; + + ubyte** pbase; + + hash_t getHash(Key* pk) + { + auto buf = (*pbase)[pk.start .. pk.end]; + hash_t hash = 0; + foreach (v; buf) + hash = hash * 11 + v; + return hash; + } + + bool equals(Key* pk1, Key* pk2) + { + const len1 = pk1.end - pk1.start; + const len2 = pk2.end - pk2.start; + + auto buf1 = *pk1; + auto buf2 = *pk2; + return len1 == len2 && + memcmp(*pbase + pk1.start, *pbase + pk2.start, len1) == 0; + } +} + +// Interface for C++ code +extern (C++) struct AApair +{ + alias AA = AArray!(TinfoPair, uint); + AA aa; + + static AApair* create(ubyte** pbase) + { + auto a = cast(AApair*)calloc(1, AApair.sizeof); + assert(a); + a.aa.tkey.pbase = pbase; + return a; + } + + static void destroy(AApair* aap) + { + aap.aa.destroy(); + free(aap); + } + + uint* get(uint start, uint end) + { + auto p = Pair(start, end); + return aa.get(&p); + } + + uint length() + { + return cast(uint)aa.length(); + } +} + +/*************************************************************/ + +version (none) +{ + +/* Since -betterC doesn't support unittests, do it this way + * for the time being. + * This is a stand-alone file anyway. + */ + +int main() +{ + testAArray(); + testAApair(); + + return 0; +} + +void testAArray() +{ + int dg(int* pk, bool* pv) { return 3; } + int dgz(int* pk, bool* pv) { return 0; } + + AArray!(Tinfo!int, bool) aa; + aa.rehash(); + assert(aa.keys() == null); + assert(aa.values() == null); + assert(aa.apply(&dg) == 0); + + assert(aa.length == 0); + int k = 8; + aa.del(&k); + bool v = true; + assert(!aa.isIn(&k)); + bool *pv = aa.get(&k); + *pv = true; + int j = 9; + pv = aa.get(&j); + *pv = false; + aa.rehash(); + + assert(aa.length() == 2); + assert(*aa.get(&k) == true); + assert(*aa.get(&j) == false); + + assert(aa.apply(&dg) == 3); + assert(aa.apply(&dgz) == 0); + + aa.del(&k); + assert(aa.length() == 1); + assert(!aa.isIn(&k)); + assert(*aa.isIn(&j) == false); + + auto keys = aa.keys(); + assert(keys.length == 1); + assert(keys[0] == 9); + + auto values = aa.values(); + assert(values.length == 1); + assert(values[0] == false); +} + +void testAApair() +{ + const(char)* buf = "abcb"; + auto aap = AApair.create(cast(ubyte**)&buf); + auto pu = aap.get(1,2); + *pu = 10; + assert(aap.length == 1); + pu = aap.get(3,4); + assert(*pu == 10); + AApair.destroy(aap); +} + +} diff --git a/src/dmd/backend/dwarf.c b/src/dmd/backend/dwarf.c index 901dca5851e7..c759e8d0bb04 100644 --- a/src/dmd/backend/dwarf.c +++ b/src/dmd/backend/dwarf.c @@ -56,7 +56,6 @@ application if debug info is needed when the application is deployed. #include "dt.h" #include "aa.h" -#include "tinfo.h" #if ELFOBJ #include "melf.h" @@ -523,84 +522,16 @@ const char* debug_frame_name = ".debug_frame"; * representing the abbreviation code itself." */ static uint abbrevcode = 1; -static AArray *abbrev_table; +static AApair *abbrev_table; static int hasModname; // 1 if has DW_TAG_module // .debug_info -static AArray *infoFileName_table; +static AAchars *infoFileName_table; -static AArray *type_table; -static AArray *functype_table; // not sure why this cannot be combined with type_table +static AApair *type_table; +static AApair *functype_table; // not sure why this cannot be combined with type_table static Outbuffer *functypebuf; -// typeinfo declarations for hash of char* - -struct Abuf -{ - const ubyte *buf; - size_t length; -}; - -struct TypeInfo_Abuf : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -TypeInfo_Abuf ti_abuf; - -const char* TypeInfo_Abuf::toString() -{ - return "Abuf"; -} - -hash_t TypeInfo_Abuf::getHash(void *p) -{ - Abuf a = *(Abuf *)p; - - hash_t hash = 0; - for (size_t i = 0; i < a.length; i++) - hash = hash * 11 + a.buf[i]; - - return hash; -} - -int TypeInfo_Abuf::equals(void *p1, void *p2) -{ - Abuf a1 = *(Abuf*)p1; - Abuf a2 = *(Abuf*)p2; - - return a1.length == a2.length && - memcmp(a1.buf, a2.buf, a1.length) == 0; -} - -int TypeInfo_Abuf::compare(void *p1, void *p2) -{ - Abuf a1 = *(Abuf*)p1; - Abuf a2 = *(Abuf*)p2; - - if (a1.length == a2.length) - return memcmp(a1.buf, a2.buf, a1.length); - else if (a1.length < a2.length) - return -1; - else - return 1; -} - -size_t TypeInfo_Abuf::tsize() -{ - return sizeof(Abuf); -} - -void TypeInfo_Abuf::swap(void *p1, void *p2) -{ - assert(0); -} - #pragma pack(1) struct DebugInfoHeader { uint total_length; @@ -1076,7 +1007,8 @@ void dwarf_initfile(const char *filename) /* ======================================== */ if (infoFileName_table) - { delete infoFileName_table; + { + AAchars::destroy(infoFileName_table); infoFileName_table = null; } @@ -1110,7 +1042,8 @@ void dwarf_initfile(const char *filename) // Free only if starting another file. Waste of time otherwise. if (abbrev_table) - { delete abbrev_table; + { + AApair::destroy(abbrev_table); abbrev_table = null; } @@ -1240,15 +1173,11 @@ void dwarf_initfile(const char *filename) int dwarf_line_addfile(const char* filename) { if (!infoFileName_table) { - infoFileName_table = new AArray(&ti_abuf, sizeof(uint)); + infoFileName_table = AAchars::create(); linebuf_filetab_end = debug_line.buf->size(); } - Abuf abuf; - abuf.buf = (const ubyte*)filename; - abuf.length = strlen(filename); - - uint *pidx = cast(uint *)infoFileName_table->get(&abuf); + uint *pidx = infoFileName_table->get(filename, strlen(filename)); if (!*pidx) // if no idx assigned yet { *pidx = infoFileName_table->length(); // assign newly computed idx @@ -1478,11 +1407,13 @@ void dwarf_termfile() // Free only if starting another file. Waste of time otherwise. if (type_table) - { delete type_table; + { + AApair::destroy(type_table); type_table = null; } if (functype_table) - { delete functype_table; + { + AApair::destroy(functype_table); functype_table = null; } if (functypebuf) @@ -1945,75 +1876,6 @@ void cv_func(Funcsym *s) /* =================== Cached Types in debug_info ================= */ -struct Atype -{ - Outbuffer *buf; - size_t start; - size_t end; -}; - -struct TypeInfo_Atype : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -TypeInfo_Atype ti_atype; - -const char* TypeInfo_Atype::toString() -{ - return "Atype"; -} - -hash_t TypeInfo_Atype::getHash(void *p) -{ - hash_t hash = 0; - - Atype a = *cast(Atype *)p; - for (size_t i = a.start; i < a.end; i++) - { - hash = hash * 11 + a.buf->buf[i]; - } - return hash; -} - -int TypeInfo_Atype::equals(void *p1, void *p2) -{ - Atype a1 = *cast(Atype*)p1; - Atype a2 = *cast(Atype*)p2; - size_t len = a1.end - a1.start; - - return len == a2.end - a2.start && - memcmp(a1.buf->buf + a1.start, a2.buf->buf + a2.start, len) == 0; -} - -int TypeInfo_Atype::compare(void *p1, void *p2) -{ - Atype a1 = *cast(Atype*)p1; - Atype a2 = *cast(Atype*)p2; - size_t len = a1.end - a1.start; - if (len == a2.end - a2.start) - return memcmp(a1.buf->buf + a1.start, a2.buf->buf + a2.start, len); - else if (len < a2.end - a2.start) - return -1; - else - return 1; -} - -size_t TypeInfo_Atype::tsize() -{ - return sizeof(Atype); -} - -void TypeInfo_Atype::swap(void *p1, void *p2) -{ - assert(0); -} - ubyte dwarf_classify_struct(uint sflags) { if (sflags & STRclass) @@ -2410,12 +2272,8 @@ uint dwarf_typidx(type *t) /* If it's in the cache already, return the existing typidx */ if (!functype_table) - functype_table = new AArray(&ti_atype, sizeof(uint)); - Atype functype; - functype.buf = functypebuf; - functype.start = functypebufidx; - functype.end = functypebuf->size(); - uint *pidx = cast(uint *)functype_table->get(&functype); + functype_table = AApair::create(&functypebuf->buf); + uint *pidx = cast(uint *)functype_table->get(functypebufidx, functypebuf->size()); if (*pidx) { // Reuse existing typidx functypebuf->setsize(functypebufidx); @@ -2839,19 +2697,13 @@ uint dwarf_typidx(type *t) /* If debug_info.buf->buf[idx .. size()] is already in debug_info.buf, * discard this one and use the previous one. */ - Atype atype; - atype.buf = debug_info.buf; - atype.start = idx; - atype.end = debug_info.buf->size(); - if (!type_table) /* uint[Adata] type_table; * where the table values are the type indices */ - type_table = new AArray(&ti_atype, sizeof(uint)); + type_table = AApair::create(&debug_info.buf->buf); - uint *pidx; - pidx = cast(uint *)type_table->get(&atype); + uint *pidx = type_table->get(idx, debug_info.buf->size()); if (!*pidx) // if no idx assigned yet { *pidx = idx; // assign newly computed idx @@ -2866,76 +2718,6 @@ uint dwarf_typidx(type *t) /* ======================= Abbreviation Codes ====================== */ -struct Adata -{ - size_t start; - size_t end; -}; - -struct TypeInfo_Adata : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -TypeInfo_Adata ti_adata; - -const char* TypeInfo_Adata::toString() -{ - return "Adata"; -} - -hash_t TypeInfo_Adata::getHash(void *p) -{ - hash_t hash = 0; - - Adata a = *cast(Adata *)p; - for (size_t i = a.start; i < a.end; i++) - { - //printf("%02x ", debug_abbrev.buf->buf[i]); - hash = hash * 11 + debug_abbrev.buf->buf[i]; - } - //printf("\nhash = %x, length = %d\n", hash, a.end - a.start); - return hash; -} - -int TypeInfo_Adata::equals(void *p1, void *p2) -{ - Adata a1 = *cast(Adata*)p1; - Adata a2 = *cast(Adata*)p2; - size_t len = a1.end - a1.start; - - return len == a2.end - a2.start && - memcmp(debug_abbrev.buf->buf + a1.start, debug_abbrev.buf->buf + a2.start, len) == 0; -} - -int TypeInfo_Adata::compare(void *p1, void *p2) -{ - Adata a1 = *cast(Adata*)p1; - Adata a2 = *cast(Adata*)p2; - size_t len = a1.end - a1.start; - if (len == a2.end - a2.start) - return memcmp(debug_abbrev.buf->buf + a1.start, debug_abbrev.buf->buf + a2.start, len); - else if (len < a2.end - a2.start) - return -1; - else - return 1; -} - -size_t TypeInfo_Adata::tsize() -{ - return sizeof(Adata); -} - -void TypeInfo_Adata::swap(void *p1, void *p2) -{ - assert(0); -} - uint dwarf_abbrev_code(ubyte *data, size_t nbytes) { @@ -2943,25 +2725,23 @@ uint dwarf_abbrev_code(ubyte *data, size_t nbytes) /* uint[Adata] abbrev_table; * where the table values are the abbreviation codes. */ - abbrev_table = new AArray(&ti_adata, sizeof(uint)); + abbrev_table = AApair::create(&debug_abbrev.buf->buf); /* Write new entry into debug_abbrev.buf */ - Adata adata; uint idx = debug_abbrev.buf->size(); abbrevcode++; debug_abbrev.buf->writeuLEB128(abbrevcode); - adata.start = debug_abbrev.buf->size(); + size_t start = debug_abbrev.buf->size(); debug_abbrev.buf->write(data, nbytes); - adata.end = debug_abbrev.buf->size(); + size_t end = debug_abbrev.buf->size(); /* If debug_abbrev.buf->buf[idx .. size()] is already in debug_abbrev.buf, * discard this one and use the previous one. */ - uint *pcode; - pcode = cast(uint *)abbrev_table->get(&adata); + uint *pcode = abbrev_table->get(start, end); if (!*pcode) // if no code assigned yet { *pcode = abbrevcode; // assign newly computed code diff --git a/src/dmd/backend/elfobj.c b/src/dmd/backend/elfobj.c index c02f3a3f711d..1aec81851860 100644 --- a/src/dmd/backend/elfobj.c +++ b/src/dmd/backend/elfobj.c @@ -36,15 +36,11 @@ #include "dt.h" #include "aa.h" -#include "tinfo.h" #if ELFOBJ #include "dwarf.h" -#include "aa.h" -#include "tinfo.h" - #ifndef ELFOSABI # if TARGET_LINUX # define ELFOSABI ELFOSABI_LINUX @@ -166,73 +162,10 @@ static Outbuffer *section_names; #define SEC_NAMES_INC 400 // Hash table for section_names -AArray *section_names_hashtable; +AApair *section_names_hashtable; int jmpseg; -/* ====================== Cached Strings in section_names ================= */ - -struct TypeInfo_Idxstr : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -TypeInfo_Idxstr ti_idxstr; - -const char* TypeInfo_Idxstr::toString() -{ - return "IDXSTR"; -} - -hash_t TypeInfo_Idxstr::getHash(void *p) -{ - IDXSTR a = *(IDXSTR *)p; - hash_t hash = 0; - for (const char *s = (char *)(section_names->buf + a); - *s; - s++) - { - hash = hash * 11 + *s; - } - return hash; -} - -int TypeInfo_Idxstr::equals(void *p1, void *p2) -{ - IDXSTR a1 = *(IDXSTR*)p1; - IDXSTR a2 = *(IDXSTR*)p2; - const char *s1 = (char *)(section_names->buf + a1); - const char *s2 = (char *)(section_names->buf + a2); - - return strcmp(s1, s2) == 0; -} - -int TypeInfo_Idxstr::compare(void *p1, void *p2) -{ - IDXSTR a1 = *(IDXSTR*)p1; - IDXSTR a2 = *(IDXSTR*)p2; - const char *s1 = (char *)(section_names->buf + a1); - const char *s2 = (char *)(section_names->buf + a2); - - return strcmp(s1, s2); -} - -size_t TypeInfo_Idxstr::tsize() -{ - return sizeof(IDXSTR); -} - -void TypeInfo_Idxstr::swap(void *p1, void *p2) -{ - assert(0); -} - - /* ======================================================================== */ // String Table - String table for all other names @@ -641,7 +574,8 @@ static IDXSTR elf_addsectionname(const char *name, const char *suffix = NULL, bo section_names->setsize(section_names->size() - 1); // back up over terminating 0 section_names->writeString(suffix); } - IDXSTR *pidx = (IDXSTR *)section_names_hashtable->get(&namidx); + IDXSTR *pidx = section_names_hashtable->get(namidx, section_names->size() - 1); + //IDXSTR *pidx = (IDXSTR *)section_names_hashtable->get(&namidx); if (*pidx) { // this section name already exists, remove addition @@ -814,8 +748,10 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) } if (section_names_hashtable) - delete section_names_hashtable; - section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); + AApair::destroy(section_names_hashtable); + //delete section_names_hashtable; + section_names_hashtable = AApair::create(§ion_names->buf); + //section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); // name,type,flags,addr,offset,size,link,info,addralign,entsize elf_newsection2(0, SHT_NULL, 0, 0,0,0,0,0, 0,0); @@ -834,19 +770,19 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) elf_newsection2(NAMIDX_CDATAREL,SHT_PROGBITS,SHF_ALLOC|SHF_WRITE,0,0,0,0,0, 16,0); IDXSTR namidx; - namidx = NAMIDX_TEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELTEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_DATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELDATA64; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_BSS; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RODATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_STRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SYMTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SHSTRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_COMMENT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_NOTE; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_GNUSTACK; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_CDATAREL; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; + namidx = NAMIDX_TEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_RELTEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_DATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_RELDATA64; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_BSS; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_RODATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_STRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_SYMTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_SHSTRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_COMMENT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_NOTE; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_GNUSTACK; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; + namidx = NAMIDX_CDATAREL; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init64 + namidx)) = namidx; } else { @@ -862,8 +798,10 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) } if (section_names_hashtable) - delete section_names_hashtable; - section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); + AApair::destroy(section_names_hashtable); + //delete section_names_hashtable; + section_names_hashtable = AApair::create(§ion_names->buf); + //section_names_hashtable = new AArray(&ti_idxstr, sizeof(IDXSTR)); // name,type,flags,addr,offset,size,link,info,addralign,entsize elf_newsection2(0, SHT_NULL, 0, 0,0,0,0,0, 0,0); @@ -882,19 +820,19 @@ Obj *Obj::init(Outbuffer *objbuf, const char *filename, const char *csegname) elf_newsection2(NAMIDX_CDATAREL,SHT_PROGBITS,SHF_ALLOC|SHF_WRITE,0,0,0,0,0, 1,0); IDXSTR namidx; - namidx = NAMIDX_TEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELTEXT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_DATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RELDATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_BSS; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_RODATA; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_STRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SYMTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_SHSTRTAB; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_COMMENT; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_NOTE; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_GNUSTACK; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; - namidx = NAMIDX_CDATAREL; *(IDXSTR *)section_names_hashtable->get(&namidx) = namidx; + namidx = NAMIDX_TEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_RELTEXT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_DATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_RELDATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_BSS; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_RODATA; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_STRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_SYMTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_SHSTRTAB; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_COMMENT; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_NOTE; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_GNUSTACK; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; + namidx = NAMIDX_CDATAREL; *section_names_hashtable->get(namidx, namidx + strlen(section_names_init + namidx)) = namidx; } if (SYMbuf) diff --git a/src/dmd/backend/machobj.c b/src/dmd/backend/machobj.c index a5c52bb4c4a0..fed3865f23d3 100644 --- a/src/dmd/backend/machobj.c +++ b/src/dmd/backend/machobj.c @@ -38,9 +38,6 @@ #include "cgcv.h" #include "dt.h" -#include "aa.h" -#include "tinfo.h" - #if MACHOBJ #if MARS diff --git a/src/dmd/backend/mscoffobj.c b/src/dmd/backend/mscoffobj.c index 5f4b706f33ce..eb2bbd0ed2a5 100644 --- a/src/dmd/backend/mscoffobj.c +++ b/src/dmd/backend/mscoffobj.c @@ -30,9 +30,6 @@ #include "cgcv.h" #include "dt.h" -#include "aa.h" -#include "tinfo.h" - #if TARGET_WINDOS #include "mscoff.h" diff --git a/src/dmd/backend/ti_achar.c b/src/dmd/backend/ti_achar.c deleted file mode 100644 index 1ab2ab1a870c..000000000000 --- a/src/dmd/backend/ti_achar.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Compiler implementation of the - * $(LINK2 http://www.dlang.org, D programming language). - * - * Copyright: Copyright (C) 2006-2018 by The D Language Foundation, All Rights Reserved - * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) - * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) - * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/ti_achar.c, backend/ti_achar.c) - */ - - -#include -#include - -#include "tinfo.h" - - -// char* - -TypeInfo_Achar ti_achar; - -const char* TypeInfo_Achar::toString() -{ - return "char*"; -} - -hash_t TypeInfo_Achar::getHash(void *p) -{ char* s; - hash_t hash = 0; - - for (s = *(char**)p; *s; s++) - { - hash = hash * 11 + *s; - } - return hash; -} - -int TypeInfo_Achar::equals(void *p1, void *p2) -{ - char* s1 = *(char**)p1; - char* s2 = *(char**)p2; - - return strcmp(s1, s2) == 0; -} - -int TypeInfo_Achar::compare(void *p1, void *p2) -{ - char* s1 = *(char**)p1; - char* s2 = *(char**)p2; - - return strcmp(s1, s2); -} - -size_t TypeInfo_Achar::tsize() -{ - return sizeof(char*); -} - -void TypeInfo_Achar::swap(void *p1, void *p2) -{ -} - diff --git a/src/dmd/backend/ti_pvoid.c b/src/dmd/backend/ti_pvoid.c deleted file mode 100644 index 5eac0d6b5b9c..000000000000 --- a/src/dmd/backend/ti_pvoid.c +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Compiler implementation of the - * $(LINK2 http://www.dlang.org, D programming language). - * - * Copyright: Copyright (C) 2011-2018 by The D Language Foundation, All Rights Reserved - * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) - * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) - * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/ti_pvoid.c, backend/ti_pvoid.c) - */ - - -#include - -#include "tinfo.h" - - -// void* - -TypeInfo_Pvoid ti_pvoid; - -const char* TypeInfo_Pvoid::toString() -{ - return "void*"; -} - -hash_t TypeInfo_Pvoid::getHash(void *p) -{ void* s = *(void **)p; - return (hash_t)s; -} - -int TypeInfo_Pvoid::equals(void *p1, void *p2) -{ - void* s1 = *(void**)p1; - void* s2 = *(void**)p2; - - return s1 == s2; -} - -int TypeInfo_Pvoid::compare(void *p1, void *p2) -{ - void* s1 = *(void**)p1; - void* s2 = *(void**)p2; - - return (s1 < s2) ? -1 : ((s1 == s2) ? 0 : 1); -} - -size_t TypeInfo_Pvoid::tsize() -{ - return sizeof(void*); -} - -void TypeInfo_Pvoid::swap(void *p1, void *p2) -{ -} - diff --git a/src/dmd/backend/tinfo.h b/src/dmd/backend/tinfo.h deleted file mode 100644 index b8c16ddc5d3b..000000000000 --- a/src/dmd/backend/tinfo.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Compiler implementation of the - * $(LINK2 http://www.dlang.org, D programming language). - * - * Copyright: Copyright (C) 2000-2018 by The D Language Foundation, All Rights Reserved - * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) - * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) - * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/tinfo.h, backend/tinfo.h) - */ - - -#ifndef TYPEINFO_H -#define TYPEINFO_H - -#include - -typedef size_t hash_t; - -struct TypeInfo -{ - virtual const char* toString() = 0; - virtual hash_t getHash(void *p) = 0; - virtual int equals(void *p1, void *p2) = 0; - virtual int compare(void *p1, void *p2) = 0; - virtual size_t tsize() = 0; - virtual void swap(void *p1, void *p2) = 0; -}; - -struct TypeInfo_Achar : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -extern TypeInfo_Achar ti_achar; - -struct TypeInfo_Pvoid : TypeInfo -{ - const char* toString(); - hash_t getHash(void *p); - int equals(void *p1, void *p2); - int compare(void *p1, void *p2); - size_t tsize(); - void swap(void *p1, void *p2); -}; - -extern TypeInfo_Pvoid ti_pvoid; - -#endif diff --git a/src/posix.mak b/src/posix.mak index ae9def1feee2..5d0c3ef0938d 100644 --- a/src/posix.mak +++ b/src/posix.mak @@ -351,8 +351,7 @@ BACK_OBJS = \ cgen.o \ dt.o \ outbuf.o \ - aa.o ti_achar.o \ - ti_pvoid.o sizecheck.o \ + sizecheck.o \ dwarf.o varstats.o \ tk.o strtold.o \ $(TARGET_OBJS) @@ -361,7 +360,8 @@ BACK_DOBJS = bcomplex.o evalu8.o divcoeff.o dvec.o go.o gsroa.o glocal.o gdag.o out.o \ gloop.o compress.o cgelem.o cgcs.o ee.o cod4.o cod5.o nteh.o blockopt.o memh.o cg.o cgreg.o \ dtype.o debugprint.o symbol.o elem.o dcode.o cgsched.o cg87.o cgxmm.o cgcod.o cod1.o cod2.o \ - cod3.o cv8.o dcgcv.o pdata.o util2.o var.o md5.o backconfig.o ph2.o drtlsym.o dwarfeh.o ptrntab.o + cod3.o cv8.o dcgcv.o pdata.o util2.o var.o md5.o backconfig.o ph2.o drtlsym.o dwarfeh.o ptrntab.o \ + aarray.o G_OBJS = $(addprefix $G/, $(BACK_OBJS)) G_DOBJS = $(addprefix $G/, $(BACK_DOBJS)) @@ -402,8 +402,8 @@ BACK_SRC = \ $C/dtype.d $C/melf.h $C/mach.h $C/mscoff.h $C/bcomplex.h \ $C/outbuf.h $C/token.h $C/tassert.h \ $C/elfobj.c $C/cv4.h $C/dwarf2.h $C/exh.h $C/go.h \ - $C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \ - $C/ti_pvoid.c $C/platform_stub.c $C/code_x86.h $C/code_stub.h \ + $C/dwarf.c $C/dwarf.h $C/aa.h $C/aarray.d \ + $C/platform_stub.c $C/code_x86.h $C/code_stub.h \ $C/machobj.c $C/mscoffobj.c \ $C/xmm.h $C/obj.h $C/pdata.d $C/cv8.d $C/backconfig.d $C/sizecheck.c $C/divcoeff.d \ $C/varstats.c $C/varstats.h $C/dvec.d \ diff --git a/src/vcbuild/dmd_backend.vcxproj b/src/vcbuild/dmd_backend.vcxproj index b41e5819a425..024385d25eed 100644 --- a/src/vcbuild/dmd_backend.vcxproj +++ b/src/vcbuild/dmd_backend.vcxproj @@ -87,7 +87,6 @@ - @@ -100,8 +99,6 @@ - - true diff --git a/src/win32.mak b/src/win32.mak index 53c236d9e955..05c40647288c 100644 --- a/src/win32.mak +++ b/src/win32.mak @@ -198,8 +198,8 @@ GBACKOBJ= $G/go.obj $G/gdag.obj $G/gother.obj $G/gflow.obj $G/gloop.obj $G/var.o $G/blockopt.obj $G/cgobj.obj $G/cg.obj $G/dcgcv.obj $G/dtype.obj $G/dt.obj \ $G/debugprint.obj $G/dcode.obj $G/cg87.obj $G/cgxmm.obj $G/cgsched.obj $G/ee.obj $G/symbol.obj \ $G/cgcod.obj $G/cod1.obj $G/cod2.obj $G/cod3.obj $G/cod4.obj $G/cod5.obj $G/outbuf.obj \ - $G/bcomplex.obj $G/ptrntab.obj $G/aa.obj $G/ti_achar.obj $G/md5.obj \ - $G/ti_pvoid.obj $G/mscoffobj.obj $G/pdata.obj $G/cv8.obj $G/backconfig.obj $G/sizecheck.obj \ + $G/bcomplex.obj $G/ptrntab.obj $G/md5.obj \ + $G/mscoffobj.obj $G/pdata.obj $G/cv8.obj $G/backconfig.obj $G/sizecheck.obj \ $G/divcoeff.obj $G/dwarf.obj $G/compress.obj $G/varstats.obj \ $G/ph2.obj $G/util2.obj $G/tk.obj $G/gsroa.obj $G/dvec.obj \ @@ -239,9 +239,9 @@ BACKSRC= $C\cdef.h $C\cc.h $C\oper.h $C\ty.h $C\optabgen.d \ $C\dtype.d $C\melf.h $C\mach.h $C\mscoff.h $C\bcomplex.h \ $C\outbuf.h $C\token.h $C\tassert.h \ $C\elfobj.c $C\cv4.h $C\dwarf2.h $C\exh.h $C\go.h \ - $C\dwarf.c $C\dwarf.h $C\machobj.c \ - $C\strtold.c $C\aa.h $C\aa.c $C\tinfo.h $C\ti_achar.c \ - $C\md5.h $C\md5.d $C\ti_pvoid.c $C\xmm.h $C\ph2.d $C\util2.d \ + $C\dwarf.c $C\dwarf.h $C\machobj.c $C\aarray.d \ + $C\strtold.c $C\aa.h \ + $C\md5.h $C\md5.d $C\xmm.h $C\ph2.d $C\util2.d \ $C\mscoffobj.c $C\obj.h $C\pdata.d $C\cv8.d $C\backconfig.d $C\sizecheck.c \ $C\divcoeff.d $C\dwarfeh.d $C\varstats.c $C\varstats.h \ $C\dvec.d $C\backend.txt @@ -454,8 +454,6 @@ $G\VERSION : ..\VERSION $G $(CC) -c $(CFLAGS) $* # D front/back end -$G/aa.obj : $C\tinfo.h $C\aa.h $C\aa.c - $(CC) -c -o$@ $(MFLAGS) -I$D -I$G $C\aa $G/backconfig.obj : $C\backconfig.d $(HOST_DC) -c -betterC -of$@ $(DFLAGS) -mv=dmd.backend=$C $C\backconfig @@ -613,12 +611,6 @@ $G/sizecheck.obj : $C\sizecheck.c $G/strtold.obj : $C\strtold.c $(CC) -c -o$@ -cpp $C\strtold -$G/ti_achar.obj : $C\tinfo.h $C\ti_achar.c - $(CC) -c -o$@ $(MFLAGS) -I$D $C\ti_achar - -$G/ti_pvoid.obj : $C\tinfo.h $C\ti_pvoid.c - $(CC) -c -o$@ $(MFLAGS) -I$D -I$G $C\ti_pvoid - $G/dtype.obj : $C\dtype.d $(HOST_DC) -c -of$@ $(DFLAGS) -betterC -mv=dmd.backend=$C $C\dtype