Skip to content

Commit

Permalink
Move backend prefixing of symbols to Target::prefixName
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed May 20, 2015
1 parent c6edba1 commit 9437575
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/cppmangle.c
Expand Up @@ -406,7 +406,7 @@ class CppMangleVisitor : public Visitor
Dsymbol *p = d->toParent();
if (p && !p->isModule()) //for example: char Namespace1::beta[6] should be mangled as "_ZN10Namespace14betaE"
{
buf.writestring(global.params.isOSX ? "__ZN" : "_ZN"); // "__Z" for OSX, "_Z" for other
buf.writestring("_ZN");
prefix_name(p);
source_name(d);
buf.writeByte('E');
Expand All @@ -415,13 +415,11 @@ class CppMangleVisitor : public Visitor
{
if (!is_temp_arg_ref)
{
if (global.params.isOSX)
buf.writeByte('_');
buf.writestring(d->ident->toChars());
}
else
{
buf.writestring(global.params.isOSX ? "__Z" : "_Z");
buf.writestring("_Z");
source_name(d);
}
}
Expand All @@ -438,7 +436,7 @@ class CppMangleVisitor : public Visitor
*/
TypeFunction *tf = (TypeFunction *)d->type;

buf.writestring(global.params.isOSX ? "__Z" : "_Z"); // "__Z" for OSX, "_Z" for other
buf.writestring("_Z");
Dsymbol *p = d->toParent();
if (p && !p->isModule() && tf->linkage == LINKcpp)
{
Expand Down Expand Up @@ -560,6 +558,7 @@ class CppMangleVisitor : public Visitor
{
assert(0);
}
Target::prefixName(&buf, LINKcpp);
return buf.extractString();
}

Expand Down
3 changes: 2 additions & 1 deletion src/magicport.json
Expand Up @@ -373,7 +373,8 @@
"root.longdouble",
"globals",
"mtype",
"dmodule"
"dmodule",
"root.outbuffer"
],
"members" :
[
Expand Down
2 changes: 2 additions & 0 deletions src/mtype.c
Expand Up @@ -2333,8 +2333,10 @@ Identifier *Type::getTypeInfoIdent(int internal)
assert(strlen(name) < namelen); // don't overflow the buffer

size_t off = 0;
#ifndef IN_GCC
if (global.params.isOSX || global.params.isWindows && !global.params.is64bit)
++off; // C mangling will add '_' back in
#endif
Identifier *id = Identifier::idPool(name + off);

if (name != namebuf)
Expand Down
19 changes: 19 additions & 0 deletions src/target.c
Expand Up @@ -14,6 +14,7 @@
#include "target.h"
#include "mars.h"
#include "mtype.h"
#include "outbuffer.h"

int Target::ptrsize;
int Target::realsize;
Expand Down Expand Up @@ -386,3 +387,21 @@ void Target::loadModule(Module *m)
{
}

/******************************
* For the given symbol written to the OutBuffer, apply any
* target-specific prefixes based on the given linkage.
*/
void Target::prefixName(OutBuffer *buf, LINK linkage)
{
switch (linkage)
{
case LINKcpp:
if (global.params.isOSX)
buf->prependbyte('_');
break;

default:
break;
}
}

8 changes: 7 additions & 1 deletion src/target.h
Expand Up @@ -15,10 +15,12 @@
// This file contains a data structure that describes a back-end target.
// At present it is incomplete, but in future it should grow to contain
// most or all target machine and target O/S specific information.
#include "globals.h"

class Expression;
class Type;
class Module;
struct OutBuffer;

struct Target
{
Expand All @@ -32,13 +34,17 @@ struct Target
static int classinfosize; // size of 'ClassInfo'

static void init();
// Type sizes and support.
static unsigned alignsize(Type* type);
static unsigned fieldalign(Type* type);
static unsigned critsecsize();
static Type *va_listType(); // get type of va_list
static Expression *paintAsType(Expression *e, Type *type);
static int checkVectorType(int sz, Type *type);
// CTFE support for cross-compilation.
static Expression *paintAsType(Expression *e, Type *type);
// ABI and backend.
static void loadModule(Module *m);
static void prefixName(OutBuffer *buf, LINK linkage);
};

#endif

0 comments on commit 9437575

Please sign in to comment.