Use the --mem argument in Golden Gate to get an accurate stack usage value. Beginnings of work on writing resource information.

This commit is contained in:
Jeremy Rand 2021-04-28 23:20:20 -04:00
parent ce6666456d
commit 8b97df852c
5 changed files with 40 additions and 23 deletions

View File

@ -12,13 +12,25 @@
#include <string.h>
#include <gsos.h>
#include <orca.h>
#include <resources.h>
#include "io.h"
#include "main.h"
// Defines
// This enables a workaround for creating the resources by writing a .rez file rather than
// writing it directly. At the moment, Golden Gate does not support writing resources
// but this will let me test it without that capability.
#define RESOURCE_WORKAROUND
// Globals
static GSString255 outputFileName;
static Word writeResId;
static IORecGS writeRec;
static char writeBuffer[4096];
static int32_t writeBufferOffset = 0;
@ -41,7 +53,6 @@ static void flushBuffer(void)
int openOutputFile(const char * filename)
{
GSString255 outputFileName;
CreateRecGS createRec;
NameRecGS destroyRec;
OpenRecGS openRec;
@ -82,6 +93,7 @@ int openOutputFile(const char * filename)
writeRec.pCount = 4;
writeRec.refNum = openRec.refNum;
writeRec.dataBuffer = writeBuffer;
return 0;
}
@ -117,12 +129,38 @@ MD_SIZE outputPos(void)
void closeOutputFile(void)
{
RefNumRecGS closeRec;
int shutdownResources = 0;
if (writeBufferOffset > 0)
flushBuffer();
closeRec.pCount = 1;
closeRec.refNum = writeRec.refNum;
CloseGS(&closeRec);
if (!ResourceStatus()) {
ResourceStartUp(userid());
shutdownResources = 1;
}
#ifdef RESOURCE_WORKAROUND
CreateResourceFile(0x5445, 0x50, destroyEnable | renameEnable | readWriteEnable, (Pointer)outputFileName);
if (toolerror()) {
fprintf(stderr, "%s: Unable to create resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
}
writeResId = OpenResourceFile(0x8000 | readWriteEnable, NULL, (Pointer)outputFileName);
if (toolerror()) {
fprintf(stderr, "%s: Unable to open resources of file %s, toolerror=0x%x\n", commandName, outputFileName.text, toolerror());
} else {
CloseResourceFile(writeResId);
}
// Implement more of this...
if (shutdownResources)
ResourceShutDown();
#else
// Implement the workaround here...
#endif
}

View File

@ -33,7 +33,6 @@
// Globals
void * lowestStackSeen;
char * commandName;
int debugEnabled = 0;
@ -89,8 +88,6 @@ int main(int argc, char * argv[])
MD_CHAR * inputBuffer;
int index;
lowestStackSeen = &result;
index = parseArgs(argc, argv);
if (index < 0)
exit(1);
@ -113,7 +110,6 @@ int main(int argc, char * argv[])
if (debugEnabled) {
fprintf(stderr, "Parser result: %d\n", result);
fprintf(stderr, "Most stack used: %lu\n", ((unsigned long)&result) - ((unsigned long)lowestStackSeen));
}
if (result != 0)

View File

@ -11,7 +11,6 @@
#pragma memorymodel 1
extern char * commandName;
extern void * lowestStackSeen;
extern int debugEnabled;

View File

@ -191,7 +191,7 @@ executeGUI: all
make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)"
executeShell: all
$(ORCA) $(TARGETDIR)/$(PGM) -d test.md $(TARGETDIR)/outfile.txt
$(ORCA) --mem $(TARGETDIR)/$(PGM) -d test.md $(TARGETDIR)/outfile.txt
make/createDiskImage "$(DISKIMAGE)" $(DESTBOOTIMAGE) "$(TARGETDIR)/outfile.txt"
make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)"

View File

@ -323,10 +323,6 @@ static int enterBlockHook(MD_BLOCKTYPE type, void * detail, void * userdata)
newBlock->next = blockList;
blockList = newBlock;
if ((detail != NULL) &&
(detail < lowestStackSeen))
lowestStackSeen = detail;
switch (type) {
case MD_BLOCK_DOC:
if (debugEnabled)
@ -501,10 +497,6 @@ static int leaveBlockHook(MD_BLOCKTYPE type, void * detail, void * userdata)
blockList = oldBlock->next;
free(oldBlock);
if ((detail != NULL) &&
(detail < lowestStackSeen))
lowestStackSeen = detail;
switch (type) {
case MD_BLOCK_DOC:
break;
@ -559,10 +551,6 @@ static int leaveBlockHook(MD_BLOCKTYPE type, void * detail, void * userdata)
static int enterSpanHook(MD_SPANTYPE type, void * detail, void * userdata)
{
if ((detail != NULL) &&
(detail < lowestStackSeen))
lowestStackSeen = detail;
switch (type) {
case MD_SPAN_EM:
if (debugEnabled)
@ -609,10 +597,6 @@ static int enterSpanHook(MD_SPANTYPE type, void * detail, void * userdata)
static int leaveSpanHook(MD_SPANTYPE type, void * detail, void * userdata)
{
if ((detail != NULL) &&
(detail < lowestStackSeen))
lowestStackSeen = detail;
switch (type) {
case MD_SPAN_EM:
textStyleMask &= ~STYLE_TEXT_MASK_EMPHASIZED;