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 <string.h>
#include <gsos.h> #include <gsos.h>
#include <orca.h>
#include <resources.h>
#include "io.h" #include "io.h"
#include "main.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 // Globals
static GSString255 outputFileName;
static Word writeResId;
static IORecGS writeRec; static IORecGS writeRec;
static char writeBuffer[4096]; static char writeBuffer[4096];
static int32_t writeBufferOffset = 0; static int32_t writeBufferOffset = 0;
@ -41,7 +53,6 @@ static void flushBuffer(void)
int openOutputFile(const char * filename) int openOutputFile(const char * filename)
{ {
GSString255 outputFileName;
CreateRecGS createRec; CreateRecGS createRec;
NameRecGS destroyRec; NameRecGS destroyRec;
OpenRecGS openRec; OpenRecGS openRec;
@ -82,6 +93,7 @@ int openOutputFile(const char * filename)
writeRec.pCount = 4; writeRec.pCount = 4;
writeRec.refNum = openRec.refNum; writeRec.refNum = openRec.refNum;
writeRec.dataBuffer = writeBuffer; writeRec.dataBuffer = writeBuffer;
return 0; return 0;
} }
@ -117,12 +129,38 @@ MD_SIZE outputPos(void)
void closeOutputFile(void) void closeOutputFile(void)
{ {
RefNumRecGS closeRec; RefNumRecGS closeRec;
int shutdownResources = 0;
if (writeBufferOffset > 0) if (writeBufferOffset > 0)
flushBuffer(); flushBuffer();
closeRec.pCount = 1; closeRec.pCount = 1;
closeRec.refNum = writeRec.refNum; closeRec.refNum = writeRec.refNum;
CloseGS(&closeRec); 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 // Globals
void * lowestStackSeen;
char * commandName; char * commandName;
int debugEnabled = 0; int debugEnabled = 0;
@ -89,8 +88,6 @@ int main(int argc, char * argv[])
MD_CHAR * inputBuffer; MD_CHAR * inputBuffer;
int index; int index;
lowestStackSeen = &result;
index = parseArgs(argc, argv); index = parseArgs(argc, argv);
if (index < 0) if (index < 0)
exit(1); exit(1);
@ -113,7 +110,6 @@ int main(int argc, char * argv[])
if (debugEnabled) { if (debugEnabled) {
fprintf(stderr, "Parser result: %d\n", result); fprintf(stderr, "Parser result: %d\n", result);
fprintf(stderr, "Most stack used: %lu\n", ((unsigned long)&result) - ((unsigned long)lowestStackSeen));
} }
if (result != 0) if (result != 0)

View File

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

View File

@ -191,7 +191,7 @@ executeGUI: all
make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)" make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)"
executeShell: all 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/createDiskImage "$(DISKIMAGE)" $(DESTBOOTIMAGE) "$(TARGETDIR)/outfile.txt"
make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)" make/launchEmulator "$(DISKIMAGE)" "$(DESTBOOTIMAGE)"

View File

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