home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
- *
- *
- * Unit containing main assembling code.
- *
- * by Adrian Bool in cooperation with Graham Cox.
- *
- * copyright © phantasm coding 1992.
- *
- *
- ************************************************************/
-
- #include "Global.h"
- #include "Assemble.h"
-
- #include "Assemble.proto.h"
-
- pHandle newProgram(void)
- {
- pHandle temp;
-
- temp = (pHandle) NewHandle(sizeof(program));
-
- if (temp != nil)
- {
- (*temp)->sourceCode = newSource();
- (*temp)->objectCode = newObject();
- (*temp)->labelHeader = newLabelList();
- }
- return(temp);
- }
-
-
- void disposeProgram(pHandle theProgram)
- {
- disposeSource((*theProgram)->sourceCode);
- disposeObject((*theProgram)->objectCode);
- disposeLabelList((*theProgram)->labelHeader);
-
- DisposHandle((Handle) theProgram);
- }
-
-
- void pass(pHandle theProgram , short pass)
- {
- str255 aSection;
- int sectionOk;
- opcode theOpcode;
-
- rBlock resultBlock;
- short resultSize;
-
- sHandle sourceCode;
- oHandle objectCode;
- lHandle labelHeader;
-
- sourceCode = (*theProgram)->sourceCode;
- objectCode = (*theProgram)->objectCode;
- labelHeader = (*theProgram)->labelHeader;
-
- (*sourceCode)->line = 0;
-
- if (sourceCode != nil && objectCode != nil && labelHeader != nil)
- {
- (*objectCode)->address = (*objectCode)->startAddress;
- (*objectCode)->position = 0;
- (*sourceCode)->caret = 0;
- (*sourceCode)->line = 1;
- do
- {
- theOpcode = 0;
- getSection(theProgram,aSection);
- if (!AsmError)
- {
- if (aSection[0] == ';')
- {
- /* a comment has been encountered */
-
- nextLine(sourceCode);
- }
- else
- {
- if (aSection[lengthOfString(aSection)-1] == ':')
- {
- /* a defining label has been found */
-
- if (pass == 1) newLabel(theProgram,aSection,(*objectCode)->address);
- }
-
- else
- {
- if (theOpcode = getOpcode(aSection))
- {
- /* an opcode has been found */
-
- assembleOpcode(theOpcode,pass,resultBlock,&resultSize,theProgram);
- if (pass == 2) addBlock(objectCode,resultBlock,resultSize);
- (*objectCode)->position += resultSize;
- (*objectCode)->address += resultSize;
- }
- }
- }
- }
- }
- while (theOpcode != end && AsmError==noErr);
- (*(*theProgram)->objectCode)->size = (*(*theProgram)->objectCode)->position;
- }
- else
- AsmError = NotEnoughMemory;
- }
-
-
-