📄 main.c
字号:
/************************************************************
2007.04.11 chenyong žùŸÝbill bluntonµÄÔŽ³ÌÐòžÄ¶š¡£
ÒÑÖª²»×㣺
<1> ¶ÔÎÄŒþžñÊœµÄÑÏœ÷ÐÔУÑé²»×ã.
<1.1> .PB ºóÓŠžÃºóœÓ.PE£¬ ŒŽ.PBºÍ.PEÓŠÅä¶Ô³öÏÖ£¬µ«ÏÖÔÚ²»ÐŽ.PEÒ²¿ÉÒÔ±àÒëÍš¹ý¡£
(žÄœøÏë·š£ºÔÚmain.c ÖÐÔöŒÓÒ»žöcurrentProcPass1ÊÇ·ñµÈÓÚOUTSIDE_PROC_PASS1µÄÅжϡ£
<1.2> ÿÌõÖžÁӊµ±ÔÚÒ»žö(.PB, .PE)Ö®Œä¡£
(žÄœøÏë·š£ºÔÚpass1_parseLine ÖÐµÄ processInstruction() ֮ǰÔöŒÓÒ»žö¶ÔcurrentProcPass1
µÄÅжϡ£
*************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include "common.h"
#include "error.h"
#include "linux.h"
#include "cmdline.h"
#include "strtbl.h"
#include "lnscan.h"
#include "linetok.h"
#include "pass1.h"
#include "pass2.h"
#include "bldfile.h"
#include "hashtbl.h"
#include "symtbl.h"
#define MAIN_DEBUG 1
#ifdef MAIN_DEBUG
#define MAIN_DEBUG0(arg); printf("main(): ");printf(arg);
#define MAIN_DEBUG1(arg1,arg2); printf("main(): ");printf(arg1,arg2);
#define MAIN_DEBUG2(arg1,arg2,arg3); printf("main(): ");printf(arg1,arg2,arg3);
#else
#define MAIN_DEBUG0(arg);
#define MAIN_DEBUG1(arg1,arg2);
#define MAIN_DEBUG2(arg1,arg2,arg3);
#endif
int main(int argc, char *argv[])
{
int bRet;
struct Line line; maxErrors = 10;
nErrors = 0;
/*1) handle command line arguments */
MAIN_DEBUG0("handling arguments\n");
cmdline_init();
if (handleArgs(argc,argv) == FALSE)
{
shutDown(SHUTDOWN_ERROR);
}
/*2) PASS1 - scan, parse, populate symbol table*/
MAIN_DEBUG0("initiating first pass\n");
bRet = strtbl_init();
if (bRet == FALSE)
{
shutDown(SHUTDOWN_ERROR);
}
bRet = SymbolTable_init();
if (bRet == FALSE)
{
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
HashTable_init();
bRet = LineScanner_init();
if (bRet == FALSE)
{
LineScanner_free();
HashTable_free();
SymbolTable_free();
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
pass1_init();
line = getInputLine();
while (line.end != TRUE)
{
pass1_parseLine(&line);
line = getInputLine();
}
pass1_parseLine(&line);
LineScanner_free();
/*if errors exist, shutdown before generate anything*/
if (nErrors > 0)
{
printf("%d Error(s) during first pass\n", nErrors);
printf("build failed\n");
HashTable_free();
SymbolTable_free();
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
/*3) PASS2 - create bytecode temp file and listing file */
MAIN_DEBUG0("\ninitiating second pass\n");
bRet = LineScanner_init();
if (bRet == FALSE)
{
LineScanner_free();
HashTable_free();
SymbolTable_free();
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
bRet = pass2_init();
if (bRet == FALSE)
{
pass2_free();
LineScanner_free();
HashTable_free();
SymbolTable_free();
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
line = getInputLine();
while (line.end != TRUE)
{
pass2_parseLine(&line);
if (nErrors > 0)
{
printf("main(): %d Error(s) during second pass\n", nErrors);
printf("main(): build failed\n");
pass2_free();
LineScanner_free();
HashTable_free();
SymbolTable_free();
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
line = getInputLine();
}
pass2_parseLine(&line);
if (nErrors > 0)
{
printf("main(): %d Error(s) during second pass\n", nErrors);
printf("main(): build failed\n");
pass2_free();
LineScanner_free();
HashTable_free();
SymbolTable_free();
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
if (listing == TRUE)
generateSymbolSummary();
pass2_free();
LineScanner_free();
MAIN_DEBUG1("%lu bytes written to tempfile\n", bytePosPass2);
/*4) build compilation unit */
MAIN_DEBUG0("building bytecode executable\n");
bRet = BuildFile_init();
if (bRet == FALSE)
{
BuildFile_free();
HashTable_free();
SymbolTable_free();
strtbl_free();
shutDown(SHUTDOWN_ERROR);
}
buildFileFormat();
BuildFile_free();
SymbolTable_free();
HashTable_free();
strtbl_free();
printf("main(): exiting with (%d) errors\n", nErrors);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -