Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ddmd/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,10 @@ extern (C++) FuncDeclaration buildXopCmp(StructDeclaration sd, Scope* sc)
fop.generated = true;
Expression e1 = new IdentifierExp(loc, Id.p);
Expression e2 = new IdentifierExp(loc, Id.q);
Expression e = new CallExp(loc, new DotIdExp(loc, e2, Id.cmp), e1);
static if (IN_GCC)
Expression e = new CallExp(loc, new DotIdExp(loc, e1, Id.cmp), e2);
else
Expression e = new CallExp(loc, new DotIdExp(loc, e2, Id.cmp), e1);
fop.fbody = new ReturnStatement(loc, e);
uint errors = global.startGagging(); // Do not report errors
Scope* sc2 = sc.push();
Expand Down
13 changes: 13 additions & 0 deletions src/ddmd/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,19 @@ extern (C++) final class CppMangleVisitor : Visitor
td = new TypeDelegate(td);
t = t.merge();
}
static if (IN_GCC)
{
// Could be a va_list, which we mangle as a pointer.
if (t.ty == Tsarray && Type.tvalist.ty == Tsarray)
{
Type tb = t.toBasetype().mutableOf();
if (tb == Type.tvalist)
{
tb = t.nextOf().pointerTo();
t = tb.castMod(t.mod);
}
}
}
if (t.ty == Tsarray)
{
// Mangle static arrays as pointers
Expand Down
8 changes: 4 additions & 4 deletions src/ddmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -1475,8 +1475,8 @@ extern (C++) Expression castTo(Expression e, Scope* sc, Type t)
*/

// Fat Value types
const(bool) tob_isFV = (tob.ty == Tstruct || tob.ty == Tsarray);
const(bool) t1b_isFV = (t1b.ty == Tstruct || t1b.ty == Tsarray);
const(bool) tob_isFV = (tob.ty == Tstruct || tob.ty == Tsarray || tob.ty == Tvector);
const(bool) t1b_isFV = (t1b.ty == Tstruct || t1b.ty == Tsarray || t1b.ty == Tvector);

// Fat Reference types
const(bool) tob_isFR = (tob.ty == Tarray || tob.ty == Tdelegate);
Expand All @@ -1487,8 +1487,8 @@ extern (C++) Expression castTo(Expression e, Scope* sc, Type t)
const(bool) t1b_isR = (t1b_isFR || t1b.ty == Tpointer || t1b.ty == Taarray || t1b.ty == Tclass);

// Arithmetic types (== valueable basic types)
const(bool) tob_isA = (tob.isintegral() || tob.isfloating());
const(bool) t1b_isA = (t1b.isintegral() || t1b.isfloating());
const(bool) tob_isA = ((tob.isintegral() || tob.isfloating()) && tob.ty != Tvector);
const(bool) t1b_isA = ((t1b.isintegral() || t1b.isfloating()) && t1b.ty != Tvector);

if (AggregateDeclaration t1ad = isAggregate(t1b))
{
Expand Down
31 changes: 31 additions & 0 deletions src/ddmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,18 @@ public:
// we can't compile asm statements
}

static if (IN_GCC)
{
override void visit(ExtAsmStatement s)
{
debug (LOGCOMPILE)
{
printf("%s ExtAsmStatement::ctfeCompile\n", s.loc.toChars());
}
// we can't compile extended asm statements
}
}

void ctfeCompile(Statement s)
{
s.accept(this);
Expand Down Expand Up @@ -1998,6 +2010,25 @@ public:
result = CTFEExp.cantexp;
}

static if (IN_GCC)
{
override void visit(ExtAsmStatement s)
{
debug (LOG)
{
printf("%s ExtAsmStatement::interpret()\n", s.loc.toChars());
}
if (istate.start)
{
if (istate.start != s)
return;
istate.start = null;
}
s.error("extended asm statements cannot be interpreted at compile time");
result = CTFEExp.cantexp;
}
}

override void visit(ImportStatement s)
{
debug (LOG)
Expand Down
6 changes: 3 additions & 3 deletions src/ddmd/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class Expression;
class DeleteDeclaration;
class OverloadSet;
struct AA;
#ifdef IN_GCC
#ifdef IN_GCC // %%
typedef union tree_node Symbol;
#else
#else // %%
struct Symbol;
#endif
#endif // %%

struct Ungag
{
Expand Down
6 changes: 3 additions & 3 deletions src/ddmd/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class StringExp;
class ArrayExp;
class SliceExp;
struct UnionExp;
#ifdef IN_GCC
#ifdef IN_GCC // %%
typedef union tree_node Symbol;
#else
#else // %%
struct Symbol; // back end symbol
#endif
#endif // %%

Expression *resolveProperties(Scope *sc, Expression *e);
Expression *resolvePropertiesOnly(Scope *sc, Expression *e1);
Expand Down
3 changes: 2 additions & 1 deletion src/ddmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import ddmd.hdrgen;
import ddmd.id;
import ddmd.identifier;
import ddmd.init;
import ddmd.mars;
import ddmd.mtype;
import ddmd.nogc;
import ddmd.objc;
Expand All @@ -50,6 +49,8 @@ import ddmd.target;
import ddmd.tokens;
import ddmd.visitor;

extern (C++) void genCmain(Scope* sc);

/// Inline Status
enum ILS : int
{
Expand Down
2 changes: 1 addition & 1 deletion src/ddmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ template xversion(string s)
enum xversion = mixin(`{ version (` ~ s ~ `) return true; else return false; }`)();
}

enum IN_GCC = xversion!`IN_GCC`;
enum IN_GCC = xversion!`IN_GCC`; // %%

enum TARGET_LINUX = xversion!`linux`;
enum TARGET_OSX = xversion!`OSX`;
Expand Down
18 changes: 18 additions & 0 deletions src/ddmd/gluelayer.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ version (NoBackend)
void objc_initSymbols() {}
}
}
else version (IN_GCC)
{
union tree_node;

alias Symbol = tree_node;
alias code = tree_node;
alias type = tree_node;

// d-frontend.cc
extern (C++)
{
RET retStyle(TypeFunction tf);
Statement asmSemantic(AsmStatement s, Scope* sc);
}

// stubs
void objc_initSymbols() { }
}
else
{
import ddmd.lib : Library;
Expand Down
61 changes: 61 additions & 0 deletions src/ddmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,67 @@ public:
buf.writenl();
}

static if (IN_GCC)
{
override void visit(ExtAsmStatement s)
{
buf.writestring ("gcc asm { ");

if (s.insn)
buf.writestring (s.insn.toChars());

buf.writestring (" : ");

if (s.args)
{
for (size_t i = 0; i < s.args.dim; i++)
{
Identifier name = (*s.names)[i];
Expression constr = (*s.constraints)[i];
Expression arg = (*s.args)[i];

if (name)
{
buf.writestring ("[");
buf.writestring (name.toChars());
buf.writestring ("] ");
}

if (constr)
{
buf.writestring (constr.toChars());
buf.writestring (" ");
}

if (arg)
buf.writestring (arg.toChars());

if (i < s.outputargs - 1)
buf.writestring (", ");
else if (i == s.outputargs - 1)
buf.writestring (" : ");
else if (i < s.args.dim - 1)
buf.writestring (", ");
}
}

if (s.clobbers)
{
buf.writestring (" : ");
for (size_t i = 0; i < s.clobbers.dim; i++)
{
Expression clobber = (*s.clobbers)[i];
buf.writestring (clobber.toChars());
if (i < s.clobbers.dim - 1)
buf.writestring (", ");
}
}

buf.writestring ("; }");
buf.writenl();
}
}

override void visit(ImportStatement s)
{
foreach (imp; *s.imports)
Expand Down
2 changes: 1 addition & 1 deletion src/ddmd/id.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct Id
* An identifier that corresponds to each static field in this struct will
* be placed in the identifier pool.
*/
void initialize()
extern (C++) void initialize()
{
mixin(msgtable.generate(&initializer));
}
Expand Down
22 changes: 18 additions & 4 deletions src/ddmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -2863,11 +2863,11 @@ extern (C++) abstract class Type : RootObject
assert(0 < length && length < namelen); // don't overflow the buffer

int off = 0;
static if (!IN_GCC)
static if (!IN_GCC) // %%
{
if (global.params.isOSX || global.params.isWindows && !global.params.is64bit)
++off; // C mangling will add '_' back in
}
} // %%
auto id = Identifier.idPool(name + off, length - off);

if (name != namebuf.ptr)
Expand Down Expand Up @@ -4531,8 +4531,22 @@ extern (C++) final class TypeVector : Type
//printf("TypeVector::implicitConvTo(%s) from %s\n", to.toChars(), toChars());
if (this == to)
return MATCHexact;
if (ty == to.ty)
return MATCHconvert;
if (to.ty == Tvector)
{
TypeVector tv = cast(TypeVector)to;
assert(basetype.ty == Tsarray && tv.basetype.ty == Tsarray);

// Can't convert to a vector which has different size.
if (basetype.size() != tv.basetype.size())
return MATCHnomatch;

// Allow conversion to void[]
if (tv.basetype.nextOf().ty == Tvoid)
return MATCHconvert;

// Otherwise implicitly convertible only if basetypes are.
return basetype.implicitConvTo(tv.basetype);
}
return MATCHnomatch;
}

Expand Down
6 changes: 3 additions & 3 deletions src/ddmd/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class TypeBasic;
class Parameter;

// Back end
#ifdef IN_GCC
#ifdef IN_GCC // %%
typedef union tree_node type;
#else
#else // %%
typedef struct TYPE type;
#endif
#endif // %%

void semanticTypeInfo(Scope *sc, Type *t);
MATCH deduceType(RootObject *o, Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, unsigned *wm = NULL, size_t inferStart = 0);
Expand Down
Loading