Skip to content

Commit

Permalink
add support for clang compiler (#592)
Browse files Browse the repository at this point in the history
* hacks to align strings for clang... wow just wow

* start work to getting built with clang

* fix issues with struct constructors, all builds, doesn't link still

* fix some narrowing issues that clang complains about

* fix compliation of zapd

* fix null deref in VersionInfo

* builds with clang

* make stringbuilding use StringHelper instead of addition

* fix linking

* add CLANG SHIP overlay on clang built versions

* doesn't need to be volatile

* mark unknown strings as extern

* rename some stuff

* can't align extern

* hopefully fix compilation for everythign

* expandtab

* allow setting LD

* Revert "allow setting LD"

This reverts commit 711aba6.

maybe to use lld it should be a LDFLAG?

* -Wno-deprecated-declarations is required for newer versions of clang

on macOS 13 beta sdk, the version of apple clang requires this

* Add jenkins support for clang

* Forward CXX flags to stormlib compilation

* Move GCC only flags to check

* use exports to set multiarch setup

* Fix Jenkins forever

* use make instead of cmake --build

add some flags to build with clang-11 as well

* address review coments

- rework extraction to allow multi thread
- misc readability cleanup

* update makefile to add WARN on linux+clang

Co-authored-by: David Chavez <david@dcvz.io>
  • Loading branch information
crowell and dcvz authored Jul 10, 2022
1 parent 89e07f8 commit d4c1c40
Show file tree
Hide file tree
Showing 27 changed files with 157 additions and 111 deletions.
6 changes: 3 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ make -j $(nproc) OPTFLAGS=-O2 DEBUG=0

## macOS

1. Requires `gcc@12, sdl2, libpng, glew, dylibbundler` (can be installed via brew, etc)
1. Requires Xcode (or xcode-tools) && `sdl2, libpng, glew, dylibbundler` (can be installed via brew, etc)
```bash
# Clone the repo
git clone https://github.com/HarbourMasters/Shipwright.git
Expand All @@ -59,9 +59,9 @@ cp <path to your ROM> OTRExporter
cd soh
# Extract the assets/Compile the exporter/Run the exporter
# -jX defines number of cores to use for compilation - lower or remove entirely if having issues
make setup -j8 DEBUG=0 CC=gcc-12 CXX=g++-12
make setup -j8 DEBUG=0
# Compile the code (watch the -j parameter as above)
make -j8 DEBUG=0 CC=gcc-12 CXX=g++-12
make -j8 DEBUG=0
# Create macOS app bundle
make filledappbundle
```
Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ pipeline {
sh '''
cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64
cd soh
make setup -j4 DEBUG=0 OPTFLAGS=-O2 CC=gcc-12 CXX=g++-12
make -j4 DEBUG=0 OPTFLAGS=-O2 CC=gcc-12 CXX=g++-12
export CC="clang -arch arm64 -arch x86_64"; export CXX="clang++ -arch arm64 -arch x86_64"; make setup -j4 OPTFLAGS=-O2 DEBUG=0 LD="ld"
export CC="clang -arch arm64 -arch x86_64"; export CXX="clang++ -arch arm64 -arch x86_64"; make -j4 DEBUG=0 OPTFLAGS=-O2 LD="ld"
make -j4 appbundle
mv ../README.md readme.txt
7z a soh-mac.7z soh.app readme.txt
Expand Down
78 changes: 39 additions & 39 deletions OTRExporter/OTRExporter/DisplayListExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
{
case G_NOOP:
{
Gfx value = gsDPNoOp();
Gfx value = {gsDPNoOp()};
word0 = value.words.w0;
word1 = value.words.w1;
}
break;
case G_ENDDL:
{
Gfx value = gsSPEndDisplayList();
Gfx value = {gsSPEndDisplayList()};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -114,7 +114,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t nnnn = (data & 0x0000FFFF00000000ULL) >> 32;
int32_t vvvvvvvv = (data & 0x00000000FFFFFFFFULL);

Gfx value = gsSPModifyVertex(nnnn / 2, ww, vvvvvvvv);
Gfx value = {gsSPModifyVertex(nnnn / 2, ww, vvvvvvvv)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -131,35 +131,35 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t cccccc = (data & 0x00FFFFFF00000000) >> 32;
int32_t ssssssss = (data & 0xFFFFFFFF);

Gfx value = gsSPGeometryMode(~cccccc, ssssssss);
Gfx value = {gsSPGeometryMode(~cccccc, ssssssss)};
word0 = value.words.w0;
word1 = value.words.w1;
}
break;
case G_RDPPIPESYNC:
{
Gfx value = gsDPPipeSync();
Gfx value = {gsDPPipeSync()};
word0 = value.words.w0;
word1 = value.words.w1;
}
break;
case G_RDPLOADSYNC:
{
Gfx value = gsDPLoadSync();
Gfx value = {gsDPLoadSync()};
word0 = value.words.w0;
word1 = value.words.w1;
}
break;
case G_RDPTILESYNC:
{
Gfx value = gsDPTileSync();
Gfx value = {gsDPTileSync()};
word0 = value.words.w0;
word1 = value.words.w1;
}
break;
case G_RDPFULLSYNC:
{
Gfx value = gsDPFullSync();
Gfx value = {gsDPFullSync()};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -169,14 +169,14 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t hhhhhh = (data & 0x00FFFFFF00000000) >> 32;
int32_t llllllll = (data & 0x00000000FFFFFFFF);

Gfx value = gsDPSetOtherMode(hhhhhh, llllllll);
Gfx value = {gsDPSetOtherMode(hhhhhh, llllllll)};
word0 = value.words.w0;
word1 = value.words.w1;
}
break;
case G_POPMTX:
{
Gfx value = gsSPPopMatrix(data);
Gfx value = {gsSPPopMatrix(data)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -188,7 +188,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
uint8_t b = (uint8_t)((data & 0xFF00FF00) >> 8);
uint8_t a = (uint8_t)((data & 0x000000FF) >> 0);

Gfx value = gsDPSetEnvColor(r, g, b, a);
Gfx value = {gsDPSetEnvColor(r, g, b, a)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -204,7 +204,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina

mm = (mm & 0x0FFFFFFF) + 1;

Gfx value = gsSPMatrix(mm, pp);
Gfx value = {gsSPMatrix(mm, pp)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -214,7 +214,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
uint32_t mm = (data & 0x00000000FFFFFFFF);
pp ^= G_MTX_PUSH;

Gfx value = gsSPMatrix(mm, pp);
Gfx value = {gsSPMatrix(mm, pp)};
word0 = value.words.w0;
word1 = value.words.w1;

Expand Down Expand Up @@ -253,7 +253,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t xxx = (data & 0x0000000000FFF000) >> 12;
int32_t ddd = (data & 0x0000000000000FFF);

Gfx value = gsDPLoadBlock(i, sss, ttt, xxx, ddd);
Gfx value = {gsDPLoadBlock(i, sss, ttt, xxx, ddd)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -263,7 +263,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t vvvv = (data & 0xFFFF00000000) >> 32;
int32_t wwww = (data & 0x0000FFFF);

Gfx value = gsSPCullDisplayList(vvvv / 2, wwww / 2);
Gfx value = {gsSPCullDisplayList(vvvv / 2, wwww / 2)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -279,7 +279,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
uint32_t z = (data & 0x00000000FFFFFFFF) >> 0;
uint32_t h = (data & 0xFFFFFFFF);

Gfx value = gsSPBranchLessZraw3(h & 0x00FFFFFF);
Gfx value = {gsSPBranchLessZraw3(h & 0x00FFFFFF)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -292,7 +292,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
break;
case G_RDPHALF_2:
{
Gfx value = gsDPWordLo(data & 0xFFFFFFFF);
Gfx value = {gsDPWordLo(data & 0xFFFFFFFF)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -305,7 +305,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t XXX = (data & 0x0000000000FFF000) >> 12;
int32_t YYY = (data & 0x0000000000000FFF);

Gfx value = gsSPTextureRectangle2(XXX, YYY, xxx, yyy, i);
Gfx value = {gsSPTextureRectangle2(XXX, YYY, xxx, yyy, i)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -324,7 +324,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina

int bp = 0;

Gfx value = gsSPBranchLessZraw2(0xDEADABCD, (a / 5) | (b / 2), z);
Gfx value = {gsSPBranchLessZraw2(0xDEADABCD, (a / 5) | (b / 2), z)};
word0 = (value.words.w0 & 0x00FFFFFF) + (G_BRANCH_Z_OTR << 24);
word1 = value.words.w1;

Expand Down Expand Up @@ -389,9 +389,9 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
u32 dListVal = (data & 0x0FFFFFFF) + 1;

if (pp != 0)
value = gsSPBranchList(dListVal);
value = {gsSPBranchList(dListVal)};
else
value = gsSPDisplayList(dListVal);
value = {gsSPDisplayList(dListVal)};

word0 = value.words.w0;
word1 = value.words.w1;
Expand Down Expand Up @@ -469,7 +469,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t ddd = (____ & 0x700) >> 8;
int32_t nnnnnnn = (____ & 0xFE) >> 1;

Gfx value = gsSPTexture(ssss, tttt, lll, ddd, nnnnnnn);
Gfx value = {gsSPTexture(ssss, tttt, lll, ddd, nnnnnnn)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -480,7 +480,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2;
int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2;

Gfx test = gsSP1Triangle(aa, bb, cc, 0);
Gfx test = {gsSP1Triangle(aa, bb, cc, 0)};
word0 = test.words.w0;
word1 = test.words.w1;
}
Expand All @@ -494,7 +494,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t ee = ((data & 0x0000000000FF00ULL) >> 8) / 2;
int32_t ff = ((data & 0x000000000000FFULL) >> 0) / 2;

Gfx test = gsSP2Triangles(aa, bb, cc, 0, dd, ee, ff, 0);
Gfx test = {gsSP2Triangles(aa, bb, cc, 0, dd, ee, ff, 0)};
word0 = test.words.w0;
word1 = test.words.w1;
}
Expand All @@ -506,7 +506,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2;
int32_t dd = ((data & 0x000000000000FFULL)) / 2;

Gfx test = gsSP1Quadrangle(aa, bb, cc, dd, 0);
Gfx test = {gsSP1Quadrangle(aa, bb, cc, dd, 0)};
word0 = test.words.w0;
word1 = test.words.w1;
}
Expand All @@ -520,7 +520,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t bb = (data & 0x000000000000FF00) >> 8;
int32_t aa = (data & 0x00000000000000FF) >> 0;

Gfx value = gsDPSetPrimColor(mm, ff, rr, gg, bb, aa);
Gfx value = {gsDPSetPrimColor(mm, ff, rr, gg, bb, aa)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -534,7 +534,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina

// TODO: Output the correct render modes in data

Gfx value = gsSPSetOtherMode(0xE2, sft, len, dd);
Gfx value = {gsSPSetOtherMode(0xE2, sft, len, dd)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -552,11 +552,11 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
if (sft == 14) // G_MDSFT_TEXTLUT
{
const char* types[] = { "G_TT_NONE", "G_TT_NONE", "G_TT_RGBA16", "G_TT_IA16" };
value = gsDPSetTextureLUT(dd >> 14);
value = {gsDPSetTextureLUT(dd >> 14)};
}
else
{
value = gsSPSetOtherMode(0xE3, sft, nn + 1, dd);
value = {gsSPSetOtherMode(0xE3, sft, nn + 1, dd)};
}

word0 = value.words.w0;
Expand All @@ -583,7 +583,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4;
int32_t uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111);

Gfx value = gsDPSetTile(fff, ii, nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, ssss, dd, bbbb, uuuu);
Gfx value = {gsDPSetTile(fff, ii, nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, ssss, dd, bbbb, uuuu)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -607,7 +607,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t ab1 = (data & 0b00000000000000000000000000000000000000000000000000000000111000) >> 3;
int32_t ad1 = (data & 0b00000000000000000000000000000000000000000000000000000000000111) >> 0;

Gfx value = gsDPSetCombineLERP2(a0, b0, c0, d0, aa0, ab0, ac0, ad0, a1, b1, c1, d1, aa1, ab1, ac1, ad1);
Gfx value = {gsDPSetCombineLERP2(a0, b0, c0, d0, aa0, ab0, ac0, ad0, a1, b1, c1, d1, aa1, ab1, ac1, ad1)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -620,7 +620,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t vvv = (data & 0x0000000000000FFF);
int32_t i = (data & 0x000000000F000000) >> 24;

Gfx value = gsDPSetTileSize(i, sss, ttt, uuu, vvv);
Gfx value = {gsDPSetTileSize(i, sss, ttt, uuu, vvv)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -630,7 +630,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t t = (data & 0x0000000007000000) >> 24;
int32_t ccc = (data & 0x00000000003FF000) >> 14;

Gfx value = gsDPLoadTLUTCmd(t, ccc);
Gfx value = {gsDPLoadTLUTCmd(t, ccc)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -643,7 +643,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int uuu = (data & 0x0000000000FFF000) >> 12;
int vvv= (data & 0x0000000000000FFF);

Gfx value = gsDPLoadTile(i, sss, ttt, uuu, vvv);
Gfx value = {gsDPLoadTile(i, sss, ttt, uuu, vvv)};
word0 = value.words.w0;
word1 = value.words.w1;
}
Expand All @@ -661,7 +661,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
uint32_t fmt = (__ & 0xE0) >> 5;
uint32_t siz = (__ & 0x18) >> 3;

Gfx value = gsDPSetTextureImage(fmt, siz, www + 1, (seg & 0x0FFFFFFF) + 1);
Gfx value = {gsDPSetTextureImage(fmt, siz, www + 1, (seg & 0x0FFFFFFF) + 1)};
word0 = value.words.w0;
word1 = value.words.w1;

Expand All @@ -679,7 +679,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
uint32_t fmt = (__ & 0xE0) >> 5;
uint32_t siz = (__ & 0x18) >> 3;

Gfx value = gsDPSetTextureImage(fmt, siz, www + 1, __);
Gfx value = {gsDPSetTextureImage(fmt, siz, www + 1, __)};
word0 = value.words.w0 & 0x00FFFFFF;
word0 += (G_SETTIMG_OTR << 24);
//word1 = value.words.w1;
Expand Down Expand Up @@ -722,7 +722,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
int32_t aa = (data & 0x000000FF00000000ULL) >> 32;
int32_t nn = (data & 0x000FF00000000000ULL) >> 44;

Gfx value = gsSPVertex(data & 0xFFFFFFFF, nn, ((aa >> 1) - nn));
Gfx value = {gsSPVertex(data & 0xFFFFFFFF, nn, ((aa >> 1) - nn))};

word0 = value.words.w0;
word1 = value.words.w1 | 1;
Expand All @@ -745,7 +745,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
{
uint32_t diff = segOffset - vtxDecl->address;

Gfx value = gsSPVertex(diff, nn, ((aa >> 1) - nn));
Gfx value = {gsSPVertex(diff, nn, ((aa >> 1) - nn))};

word0 = value.words.w0;
word0 &= 0x00FFFFFF;
Expand Down Expand Up @@ -893,4 +893,4 @@ std::string OTRExporter_DisplayList::GetPrefix(ZResource* res)
prefix = "code";

return prefix;
}
}
4 changes: 2 additions & 2 deletions OTRExporter/OTRExporter/VersionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ std::map<Ship::ResourceType, uint32_t> resourceVersions;

void InitVersionInfo()
{
resourceVersions = {
resourceVersions = std::map<Ship::ResourceType, uint32_t> {
{ Ship::ResourceType::Animation, 0 },
{ Ship::ResourceType::Model, 0 },
{ Ship::ResourceType::Texture, 0 },
Expand All @@ -24,4 +24,4 @@ void InitVersionInfo()
{ Ship::ResourceType::Text, 0 },
{ Ship::ResourceType::Blob, 0 },
};
}
}
2 changes: 1 addition & 1 deletion ZAPDTR/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ lib/libgfxd/libgfxd.a:
.PHONY: StormLib
StormLib:
LDFLAGS="" cmake -B ../StormLib/build -S ../StormLib
LDFLAGS="" cmake --build ../StormLib/build
$(MAKE) -C ../StormLib/build

.PHONY: ExporterTest
ExporterTest:
Expand Down
Loading

0 comments on commit d4c1c40

Please sign in to comment.