Skip to content

Commit

Permalink
make X86 a positive affirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed May 30, 2024
1 parent 1dae282 commit 04d872f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dmd/dmdparams.d
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,14 @@ void setTargetBuildDefaults(ref Target target)
target.osMajor = defaultTargetOSMajor();
target.cpu = CPU.baseline;
target.isX86_64 = (size_t.sizeof == 8);
target.isX86 = !target.isX86_64;
}

void setTriple(ref Target target, const ref Triple triple) @safe
{
target.cpu = triple.cpu;
target.isX86_64 = triple.isX86_64;
target.isX86 = !target.isX86_64;
target.isLP64 = triple.isLP64;
target.os = triple.os;
target.osMajor = triple.osMajor;
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void initDMD(

target.os = defaultTargetOS();
target.isX86_64 = (size_t.sizeof == 8);
target.isX86 = !target.isX86_64;
target._init(global.params);
Type._init();
Id.initialize();
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -7542,6 +7542,7 @@ struct Target final
_d_dynamicArray< const char > architectureName;
CPU cpu;
bool isX86_64;
bool isX86;
bool isLP64;
_d_dynamicArray< const char > obj_ext;
_d_dynamicArray< const char > lib_ext;
Expand Down Expand Up @@ -7613,6 +7614,7 @@ struct Target final
objc(),
architectureName(),
isX86_64(),
isX86(),
isLP64(),
obj_ext(),
lib_ext(),
Expand All @@ -7625,7 +7627,7 @@ struct Target final
params()
{
}
Target(OS os, uint8_t osMajor = 0u, uint8_t ptrsize = 0u, uint8_t realsize = 0u, uint8_t realpad = 0u, uint8_t realalignsize = 0u, uint8_t classinfosize = 0u, uint64_t maxStaticDataSize = 0LLU, TargetC c = TargetC(), TargetCPP cpp = TargetCPP(), TargetObjC objc = TargetObjC(), _d_dynamicArray< const char > architectureName = {}, CPU cpu = (CPU)0u, bool isX86_64 = false, bool isLP64 = false, _d_dynamicArray< const char > obj_ext = {}, _d_dynamicArray< const char > lib_ext = {}, _d_dynamicArray< const char > dll_ext = {}, bool run_noext = false, FPTypeProperties<float > FloatProperties = FPTypeProperties<float >(), FPTypeProperties<double > DoubleProperties = FPTypeProperties<double >(), FPTypeProperties<_d_real > RealProperties = FPTypeProperties<_d_real >(), Type* tvalist = nullptr, const Param* params = nullptr) :
Target(OS os, uint8_t osMajor = 0u, uint8_t ptrsize = 0u, uint8_t realsize = 0u, uint8_t realpad = 0u, uint8_t realalignsize = 0u, uint8_t classinfosize = 0u, uint64_t maxStaticDataSize = 0LLU, TargetC c = TargetC(), TargetCPP cpp = TargetCPP(), TargetObjC objc = TargetObjC(), _d_dynamicArray< const char > architectureName = {}, CPU cpu = (CPU)0u, bool isX86_64 = false, bool isX86 = false, bool isLP64 = false, _d_dynamicArray< const char > obj_ext = {}, _d_dynamicArray< const char > lib_ext = {}, _d_dynamicArray< const char > dll_ext = {}, bool run_noext = false, FPTypeProperties<float > FloatProperties = FPTypeProperties<float >(), FPTypeProperties<double > DoubleProperties = FPTypeProperties<double >(), FPTypeProperties<_d_real > RealProperties = FPTypeProperties<_d_real >(), Type* tvalist = nullptr, const Param* params = nullptr) :
os(os),
osMajor(osMajor),
ptrsize(ptrsize),
Expand All @@ -7640,6 +7642,7 @@ struct Target final
architectureName(architectureName),
cpu(cpu),
isX86_64(isX86_64),
isX86(isX86),
isLP64(isLP64),
obj_ext(obj_ext),
lib_ext(lib_ext),
Expand Down
6 changes: 6 additions & 0 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param

files.reserve(arguments.length - 1);

// default
target.isX86 = true;

for (size_t i = 1; i < arguments.length; i++)
{
const(char)* p = arguments[i];
Expand Down Expand Up @@ -883,14 +886,17 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
}
else if (arg == "-m32") // https://dlang.org/dmd.html#switch-m32
{
target.isX86 = true;
target.isX86_64 = false;
}
else if (arg == "-m64") // https://dlang.org/dmd.html#switch-m64
{
target.isX86 = false;
target.isX86_64 = true;
}
else if (arg == "-m32mscoff") // https://dlang.org/dmd.html#switch-m32mscoff
{
target.isX86 = true;
target.isX86_64 = false;
}
else if (startsWith(p + 1, "mscrtlib="))
Expand Down
15 changes: 13 additions & 2 deletions compiler/src/dmd/target.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

module dmd.target;

import core.stdc.stdio;

import dmd.astenums : CHECKENABLE;
import dmd.globals : Param;

Expand Down Expand Up @@ -348,6 +350,7 @@ extern (C++) struct Target
const(char)[] architectureName;
CPU cpu; // CPU instruction set to target
bool isX86_64; // generate 64 bit code for x86_64; true by default for 64 bit dmd
bool isX86 = true; // generate 32 bit Intel x86 code
bool isLP64; // pointers are 64 bits

// Environmental
Expand Down Expand Up @@ -403,6 +406,8 @@ extern (C++) struct Target
extern (C++) void _init(ref const Param params)
{
// isX86_64 and cpu are initialized in parseCommandLine
printf("X: %d %d\n", isX86, isX86_64);
assert(isX86 != isX86_64);

this.params = &params;

Expand Down Expand Up @@ -1329,7 +1334,13 @@ extern (C++) struct Target
*/
extern (D) uint stackAlign() @safe
{
return isXmmSupported() ? 16 : (isX86_64 ? 8 : 4);
assert(isX86_64 != isX86);
uint sz = isXmmSupported() ? 16 :
isX86_64 ? 8 :
isX86 ? 4 : 0;
assert(sz);
return sz;
// return isXmmSupported() ? 16 : (isX86_64 ? 8 : 4);
}
}

Expand Down Expand Up @@ -1482,7 +1493,7 @@ struct TargetCPP
else
assert(0);
// C++ and D ABI incompatible on all (?) x86 32-bit platforms
wrapDtorInExternD = !target.isX86_64;
wrapDtorInExternD = target.isX86;
}

/**
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ struct Target
DString architectureName; // name of the platform architecture (e.g. X86_64)
CPU cpu; // CPU instruction set to target
d_bool isX86_64; // generate 64 bit code for x86_64; true by default for 64 bit dmd
d_bool isX86; // generate 32 bit Intel x86 code
d_bool isLP64; // pointers are 64 bits

// Environmental
Expand Down

0 comments on commit 04d872f

Please sign in to comment.