Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
IRState::addTypeModifiers - Add D2 type modifiers (const/shared) onto…
Browse files Browse the repository at this point in the history
… GCC types (const/volatile).
  • Loading branch information
Iain Buclaw committed Mar 10, 2011
1 parent 9001ea8 commit f87a03a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 77 deletions.
15 changes: 8 additions & 7 deletions d/d-builtins2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ void
d_bi_init()
{
// assumes va_list_type_node already built
d_gcc_builtin_va_list_d_type = gcc_type_to_d_type(va_list_type_node);
tree t, m = va_list_type_node;
d_gcc_builtin_va_list_d_type = gcc_type_to_d_type(m);
if (! d_gcc_builtin_va_list_d_type)
{ // fallback to array of byte of the same size?
error("cannot represent built in va_list type in D");
abort();
}
// generate ctype if it doesn't already exist
d_gcc_builtin_va_list_d_type->toCtype();
// D type main variant same as C va_list type.
t = d_gcc_builtin_va_list_d_type->toCtype();
TYPE_MAIN_VARIANT(t) = TYPE_MAIN_VARIANT(m);
}

/*
Expand All @@ -75,7 +77,6 @@ gcc_type_to_d_type(tree t)
if (TYPE_MAIN_VARIANT(TREE_TYPE(t)) == char_type_node)
{
d = Type::tchar;
d->ctype = TREE_TYPE(t);
return d->pointerTo();
}
d = gcc_type_to_d_type(TREE_TYPE(t));
Expand Down Expand Up @@ -396,11 +397,11 @@ d_gcc_magic_builtins_module(Module *m)
const char * name = IDENTIFIER_POINTER(DECL_NAME(decl));
TypeFunction * dtf = (TypeFunction *) gcc_type_to_d_type(TREE_TYPE(decl));
if (! dtf)
{ //warning("cannot create built in function type for %s", name);
{ //warning(0, "cannot create built in function type for %s", name);
continue;
}
if (dtf->parameters && dtf->parameters->dim == 0 && dtf->varargs)
{ //warning("one-arg va problem: %s", name);
{ //warning(0, "one-arg va problem: %s", name);
continue;
}
#if V2
Expand Down Expand Up @@ -430,7 +431,7 @@ d_gcc_magic_builtins_module(Module *m)
const char * name = IDENTIFIER_POINTER(DECL_NAME(decl));
Type * dt = gcc_type_to_d_type(type);
if (! dt)
{ //warning("cannot create built in type for %s", name);
{ //warning(0, "cannot create built in type for %s", name);
continue;
}
funcs->push(new AliasDeclaration(0, Lexer::idPool(name), dt));
Expand Down
34 changes: 34 additions & 0 deletions d/d-codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,40 @@ IRState::attributes(Expressions * in_attrs)
return out_attrs.head;
}

tree
IRState::addTypeModifiers(tree type, unsigned mod)
{
int quals = 0;
gcc_assert(type);

switch (mod)
{
case 0:
break;

case MODconst:
case MODwild:
case MODimmutable:
quals |= TYPE_QUAL_CONST;
break;

case MODshared:
quals |= TYPE_QUAL_VOLATILE;
break;

case MODshared | MODwild:
case MODshared | MODconst:
quals |= TYPE_QUAL_CONST;
quals |= TYPE_QUAL_VOLATILE;
break;

default:
gcc_unreachable();
}

return build_qualified_type(type, quals);
}

tree
IRState::integerConstant(dinteger_t value, tree type)
{
Expand Down
1 change: 1 addition & 0 deletions d/d-codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ struct IRState : IRBase
static tree addTypeAttribute(tree type, const char * attrname, tree value = NULL_TREE);
static void addDeclAttribute(tree type, const char * attrname, tree value = NULL_TREE);
static tree attributes(Expressions * in_attrs);
static tree addTypeModifiers(tree type, unsigned mod);

// ** Simple constants

Expand Down
84 changes: 30 additions & 54 deletions d/d-glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3316,31 +3316,7 @@ Module::genobjfile(int multiobj)
unsigned
Type::totym()
{
gcc_assert(ctype);
#if V2
// Apply modifiers to ctype
switch (mod)
{
case 0:
break;
case MODconst:
case MODwild:
case MODimmutable:
TYPE_READONLY(ctype) = 1;
break;
case MODshared:
TYPE_VOLATILE(ctype) = 1;
break;
case MODshared | MODwild:
case MODshared | MODconst:
TYPE_READONLY(ctype) = 1;
TYPE_VOLATILE(ctype) = 1;
break;
default:
gcc_unreachable();
}
#endif
return 0;
return 0; // Unused
}

type *
Expand Down Expand Up @@ -3452,14 +3428,8 @@ Type::toCtype()
abort();
return NULL_TREE;
}
#if V2
// Build a variant of the tree type.
if (this->mod && ty != Terror)
ctype = build_variant_type_copy(ctype);
#endif
this->totym();
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

// This is not used for GCC
Expand Down Expand Up @@ -3523,10 +3493,13 @@ type *
TypeEnum::toCtype()
{
if (! ctype)
{
/* Enums in D2 can have a base type that is not necessarily integral.
{ /* Enums in D2 can have a base type that is not necessarily integral.
So don't bother trying to make an ENUMERAL_TYPE using them. */
if (sym->memtype->isintegral())
if (! sym->memtype->isintegral())
{
ctype = sym->memtype->toCtype();
}
else
{
tree enum_mem_type_node = sym->memtype->toCtype();

Expand Down Expand Up @@ -3574,17 +3547,20 @@ TypeEnum::toCtype()
g.ofile->initTypeDecl(ctype, sym);
g.ofile->declareType(ctype, sym);
}
else
{
ctype = sym->memtype->toCtype();
}
}
return ctype;
}

type *
TypeStruct::toCtype()
{
#if V2
if (mod)
{ // const, shared, just derivatives of the naked type.
Type * tm = mutableOf()->unSharedOf();
ctype = tm->toCtype();
}
#endif
if (! ctype)
{ // need to set this right away in case of self-references
ctype = make_node(sym->isUnionDeclaration() ? UNION_TYPE : RECORD_TYPE);
Expand Down Expand Up @@ -3638,7 +3614,7 @@ TypeStruct::toCtype()

agg_layout.finish(sym->attributes);
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

void
Expand Down Expand Up @@ -3756,15 +3732,14 @@ TypeSArray::toCtype()
ctype = gen.arrayType(Type::tuns8, size);
else
ctype = gen.arrayType(next, size);

}
else
{
::error("invalid expressions for static array dimension: %s", dim->toChars());
abort();
}
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

type *
Expand All @@ -3782,24 +3757,20 @@ TypeDArray::toCtype()
{
if (! ctype)
{
#if V2
if (mod)
{ /* Rather than making const(T[]) and const(T)[] two distinct
types, make the former a variant of the latter, and apply
modifiers afterwards. */
ctype = next->arrayOf()->toCtype();
ctype = build_variant_type_copy(ctype);
this->totym();
}
else
#endif
{
ctype = gen.twoFieldType(Type::tsize_t, next->pointerTo(), this,
"length", "ptr");
}
dkeep(ctype);
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

type *
Expand All @@ -3813,8 +3784,7 @@ TypeAArray::toCtype()
*/

if (! ctype)
{
/* Library functions expect a struct-of-pointer which could be passed
{ /* Library functions expect a struct-of-pointer which could be passed
differently from a pointer. */
static tree aa_type = NULL_TREE;
if (! aa_type)
Expand All @@ -3829,7 +3799,7 @@ TypeAArray::toCtype()
}
ctype = aa_type;
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

type *
Expand All @@ -3838,9 +3808,8 @@ TypePointer::toCtype()
if (! ctype)
{
ctype = build_pointer_type(next->toCtype());
this->totym();
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

type *
Expand All @@ -3853,7 +3822,7 @@ TypeDelegate::toCtype()
this, "object", "func");
dkeep(ctype);
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

/* Create debug information for a ClassDeclaration's inheritance tree.
Expand Down Expand Up @@ -3952,6 +3921,13 @@ intfc_binfo_for(tree tgt_binfo, ClassDeclaration * iface, unsigned & inout_offse
type *
TypeClass::toCtype()
{
#if V2
if (mod)
{ // const, shared, just derivatives of the naked type.
Type * tm = mutableOf()->unSharedOf();
ctype = tm->toCtype();
}
#endif
if (! ctype)
{
tree rec_type;
Expand Down Expand Up @@ -4026,7 +4002,7 @@ TypeClass::toCtype()

agg_layout.finish(sym->attributes);
}
return ctype;
return gen.addTypeModifiers(ctype, mod);
}

void
Expand Down
10 changes: 0 additions & 10 deletions d/d-lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -935,17 +935,7 @@ d_parse_file (int /*set_yydebug*/)
for (TY ty = (TY) 0; ty < TMAX; ty = (TY)(ty + 1))
{
if (Type::basic[ty] && ty != Terror)
{
#if V2
nametype(Type::basic[ty]->constOf());
nametype(Type::basic[ty]->invariantOf());
nametype(Type::basic[ty]->sharedOf());
nametype(Type::basic[ty]->sharedConstOf());
nametype(Type::basic[ty]->wildOf());
nametype(Type::basic[ty]->sharedWildOf());
#endif
nametype(Type::basic[ty]);
}
}

/*
Expand Down
10 changes: 4 additions & 6 deletions d/d-objfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,12 @@ ObjectFile::initTypeDecl(tree t, tree decl)
case UNION_TYPE:
{ /* Not sure if there is a need for separate TYPE_DECLs in
TYPE_NAME and TYPE_STUB_DECL. */
TYPE_STUB_DECL(t) = d_build_decl(TYPE_DECL, DECL_NAME(decl), t);
TYPE_STUB_DECL(t) = decl;
// g++ does this and the debugging code assumes it:
DECL_ARTIFICIAL(decl) = 1;
#if D_GCC_VER >= 43
DECL_ARTIFICIAL(TYPE_STUB_DECL(t)) = 1; // dunno...
// code now assumes...
DECL_SOURCE_LOCATION(TYPE_STUB_DECL(t)) = DECL_SOURCE_LOCATION(decl);
#else
// g++ does this and the debugging code assumes it:
DECL_ARTIFICIAL(TYPE_STUB_DECL(t)) = 1;
DECL_SOURCE_LOCATION(decl) = DECL_SOURCE_LOCATION(decl);
#endif
break;
}
Expand Down

0 comments on commit f87a03a

Please sign in to comment.