From 23130678a10070028754f687b168a4c1bbebfeed Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 12 Mar 2017 13:10:15 +0200 Subject: [PATCH 1/4] Fixed compilation errors and warnings in Mac PowerPC target Tested with GCC 5.2 on 10.4 (32-bit only) and Clang from Xcode 8.2 on 10.12 (64-bit only) --- src/posix/cocoa/i_main.mm | 4 +++- src/sound/music_audiotoolbox_mididevice.cpp | 19 +++++++++++++++---- src/stats.h | 9 +++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/posix/cocoa/i_main.mm b/src/posix/cocoa/i_main.mm index 851e72e48..0d426caaa 100644 --- a/src/posix/cocoa/i_main.mm +++ b/src/posix/cocoa/i_main.mm @@ -173,7 +173,9 @@ static void I_DetectOS() "Unknown"; #endif - Printf("OS: %s %d.%d.%d (%s) %s\n", name, majorVersion, minorVersion, bugFixVersion, release, architecture); + Printf("OS: %s %d.%d.%d (%s) %s\n", name, + int(majorVersion), int(minorVersion), int(bugFixVersion), + release, architecture); } diff --git a/src/sound/music_audiotoolbox_mididevice.cpp b/src/sound/music_audiotoolbox_mididevice.cpp index 3dc57fdb0..ba48055e5 100644 --- a/src/sound/music_audiotoolbox_mididevice.cpp +++ b/src/sound/music_audiotoolbox_mididevice.cpp @@ -35,7 +35,7 @@ { \ DPrintf(DMSG_ERROR, \ "Failed with error 0x%08X at " __FILE__ ":%d:\n> %s", \ - result, __LINE__, #CALL); \ + int(result), __LINE__, #CALL); \ return __VA_ARGS__; \ } \ } @@ -55,7 +55,7 @@ int AudioToolboxMIDIDevice::Open(void (*callback)(unsigned int, void *, DWORD, D return 1; } - CFRunLoopAddTimer(CFRunLoopGetMain(), m_timer, kCFRunLoopDefaultMode); + CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_timer, kCFRunLoopDefaultMode); m_callback = callback; m_userData = userData; @@ -73,7 +73,7 @@ void AudioToolboxMIDIDevice::Close() if (nullptr != m_timer) { - CFRunLoopRemoveTimer(CFRunLoopGetMain(), m_timer, kCFRunLoopDefaultMode); + CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), m_timer, kCFRunLoopDefaultMode); CFRelease(m_timer); m_timer = nullptr; @@ -142,9 +142,16 @@ int AudioToolboxMIDIDevice::Resume() AUNode node; AT_MIDI_CHECK_ERROR(AUGraphGetIndNode(graph, i, &node), false); - AudioComponentDescription desc = {}; AudioUnit audioUnit = nullptr; +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 + ComponentDescription desc = {}; + UInt32 classdatasize = 0; + void *classdata = nullptr; + AT_MIDI_CHECK_ERROR(AUGraphGetNodeInfo(graph, node, &desc, &classdatasize, &classdata, &audioUnit), false); +#else // 10.5 and above + AudioComponentDescription desc = {}; AT_MIDI_CHECK_ERROR(AUGraphNodeInfo(graph, node, &desc, &audioUnit), false); +#endif // prior to 10.5 if ( kAudioUnitType_Output != desc.componentType || kAudioUnitSubType_DefaultOutput != desc.componentSubType) @@ -260,7 +267,11 @@ bool AudioToolboxMIDIDevice::Preprocess(MIDIStreamer* song, bool looping) return false; } +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 + AT_MIDI_CHECK_ERROR(MusicSequenceLoadSMFDataWithFlags(m_sequence, data, 0), false); +#else // 10.5 and above AT_MIDI_CHECK_ERROR(MusicSequenceFileLoadData(m_sequence, data, kMusicSequenceFile_MIDIType, 0), CFRelease(data), false); +#endif // prior to 10.5 CFRelease(data); diff --git a/src/stats.h b/src/stats.h index f18159616..c82410db1 100644 --- a/src/stats.h +++ b/src/stats.h @@ -130,6 +130,15 @@ inline unsigned long long rdtsc() unsigned long long tsc; asm volatile ("rdtsc; shlq $32, %%rdx; orq %%rdx, %%rax" : "=a" (tsc) :: "%rdx"); return tsc; +#elif defined __ppc__ + unsigned int lower, upper, temp; + do + { + asm volatile ("mftbu %0 \n mftb %1 \n mftbu %2 \n" + : "=r"(upper), "=r"(lower), "=r"(temp)); + } + while (upper != temp); + return (static_cast(upper) << 32) | lower; #else // i386 if (CPU.bRDTSC) { From bd889cc8f122ffec266bad763780624e10c0e5b4 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Sun, 12 Mar 2017 04:44:22 +0200 Subject: [PATCH 2/4] Fixed various virtualscope oddities; set scope for DECORATE classes to play. --- src/scripting/backend/codegen.cpp | 7 ++----- src/scripting/decorate/thingdef_parse.cpp | 6 ++++++ src/scripting/vm/vmexec.h | 8 ++++---- src/scripting/zscript/zcc_compile.cpp | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index dc904b804..76414e235 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -8815,11 +8815,8 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build) if (outerside == FScopeBarrier::Side_Virtual) outerside = FScopeBarrier::SideFromObjectFlags(CallingFunction->OwningClass->ObjectFlags); - if (selfside != outerside && (selfside == FScopeBarrier::Side_Play || selfside == FScopeBarrier::Side_UI)) // if the self pointer and the calling functions have the same scope the check here is not needed. - { - // Check the self object against the calling function's flags at run time - build->Emit(OP_SCOPE, selfemit.RegNum, outerside + 1, build->GetConstantAddress(vmfunc, ATAG_OBJECT)); - } + // Check the self object against the calling function's flags at run time + build->Emit(OP_SCOPE, selfemit.RegNum, outerside + 1, build->GetConstantAddress(vmfunc, ATAG_OBJECT)); } if (selfemit.Fixed && selfemit.Target) diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index 05a927288..9ad5e0e67 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -97,6 +97,12 @@ PClassActor *DecoDerivedClass(const FScriptPosition &sc, PClassActor *parent, FN sc.Message(MSG_FATAL, "Tried to define class '%s' more than twice in the same file.", typeName.GetChars()); } } + else + { + // [ZZ] DECORATE classes are always play + type->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(type->ObjectFlags, FScopeBarrier::Side_Play); + } + return type; } diff --git a/src/scripting/vm/vmexec.h b/src/scripting/vm/vmexec.h index b588d15d3..900d06ffa 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/scripting/vm/vmexec.h @@ -648,10 +648,10 @@ begin: reg.a[a] = p->Virtuals[C]; } NEXTOP; - OP(SCOPE) : - { - ASSERTA(a); ASSERTA(C); - FScopeBarrier::ValidateCall(((DObject*)konsta[a].v)->GetClass(), (VMFunction*)konsta[C].v, B - 1); + OP(SCOPE): + { + ASSERTA(a); ASSERTKA(C); + FScopeBarrier::ValidateCall(((DObject*)reg.a[a])->GetClass(), (VMFunction*)konsta[C].v, B - 1); } NEXTOP; diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 222c20a26..f18c3230f 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -658,12 +658,12 @@ void ZCCCompiler::CreateClassTypes() { Error(c->cls, "Can't change class scope in class %s", c->NodeName().GetChars()); } - c->Type()->ObjectFlags = (c->Type()->ObjectFlags & ~(OF_UI | OF_Play)) | (parent->ObjectFlags & (OF_UI | OF_Play)); + c->Type()->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(c->Type()->ObjectFlags, FScopeBarrier::SideFromObjectFlags(parent->ObjectFlags)); } } else { - c->Type()->ObjectFlags = (c->Type()->ObjectFlags&~OF_UI) | OF_Play; + c->Type()->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(c->Type()->ObjectFlags, FScopeBarrier::Side_Play); } c->Type()->bExported = true; // this class is accessible to script side type casts. (The reason for this flag is that types like PInt need to be skipped.) From 91e83bf3c6cfeb8b0f991a0efebb381ae33a10c5 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Sun, 12 Mar 2017 05:16:44 +0200 Subject: [PATCH 3/4] Fixed DECORATE scope for duplicates --- src/scripting/decorate/thingdef_parse.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scripting/decorate/thingdef_parse.cpp b/src/scripting/decorate/thingdef_parse.cpp index 9ad5e0e67..7ccc0b7d7 100644 --- a/src/scripting/decorate/thingdef_parse.cpp +++ b/src/scripting/decorate/thingdef_parse.cpp @@ -97,7 +97,8 @@ PClassActor *DecoDerivedClass(const FScriptPosition &sc, PClassActor *parent, FN sc.Message(MSG_FATAL, "Tried to define class '%s' more than twice in the same file.", typeName.GetChars()); } } - else + + if (type != nullptr) { // [ZZ] DECORATE classes are always play type->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(type->ObjectFlags, FScopeBarrier::Side_Play); From 0176c29ec29901c8f3f3bb9c30bdb3544abacb51 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Sun, 12 Mar 2017 12:03:41 +0200 Subject: [PATCH 4/4] Will not emit OP_SCOPE if self type can be checked at compile time. --- src/scripting/backend/codegen.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 76414e235..0ea6517da 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -8815,8 +8815,12 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build) if (outerside == FScopeBarrier::Side_Virtual) outerside = FScopeBarrier::SideFromObjectFlags(CallingFunction->OwningClass->ObjectFlags); - // Check the self object against the calling function's flags at run time - build->Emit(OP_SCOPE, selfemit.RegNum, outerside + 1, build->GetConstantAddress(vmfunc, ATAG_OBJECT)); + // [ZZ] only emit if target side cannot be checked at compile time. + if (selfside == FScopeBarrier::Side_PlainData) + { + // Check the self object against the calling function's flags at run time + build->Emit(OP_SCOPE, selfemit.RegNum, outerside + 1, build->GetConstantAddress(vmfunc, ATAG_OBJECT)); + } } if (selfemit.Fixed && selfemit.Target)