forked from KolibriOS/kolibrios
Add sources of "C--"'like compiler written in C--.
git-svn-id: svn://kolibrios.org@1846 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
d21a6e85e7
commit
02b76505a6
@ -222,6 +222,7 @@ CMM_PROGRAMS:=\
|
||||
games/clicks:GAMES/CLICKS:$(PROGS)/games/clicks/trunk/clicks.c-- \
|
||||
games/FindNumbers:GAMES/FindNumbers:$(PROGS)/games/FindNumbers/trunk/FindNumbers.c-- \
|
||||
games/mine:GAMES/MINE:$(PROGS)/games/mine/trunk/mine.c--:/MEOS \
|
||||
develop/c--:DEVELOP/C--:$(PROGS)/develop/c--/trunk/32.c-- \
|
||||
# end of list
|
||||
|
||||
# List of other files to be included in the image file.
|
||||
|
1441
programs/develop/c--/trunk/32.c--
Normal file
1441
programs/develop/c--/trunk/32.c--
Normal file
File diff suppressed because it is too large
Load Diff
157
programs/develop/c--/trunk/data.h--
Normal file
157
programs/develop/c--/trunk/data.h--
Normal file
@ -0,0 +1,157 @@
|
||||
//===== ƒ«®¡ «ìë¥ ¯¥à¥¬¥ë¥
|
||||
// ---- ˆä®à¬ æ¨ï ¯® tokens
|
||||
dword tok=0;
|
||||
dword type=0;
|
||||
dword src=0;
|
||||
dword post=0;
|
||||
dword number=0;
|
||||
byte string[STRLEN]=0;
|
||||
dword tok2=0;
|
||||
dword type2=0;
|
||||
dword src2=0;
|
||||
dword post2=0;
|
||||
dword number2=0;
|
||||
dword modline=0;
|
||||
byte string2[STRLEN]=0;
|
||||
// ---- <20>ãä¥à ã¯à ¢«ïî騥 ä« £¨
|
||||
dword currmod=0; // <20>®¬¥à ⥪ã饣® ä ©«
|
||||
dword displaytokerrors=1;// ”« £ ¢ë¢®¤ á®®¡é¥ © ®¡ ®è ¡ª¥
|
||||
dword error=0; // ‘®¤¥à¦¨â ®¬¥à ⥪ã饩 ®è¨¡ª
|
||||
dword maxerrors = 16; // <20>।¥« ¯® ª®«¨ç¥áâ¢ã ®è¨¡®ª
|
||||
dword makemapfile=0; // ”« £ £¥¥à æ ¨ MAP-ä ©«
|
||||
dword dbg=0; // ”« £ £¥¥à æ ¨ TDS-ä ©« ¤«ï TD32
|
||||
dword dbginfo=0; // “ª § â¥«ì ¡ãä¥à dbg ¨ä®à¬ 樥© (á¬.®¯¨á ¨¥ ¢ enum dbg_...)
|
||||
dword dbgs=0; // ’¥ªã騩 㪠§ â¥«ì ¢ dbginfo
|
||||
dword input=0; // “ª § ⥫ì ç «® ¤¨ ¬¨ç¥áª®£® ¡ãä¥à á ¢å®¤ë¬ ä ©«®¬
|
||||
dword inptr=0; // “ª § ⥫ì ⥪ãé ᨬ¢®« ¢ ¡ãä¥à¥ input
|
||||
dword inptr2=0; // Š®¯¨ï inptr
|
||||
dword endoffile=0; // ”« £ ª®æ ä ©«
|
||||
dword totallines=1; // Ž¡é¥¥ ª®«¨ç¥á⢮ ®âª®¬¯¨«¨à®¢ ëå áâப
|
||||
dword linenumber=0; // <20>®¬¥à ⥪ã饩 áâப¨
|
||||
dword linenum2=0; // <20>®¬¥à á«¥¤ãî饩 áâப¨
|
||||
dword list=0; // ”« £ ¢ë¤ ç¨ «¨á⨣
|
||||
dword label=0; // ‘ª¢®§®© ®¬¥à ¤«ï «®ª «ìëå ¬¥â®ª
|
||||
dword mapfile=0; // Handle ¤«ï MAP ä ©«
|
||||
dword module=0; // ‘ç¥â稪 ®âª®¬¯¨«¨à®¢ ëå ¬®¤ã«¥©
|
||||
dword outptr=0; // ˆ¤¥ªá ¢ output
|
||||
dword output=0; // “ª § â¥«ì ¡ãä¥à á ª®¤®¬
|
||||
dword localsize=0; // <20> §¬¥à á⥪ ¯®¤ «®ª «ì묨 ¯¥à¥¬¥ë¬¨
|
||||
dword posttype=0; // “ª § ⥫ì ⨯ POST
|
||||
dword postloc=0; // “ª § â¥«ì ¯®«®¦¥¨¥ ¢ output
|
||||
dword postnum=0; // “ª § â¥«ì § 票¥ ¯® postloc
|
||||
dword posts=0; // <20>®¬¥à ⥪ã饩 § ¯¨á¨ ¢ posttype, postloc ¨ postnum
|
||||
dword postsize=0; // ‘㬬 àë© à §¬¥à ¢á¥å post-¯¥à¥¬¥ëå
|
||||
dword poststrptr=MAXDATA-1; // ˆ¤¥ªá ¤«ï ¢ë¢®¤ post-áâப
|
||||
dword procedure_start=0;// €¤à¥á ç « ¯à®æ¥¤ãàë
|
||||
dword runfilesize=0;
|
||||
dword startptr=0; // “ª § ⥫ì main()
|
||||
dword treestart=0; // “ª § ⥫ì ç «® ᯨ᪠¨¤¥â¨ä¨ª â®à®¢
|
||||
dword treeptr=0; // “ª § ⥫ì ⥪ãéã § ¯¨áì ¢ ᯨ᪥ ¨¤¥â ª â®à®¢
|
||||
dword locallist = NULL; // “ª § ⥫ì ç «® ᯨ᪠«®ª «ìëå ¯¥à¥¬¥ëå
|
||||
dword localptr=NULL; // “ª § ⥫ì ⥪ãéãî § ¯¨áì ¢ ᯨ᪥ «®ª «ìëå
|
||||
dword DLLcount=0; // ‘ç¥â稪 ¨¬¯®àâ¨à®¢ ëå DLL
|
||||
dword APIcount=0; // ‘ç¥â稪 ¨á¯®«ì§ã¥¬ëå API
|
||||
dword importFlag=0; // ”« £ ¨¬¯®àâ ¨§ DLL
|
||||
dword DLLlist[MAXDLLS];
|
||||
byte currentfilename[FILENAMESIZE] = 0;
|
||||
byte inputfile[FILENAMESIZE]=0;
|
||||
byte rawfilename[FILENAMESIZE]=0;
|
||||
byte mapstr[120]=0;
|
||||
// ---- DOS&PE headers
|
||||
word exeheader[34]={
|
||||
0x5A4D,0x40,1,0,2,0,0xFFFF,0,
|
||||
0,0,0,0,0x40,0,0,0,
|
||||
0xC88C,0xD88E,0x0FBA,0xB400,0xCD09,0xB821,0x4C00,0x21CD,
|
||||
0x6957,0x336E,0x2032,0x6E6F,0x796C,0x2421,0x40,0,
|
||||
0x4550,0};
|
||||
// PE Header
|
||||
//unsigned dword PEsign = 0x4550;
|
||||
word PEmachine=0x14C; // target machine = Intel 386
|
||||
word PEnSections=1; // XAC - only .text!!! number of sections in Sections table
|
||||
word PEDate=0;
|
||||
word PEtime=0;
|
||||
dword PEpSymbolTable=0; // Offset within COFF file of the symbol table
|
||||
dword PEnSymbols=0; // number of entries in the symbol table
|
||||
word PEOptHeaderSize=0xE0; // Size of optional header
|
||||
word PECharacteristics=0x30E; //0x30E 32-bit+...
|
||||
// Optional header (only in EX image)
|
||||
word OptMagic=0x10B; // normal executable
|
||||
byte OptLmajor=2; // Linker major version number
|
||||
byte OptLminor=0x37; // Linker minor version number
|
||||
dword OptCodeSize=0; // Size of the code section
|
||||
dword OptInitDataSize=0; // Size of the initialized data section
|
||||
dword OptUninitDataSize=0;// Size of the uninitialized data section (BSS)
|
||||
dword OptEntryPointRVA=0x1000;// Address of entry point, relative to image base
|
||||
dword OptBaseOfCode=0x1000;// Address realtive to image base
|
||||
dword OptBaseOfData=0;//Address realtive to image base
|
||||
dword OptImageBase=0x00400000;// Preferred address of first byte of image
|
||||
dword OptSectionAlignment=0x1000;
|
||||
dword OptFileAlignment=0x200;
|
||||
word OptOSmajor=1;
|
||||
word OptOSminor=0;
|
||||
dword OptUserVersion=0;
|
||||
word OptSubSysMajor=4;
|
||||
word OptSubSysMinor=0;
|
||||
dword OptReserved=0;
|
||||
dword OptImageSize=0x0; // Size of image, including all headers
|
||||
dword OptHeaderSize=0x200; //DOSheader+PEheader+ObjectTable
|
||||
dword OptFileChecksum=0; // Image file checksum
|
||||
word OptSubSystem=3; // 2-GUI; 3-console
|
||||
word OptDLLflag=0;
|
||||
dword OptStackReserveSize=0x100000;
|
||||
dword OptStackCommitSixe=0x1000;
|
||||
dword OptHeapReserveSize=0x100000;
|
||||
dword OptHeapCommitSize=0x1000;
|
||||
dword OptLoaderSize=0;
|
||||
dword OptNumOfDataDirectories=16;
|
||||
// Optional header Data Directories
|
||||
dword OptExportTableAdr=0;
|
||||
dword OptExportTableSize=0;
|
||||
dword OptImportTableAdr=0;
|
||||
dword OptImportTableSize=0;
|
||||
dword OptResourceTableAdr=0;
|
||||
dword OptResourceTablesize=0;
|
||||
dword OptExceptionTableAdr=0;
|
||||
dword OptExceptionTableSize=0;
|
||||
dword OptSecurityTableAdr=0;
|
||||
dword OptSecurityTableSize=0;
|
||||
dword OptBaseRelocationTableAdr=0;
|
||||
dword OptBaseRelocationTableSize=0;
|
||||
dword OptDebugAdr=0;
|
||||
dword OptDebugSize=0;
|
||||
dword OptCopyrightAdr=0;
|
||||
dword OptCopyrightSize=0;
|
||||
dword OptGlobalPtrAdr=0;
|
||||
dword OptGlobalPtrSize=0;
|
||||
dword OptTLStableAdr=0;
|
||||
dword OptTLStablesize=0;
|
||||
dword OptLoadConfigTableAdr=0;
|
||||
dword OptLoadConfigTableSize=0;
|
||||
dword OptReserved2[10]={0,0,0,0,0,0,0,0,0,0};
|
||||
// Sections Table
|
||||
// TEXT section header
|
||||
byte TxtSectionName[8]=".text";
|
||||
dword TxtVirtualSize=0;
|
||||
dword TxtRVAoffset=0x1000;
|
||||
dword TxtSizeOfRawData=0;
|
||||
dword TxtPointerToRawData=0x200;
|
||||
dword TxtPointerToRelocs=0;
|
||||
dword TxtPointerToLinenumbers=0;
|
||||
word TxtNumberOfRelocs=0;
|
||||
word TxtNumberOfLinenumbers=0;
|
||||
dword TxtSectionFlags=0xE00000E0; // can be executed + contain executable code
|
||||
// ---- <20>¥¨¨æ àã¥¬ë¥ ¤ ë¥
|
||||
dword stdout; // Handle to stdout
|
||||
byte cha,cha2;
|
||||
dword numberofids;
|
||||
dword current_proc_type; // ’¨¯ ⥪ã饩 ¯à®æ¥¤ãàë (cpt_near, cpt_far)
|
||||
dword returntype; // ’¨¯ ¢®§¢à é ¥¬®£® § 票ï (void, byte, word, ...)
|
||||
dword paramsize;
|
||||
dword relation;
|
||||
dword startlabel,endlabel;
|
||||
byte modules[MAXMDL*FILENAMESIZE];
|
||||
dword St_Mnemonics[26];
|
||||
dword St_Registers[26];
|
||||
dword St_Directives[26];
|
||||
dword St_Sizes[26];
|
||||
byte Buffer16[64]; // <20>ãä¥à ¤«ï á®àâ¨à®¢ª áâப
|
986
programs/develop/c--/trunk/directiv.h--
Normal file
986
programs/develop/c--/trunk/directiv.h--
Normal file
@ -0,0 +1,986 @@
|
||||
byte Directives={
|
||||
"IF","ELSE","ENDIF", // “á«®¢ ï ª®¬¯¨«ïæ¨ï
|
||||
"INCLUDE","DEFINE", // ‚ª«î票¥ ä ©« /Ž¯à¥¤¥«¥¨¥ ª®áâ âë
|
||||
"IMPORT", // ˆ¬¯®àâ ¨§ DLL ¯® ¨¬¥¨ API
|
||||
"IMPORTN", // ˆ¬¯®àâ ¨§ DLL ¯® ®¬¥àã API
|
||||
"MAP", // ƒ¥¥à æ¨ï MAP-ä ©«
|
||||
"DEBUG", // ƒ¥¥à æ¨ï ®â« ¤®ç®© ¨ä®à¬ 樨
|
||||
"LIST", // ‚ë¤ ç ASM-«¨á⨣
|
||||
"DLL", // ƒ¥¥à æ¨ï DLL-ä ©«
|
||||
"DB","DW","DD", // ’¨¯ë ¯¥à¥¬¥ëå
|
||||
"BYTE","CHAR","WORD","SHORT","DWORD","INT",
|
||||
"ENUM", // <20>㬥஢ ë¥ ª®áâ âë
|
||||
"STRUC", // Ž¯à¥¤¥«¥¨¥ áâàãªâãàë
|
||||
"CYCLE","RETURN",
|
||||
"WHILE","DO","INLINE",
|
||||
"CONTINUE","BREAK",
|
||||
"DOCASE","CASE","DEFAULT",
|
||||
"CARRYFLAG","EXTRACT","FROM",
|
||||
"NOTCARRYFLAG","NOTOVERFLOW","OVERFLOW",
|
||||
"ZEROFLAG","NOTZEROFLAG",_END};
|
||||
// ----- „«ï tokens, <20>… ®¡à ¡ âë¢ ¥¬ëå ç¥à¥§ â ¡«¨æã ¯¥à¥ª«îç ⥫¥©
|
||||
EMPTY()
|
||||
{
|
||||
WRITESTR(#string);
|
||||
WRITESTR("-ToDo\n");
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// ---- ‚®§¢à é ¥â ¤à¥á ¨§ Jmp_....
|
||||
dword GetDirAddr(dword table,num)
|
||||
{
|
||||
EAX=num<<2+table;
|
||||
EAX=DSDWORD[EAX];
|
||||
}
|
||||
|
||||
// ----- „¨à¥ªâ¨¢ #define
|
||||
DirDefine()
|
||||
byte holdid[IDLENGTH];
|
||||
dword next;
|
||||
{
|
||||
next=1;
|
||||
NextTok();
|
||||
if(tok==tk_id){
|
||||
lstrcpyA(#holdid,#string); // ˆ¬ï ª®áâ âë
|
||||
NextTok();
|
||||
IF(tok==tk_eof) unexpectedeof();
|
||||
ELSE IF(tok==tk_number){
|
||||
AddConstToTree(#holdid,DoConstLongMath()); next = 0;
|
||||
}
|
||||
ELSE IF(tok==tk_minus){
|
||||
IF(tok2==tk_number) {
|
||||
AddConstToTree(#holdid,DoConstLongMath());
|
||||
next = 0;
|
||||
}
|
||||
}
|
||||
ELSE IF(tok==tk_undefproc){
|
||||
tok = tk_id; AddToTree(#holdid);
|
||||
}
|
||||
ELSE AddToTree(#holdid);
|
||||
}
|
||||
ELSE idexpected();
|
||||
IF(next)NextTok();
|
||||
}
|
||||
|
||||
// -- #enum
|
||||
DirEnum()
|
||||
dword counter;
|
||||
byte holdid[IDLENGTH];
|
||||
{
|
||||
counter=0;
|
||||
NextTok();
|
||||
IF(tok!=tk_openbrace)expected('{');
|
||||
for(;;){
|
||||
NextTok();
|
||||
IF(tok==tk_id){
|
||||
lstrcpyA(#holdid,#string);
|
||||
IF( tok2 == tk_assign ){
|
||||
NextTok(); NextTok();
|
||||
IF(tok==tk_number)counter=DoConstLongMath();
|
||||
ELSE numexpected();
|
||||
}
|
||||
AddConstToTree(#holdid,counter);
|
||||
counter++;
|
||||
CONTINUE;
|
||||
}
|
||||
IF(tok==tk_comma)CONTINUE;
|
||||
IF(tok==tk_semicolon)BREAK;
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// „¨à¥ªâ¨¢ #import
|
||||
DirImport()
|
||||
{
|
||||
NextTok();
|
||||
IF(tok==tk_string)GetImport(1); // import ¯® ¨¬¥¨ API-äãªæ¨©
|
||||
ELSE stringexpected();
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// „¨à¥ªâ¨¢ #importN
|
||||
DirImportN()
|
||||
{
|
||||
NextTok();
|
||||
IF(tok==tk_string)GetImport(0); // import ¯® ¨¬¥¨ API-äãªæ¨©
|
||||
ELSE stringexpected();
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// ---- ˆ¬¯®àâ ¨§ DLL
|
||||
GetImport(dword byName)
|
||||
dword dll;
|
||||
dword dllpos,base,export,fptr,i,nexports,nsect,delta;
|
||||
byte path[80],name[120];
|
||||
dword tok0,type0,src0,post0;
|
||||
dword number0;
|
||||
dword ord;
|
||||
dword pname1,pname2,j;
|
||||
{
|
||||
pname1 = 0; ord=0; importFlag=1;
|
||||
IF(DLLcount>=MAXDLLS)outofmemory2();
|
||||
IF(SearchTree(#tok0,#type0,#src0,#post0,#string,#number0))return; // DLL 㦥 ¨¬¯®àâ¨à®¢
|
||||
wsprintfA(#name,"%s",#string);
|
||||
dll=_lopen(#name,0);
|
||||
IF(dll== -1){
|
||||
GetSystemDirectoryA(#path,80);
|
||||
wsprintfA(#name,"%s\\%s",#path,#string);
|
||||
dll=_lopen(#name,0);
|
||||
IF(dll==-1) {
|
||||
unabletoopen(#string);
|
||||
return;
|
||||
}
|
||||
}
|
||||
nsect=0;
|
||||
_llseek(dll,0x3c,0); _lread(dll,#fptr,4);
|
||||
_llseek(dll,fptr+120,0); _lread(dll,#export,4); // Get export address
|
||||
IF(export==0) {
|
||||
wsprintfA(#mapstr,"ERROR: No export directory in file %s.\n",#string);
|
||||
preerror(#mapstr); return;
|
||||
}
|
||||
_llseek(dll,fptr+6,0); _lread(dll,#nsect,2); // Number of sections
|
||||
delta=export;
|
||||
i=1;
|
||||
while(i<=nsect){
|
||||
EAX=i; EAX--; EAX=EAX*40; EAX+=260; EAX+=fptr; // fptr+260+40*(i-1)
|
||||
_llseek(dll,EAX,0); _lread(dll,#base,4); // RVA of section
|
||||
IF(base<=export){
|
||||
EAX=export-base;
|
||||
IF(EAX<delta){
|
||||
delta=export-base;
|
||||
EAX=i; EAX--; EAX=EAX*40; EAX+=268; EAX+=fptr; // fptr+268+40*(i-1)
|
||||
_llseek(dll,EAX,0); _lread(dll,#dllpos,4);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
dllpos = dllpos + delta; // filepos for export directory table
|
||||
delta = dllpos - export;
|
||||
_llseek(dll,dllpos+24,0); _lread(dll,#nexports,4); // number of entries for export
|
||||
_llseek(dll,dllpos+32,0); _lread(dll,#base,4); // address of export name pointer table
|
||||
_llseek(dll,dllpos+36,0); _lread(dll,#fptr,4);// address of Ordinal Table
|
||||
base=base+delta; fptr=fptr+delta;
|
||||
tok0=tok; number0=number;src0=src;type0=type;post0=post;
|
||||
tok=tk_DLL; number=nexports;src=NULL; type=byName; post=0; modline=0;
|
||||
AddToTree(#string);
|
||||
EBX=DLLcount; EBX<<=2;
|
||||
DLLlist[EBX] = treeptr; // save ptr in tree
|
||||
tok=tk_API; type=treeptr;
|
||||
i=0;
|
||||
while(nexports-1>i){
|
||||
EAX=i; EAX<<=1; EAX+=fptr; // fptr+2*i
|
||||
_llseek(dll,EAX,0); _lread(dll,#ord,2);// Ordinal number
|
||||
EAX=i; EAX<<=2; EAX+=base; // base+4*i
|
||||
_llseek(dll,EAX,0); _lread(dll,#pname1,8); // address of name
|
||||
_llseek(dll,pname1+delta,0); _lread(dll,#string,pname2-pname1);// address of Ordinal Table
|
||||
number=ord+1; // ¯à¨ § £à㧪¥ ¨á¯®«ì§ã¥âáï ®¬¥à 1 ¡®«ìè¥ íªá¯®àâ¨à㥬®£® ¨§ DLL
|
||||
AddToTree(#string);
|
||||
// SHOW(#string);SHOW("\n");
|
||||
i++;
|
||||
}
|
||||
EAX=i; EAX<<=1; EAX+=fptr; // fptr+2*i
|
||||
_llseek(dll,EAX,0); _lread(dll,#ord,2); // Ordinal number
|
||||
j=0;
|
||||
for(;;){
|
||||
_llseek(dll,pname2+delta+j,0); EAX=j;
|
||||
_lread(dll,#string[EAX],1); EAX=j;
|
||||
IF(string[EAX]==0)BREAK;
|
||||
j++;
|
||||
}
|
||||
number=ord+1;
|
||||
AddToTree(#string);
|
||||
tok=tok0; number=number0;src=src0;type=type0;post=post0;
|
||||
_lclose(dll);
|
||||
DLLcount++; importFlag=0;
|
||||
}
|
||||
|
||||
// ----- „¨à¥ªâ¨¢ #include
|
||||
DirInclude()
|
||||
byte s[STRLEN],s2[STRLEN];
|
||||
{
|
||||
NextTok();
|
||||
if(tok==tk_string) {
|
||||
AL=cha2;
|
||||
$PUSH EAX,linenum2,inptr2,number,tok2,tok,input,inptr,endoffile,
|
||||
displaytokerrors,currmod;
|
||||
lstrcpyA(#s,#string); lstrcpyA(#s2,#string2);
|
||||
Preview(#s);
|
||||
lstrcpyA(#string,#s); lstrcpyA(#string2,#s2);
|
||||
$POP currmod,displaytokerrors,endoffile,inptr,input,tok,tok2,number,inptr2,
|
||||
linenum2,EAX;
|
||||
cha2=AL;
|
||||
NextTok();
|
||||
}
|
||||
ELSE stringexpected();
|
||||
}
|
||||
|
||||
// ----- „¨à¥ªâ¨¢ list
|
||||
DirList()
|
||||
{
|
||||
IF(mapfile==0){
|
||||
makemapfile=1;
|
||||
StartMapfile();
|
||||
}
|
||||
list^=1; // <20>¥à¥ª«î票¥ ¢ë¢®¤ «¨á⨣
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// ----- „¨à¥ªâ¨¢ map
|
||||
DirMap()
|
||||
{
|
||||
makemapfile = 1; StartMapfile();
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// ---- Ž¡à ¡®âª £«®¡ «ì®© ¯¥à¥¬¥®© ¨«¨ ¯à®æ¥¤ãàë á ⨯®¬
|
||||
GetProc(dword vartype)
|
||||
dword src0,beg,count;
|
||||
byte var_name[IDLENGTH];
|
||||
{
|
||||
lstrcpyA(#var_name,#string); // ˆ¬ï ¯à®æ¥¤ãàë
|
||||
beg=inptr2; // ®â¬¥â¨¬ ç «® ®¯¨á ¨ï
|
||||
count=0; EAX=0; // ¨é¥¬ ç «® ¡«®ª ¯à®æ¥¤ãàë
|
||||
modline=currmod<<16+linenum2;
|
||||
for(;;){
|
||||
ESI><inptr2;
|
||||
$LODSB;
|
||||
ESI><inptr2;
|
||||
cha2=AL;
|
||||
IF(AL==0){
|
||||
unexpectedeof();
|
||||
return;
|
||||
}
|
||||
IF(AL==13){ // CR
|
||||
linenum2++; // Ž¡ à㦥 ª®¥æ áâப¨
|
||||
totallines++;
|
||||
CONTINUE;
|
||||
}
|
||||
IF(AL=='{'){ // ᯨ᮪ ¨¨æ¨ «¨§ 樨
|
||||
count++;
|
||||
BREAK;
|
||||
}
|
||||
}
|
||||
for(;;){
|
||||
ESI><inptr2;
|
||||
$LODSB;
|
||||
ESI><inptr2;
|
||||
cha2=AL;
|
||||
IF(AL==0){
|
||||
unexpectedeof();
|
||||
break;
|
||||
}
|
||||
IF(AL==13){ // CR
|
||||
linenum2++; // Ž¡ à㦥 ª®¥æ áâப¨
|
||||
totallines++;
|
||||
}
|
||||
else if(AL=='}'){ // ¡«®ª § ªàëâ
|
||||
count--;
|
||||
IF(count==0){ // ª®¥æ ¯à®æ¥¤ãàë
|
||||
ESI><inptr2;
|
||||
$LODSB;
|
||||
ESI><inptr2;
|
||||
cha2=AL; // § ¬ëª îé ï }
|
||||
src0=LocalAlloc(0x40,inptr2-beg+2); // ª®¯¨à㥬 ¨áå.⥪áâ
|
||||
EAX=src0;
|
||||
DSBYTE[EAX]='(';
|
||||
lstrcpynA(src0+1,beg,inptr2-beg);
|
||||
tok=tk_proc;
|
||||
type=vartype;
|
||||
src=src0;
|
||||
number=0;
|
||||
post=1;
|
||||
AddToTree(#var_name);
|
||||
BREAK;
|
||||
}
|
||||
}
|
||||
ELSE IF(AL=='{'){ // ᯨ᮪ ¨¨æ¨ «¨§ 樨
|
||||
count++;
|
||||
}
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// ---- Ž¡à ¡®âª £«®¡ «ì®© ¯¥à¥¬¥®© ¨«¨ ¯à®æ¥¤ãàë á ⨯®¬
|
||||
GetVar(dword vartype)
|
||||
dword src0,beg,end,count,size;
|
||||
byte var_name[IDLENGTH];
|
||||
{
|
||||
beg=inptr;
|
||||
modline=0; // ®â¬¥â¨¬ ç «® ®¯¨á ¨ï
|
||||
NextTok();
|
||||
IF(tok2==tk_openbracket){ // Ž¡ê¥¨¥ äãªæ¨¨: type FunctionName(...)
|
||||
GetProc(vartype);
|
||||
return;
|
||||
}
|
||||
for(;;){ // Ž¡ê¥¨¥ ¯¥à¥¬¥®©
|
||||
IF(tok==tk_semicolon){ // Š®¥æ ®¯à¥¤¥«¥¨ï ¯¥à¥¬¥®©
|
||||
tok=tk_var;
|
||||
type=vartype;
|
||||
src=src0;
|
||||
number=0;
|
||||
post=1;
|
||||
AddToTree(#var_name);
|
||||
break;
|
||||
}
|
||||
IF(tok==tk_comma){ // ᯨ᮪ ¯¥à¥¬¥ëå
|
||||
tok=tk_var;
|
||||
type=vartype;
|
||||
src=src0;
|
||||
number=0;
|
||||
post=1;
|
||||
AddToTree(#var_name);
|
||||
NextTok();
|
||||
}
|
||||
else IF(tok==tk_id){ // tk_id
|
||||
src0=NULL;
|
||||
beg=inptr2;
|
||||
size=0;
|
||||
lstrcpyA(#var_name,#string); // ˆ¬ï ¯¥à¥¬¥®©
|
||||
number=0;
|
||||
tok=tk_var;
|
||||
type=vartype;
|
||||
post=1;
|
||||
NextTok();
|
||||
}
|
||||
else if(tok==tk_assign)||(tok==tk_openblock){
|
||||
inptr2--;
|
||||
count=0;
|
||||
EAX=0;
|
||||
for(;;){
|
||||
ESI><inptr2;
|
||||
$LODSB;
|
||||
ESI><inptr2;
|
||||
cha2=AL;
|
||||
IF(AL==0){
|
||||
unexpectedeof();
|
||||
break;
|
||||
}
|
||||
IF(AL=='"'){
|
||||
ESI><inptr2;
|
||||
do{
|
||||
$LODSB;
|
||||
}while(AL!='"');
|
||||
ESI><inptr2;
|
||||
cha2=AL;
|
||||
}
|
||||
else IF(AL==',')||(AL==';'){
|
||||
IF(count==0){
|
||||
end=inptr2;
|
||||
src0 = LocalAlloc(0x40,end-beg+2);
|
||||
IF(size){
|
||||
EAX=src0;
|
||||
DSBYTE[EAX]='[';
|
||||
lstrcpynA(src0+1,beg,end-beg);
|
||||
}
|
||||
ELSE lstrcpynA(src0,beg,end-beg);
|
||||
modline=currmod<<16+linenumber;
|
||||
BREAK;
|
||||
}
|
||||
}
|
||||
ELSE IF(AL=='}'){ // ᯨ᮪ § ª®ç¥
|
||||
count--;
|
||||
}
|
||||
ELSE IF(AL=='{'){ // ᯨ᮪ ¨¨æ¨ «¨§ 樨
|
||||
count++;
|
||||
}
|
||||
IF(AL==']'){ // à §¬¥à®áâì
|
||||
size++;
|
||||
}
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
|
||||
// ---- Ž¡ê¥¨¥ ⨯ ¤ ëå
|
||||
CmdByte()
|
||||
{
|
||||
GetVar(tk_byte);
|
||||
}
|
||||
|
||||
CmdChar()
|
||||
{
|
||||
GetVar(tk_char);
|
||||
}
|
||||
|
||||
CmdWord()
|
||||
{
|
||||
GetVar(tk_word);
|
||||
}
|
||||
|
||||
CmdShort()
|
||||
{
|
||||
GetVar(tk_short);
|
||||
}
|
||||
|
||||
CmdDword()
|
||||
{
|
||||
GetVar(tk_dword);
|
||||
}
|
||||
|
||||
CmdInt()
|
||||
{
|
||||
GetVar(tk_int);
|
||||
}
|
||||
|
||||
// ---- break;
|
||||
CmdBreak()
|
||||
{
|
||||
wsprintfA(#mapstr,"jmp @L%d",endlabel);
|
||||
Asm(#mapstr);
|
||||
NextSemiNext();
|
||||
}
|
||||
|
||||
// ---- case(Cond) ...
|
||||
CmdCase()
|
||||
dword loclabel;
|
||||
{
|
||||
NextTok();
|
||||
expecting(tk_openbracket);
|
||||
loclabel=label;
|
||||
label++;
|
||||
relation=0;
|
||||
if(tok==tk_command){
|
||||
GetDirAddr(#Jmp_Commands,number);
|
||||
IF(EAX==#CmdCarryFlag)wsprintfA(#mapstr,"jnc @L%d",loclabel);
|
||||
else IF(EAX==#CmdNotCarryFlag)wsprintfA(#mapstr,"jc @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdZeroFlag)wsprintfA(#mapstr,"jnz @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdNotZeroFlag)wsprintfA(#mapstr,"jz @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdOverflow)wsprintfA(#mapstr,"jno @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdNotOverflow)wsprintfA(#mapstr,"jo @L%d",loclabel);
|
||||
NextTok();
|
||||
}
|
||||
ELSE{
|
||||
IF(Expression("eax",tk_reg,tk_dword))wsprintfA(loclabel,"test eax,eax;jnz @L%d",#mapstr);
|
||||
ELSE wsprintfA(#mapstr,"test eax,eax;jz @L%d",loclabel);
|
||||
}
|
||||
Asm(#mapstr);
|
||||
expecting(tk_closebracket);
|
||||
DoCommand();
|
||||
wsprintfA(#mapstr,"jmp @L%d",endlabel);
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"@L%d:",loclabel);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
|
||||
// ---- continue;
|
||||
CmdContinue()
|
||||
{
|
||||
wsprintfA(#mapstr,"jmp @L%d",startlabel);
|
||||
Asm(#mapstr); NextSemiNext();
|
||||
}
|
||||
|
||||
// ---- cycle(Var) ...
|
||||
CmdCycle()
|
||||
byte varName[2*IDLENGTH];
|
||||
{
|
||||
NextTok();
|
||||
expecting(tk_openbracket);
|
||||
$PUSH startlabel,endlabel;
|
||||
startlabel=label;
|
||||
label++;
|
||||
endlabel=label;
|
||||
label++;
|
||||
relation=0;
|
||||
wsprintfA(#mapstr,"@L%d:",startlabel);
|
||||
Asm(#mapstr);
|
||||
GetVarname(#varName);
|
||||
NextTok();
|
||||
expecting(tk_closebracket);
|
||||
DoCommand();
|
||||
IF(varName[0]==0){ // ‘ç¥â稪 横« ®âáãâáâ¢ã¥â - ¡¥áª®¥çë© æ¨ª«
|
||||
wsprintfA(#mapstr,"jmp @L%d",startlabel);
|
||||
}
|
||||
ELSE{
|
||||
wsprintfA(#mapstr,"dec %s;jnz @L%d",#varName,startlabel);
|
||||
}
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"@L%d:",endlabel);
|
||||
Asm(#mapstr);
|
||||
$POP endlabel,startlabel;
|
||||
}
|
||||
|
||||
// ---- ”« £¨ ãá«®¢¨© ¢ if
|
||||
CmdCarryFlag()
|
||||
{
|
||||
CmdNotCarryFlag:
|
||||
CmdZeroFlag:
|
||||
CmdNotZeroFlag:
|
||||
CmdOverflow:
|
||||
CmdNotOverflow:
|
||||
}
|
||||
// ---- ... else ...
|
||||
CmdElse()
|
||||
{
|
||||
}
|
||||
|
||||
// ---- Ž¡ê¥¨¥ 㬥஢ ëå ª®áâ â
|
||||
CmdEnum()
|
||||
dword counter;
|
||||
byte holdid[IDLENGTH];
|
||||
{
|
||||
counter=0;
|
||||
NextTok();
|
||||
expecting(tk_openbrace);
|
||||
for(;;){
|
||||
IF(tok==tk_eof)unexpectedeof();
|
||||
ELSE IF(tok==tk_comma)NextTok();
|
||||
ELSE IF(tok==tk_closebrace)BREAK;
|
||||
ELSE IF(tok==tk_id){
|
||||
lstrcpyA(#holdid,#string);
|
||||
IF(tok2==tk_assign ){
|
||||
NextTok();
|
||||
NextTok();
|
||||
IF(tok==tk_number)counter=DoConstLongMath();
|
||||
ELSE numexpected();
|
||||
}
|
||||
AddConstToTree(#holdid,counter);
|
||||
counter++;
|
||||
NextTok();
|
||||
}
|
||||
ELSE{
|
||||
idexpected();
|
||||
NextTok();
|
||||
}
|
||||
}
|
||||
expecting(tk_closebrace);
|
||||
SemiNext();
|
||||
}
|
||||
|
||||
// ---- while(Cond) ...
|
||||
CmdWhile()
|
||||
{
|
||||
NextTok();
|
||||
expecting(tk_openbracket);
|
||||
$PUSH startlabel,endlabel;
|
||||
startlabel=label;
|
||||
label++;
|
||||
endlabel=label;
|
||||
label++;
|
||||
relation=0;
|
||||
wsprintfA(#mapstr,"@L%d:",startlabel);
|
||||
Asm(#mapstr);
|
||||
if(tok==tk_command){
|
||||
GetDirAddr(#Jmp_Commands,number);
|
||||
IF(EAX==#CmdCarryFlag)wsprintfA(#mapstr,"jnc @L%d",endlabel);
|
||||
else IF(EAX==#CmdNotCarryFlag)wsprintfA(#mapstr,"jc @L%d",endlabel);
|
||||
else IF(EAX==#CmdZeroFlag)wsprintfA(#mapstr,"jnz @L%d",endlabel);
|
||||
ELSE IF(EAX==#CmdNotZeroFlag)wsprintfA(#mapstr,"jz @L%d",endlabel);
|
||||
ELSE IF(EAX==#CmdOverflow)wsprintfA(#mapstr,"jno @L%d",endlabel);
|
||||
ELSE IF(EAX==#CmdNotOverflow)wsprintfA(#mapstr,"jo @L%d",endlabel);
|
||||
NextTok();
|
||||
}
|
||||
ELSE{
|
||||
IF(Expression("eax",tk_reg,tk_dword))wsprintfA(#mapstr,"test eax,eax;jnz @L%d",endlabel);
|
||||
ELSE wsprintfA(#mapstr,"test eax,eax;jz @L%d",endlabel);
|
||||
}
|
||||
Asm(#mapstr);
|
||||
expecting(tk_closebracket);
|
||||
DoCommand();
|
||||
wsprintfA(#mapstr,"jmp @L%d",startlabel);
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"@L%d:",endlabel);
|
||||
Asm(#mapstr);
|
||||
$POP endlabel,startlabel;
|
||||
}
|
||||
|
||||
// ---- default
|
||||
CmdDefault()
|
||||
{
|
||||
NextTok();
|
||||
DoCommand();
|
||||
}
|
||||
|
||||
CmdDb()
|
||||
{
|
||||
NextTok();
|
||||
for(;;){
|
||||
IF(tok==tk_number)OP(byte DoConstLongMath());
|
||||
ELSE IF(tok==tk_string ){
|
||||
ECX=number;
|
||||
EDX=#string;
|
||||
loop(ECX){
|
||||
OP(byte DSBYTE[EDX]);
|
||||
EDX++;
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
ELSE IF(tok==tk_comma)NextTok();
|
||||
ELSE IF(tok==tk_semicolon)BREAK;
|
||||
ELSE{
|
||||
numexpected();
|
||||
NextTok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CmdDd()
|
||||
{
|
||||
NextTok();
|
||||
for(;;){
|
||||
IF(tok==tk_number)OUTDWORD(DoConstDwordMath());
|
||||
ELSE IF(tok==tk_comma)NextTok();
|
||||
ELSE IF(tok==tk_semicolon)BREAK;
|
||||
ELSE{
|
||||
numexpected();
|
||||
NextTok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CmdDw()
|
||||
{
|
||||
NextTok();
|
||||
for(;;){
|
||||
IF(tok==tk_number)OUTWORD(DoConstDwordMath());
|
||||
ELSE IF(tok==tk_comma)NextTok();
|
||||
ELSE IF(tok==tk_semicolon)BREAK;
|
||||
ELSE{
|
||||
numexpected();
|
||||
NextTok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- do ... while(Cond)
|
||||
CmdDo()
|
||||
{
|
||||
NextTok();
|
||||
$PUSH startlabel,endlabel;
|
||||
startlabel=label;
|
||||
label++;
|
||||
endlabel=label;
|
||||
label++;
|
||||
relation=0;
|
||||
wsprintfA(#mapstr,"@L%d:",startlabel);
|
||||
Asm(#mapstr);
|
||||
DoCommand();
|
||||
if(tok==tk_command){
|
||||
if(GetDirAddr(#Jmp_Commands,number)==#CmdWhile){
|
||||
NextTok();
|
||||
expecting(tk_openbracket);
|
||||
if(tok==tk_command){
|
||||
GetDirAddr(#Jmp_Commands,number);
|
||||
IF(EAX==#CmdCarryFlag)wsprintfA(#mapstr,"jc @L%d",startlabel);
|
||||
else IF(EAX==#CmdNotCarryFlag)wsprintfA(#mapstr,"jnc @L%d",startlabel);
|
||||
else IF(EAX==#CmdZeroFlag)wsprintfA(#mapstr,"jz @L%d",startlabel);
|
||||
ELSE IF(EAX==#CmdNotZeroFlag)wsprintfA(#mapstr,"jnz @L%d",startlabel);
|
||||
ELSE IF(EAX==#CmdOverflow)wsprintfA(#mapstr,"jo @L%d",startlabel);
|
||||
ELSE IF(EAX==#CmdNotOverflow)wsprintfA(#mapstr,"jno @L%d",startlabel);
|
||||
NextTok();
|
||||
}
|
||||
ELSE{
|
||||
IF(Expression("eax",tk_reg,tk_dword))wsprintfA(#mapstr,"test eax,eax;jz @L%d",startlabel);
|
||||
ELSE wsprintfA(#mapstr,"test eax,eax;jnz @L%d",startlabel);
|
||||
}
|
||||
Asm(#mapstr);
|
||||
expecting(tk_closebracket);
|
||||
}
|
||||
ELSE{
|
||||
ER:
|
||||
preerror("'while' expected following 'do'");
|
||||
}
|
||||
}
|
||||
ELSE GOTO ER;
|
||||
wsprintfA(#mapstr,"@L%d:",endlabel);
|
||||
Asm(#mapstr);
|
||||
$POP endlabel,startlabel;
|
||||
}
|
||||
|
||||
// ---- docase ...
|
||||
CmdDoCase()
|
||||
{
|
||||
NextTok();
|
||||
$PUSH startlabel,endlabel;
|
||||
startlabel=label;
|
||||
label++;
|
||||
endlabel=label;
|
||||
label++;
|
||||
wsprintfA(#mapstr,"@L%d:",startlabel);
|
||||
Asm(#mapstr);
|
||||
DoCommand();
|
||||
wsprintfA(#mapstr,"@L%d:",endlabel);
|
||||
Asm(#mapstr);
|
||||
$POP endlabel,startlabel;
|
||||
}
|
||||
|
||||
// ---- if(Cond) ...
|
||||
CmdIf()
|
||||
dword loclabel;
|
||||
{
|
||||
NextTok();
|
||||
expecting(tk_openbracket);
|
||||
loclabel=label;
|
||||
label++;
|
||||
relation=0;
|
||||
if(tok==tk_command){
|
||||
GetDirAddr(#Jmp_Commands,number);
|
||||
IF(EAX==#CmdCarryFlag)wsprintfA(#mapstr,"jnc @L%d",loclabel);
|
||||
else IF(EAX==#CmdNotCarryFlag)wsprintfA(#mapstr,"jc @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdZeroFlag)wsprintfA(#mapstr,"jnz @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdNotZeroFlag)wsprintfA(#mapstr,"jz @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdOverflow)wsprintfA(#mapstr,"jno @L%d",loclabel);
|
||||
ELSE IF(EAX==#CmdNotOverflow)wsprintfA(#mapstr,"jo @L%d",loclabel);
|
||||
NextTok();
|
||||
}
|
||||
ELSE{
|
||||
IF(Expression("eax",tk_reg,tk_dword))wsprintfA(#mapstr,"test eax,eax;jnz @L%d",loclabel);
|
||||
ELSE wsprintfA(#mapstr,"test eax,eax;jz @L%d",loclabel);
|
||||
}
|
||||
Asm(#mapstr);
|
||||
expecting(tk_closebracket);
|
||||
DoCommand();
|
||||
IF(tok==tk_command){
|
||||
IF(GetDirAddr(#Jmp_Commands,number)==#CmdElse){
|
||||
wsprintfA(#mapstr,"jmp @L%d;\n@L%d:",label,loclabel);
|
||||
Asm(#mapstr);
|
||||
loclabel=label;
|
||||
label++;
|
||||
NextTok();
|
||||
DoCommand();
|
||||
}
|
||||
}
|
||||
wsprintfA(#mapstr,"@L%d:",loclabel);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
|
||||
// ---- return(Expr)
|
||||
CmdReturn()
|
||||
{
|
||||
NextTok();
|
||||
IF(tok==tk_openbracket){
|
||||
NextTok();
|
||||
IF(tok!=tk_closebracket){
|
||||
IF(returntype!=tk_void)Expression("eax",tk_reg,returntype);
|
||||
}
|
||||
expecting(tk_closebracket);
|
||||
}
|
||||
LeaveProc();
|
||||
SemiNext();
|
||||
}
|
||||
|
||||
// ---- Ž¡ê¥¨¥ £«®¡ «ì®© ¯¥à¥¬¥®©
|
||||
GlobalVar(dword vartype) // both initialized and unitialized combined
|
||||
dword size,elements,ptr;
|
||||
long i,count;
|
||||
{
|
||||
ptr=treeptr;
|
||||
elements=1;
|
||||
size = TypeSize(vartype);
|
||||
NextTok();
|
||||
for(;;){
|
||||
IF(tok==tk_eof)goto G04; //break;
|
||||
ELSE IF(tok==tk_semicolon)NextTok();
|
||||
else IF(tok==tk_assign)NextTok();
|
||||
else IF(tok==tk_plus)NextTok();
|
||||
else IF(tok==tk_openblock){ // type VarName[...]
|
||||
NextTok();
|
||||
elements = DoConstLongMath();
|
||||
expecting(tk_closeblock);
|
||||
}
|
||||
else if(tok==tk_number){ // type VarName=initvalue
|
||||
ESI=ptr; // Žâª®à४â¨à㥬 à ¥¥ ᤥ« ãî § ¯¨áì
|
||||
DSDWORD[ESI+recnumber] = outptr-output+OptImageBase+OptBaseOfCode;
|
||||
DSDWORD[ESI+recpost] = 0;
|
||||
G01:
|
||||
IF(vartype==tk_byte)i=DoConstDwordMath();
|
||||
ELSE IF(vartype==tk_word)i=DoConstDwordMath();
|
||||
ELSE IF(vartype==tk_dword)i=DoConstDwordMath();
|
||||
ELSE i=DoConstLongMath();
|
||||
count=elements;
|
||||
loop(count){
|
||||
IF(size==1)OP(byte i);
|
||||
ELSE IF(size==2)OUTWORD(i);
|
||||
ELSE IF(size==4)OUTDWORD(i);
|
||||
}
|
||||
}
|
||||
else IF(tok==tk_minus){
|
||||
NextTok();
|
||||
number=-number;
|
||||
goto G01;
|
||||
}
|
||||
else IF(tok==tk_string){
|
||||
ESI=ptr; // Žâª®à४â¨à㥬 à ¥¥ ᤥ« ãî § ¯¨áì
|
||||
DSDWORD[ESI+recnumber] = outptr-output+OptImageBase+OptBaseOfCode;
|
||||
DSDWORD[ESI+recpost] = 0;
|
||||
count = 1;
|
||||
do{
|
||||
i=number;
|
||||
EDX=#string;
|
||||
loop(i){
|
||||
OP(byte DSBYTE[EDX]);
|
||||
EDX++;
|
||||
count++;
|
||||
}
|
||||
NextTok();
|
||||
}while(tok==tk_string);
|
||||
OP(byte 0);// count++;
|
||||
i=elements;
|
||||
i-=count;
|
||||
IF(i>0)loop(i)OP(byte 0);
|
||||
}
|
||||
else IF(tok==tk_from){
|
||||
NextTok();
|
||||
SHOW("count = DoFrom(1);\n");
|
||||
i=size*elements;
|
||||
i-=count;
|
||||
loop(i)OP(byte 0);
|
||||
NextTok();
|
||||
}
|
||||
else IF(tok==tk_extract){
|
||||
NextTok();
|
||||
SHOW("count = DoExtract(1);\n");
|
||||
i=size*elements;
|
||||
i-=count;
|
||||
loop(i)OP(byte 0);
|
||||
}
|
||||
else if(tok==tk_openbrace){ // varname={...};
|
||||
ESI=ptr; // Žâª®à४â¨à㥬 à ¥¥ ᤥ« ãî § ¯¨áì
|
||||
DSDWORD[ESI+recnumber] = outptr-output+OptImageBase+OptBaseOfCode;
|
||||
DSDWORD[ESI+recpost] = 0;
|
||||
count = 0;
|
||||
NextTok();
|
||||
for(;;){
|
||||
IF(tok==tk_closebrace)break;
|
||||
ELSE IF(tok==tk_comma)NextTok();
|
||||
else IF(tok==tk_plus)NextTok();
|
||||
else IF(tok==tk_string){
|
||||
i=number;
|
||||
EDX=#string;
|
||||
loop(i){
|
||||
OP(DSBYTE[EDX]);
|
||||
EDX++;
|
||||
count++;
|
||||
}
|
||||
IF(tok2!=tk_plus){
|
||||
OP(byte 0);
|
||||
count++;
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
else IF(tok==tk_postnumber){
|
||||
SetPost(treeptr,POST_DATA);
|
||||
OUTDWORD(number);
|
||||
NextTok();
|
||||
}
|
||||
else IF(tok==tk_number){
|
||||
G02:
|
||||
IF(vartype==tk_byte)OP(byte DoConstDwordMath());
|
||||
ELSE IF(vartype==tk_word)OUTWORD(DoConstDwordMath());
|
||||
ELSE IF(vartype==tk_char)OP(byte DoConstLongMath());
|
||||
ELSE IF(vartype==tk_short) OUTWORD(DoConstLongMath());
|
||||
ELSE IF(vartype==tk_dword) OUTDWORD(DoConstDwordMath());
|
||||
ELSE IF(vartype==tk_int) OUTDWORD(DoConstLongMath());
|
||||
count++;
|
||||
}
|
||||
ELSE IF(tok==tk_minus){
|
||||
NextTok();
|
||||
number=-number;
|
||||
goto G02;
|
||||
}
|
||||
ELSE{
|
||||
numexpected();
|
||||
NextTok();
|
||||
}
|
||||
}
|
||||
count=elements-count;
|
||||
IF(count>0){
|
||||
loop(count){
|
||||
IF(size==1)OP(byte 0);
|
||||
ELSE IF(size==2)OUTWORD(0);
|
||||
ELSE IF(size==4)OUTDWORD(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
ELSE{
|
||||
G04:
|
||||
ESI=ptr;
|
||||
DSDWORD[ESI+recnumber] = postsize;
|
||||
DSDWORD[ESI+recpost] = 1;
|
||||
postsize = elements * size + postsize;
|
||||
BREAK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===== ’ ¡«¨æ ¯¥à¥ª«îç ⥫¥© ¤¨à¥ªâ¨¢
|
||||
dword Jmp_Directives={
|
||||
// "if","else","endif", // “á«®¢ ï ª®¬¯¨«ïæ¨ï
|
||||
#EMPTY,#EMPTY,#EMPTY,
|
||||
// "include","define", // ‚ª«î票¥ ä «
|
||||
#DirInclude,#DirDefine,
|
||||
// "import", // ˆ¬¯®àâ ¨§ DLL
|
||||
#DirImport,
|
||||
// "importN", // ˆ¬¯®àâ ¨§ DLL
|
||||
#DirImportN,
|
||||
// "map", // ƒ¥¥à æ¨ï MAP-ä ©«
|
||||
#DirMap,
|
||||
// "debug", // ƒ¥¥à æ¨ï ®â« ¤®ç®© ¨ä®à¬ 樨
|
||||
#EMPTY,
|
||||
// "list", // ‚ë¤ ç ASM-«¨á⨣
|
||||
#DirList,
|
||||
// "dll", // ƒ¥¥à æ¨ï DLL-ä ©«
|
||||
#EMPTY,
|
||||
// "db","dw","dd", // ’¨¯ë ¯¥à¥¬¥ëå
|
||||
#EMPTY,#EMPTY,#EMPTY,
|
||||
// "byte","char","word","short","dword","int",
|
||||
#EMPTY,#EMPTY,#EMPTY,#EMPTY,#EMPTY,#EMPTY,
|
||||
// "enum", // <20>㬥஢ ë¥ ª®áâ âë
|
||||
#DirEnum,
|
||||
// "struc", // Ž¯à¥¤¥«¥¨¥ áâàãªâãàë
|
||||
#EMPTY,
|
||||
// "cycle","return",
|
||||
#EMPTY,#EMPTY,
|
||||
// "while","do","inline",
|
||||
#EMPTY,#EMPTY,#EMPTY,
|
||||
// "continue","break",
|
||||
#EMPTY,#EMPTY,
|
||||
// "docase","case","default",
|
||||
#EMPTY,#EMPTY,#EMPTY,
|
||||
// "CARRYFLAG","extract","from",
|
||||
#EMPTY,#EMPTY,#EMPTY,
|
||||
// "NOTCARRYFLAG","NOTOVERFLOW","OVERFLOW",
|
||||
#EMPTY,#EMPTY,#EMPTY,
|
||||
// "ZEROFLAG","NOTZEROFLAG"
|
||||
#EMPTY,#EMPTY
|
||||
};
|
||||
//===== ’ ¡«¨æ ¯¥à¥ª«îç ⥫¥© ª®¬ ¤
|
||||
dword Jmp_Commands={
|
||||
// "if","else","endif", // “á«®¢ ï ª®¬¯¨«ïæ¨ï
|
||||
#CmdIf,#CmdElse,#EMPTY,
|
||||
// "include","define", // ‚ª«î票¥ ä «
|
||||
#EMPTY,#EMPTY,
|
||||
// "import","importN", // ˆ¬¯®àâ ¨§ DLL
|
||||
#EMPTY,#EMPTY,
|
||||
// "map", // ƒ¥¥à æ¨ï MAP-ä ©«
|
||||
#EMPTY,
|
||||
// "debug", // ƒ¥¥à æ¨ï ®â« ¤®ç® ¨ä®à¬ 樨
|
||||
#EMPTY,
|
||||
// "list", // ‚ë¤ ç ASM-« á⨣
|
||||
#EMPTY,
|
||||
// "dll", // ƒ¥¥à æ¨ï DLL-ä ©«
|
||||
#EMPTY,
|
||||
// "db","dw","dd", // ’¨¯ë ¯¥à¥¬¥ëå
|
||||
#CmdDb,#CmdDw,#CmdDd,
|
||||
// "byte","char","word","short","dword","int",
|
||||
#CmdByte,#CmdChar,#CmdWord,#CmdShort,#CmdDword,#CmdInt,
|
||||
// "enum", // <20>㬥஢ ë¥ ª®áâ âë
|
||||
#CmdEnum,
|
||||
// "struc", // Ž¯à¥¤¥«¥¨¥ áâàãªâãàë
|
||||
#EMPTY,
|
||||
// "cycle","return",
|
||||
#CmdCycle,#CmdReturn,
|
||||
// "while","do","inline",
|
||||
#CmdWhile,#CmdDo,#EMPTY,
|
||||
// "continue","break",
|
||||
#CmdContinue,#CmdBreak,
|
||||
// "docase","case","default",
|
||||
#CmdDoCase,#CmdCase,#CmdDefault,
|
||||
// "CARRYFLAG","extract","from",
|
||||
#CmdCarryFlag,#EMPTY,#EMPTY,
|
||||
// "NOTCARRYFLAG","NOTOVERFLOW","OVERFLOW",
|
||||
#CmdNotCarryFlag,#CmdNotOverflow,#CmdOverflow,
|
||||
// "ZEROFLAG","NOTZEROFLAG"
|
||||
#CmdZeroFlag,#CmdNotZeroFlag
|
||||
};
|
111
programs/develop/c--/trunk/enums.h--
Normal file
111
programs/develop/c--/trunk/enums.h--
Normal file
@ -0,0 +1,111 @@
|
||||
//===== ƒ«®¡ «ìë¥ ª®áâ âë
|
||||
#define SHOW "WRITESTR"
|
||||
// ----
|
||||
#define STD_INPUT_HANDLE -10
|
||||
#define STD_OUTPUT_HANDLE -11
|
||||
#define STD_ERROR_HANDLE -12
|
||||
#define CREATE_NEW 1
|
||||
#define CREATE_ALWAYS 2
|
||||
#define OPEN_EXISTING 3
|
||||
#define OPEN_ALWAYS 4
|
||||
#define TRUNCATE_EXISTING 5
|
||||
// ----
|
||||
#define GENERIC_READ 0x80000000
|
||||
#define GENERIC_WRITE 0x40000000
|
||||
#define GENERIC_EXECUTE 0x20000000
|
||||
#define GENERIC_ALL 0x10000000
|
||||
// ---- Š®áâ âë ª®¬¯¨«ïâ®à
|
||||
#define _END 0x1B
|
||||
#define FILENAMESIZE 80
|
||||
#define IDLENGTH 65 // „«¨ ¨¬¥¨ ¨¤¥â¨ä¨ª â®à , ¢ª«îç ï NULL-â¥à¬¨ â®à
|
||||
#define MAXDATA 512000 // <20> §¬¥à ¡ãä¥à®¢ ¯®¤ ª®¤ ¨ ¤ ë¥
|
||||
#define MAXDBGS 50000 // <20> §¬¥à ¡ãä¥à®¢ ¯®¤ ®â« ¤®çã ¨ä®à¬ æ¨î
|
||||
#define MAXDLLS 100
|
||||
#define MAXINPUT 512000 // Œ ªá¨¬ «ìë à §¬¥à ¢å®¤®£® ä ©«
|
||||
#define MAXMDL 100 // Œ ªá¨¬ «ì®¥ ç¨á«® includes
|
||||
#define MAXPOSTS 150000 // <20> §¬¥à ¡ãä¥à®¢ ¯®¤ POST ®¡à ¡®âªã
|
||||
#define NULL 0
|
||||
#define SORTSIZE 20
|
||||
#define STRLEN 1000 // „«¨ ¡ãä¥à ¯®¤ token
|
||||
// ------------------------------------------
|
||||
//===== <20>㬥஢ ë¥ ª®áâ âë
|
||||
// ---- Š®¤ë ¢®§¢à â
|
||||
enum{ e_ok, e_outofmemory, e_cannotopeninput, e_toomanyerrors,
|
||||
e_internalerror, e_noinputspecified, e_unknowncommandline,
|
||||
e_extract, e_cannotopenmapfile, e_someerrors };
|
||||
// ---- Š®¤ë tokens tk_xxxx
|
||||
enum{
|
||||
tk_eof,tk_number,tk_string,tk_var,
|
||||
tk_id,
|
||||
tk_db,tk_dw,tk_dd,tk_dq, // ’¨¯ë ¯¥à¥¬¥ëå
|
||||
tk_byte,tk_char,tk_word,tk_short,
|
||||
tk_dword,tk_int,
|
||||
tk_enum, // <20>㬥஢ ë¥ ª®áâ âë
|
||||
tk_struc, // Ž¯à¥¤¥«¥¨¥ áâàãªâãàë
|
||||
tk_if,tk_else,tk_endif, // “á«®¢ ï ª®¬¯¨«ïæ¨ï
|
||||
tk_include,tk_define, // ‚ª«î票¥ ä « //Ž¯à¥¤¥«¥¨¥ ª®áâ âë
|
||||
tk_import, // ˆ¬¯®àâ ¨§ DLL
|
||||
tk_map, // ƒ¥¥à æ¨ï MAP-ä ©«
|
||||
tk_debug, // ƒ¥¥à æ¨ï ®â« ¤®ç®© ¨ä®à¬ 樨
|
||||
tk_list, // ‚ë¤ ç ASM-«¨á⨣
|
||||
tk_dll, // ƒ¥¥à æ¨ï DLL-ä ©«
|
||||
tk_loop,tk_return,tk_do,
|
||||
tk_while,tk_void,
|
||||
tk_continue,tk_break,
|
||||
tk_docase,tk_case,tk_default,
|
||||
tk_carryflag,tk_extract,tk_FALSE,tk_from,
|
||||
tk_notcarryflag,tk_notoverflow,tk_overflow,tk_TRUE,
|
||||
tk_zeroflag,tk_notzeroflag,
|
||||
tk_assign,tk_swap,
|
||||
tk_minus,tk_plus,
|
||||
tk_minusminus,tk_plusplus,tk_mult,tk_div,tk_mod,
|
||||
tk_multminus,tk_divminus,tk_modminus,tk_rr,tk_ll,
|
||||
tk_rrminus,
|
||||
tk_llminus,
|
||||
tk_minusequals,tk_plusequals,tk_rrequals,tk_llequals,
|
||||
tk_or,tk_and,tk_xor,tk_not,
|
||||
tk_orminus,
|
||||
tk_andminus,tk_xorminus,
|
||||
tk_orequals,tk_andequals,tk_xorequals,
|
||||
tk_equalto,
|
||||
tk_notequal,tk_greater,tk_greaterequal,tk_less,
|
||||
tk_lessequal,
|
||||
tk_oror,tk_andand,tk_openbrace,tk_closebrace,
|
||||
tk_openbracket,tk_closebracket,tk_openblock,tk_closeblock,
|
||||
tk_colon,tk_semicolon,tk_comma,tk_period,
|
||||
tk_dollar,tk_question,tk_tilda,
|
||||
tk_reg,tk_controlreg,tk_debugreg,tk_testreg,tk_seg,
|
||||
tk_undefproc,tk_proc,
|
||||
tk_postnumber,
|
||||
tk_local,tk_locallabel,tk_param,tk_locnumber,
|
||||
tk_DLL,tk_API,tk_directive,tk_command,tk_mnemonics,
|
||||
tokens
|
||||
};
|
||||
// ---- Š®¤¨à®¢ª ⨯ ¯à®æ¥¤ãà
|
||||
enum{ cpt_near, cpt_far };
|
||||
// ---- Š®¤¨à®¢ª POST § ¯¨á¥©
|
||||
enum { POST_CALL=1, POST_API, POST_DATA, POST_LOC, POST_STR };
|
||||
// ---- Ž¯¨á ¨¥ áâàãªâãàë ¢ dbginfo: dbg_...
|
||||
enum{ dbg_mod=0, // <20>®¬¥à ¬®¤ã«ï
|
||||
dbg_line=4, // <20>®¬¥à áâப ¢ ¬®¤ã«¥
|
||||
dbg_loc=8, // <20>®§¨æ¨ï ¢ EXE-ä ©«¥
|
||||
dbg_size=12}; // à §¬¥à áâàãªâãàë
|
||||
// ---- Ž¯¨á ¨¥ áâàãªâãàë idrec
|
||||
enum{ left=0, // “ª § ⥫ì idrec
|
||||
right=4, // “ª § ⥫ì idrec
|
||||
recid=8, // ˆ¬ï ¨¤¥â¨ä¨ª â®à
|
||||
newid=recid+4, // “ª § â¥«ì «¨ á ¤«ï recid
|
||||
rectok=newid+4, // <20>®¬¥à token
|
||||
rectype=rectok+4, // ’¨¯ token: void, byte, char, word, ...
|
||||
recsrc=rectype+4, // ˆáå®¤ë© â¥ªáâ
|
||||
recpost=recsrc+4, // ”« £ POST ¯¥à¥¬¥®©
|
||||
recnumber=recpost+4, // ‡ 票¥ ¨«¨ offset ¢ recsrc
|
||||
recmodline=recnumber+4,// <20>®¬¥à ¬®¤ã«ï ¨ áâப¨
|
||||
recsize=recnumber+4};// à §¬¥à áâàãªâãàë
|
||||
// ---- Ž¯¨á ¨¥ áâàãªâãàë localrec
|
||||
enum{ localnext=0, // “ª § ⥫ì á«¥¤ãîéãî localrec
|
||||
localid=4, // ˆ¬ï «®ª «ì® ¯¥à¥¬¥®©
|
||||
localtok=localid+IDLENGTH,// ‡ 票¥ token
|
||||
localtype=localtok+4, // ⨯ ¯¥à¥¬¥®©
|
||||
localnumber=localtype+4, // <20>®§¨æ¨ï ¢ á⥪¥
|
||||
local_size=localnumber+4}; // <20> §¬¥à áâàãªâãàë
|
17
programs/develop/c--/trunk/examples/docase.c-
Normal file
17
programs/develop/c--/trunk/examples/docase.c-
Normal file
@ -0,0 +1,17 @@
|
||||
#map
|
||||
#debug
|
||||
#list
|
||||
main() // execution always starts at main ()
|
||||
{
|
||||
docase{
|
||||
EBX+=80;
|
||||
case(ECX==10)
|
||||
//#list
|
||||
EBX=10;
|
||||
case(EBX<5){
|
||||
ECX=5; continue;}
|
||||
default
|
||||
EDX+=8;
|
||||
}
|
||||
EAX=9;
|
||||
}
|
71
programs/develop/c--/trunk/examples/docase.map
Normal file
71
programs/develop/c--/trunk/examples/docase.map
Normal file
@ -0,0 +1,71 @@
|
||||
MAP FILE FOR DOCASE.EXE
|
||||
|
||||
{
|
||||
docase{
|
||||
EBX+=80;
|
||||
// @L0:
|
||||
// add EBX,80
|
||||
case(ECX==10)
|
||||
// mov eax,ECX
|
||||
// cmp eax,0xa
|
||||
// sete al
|
||||
// movzx eax,al
|
||||
//#list
|
||||
// test eax,eax;jz @L2
|
||||
EBX=10;
|
||||
// mov EBX,10
|
||||
case(EBX<5){
|
||||
// jmp @L1
|
||||
// @L2:
|
||||
// mov eax,EBX
|
||||
// cmp eax,0x5
|
||||
// setl al
|
||||
// movzx eax,al
|
||||
// test eax,eax;jz @L3
|
||||
ECX=5; continue;}
|
||||
// mov ECX,5
|
||||
// jmp @L0
|
||||
default
|
||||
EDX+=8;
|
||||
// jmp @L1
|
||||
// @L3:
|
||||
// add EDX,8
|
||||
}
|
||||
EAX=9;
|
||||
// @L1:
|
||||
// mov EAX,9
|
||||
}
|
||||
// ret
|
||||
Compile all sources
|
||||
|
||||
ALL GLOBAL IDENTIFIERS LIST:
|
||||
tok type number post IDENTIFIER
|
||||
104 1Fh 401000h 0h main
|
||||
File:DOCASE.C-, line=4:
|
||||
() // execution always starts at main ()
|
||||
{
|
||||
docase{
|
||||
EBX+=80;
|
||||
case(ECX==10)
|
||||
//#list
|
||||
EBX=10;
|
||||
case(EBX<5){
|
||||
ECX=5; continue;}
|
||||
default
|
||||
EDX+=8;
|
||||
}
|
||||
EAX=9;
|
||||
}
|
||||
|
||||
1 Unique Global Identifiers.
|
||||
|
||||
GLOBAL CONSTANT IDENTIFIER LIST:
|
||||
|
||||
0 Unique Global Constant Value Identifiers.
|
||||
|
||||
Component Sizes:
|
||||
Code:128 bytes, Post: 0 bytes
|
||||
Run file size: 128 bytes
|
||||
|
||||
END OF MAP FILE FOR DOCASE.EXE
|
||||
|
145
programs/develop/c--/trunk/exe.h--
Normal file
145
programs/develop/c--/trunk/exe.h--
Normal file
@ -0,0 +1,145 @@
|
||||
// ---- ”®à¬¨à®¢ ¨¥ IMPORT ᥪ樨
|
||||
void DoLink()
|
||||
dword i,j,DirTable,AddrTable,dllName,apiName,byName,hold;
|
||||
dword dll,api;
|
||||
{
|
||||
OptImportTableAdr=outptr-output;
|
||||
DirTable=outptr;
|
||||
if(APIcount==0){
|
||||
OUTDWORD(outptr -output + OptBaseOfCode + 4);
|
||||
OUTDWORD(0x80000001);
|
||||
OUTDWORD(0);
|
||||
OUTDWORD(DirTable-output+40+OptBaseOfCode);
|
||||
OUTDWORD(outptr-output + OptBaseOfCode - 12);
|
||||
DirTable=outptr;
|
||||
outptr = outptr + 20;
|
||||
OUTDWORD('resu');
|
||||
OUTDWORD('d.23');
|
||||
OUTDWORD('ll');
|
||||
// OUTDWORD(0x72657375); OUTDWORD(0x642E3233); OUTDWORD(0x6C6C);
|
||||
apiName=outptr;
|
||||
}
|
||||
else {
|
||||
EAX=DLLcount+1*20;
|
||||
outptr+=EAX; // ç «® LookupTables
|
||||
i=0;
|
||||
while(i<DLLcount){ // <20>à®á¬®âà ᯨ᪠DLL
|
||||
EAX=i<<2;
|
||||
dll=DLLlist[EAX];
|
||||
EBX=dll; // ‘á뫪 DLL ¢ ᯨ᪥ ¨¤¥â¨ä¨ª â®à®¢
|
||||
byName = DSDWORD[EBX+rectype]; // ˆ¬¯®àâ ¯® ¨¬¥¨?
|
||||
if(DSDWORD[EBX+recmodline]){ // <20>뫨 ¢ë§®¢ë API ¨§ ¤ ®© DLL?
|
||||
dllName=outptr;
|
||||
ESI=DSDWORD[EBX+recid]; // “ª § â¥«ì ¨¬ï DLL
|
||||
do{
|
||||
$LODSB;
|
||||
OP(byte AL);
|
||||
}while(AL!=0); // ‘®åà ¨¬ ¨¬ï DLL
|
||||
AddrTable = outptr; //䨪á¨à㥬 ç «® AddrTable ¤«ï ¤ ®£® DLL
|
||||
apiName=DSDWORD[EBX+recmodline]+1<<2+AddrTable;
|
||||
j=0;
|
||||
while(j<posts){ // ˆé¥¬ ¢ post
|
||||
EBX=j<<2+posttype;
|
||||
if(DSDWORD[EBX]==POST_API){
|
||||
EBX=j<<2+postnum;
|
||||
api=DSDWORD[EBX];
|
||||
ECX=api;
|
||||
if(DSDWORD[ECX+rectype]==dll){ // ˆ§ ®¡à ¡ âë¢ ¥¬®£® DLL?
|
||||
if(DSDWORD[ECX+recmodline]==0){ // …é¥ ¥ ¢¥á¥ ¢ Lookup
|
||||
DSDWORD[ECX+recmodline]=outptr-output+OptBaseOfCode;
|
||||
IF(byName){
|
||||
OUTDWORD(apiName - output + OptBaseOfCode - 2);
|
||||
hold=outptr;
|
||||
outptr=apiName;
|
||||
EAX=DSDWORD[ECX+newid];
|
||||
IF(EAX!=0){ // …áâì «¨ á?
|
||||
IF(lstrcmpA(DSDWORD[ECX+recid],EAX)!=0){
|
||||
ESI=api;
|
||||
ESI=DSDWORD[ESI+newid];
|
||||
GOTO L1;
|
||||
}
|
||||
}
|
||||
ESI=DSDWORD[ECX+recid];
|
||||
L1:
|
||||
do{
|
||||
$LODSB;
|
||||
OP(byte AL);
|
||||
}while(AL!=0); // ‘®åà ¨¬ ¨¬ï API
|
||||
apiName=outptr;
|
||||
outptr=hold;
|
||||
}
|
||||
ELSE{
|
||||
EAX=DSDWORD[ECX+recnumber]|0x80000000; // ord number
|
||||
OUTDWORD(EAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
j++;
|
||||
} // end search in post
|
||||
OUTDWORD(0);
|
||||
outptr=hold;
|
||||
outptr=DirTable;
|
||||
OUTDWORD(AddrTable-output+OptBaseOfCode);
|
||||
OUTDWORD(0);
|
||||
OUTDWORD(0);
|
||||
OUTDWORD(dllName-output+OptBaseOfCode);
|
||||
OUTDWORD(AddrTable-output+OptBaseOfCode);
|
||||
DirTable=outptr;
|
||||
outptr=apiName;
|
||||
}
|
||||
i++;
|
||||
} // end search in DLLlist
|
||||
}
|
||||
outptr=DirTable;
|
||||
OUTDWORD(0);
|
||||
OUTDWORD(0);
|
||||
OUTDWORD(0);
|
||||
OUTDWORD(0);
|
||||
OUTDWORD(0);
|
||||
outptr=apiName;
|
||||
OptImportTableSize=outptr-output-OptImportTableAdr;
|
||||
OptImportTableAdr=OptImportTableAdr+OptBaseOfCode;
|
||||
}
|
||||
|
||||
// ---- ”®à¬¨à®¢ ¨¥ EXE
|
||||
dword WriteEXE()
|
||||
dword diskout; // Handle ¢ë室®£® ä ©«
|
||||
byte exefile[FILENAMESIZE];
|
||||
{
|
||||
wsprintfA(#exefile,"%s.EXE",#rawfilename);
|
||||
SHOW(#exefile);
|
||||
diskout=_lcreat(#exefile,0);
|
||||
IF(EAX==0){
|
||||
wsprintfA(#mapstr,"ERROR, unable to create output file %s.\n",#exefile);
|
||||
WRITESTR(#mapstr);
|
||||
return(-1);
|
||||
}
|
||||
OptCodeSize=outptr-startptr+1;
|
||||
OptImageSize=OptCodeSize/OptSectionAlignment;
|
||||
OptImageSize+=2;
|
||||
OptImageSize=OptImageSize*OptSectionAlignment;
|
||||
OptImageSize+=0x80000;
|
||||
TxtVirtualSize=OptCodeSize+0x80000;
|
||||
TxtSizeOfRawData=OptCodeSize/OptFileAlignment;
|
||||
TxtSizeOfRawData++;
|
||||
TxtSizeOfRawData=TxtSizeOfRawData*OptFileAlignment;
|
||||
_lwrite(diskout,#exeheader,0x160);
|
||||
WriteZero(diskout, 0xA0);
|
||||
IF(outptr-output)_lwrite(diskout,output,outptr-output);
|
||||
EAX=OptCodeSize%OptFileAlignment;
|
||||
EAX><EBX;
|
||||
EAX=OptFileAlignment-EBX;
|
||||
EAX++;
|
||||
WriteZero(diskout, EAX);
|
||||
_lclose(diskout);
|
||||
return(0);
|
||||
}
|
||||
|
||||
// ----
|
||||
WriteZero(dword handle,size)
|
||||
byte c;
|
||||
{
|
||||
c=0;
|
||||
loop(size)_lwrite(handle,#c,1);
|
||||
}
|
1718
programs/develop/c--/trunk/generate.h--
Normal file
1718
programs/develop/c--/trunk/generate.h--
Normal file
File diff suppressed because it is too large
Load Diff
591
programs/develop/c--/trunk/opcodesc.h--
Normal file
591
programs/develop/c--/trunk/opcodesc.h--
Normal file
@ -0,0 +1,591 @@
|
||||
//CODE GENERATION DESCRIPTORS
|
||||
// =========================
|
||||
// >>> DESCRIPTION CODES <<<
|
||||
// =========================
|
||||
|
||||
//T_<MNEMONIC>:
|
||||
// DB <TRANSFER SIZE|# OF OPERANDS|ALLOWED OPERANDS>
|
||||
// [DB <OPERAND CODES>]
|
||||
// [DB <PROCESSOR VERSION>]
|
||||
// DB <TYPE OF OPCODE DESCRIPTION>
|
||||
// DB <OPCODE DESCRIPTOR>
|
||||
// DB 0
|
||||
//OR DB _END //IF THERE'RE NO MORE INFO ABOUT THIS MNEMONIC
|
||||
|
||||
// OPERATION SIZE CODES
|
||||
enum { _B, //OPERATION MAY BE OF SIZE BYTE,WORD OR DWORD SEIN. THE OPCODE'S
|
||||
// W BIT INDICATES IF IT'S A BYTE OR WORD OPERATION.
|
||||
// FOR DWORD OPERATIONS, THE W BIT MUST BE TRUE (WORD OPERATION)
|
||||
// AND THE RAND:PREFIX MUST BE GENERATED.
|
||||
_W, //OPERATION SIZE MAY BE WORD OR DWORD.
|
||||
_D, //OPERATION MAY ONLY BE DWORD.
|
||||
WB, //1. OPERAND WORD, 2. OPERAND BYTE
|
||||
_DW, //1. OPERAND DWORD, 2. OPERAND WORD
|
||||
BW, //1. OPERAND BYTE, 2. OPERAND WORD
|
||||
NB, //ONLY BYTE SIZE.
|
||||
_OW, //ONLY WORD SIZE.
|
||||
_OD, // Only DWORD size
|
||||
AF}; //ONLY ABSOLUTE FAR 32/48 BIT ADDRESS
|
||||
|
||||
#define _JB 1 //OPERAND IS A JUMP - DESTINATION +/-128
|
||||
#define _JW 2 //OPERAND IS A JUMP - DESTINATION +/-32678
|
||||
|
||||
// 0-2 = OPERATION SIZE CODE
|
||||
// 3-4 = # OF OPERANDS NEEDED.
|
||||
|
||||
// # OF OPERANDS
|
||||
#define OL0 0
|
||||
#define OL1 0o10
|
||||
#define OL2 0o20
|
||||
#define OL3 0o30
|
||||
|
||||
#define OLBITS 0o30 //MASKS FOR # OF OPERANDS.
|
||||
#define NOLBITS 0o347
|
||||
#define TRANSBITS 0o7 //MASKS FOR OPERATION SIZE CODES.
|
||||
#define NTRANSBITS 0o370
|
||||
|
||||
// IF OL1, USE THIS OPERAND TYPES:
|
||||
#define SOJ 0b00000000 //JUMP
|
||||
#define SOE 0b00100000 //EA
|
||||
#define SOR 0b01000000 //REG
|
||||
#define SOC 0b01100000 //CONST
|
||||
#define SO3 0b10000000 //_3
|
||||
#define SOS 0b10100000 //SREG
|
||||
#define SOM 0b11000000 //EA-MEMORY-POINTER
|
||||
#define SOO 0b11100000 //THERE IS INFORMATION USING THE OPERAND SIZE CODE BITS.
|
||||
#define SOO_FS 0o340 //FS-REGISTER
|
||||
#define SOO_GS 0o341 //GS-REGISTER
|
||||
#define SOO_AF 0o342 //ABSOLUTE ADRESS
|
||||
#define SOO_CC 0o343 //SIGNED BYTE
|
||||
#define OPBITS 0b11100000
|
||||
|
||||
// IF OL2, USE THOSE INSTEAD:
|
||||
// 00000000B //DIRECT DESCRIPTOR
|
||||
//AR,CO
|
||||
#define ERO 0b00100000 //FIXED EA,REG ORDER
|
||||
#define REO 0b01000000 //FIXED REG,EA ORDER
|
||||
#define DER 0b01100000 //EA,REG OR REG,EA DEFINED BY A D-BIT
|
||||
#define ECO 0b10000000 //EA,CONSTANT// SIZE DEFINED BY W-BIT
|
||||
#define ECCO 0b10100000 //EA,CC
|
||||
#define RCO 0b11000000 //REG,CONSTANT// SIZE DEFINED BY W-BIT
|
||||
#define EAO 0b11100000 //EA,? // SECOND OPERAND DESCRIBED BY OLD DESCIPTORS
|
||||
//?=_1,rCL,CO
|
||||
|
||||
// OPERAND TYPE CODES
|
||||
enum { R, //GENERAL REGISTER
|
||||
E, //EFFEKTIVE ADRESS
|
||||
CO, //CONSTANT
|
||||
_SR, //SEGMENT REGISTER
|
||||
SYSR, //SYSTEM REGISTER
|
||||
_DR, //DEBUG REGISTER
|
||||
_TR, //TASK REGISTER
|
||||
_CR, //CONTROL REGISTER
|
||||
_CR4, //
|
||||
_AF, //ABSOLUTE 32/48 BIT FAR ADDRESS
|
||||
AR=11, //AX/AL REGISTER, INDICATED BY OPERATION SIZE
|
||||
_1}; //CONSTANT VALUE 1
|
||||
|
||||
// IF OL3, USE THIS:
|
||||
// INSTRUCTION WITH THREE OPERANDS ARE ALWAYS OF SIZE WORD.
|
||||
// THE FOLLOWING CODES DESCRIBE THE 3RD OPERAND.
|
||||
enum { CB3, //BYTE CONSTANT
|
||||
CW3, //WORD CONSTANT
|
||||
CC3, //SBYTE CONSTANT
|
||||
CL3}; //CL REGISTER
|
||||
|
||||
// OPCODE DESCRIPTORS
|
||||
enum{ O=1, //OPCODE IS A BYTE
|
||||
OW, //OPCODE IS A WORD
|
||||
OS, //OPCODE IS A BYTE PLUS A SECOND BYTE THAT IS DESCRIBED BY AN
|
||||
//OCTAL STRING.
|
||||
S, //OCTAL STRING FOLLOWS FOR OPCODE
|
||||
XRM, //MODRM BYTE
|
||||
XPM, //MODRM MIT P-FLAG (GRUPPE VON ARITHMETIC INSTRUCTIONS)
|
||||
XSM, //MODRM MIT SEGMENTREGISTER
|
||||
X0M,X1M,X2M,X3M,X4M,X5M,X6M,X7M //MODRM WITH CONSTANT R DIGIT
|
||||
};
|
||||
|
||||
byte OVERRIDETAB={0o46,0o56,0o66,0o76,0o144,0o145};
|
||||
// ---- Š®¤¨à®¢ª ॣ¨áâ஢
|
||||
enum{ rAL ,rCL ,rDL ,rBL ,rAH ,rCH ,rDH ,rBH, // 0-7 byte regs
|
||||
rAX ,rCX ,rDX ,rBX ,rSP ,rBP ,rSI ,rDI, // 8-15 16-bit word regs
|
||||
rEAX,rECX,rEDX,rEBX,rESP,rEBP,rESI,rEDI,// 16-23 32-bit regs
|
||||
rCR0,rCR1,rCR2,rCR3,rCR4,rCR5,rCR6,rCR7,// 24-31 control regs
|
||||
rDR0,rDR1,rDR2,rDR3,rDR4,rDR5,rDR6,rDR7,// 32-39 debug regs
|
||||
rTR0,rTR1,rTR2,rTR3,rTR4,rTR5,rTR6,rTR7,// 40-47 test regs
|
||||
rES,rCS,rSS,rDS, rFS,rGS}; // 48-53 seg regs
|
||||
byte Registers={
|
||||
"AL","CL","DL","BL","AH","CH","DH","BH",
|
||||
"AX","CX","DX","BX","SP","BP","SI","DI",
|
||||
"EAX","ECX","EDX","EBX","ESP","EBP","ESI","EDI",
|
||||
"CR0","CR1","CR2","CR3","CR4","CR5","CR6","CR7",
|
||||
"DR0","DR1","DR2","DR3","DR4","DR5","DR6","DR7",
|
||||
"TR0","TR1","TR2","TR3","TR4","TR5","TR6","TR7",
|
||||
"ES","CS","SS","DS","FS","GS",_END};
|
||||
byte Sizes={"BYTE","WORD","DWORD",_END};
|
||||
|
||||
// ---- Ž¯¨á ¨ï ¬¥¬®¨ª
|
||||
byte PCOMMANDS1={
|
||||
0, //P FLAG STARTS AT 0
|
||||
_B+OL2+EAO,AR,CO,S,"0P4",
|
||||
_B+OL2+DER,S,'0','P','0',XRM,0,
|
||||
_W+OL2+ECCO,O,0o203,XPM,0,
|
||||
_B+OL2+ECO,O,0o200,XPM,_END};
|
||||
|
||||
byte PCOMMANDS2={
|
||||
4, //P FLAG STARTS AT 4
|
||||
_B+OL1+SOE,O,0xF6,XPM,_END};
|
||||
byte PCOMMANDS3= 0; //P FLAG STARTS AT 0
|
||||
byte PCOMMANDS3_={
|
||||
_B+OL2+EAO,-1,_1,O,0xD0,XPM,0,
|
||||
_B+OL2+EAO,-1,rCL,O,0xD2,XPM,0,
|
||||
_B+OL2+ECCO,O,0xC0,XPM,_END};
|
||||
|
||||
byte PCOMMANDS4={
|
||||
4, //P FLAG STARTS AT 4
|
||||
_W+OL2+ERO,OS,0xF,'2','P','3',XRM,0,
|
||||
WB+OL2+ECO,OW,0xF,0o272,XPM,_END};
|
||||
// Ž¤®¡ ©â®¢ë¥ ¨áâàãªæ¨¨
|
||||
byte T_DAA={ O,0o47,_END};
|
||||
byte T_DAS={ O,0o57,_END};
|
||||
byte T_AAA={ O,0o67,_END};
|
||||
byte T_AAD={ OW,0o325,0o12,_END};
|
||||
byte T_AAM={ OW,0o324,0o12,_END};
|
||||
byte T_AAS={ O,0o77,_END};
|
||||
byte T_CWDE={ O,0o230,_END};
|
||||
byte T_CBW={ OW,0x66,0o230,_END};
|
||||
byte T_CDQ={ O,0o231,_END};
|
||||
byte T_CWD={ OW,0x66,0o231,_END};
|
||||
byte T_XLATB={ O,0o327,_END};
|
||||
byte T_NOP={ O,0o220,_END};
|
||||
byte T_WAIT={ O,0o233,_END};
|
||||
byte T_LOCK={ O,0o360,_END};
|
||||
byte T_HLT={ O,0o364,_END};
|
||||
byte T_INTO={ O,0o316,_END};
|
||||
byte T_IRET={ O,0o317,_END};
|
||||
byte T_POPFD={ O,0o235,_END};
|
||||
byte T_POPF={ OW,0x66,0o235,_END};
|
||||
byte T_PUSHFD={ O,0o234,_END};
|
||||
byte T_PUSHF={ OW,0x66,0o234,_END}; //PUSHF / (#) PUSHFD
|
||||
byte T_SAHF={ O,0o236,_END};
|
||||
byte T_LAHF={ O,0o237,_END};
|
||||
byte T_CMC={ O,0o365,_END};
|
||||
byte T_CLC={ O,0o370,_END};
|
||||
byte T_STC={ O,0o371,_END};
|
||||
byte T_CLI={ O,0o372,_END};
|
||||
byte T_STI={ O,0o373,_END};
|
||||
byte T_CLD={ O,0o374,_END};
|
||||
byte T_STD={ O,0o375,_END};
|
||||
byte T_PUSHAD={ O,0o140,_END};
|
||||
byte T_PUSHA={ OW,0x66,0o140,_END};
|
||||
byte T_POPAD={ O,0o141,_END};
|
||||
byte T_POPA={ OW,0x66,0o141,_END};
|
||||
byte T_INSB={ O,0o154,_END};
|
||||
byte T_INSW={ OW,0x66,0o155,_END};
|
||||
byte T_INSD={ O,0o155,_END};
|
||||
byte T_OUTSB={ O,0o156,_END};
|
||||
byte T_OUTSW={ OW,0x66,0o157,_END};
|
||||
byte T_OUTSD={ O,0o157,_END};
|
||||
byte T_MOVSB={ O,0o244,_END};
|
||||
byte T_MOVSW={ OW,0x66,0o245,_END};
|
||||
byte T_MOVSD={ O,0o245,_END};
|
||||
byte T_CMPSB={ O,0o246,_END};
|
||||
byte T_CMPSW={ OW,0x66,0o247,_END};
|
||||
byte T_CMPSD={ O,0o247,_END};
|
||||
byte T_STOSB={ O,0o252,_END};
|
||||
byte T_STOSW={ OW,0x66,0o253,_END};
|
||||
byte T_STOSD={ O,0o253,_END};
|
||||
byte T_LODSB={ O,0o254,_END};
|
||||
byte T_LODSW={ OW,0x66,0o255,_END};
|
||||
byte T_LODSD={ O,0o255,_END};
|
||||
byte T_SCASB={ O,0o256,_END};
|
||||
byte T_SCASW={ OW,0x66,0o257,_END};
|
||||
byte T_SCASD={ O,0o257,_END};
|
||||
byte T_REP={ O,0o362,_END};
|
||||
byte T_REPE={ O,0o363,_END};
|
||||
byte T_RAND={ O,0o146,_END}; //RAND:
|
||||
byte T_ADDR={ O,0o147,_END}; //ADDR:
|
||||
byte T_LEAVE={ O,0o311,_END};
|
||||
byte T_CLTS={ OW,0xF,6,_END};
|
||||
byte T_INVD={ OW,0xF,0o10,_END};
|
||||
byte T_WBINVD={ OW,0xF,0o11,_END};
|
||||
byte T_WRMSR={ OW,0xF,0x30,_END}; //WRMSR WRITE EDXEAX TO MODEL SPECIFIC REG #ECX
|
||||
byte T_CPUID={ OW,0xF,0xA2,_END}; //CPUID IF EAX=1 SET EDXEAX TO CPU IDENTIFICATION VALUES
|
||||
byte T_RDMSR={ OW,0xF,0x32,_END}; //RDMSR READ MODEL SPECIFIC REG #ECX TO EDXEAX
|
||||
byte T_RDTSC={ OW,0xF,0x31,_END}; //RDTSC READ TIME STAMP COUNTER TO EDXEAX
|
||||
byte T_RSM={ OW,0xF,0xAA,_END}; //RSM RESUME FROM SYSTEM MANAGEMENT MODE
|
||||
//===== INTEL PENTIUM PRO INSTRUCTIONS
|
||||
byte T_RDPMC={ OW,0xF,0x33,_END}; //READ PERFORMANCE MONITORING COUNTERS
|
||||
byte T_UD2={ OW,0xF,0xB,_END}; //UNDEFINED INSTRUCTION EXCEPTION
|
||||
byte T_EMMX={ OW,0xF,0x77,_END}; //EMPTY MMX STATE
|
||||
byte T_SALC={ O,0xD6,_END};
|
||||
byte T_ICEBP={ O,0xF1,_END};
|
||||
byte T_PSHIMW={ OW,0xF,0x71,_END};
|
||||
byte T_PSHIMD={ OW,0xF,0x72,_END};
|
||||
byte T_PSHIMQ={ OW,0xF,0x73,_END};
|
||||
|
||||
byte T_NOT={ _B+OL1+SOE,O,0xF6,X2M,_END};
|
||||
byte T_NEG={ _B+OL1+SOE,O,0xF6,X3M,_END};
|
||||
byte T_INC={ _W+OL1+SOR,S,"10R",
|
||||
_B+OL1+SOE,O,0xFE,X0M,_END};
|
||||
byte T_DEC={ _W+OL1+SOR,S,"11R",
|
||||
_B+OL1+SOE,O,0xFE,X1M,_END};
|
||||
byte T_TEST={ _B+OL2+ERO,O,0o204,XRM,0, //ALPHA:WAS 204O
|
||||
_B+OL2+REO,O,0o204,XRM,0, //"
|
||||
_B+OL2+EAO,AR,CO,O,0o250,0,
|
||||
_B+OL2+ECO,O,0xF6,X0M,_END};
|
||||
// EXTENDED 386 INTEGER MULTIPLICATION
|
||||
byte T_IMUL={ _B+OL1+SOE,O,0xF6,X5M,0, //IMUL EB
|
||||
_B+OL2+ECO,O,0xC0,X1M,0,
|
||||
_B+OL2+EAO,-1,_1,O,0xD0,X1M,0,
|
||||
_B+OL2+EAO,-1,rCL,O,0xD2,X1M,0,
|
||||
_W+OL1+REO,OW,0xF,0o257,XRM,0, //IMUL RW, EW
|
||||
OL3+REO+CC3,O,0o153,XRM,0, //IMUL RW, EW, DC
|
||||
OL3+REO+CW3,O,0o151,XRM,_END}; //IMUL RW, EW, DW
|
||||
byte T_SHLD={ OL3+ERO+CB3,OW,0xF,0o244,XRM,0,
|
||||
OL3+ERO+CL3,OW,0xF,0o245,XRM,_END};
|
||||
byte T_SHRD={ OL3+ERO+CB3,OW,0xF,0o254,XRM,0,
|
||||
OL3+ERO+CL3,OW,0xF,0o255,XRM,_END};
|
||||
byte T_MOVSX={ WB+OL2+REO,OW,0xF,0o276,XRM,0,
|
||||
_DW+OL2+REO,OW,0xF,0o277,XRM,_END};
|
||||
byte T_MOVZX={ WB+OL2+REO,OW,0xF,0o266,XRM,0,
|
||||
_DW+OL2+REO,OW,0xF,0o267,XRM,_END};
|
||||
byte T_BSWAP={ _D+OL1+SOR,OS,0xF,"31R",_END};
|
||||
byte T_BSF={ _W+OL2+REO,OW,0xF,0o274,XRM,_END};
|
||||
byte T_BSR={ _W+OL2+REO,OW,0xF,0o275,XRM,_END};
|
||||
byte T_CMPXCHG={_B+OL2+ERO,OW,0xF,0xB0,XRM,_END};
|
||||
byte T_CMPXCHG486={_B+OL2+ERO,OW,0xF,0xA7,XRM,_END};
|
||||
byte T_CMPXCHG8B={_B+OL2+ERO,OW,0xF,0xC7,XRM,_END};
|
||||
byte T_XADD={ _B+OL2+ERO,OW,0xF,0xC0,XRM,_END};
|
||||
byte T_XCHG={ _W+OL2+EAO,-1,AR,S,"22M", //ALPHA:WAS "22R" BUT GENERATED NOP
|
||||
_W+OL2+EAO,AR,-1,S,"22R",
|
||||
_B+OL2+REO,O,0o206,XRM,0,
|
||||
_B+OL2+ERO,O,0o206,XRM,_END};
|
||||
byte T_MOV=0; //DUMMY BYTE
|
||||
byte T_LEA={ _D+OL2+REO,O,0o215,XRM,_END}; //LEA RW, EN (X != 3)
|
||||
byte T_LSS={ _D+OL2+REO,OW,0xF,0o262,XRM,_END};//LSS RW, EF (X != 3)
|
||||
byte T_LFS={ _D+OL2+REO,OW,0xF,0o264,XRM,_END};//LFS RW, EF (X != 3)
|
||||
byte T_LGS={ _D+OL2+REO,OW,0xF,0o265,XRM,_END};//LGS RW, EF (X != 3)
|
||||
byte T_LES={ _D+OL2+REO,O,0o304,XRM,_END}; //LES RW, EF (X != 3)
|
||||
byte T_LDS={ _D+OL2+REO,O,0o305,XRM,_END}; //LDS RW, EF (X != 3)
|
||||
byte T_SET0={ NB+OL1+SOE,OW,0xF,0o220,X0M,_END};
|
||||
byte T_SET1={ NB+OL1+SOE,OW,0xF,0o221,X0M,_END};
|
||||
byte T_SET2={ NB+OL1+SOE,OW,0xF,0o222,X0M,_END};
|
||||
byte T_SET3={ NB+OL1+SOE,OW,0xF,0o223,X0M,_END};
|
||||
byte T_SET4={ NB+OL1+SOE,OW,0xF,0o224,X0M,_END};
|
||||
byte T_SET5={ NB+OL1+SOE,OW,0xF,0o225,X0M,_END};
|
||||
byte T_SET6={ NB+OL1+SOE,OW,0xF,0o226,X0M,_END};
|
||||
byte T_SET7={ NB+OL1+SOE,OW,0xF,0o227,X0M,_END};
|
||||
byte T_SET8={ NB+OL1+SOE,OW,0xF,0o230,X0M,_END};
|
||||
byte T_SET9={ NB+OL1+SOE,OW,0xF,0o231,X0M,_END};
|
||||
byte T_SETA={ NB+OL1+SOE,OW,0xF,0o232,X0M,_END};
|
||||
byte T_SETB={ NB+OL1+SOE,OW,0xF,0o233,X0M,_END};
|
||||
byte T_SETC={ NB+OL1+SOE,OW,0xF,0o234,X0M,_END};
|
||||
byte T_SETD={ NB+OL1+SOE,OW,0xF,0o235,X0M,_END};
|
||||
byte T_SETE={ NB+OL1+SOE,OW,0xF,0o236,X0M,_END};
|
||||
byte T_SETF={ NB+OL1+SOE,OW,0xF,0o237,X0M,_END};
|
||||
//
|
||||
byte T_JCXZ={ OL1,_JB,O,0o343,_END};
|
||||
byte T_LOOPNZ={ OL1,_JB,O,0o340,_END};
|
||||
byte T_LOOPZ={ OL1,_JB,O,0o341,_END};
|
||||
byte T_LOOP={ OL1,_JB,O,0o342,_END};
|
||||
byte T_J0={ OL1,_JB,O,0o160,0,
|
||||
OL1,_JW,6,OW,0o17,0o200,_END};
|
||||
byte T_J1={ OL1,_JB,O,0o161,0,
|
||||
OL1,_JW,6,OW,0o17,0o201,_END};
|
||||
byte T_J2={ OL1,_JB,O,0o162,0,
|
||||
OL1,_JW,6,OW,0o17,0o202,_END};
|
||||
byte T_J3={ OL1,_JB,O,0o163,0,
|
||||
OL1,_JW,6,OW,0o17,0o203,_END};
|
||||
byte T_J4={ OL1,_JB,O,0o164,0,
|
||||
OL1,_JW,6,OW,0o17,0o204,_END};
|
||||
byte T_J5={ OL1,_JB,O,0o165,0,
|
||||
OL1,_JW,6,OW,0o17,0o205,_END};
|
||||
byte T_J6={ OL1,_JB,O,0o166,0,
|
||||
OL1,_JW,6,OW,0o17,0o206,_END};
|
||||
byte T_J7={ OL1,_JB,O,0o167,0,
|
||||
OL1,_JW,6,OW,0o17,0o207,_END};
|
||||
byte T_J8={ OL1,_JB,O,0o170,0,
|
||||
OL1,_JW,6,OW,0o17,0o210,_END};
|
||||
byte T_J9={ OL1,_JB,O,0o171,0,
|
||||
OL1,_JW,6,OW,0o17,0o211,_END};
|
||||
byte T_JA={ OL1,_JB,O,0o172,0,
|
||||
OL1,_JW,6,OW,0o17,0o212,_END};
|
||||
byte T_JB={ OL1,_JB,O,0o173,0,
|
||||
OL1,_JW,6,OW,0o17,0o213,_END};
|
||||
byte T_JC={ OL1,_JB,O,0o174,0,
|
||||
OL1,_JW,6,OW,0o17,0o214,_END};
|
||||
byte T_JD={ OL1,_JB,O,0o175,0,
|
||||
OL1,_JW,6,OW,0o17,0o215,_END};
|
||||
byte T_JE={ OL1,_JB,O,0o176,0,
|
||||
OL1,_JW,6,OW,0o17,0o216,_END};
|
||||
byte T_JF={ OL1,_JB,O,0o177,0,
|
||||
OL1,_JW,6,OW,0o17,0o217,_END};
|
||||
byte T_JMP={ OL1,_JB,O,0o353,0, //JMP SHORT CB
|
||||
OL1,_JW,5,O,0o351,0, //JMP NEAR CW
|
||||
_OW+OL1+SOE,O,0o377,X4M,0}; // JMP NEAR EN
|
||||
byte T_JMPFAR={ _D+OL1+SOE,O,0o377,X5M,0, // JMP FAR EF
|
||||
OL1+SOO_AF,O,0o352,_END}; //JMP FAR AF
|
||||
byte T_JMPSHORT={
|
||||
OL1,_JB,O,0o353,_END}; //JMP SHORT CB
|
||||
byte T_JMPNEAR={OL1,_JW,5,O,0o351,0, //JMP NEAR CW
|
||||
_OW+OL1+SOE,O,0o377,X4M,_END}; // JMP NEAR EN
|
||||
byte T_CALL={ OL1,_JW,5,O,0o350,0, //CALL CW
|
||||
_OW+OL1+SOE,O,0o377,X2M,0}; //CALL EN
|
||||
byte T_CALLFAR={
|
||||
OL1+SOO_AF,O,0o232,0, //CALL AF
|
||||
_D+OL1+SOE,O,0o377,X3M,_END}; //CALL FAR EF
|
||||
byte T_RETF={ 0,O,0o313,0, //RETF/RET FAR
|
||||
_OW+OL1+SOC,O,0o312,_END}; //RETF DW/RET FAR DW
|
||||
byte T_ENTER={ WB+OL2+EAO,CO,CO,O,0o310,_END};
|
||||
byte T_BOUND={ _W+OL2+REO,O,0o142,XRM,_END}; //BOUND RW, ED
|
||||
/*byte T_INT={ NB+OL1+SO3,O,0o314,0, // !!! No interrupts in Win32
|
||||
NB+OL1+SOC,O,0o315,_END};*/
|
||||
byte T_IN={ NB+OL2+EAO,AR,CO,O,0o344,0, //IN AL, DB
|
||||
WB+OL2+EAO,AR,CO,O,0o345,0, //IN AX,CO
|
||||
_B+OL2+EAO,AR,rDX,O,0o354,0, //IN AL,DX
|
||||
_OW+OL2+EAO,AR,rDX,O,0o355,_END}; //IN AX, DX
|
||||
byte T_OUT={ NB+OL2+EAO,CO,AR,O,0o346,0, //OUT DB, AL
|
||||
BW+OL2+EAO,CO,AR,O,0o347,0, //OUT DB, AX
|
||||
WB+OL2+EAO,rDX,AR,O,0o356,0, //OUT DX, AL
|
||||
_OW+OL2+EAO,rDX,AR,O,0o357,_END}; //OUT DX, AX
|
||||
byte T_PUSH={ OL1+SOO_CC,O,0o152,0,
|
||||
_D+OL1+SOR,S,"12R",
|
||||
_D+OL1+SOE,O,0o377,X6M,0,
|
||||
_D+OL1+SOC,O,0o150,0,
|
||||
OL1+SOO_FS,OW,0xF,0o240,0,
|
||||
OL1+SOO_GS,OW,0xF,0o250,0,
|
||||
_OW+OL1+SOS,S,"0S6", //WIEDER ANS ENDE PACKEN
|
||||
_END};
|
||||
byte T_RET={ _OW+OL1+SOC,O,0o302,0, //RET DW
|
||||
O,0o303,0,_END}; //RET
|
||||
byte T_POP={ _D+OL1+SOR,S,"13R",
|
||||
_D+OL1+SOE,O,0o217,X0M,0,
|
||||
OL1+SOO_FS,OW,0xF,0o241,0,
|
||||
OL1+SOO_GS,OW,0xF,0o251,0,
|
||||
_OW+OL1+SOS,S,"0S7",_END};
|
||||
byte T_ARPL={ _W+OL2+ERO,O,0o143,XRM,_END}; //ARPL ES, RW
|
||||
byte T_SLDT={ _OW+OL1+SOE,OW,0xF,0,X0M,_END}; //SLDT EW
|
||||
byte T_STR={ _OW+OL1+SOE,OW,0xF,0,X1M,_END}; //STR EW
|
||||
byte T_LLDT={ _OW+OL1+SOE,OW,0xF,0,X2M,_END}; //LLDT EW
|
||||
byte T_LTR={ _OW+OL1+SOE,OW,0xF,0,X3M,_END}; //LTR EW
|
||||
byte T_VERR={ _OW+OL1+SOE,OW,0xF,0,X4M,_END}; //VERR EW
|
||||
byte T_VERW={ _OW+OL1+SOE,OW,0xF,0,X5M,_END}; //VERW EW
|
||||
byte T_LAR={ _OW+OL1+REO,OW,0xF,2,XRM,_END}; //LAR RW, EW
|
||||
byte T_LSL={ _OW+OL1+REO,OW,0xF,3,XRM,_END}; //LSL RW, EW
|
||||
byte T_SGDT={ _OW+OL1+SOM,OW,0xF,1,X0M,_END}; //SGDT EP
|
||||
byte T_SIDT={ _OW+OL1+SOM,OW,0xF,1,X1M,_END}; //SIDT EP
|
||||
byte T_LGDT={ _OW+OL1+SOM,OW,0xF,1,X2M,_END}; //LGDT EP
|
||||
byte T_LIDT={ _OW+OL1+SOM,OW,0xF,1,X3M,_END}; //LIDT EP
|
||||
byte T_SMSW={ _OW+OL1+SOE,OW,0xF,1,X4M,_END}; //SMSW EW
|
||||
byte T_LMSW={ _OW+OL1+SOE,OW,0xF,1,X6M,_END}; //LMSW EW
|
||||
//===== X486 INSTRUCTIONS
|
||||
byte T_INVLPD={ _OW+OL1+SOM,OW,0xF,0o20,X7M,_END}; //INVLPG EA
|
||||
//===== INTEL PENTIUM INSTRUCTIONS
|
||||
byte T_CMPX8={ _OW+OL1+SOE,OW,0xF,0xC7,X1M,_END}; //CMPX8 EW 5 IF EDXEAX=MQ THEN MQ:=ECXEBX, ELSE EAXEDX:=MQ
|
||||
byte T_CMOV={ _W+OL2,REO,OW,0xF,0x40,XRM,_END};
|
||||
//===== MMX INSTRUCTIONS
|
||||
byte T_EMMS={ _END};
|
||||
byte T_UMOV={ _B+OL2,DER,OW,0xF,0x10,XRM,_END};
|
||||
#define _Q 1
|
||||
#define MMXE 1
|
||||
#define MMXP 1
|
||||
#define MMXPI 1
|
||||
#define MMXPE 1
|
||||
#define MMXEP 1
|
||||
byte T_PUNPCKLBW={ _D+OL2,MMXE,OW,0xF,0x60,_END};
|
||||
byte T_PUNPCKLWD={ _D+OL2,MMXE,OW,0xF,0x61,_END};
|
||||
byte T_PUNPCKLDQ={ _D+OL2,MMXE,OW,0xF,0x62,_END};
|
||||
byte T_PACKSSWB={ _Q+OL2,MMXE,OW,0xF,0x63,_END};
|
||||
byte T_PCMPGTB={ _Q+OL2,MMXE,OW,0xF,0x64,_END};
|
||||
byte T_PCMPGTW={ _Q+OL2,MMXE,OW,0xF,0x65,_END};
|
||||
byte T_PCMPGTD={ _Q+OL2,MMXE,OW,0xF,0x66,_END};
|
||||
byte T_PACKUSWB={ _Q+OL2,MMXE,OW,0xF,0x67,_END};
|
||||
byte T_PCMPEQB={ _Q+OL2,MMXE,OW,0xF,0x74,_END};
|
||||
byte T_PCMPEQW={ _Q+OL2,MMXE,OW,0xF,0x75,_END};
|
||||
byte T_PCMPEQD={ _Q+OL2,MMXE,OW,0xF,0x76,_END};
|
||||
byte T_PSRLW={ _Q+OL2,MMXE,OW,0xF,0xD1,_END};
|
||||
byte T_PSRLD={ _Q+OL2,MMXE,OW,0xF,0xD2,_END};
|
||||
byte T_PSRLQ={ _Q+OL2,MMXE,OW,0xF,0xD3,_END};
|
||||
byte T_PMULLW={ _Q+OL2,MMXE,OW,0xF,0xD5,_END};
|
||||
byte T_PSRAW={ _Q+OL2,MMXE,OW,0xF,0xE1,_END};
|
||||
byte T_PSRAD={ _Q+OL2,MMXE,OW,0xF,0xE2,_END};
|
||||
byte T_PMULHW={ _Q+OL2,MMXE,OW,0xF,0xE5,_END};
|
||||
byte T_PSLLW={ _Q+OL2,MMXE,OW,0xF,0xF1,_END};
|
||||
byte T_PSLLD={ _Q+OL2,MMXE,OW,0xF,0xF2,_END};
|
||||
byte T_PSLLQ={ _Q+OL2,MMXE,OW,0xF,0xF3,_END};
|
||||
byte T_PMADDWD={ _Q+OL2,MMXE,OW,0xF,0xF5,_END};
|
||||
byte T_PUNPCKHBW={ _Q+OL2,MMXE,OW,0xF,0x68,_END};
|
||||
byte T_PUNPCKHWD={ _Q+OL2,MMXE,OW,0xF,0x69,_END};
|
||||
byte T_PUNPCKHDQ={ _Q+OL2,MMXE,OW,0xF,0x6A,_END};
|
||||
byte T_PACKSSDW={ _Q+OL2,MMXE,OW,0xF, 0x6B,_END};
|
||||
byte T_MOVD={ _D+OL2,MMXPE,OW,0xF,0x6E,0,
|
||||
_Q+OL2,MMXEP,OW,0xF,0x7E,_END};
|
||||
byte T_MOVQ={ _Q+OL2,MMXE,OW,0xF,0x6F,0,
|
||||
_Q+OL2,MMXE,OW,0xF,0x7F,_END};
|
||||
byte T_PSUBUSB={ _Q+OL2,MMXE,OW,0xF,0xD8,_END};
|
||||
byte T_PSUBUSW={ _Q+OL2,MMXE,OW,0xF,0xD9,_END};
|
||||
byte T_PAND={ _Q+OL2,MMXE,OW,0xF,0xDB,_END};
|
||||
byte T_PADDUSB={ _Q+OL2,MMXE,OW,0xF,0xDC,_END};
|
||||
byte T_PADDUSW={ _Q+OL2,MMXE,OW,0xF,0xDD,_END};
|
||||
byte T_PANDN={ _Q+OL2,MMXE,OW,0xF,0xDF,_END};
|
||||
byte T_PSUBSB={ _Q+OL2,MMXE,OW,0xF,0xE8,_END};
|
||||
byte T_PSUBSW={ _D+OL2,MMXE,OW,0xF,0xE9,_END};
|
||||
byte T_POR={ _Q+OL2,MMXE,OW,0xF,0xEB,_END};
|
||||
byte T_PADDSB={ _Q+OL2,MMXE,OW,0xF,0xEC,_END};
|
||||
byte T_PADDSW={ _Q+OL2,MMXE,OW,0xF,0xED,_END};
|
||||
byte T_PXOR={ _Q+OL2,MMXE,OW,0xF,0xEF,_END};
|
||||
byte T_PSUBB={ _Q+OL2,MMXE,OW,0xF,0xF8,_END};
|
||||
byte T_PSUBW={ _Q+OL2,MMXE,OW,0xF,0xF9,_END};
|
||||
byte T_PSUBD={ _Q+OL2,MMXE,OW,0xF,0xFA,_END};
|
||||
byte T_PADDB={ _Q+OL2,MMXE,OW,0xF,0xFC,_END};
|
||||
byte T_PADDW={ _Q+OL2,MMXE,OW,0xF,0xFD,_END};
|
||||
byte T_PADDD={ _Q+OL2,MMXE,OW,0xF,0xFE,_END};
|
||||
byte T_PSRL={ _Q+OL2,MMXPI,OW,0xF,_END};
|
||||
byte T_PSRA={ _Q+OL2,MMXPI,OW,0xF,_END};
|
||||
byte T_PSLL={ _Q+OL2,MMXE,OW,0xF,_END};
|
||||
|
||||
byte Mnemonics={
|
||||
// FIRST OF ALL THE COMMANDS WITH A P-FLAG. THIS"LL MAKE THINGS EASIER FOR
|
||||
// COMPARISON IN THE PARSE ENGINE
|
||||
//P1=0-7
|
||||
"ADD","OR","ADC","SBB/BC","AND","SUB","XOR","CMP",
|
||||
//P2=4-7
|
||||
"MUL","-","DIV","IDIV",
|
||||
// IMUL ENTFERNT
|
||||
//P3=0-5/7
|
||||
"ROL","ROR","RCL","RCR","SHL/AL","SHR","-","SAR",
|
||||
//P4=4-7
|
||||
"BT","BTS","BTR","BTC",
|
||||
// USUAL COMMANDS
|
||||
"NOT","NEG","INC","DEC","TEST", "IMUL","SHLD","SHRD",
|
||||
"DAA","DAS","AAA","AAS","AAM","AAD",
|
||||
"MOVSX","MOVZX","CBW","CWDE","CWD","CDQ",
|
||||
"BSWAP","XLAT/LATB","BSF","BSR",
|
||||
"CMPXCHG","CMPXCHG486","CMPXCHG8B","XADD",
|
||||
"NOP","WAIT","LOCK","HLT", //"INT",
|
||||
"INTO","IRET",
|
||||
"POPF","POPFD","PUSHF","PUSHFD","SAHF","LAHF",
|
||||
"CMC","CLC","STC","CLI","STI","CLD","STD",
|
||||
"PUSH","PUSHA","PUSHAD","POP","POPA","POPAD",
|
||||
"XCHG","MOV","LEA","LSS","LFS","LGS","LES","LDS",
|
||||
"ADDR","RAND",
|
||||
"IN","OUT","INSB","INSW","INSD","OUTSB","OUTSW","OUTSD",
|
||||
"MOVSB","MOVSW","MOVSD","CMPSB","CMPSW","CMPSD",
|
||||
"STOSB","STOSW","STOSD","LODSB","LODSW","LODSD",
|
||||
"SCASB","SCASW","SCASD","REP/EPNE/EPNZ","REPE/EPZ",
|
||||
"JCXZ/ECXZ","LOOP","LOOPZ/OOPE","LOOPNZ/OOPNE",
|
||||
"JO","JNO","JC/B/NAE","JNC/AE/NB",
|
||||
"JE/Z","JNE/NZ","JBE/NA","JA/NBE",
|
||||
"JS","JNS","JP/PE","JNP/PO","JL/NGE","JGE/NL",
|
||||
"JLE/NG","JG/NLE",
|
||||
"SETO","SETNO","SETC/ETB/ETNAE","SETNC/ETAE/ETNB",
|
||||
"SETE/ETZ","SETNE/ETNZ","SETBE/ETNA","SETA/ETNBE",
|
||||
"SETS","SETNS","SETP/ETPE","SETNP/ETPO","SETL/ETNGE","SETGE/ETNL",
|
||||
"SETLE/ETNG","SETG/ETNLE",
|
||||
"JMPS","JMPN","JMPF","JMP",
|
||||
"CALL","CALLF","RET","RETF",
|
||||
"ENTER","LEAVE","BOUND","ARPL",
|
||||
"SLDT","STR","LLDT","LTR","VERR","VERW","LAR","LSL",
|
||||
"SGDT","SIDT","LGDT","LIDT","SMSW","LMSW","CLTS",
|
||||
"INVD","WBINVD","INVLPD",
|
||||
//INTEL PENTIUM COMMANDS
|
||||
"WRMSR","CMPX8/MPXCHG8B","CPUID","RDMSR","RDTSC","RSM",
|
||||
//INTEL PENTIUM PRO INSTRUCTIONS
|
||||
"RDPMC","UD2","EMMX","SETALC",
|
||||
//MMX INSTRUCTIONS
|
||||
"MOVD","MOVQ", //MOVE MMX REG
|
||||
"PACKUS/PACKUSWB", //PACK MMX REG WITH UNSIGNED SATURATION
|
||||
"PACKSSWB","PACKSSDW", //PACK MMX REG WITH SIGNED SATURATION
|
||||
"PUNPCKHBW","PUNPCKHWD",
|
||||
"PUNPCKHDQ", //UNPACK HIGH ORDER
|
||||
"PUNPCKLBW","PUNPCKLWD",
|
||||
"PUNPCKLDQ", //UNPACK LOW ORDER
|
||||
"PADDB","PADDW","PADDD", //ADD MMX REG WITH WRAP-AROUND
|
||||
"PADDSB","PADDSW", //" WITH SIGNED SATURATION
|
||||
"PADDUSB","PADDUSW", //" WITH UNSIGNED SATURATION
|
||||
"PSUBB","PSUBW","PSUBD", //SUBTRACT MMX REG
|
||||
"PSUBSB","PSUBSW","PSUBUSB","PSUBUSW",
|
||||
"PMULH/PMULHW","PMULL/PMULLW","PMADD/PMADDWD",
|
||||
"PSLLW","PSLLD","PSLLQ","PSRLW","PSRLD","PSRLQ",
|
||||
"PSRAW","PSRAD","PCMPEQB","PCMPEQW","PCMPEQD",
|
||||
"PCMPGTB","PCMPGTW","PCMPGTD","PAND","PANDN","POR","PXOR","EMMS",_END};
|
||||
|
||||
dword TAB_MNEMONICS={
|
||||
#T_NOT,#T_NEG,#T_INC,#T_DEC,#T_TEST,
|
||||
#T_IMUL,#T_SHLD,#T_SHRD,
|
||||
#T_DAA,#T_DAS,#T_AAA,#T_AAS,#T_AAM,#T_AAD,
|
||||
#T_MOVSX,#T_MOVZX,#T_CBW,#T_CWDE,#T_CWD,#T_CDQ,
|
||||
#T_BSWAP,#T_XLATB,
|
||||
#T_BSF,#T_BSR,#T_CMPXCHG,#T_CMPXCHG486,#T_CMPXCHG8B,#T_XADD,
|
||||
#T_NOP,#T_WAIT,#T_LOCK,#T_HLT,
|
||||
// #T_INT,
|
||||
#T_INTO,#T_IRET,
|
||||
#T_POPF,#T_POPFD,#T_PUSHF,#T_PUSHFD,
|
||||
#T_SAHF,#T_LAHF,
|
||||
#T_CMC,#T_CLC,#T_STC,#T_CLI,#T_STI,#T_CLD,#T_STD,
|
||||
#T_PUSH,#T_PUSHA,#T_PUSHAD,
|
||||
#T_POP,#T_POPA,#T_POPAD,
|
||||
#T_XCHG,#T_MOV,
|
||||
#T_LEA,#T_LSS,#T_LFS,#T_LGS,#T_LES,#T_LDS,
|
||||
#T_ADDR,#T_RAND,
|
||||
#T_IN,#T_OUT,
|
||||
#T_INSB,#T_INSW,#T_INSD,
|
||||
#T_OUTSB,#T_OUTSW,#T_OUTSD,
|
||||
#T_MOVSB,#T_MOVSW,#T_MOVSD,
|
||||
#T_CMPSB,#T_CMPSW,#T_CMPSD,
|
||||
#T_STOSB,#T_STOSW,#T_STOSD,
|
||||
#T_LODSB,#T_LODSW,#T_LODSD,
|
||||
#T_SCASB,#T_SCASW,#T_SCASD,
|
||||
#T_REP,
|
||||
#T_REPE,
|
||||
#T_JCXZ,#T_LOOP,#T_LOOPZ,#T_LOOPNZ,
|
||||
#T_J0,#T_J1,#T_J2,#T_J3,
|
||||
#T_J4,#T_J5,#T_J6,#T_J7,
|
||||
#T_J8,#T_J9,#T_JA,#T_JB,
|
||||
#T_JC,#T_JD,#T_JE,#T_JF,
|
||||
#T_SET0,#T_SET1,#T_SET2,#T_SET3,
|
||||
#T_SET4,#T_SET5,#T_SET6,#T_SET7,
|
||||
#T_SET8,#T_SET9,#T_SETA,#T_SETB,
|
||||
#T_SETC,#T_SETD,#T_SETE,#T_SETF,
|
||||
#T_JMPSHORT,#T_JMPNEAR,#T_JMPFAR,#T_JMP,
|
||||
#T_CALL,#T_CALLFAR,
|
||||
#T_RET,#T_RETF,
|
||||
#T_ENTER,#T_LEAVE,
|
||||
#T_BOUND,#T_ARPL,
|
||||
#T_SLDT,#T_STR,#T_LLDT,#T_LTR,#T_VERR,#T_VERW,
|
||||
#T_LAR,#T_LSL,
|
||||
#T_SGDT,#T_SIDT,#T_LGDT,#T_LIDT,
|
||||
#T_SMSW,#T_LMSW,#T_CLTS,
|
||||
#T_INVD,#T_WBINVD,#T_INVLPD,
|
||||
//INTEL PENTIUM INSTRUCTIONS
|
||||
#T_WRMSR,#T_CMPX8,#T_CPUID,#T_RDMSR,#T_RDTSC,#T_RSM,
|
||||
//INTEL PENTIUM PRO INSTRUCTIONS
|
||||
#T_RDPMC,#T_UD2,#T_EMMX,#T_SALC,
|
||||
//MMX INSTRUCTIONS
|
||||
#T_MOVD,#T_MOVQ, //MOVE MMX REG
|
||||
#T_PACKUSWB, //PACK MMX REG WITH UNSIGNED SATURATION
|
||||
#T_PACKSSWB,#T_PACKSSDW, //PACK MMX REG WITH SIGNED SATURATION
|
||||
#T_PUNPCKHBW,#T_PUNPCKHWD,#T_PUNPCKHDQ, //UNPACK HIGH ORDER
|
||||
#T_PUNPCKLBW,#T_PUNPCKLWD,#T_PUNPCKLDQ, //UNPACK LOW ORDER
|
||||
#T_PADDB,#T_PADDW,#T_PADDD, //ADD MMX REG WITH WRAP-AROUND
|
||||
#T_PADDSB,#T_PADDSW, //" WITH SIGNED SATURATION
|
||||
#T_PADDUSB,#T_PADDUSW, //" WITH UNSIGNED SATURATION
|
||||
#T_PSUBB,#T_PSUBW,#T_PSUBD, //SUBTRACT MMX REG
|
||||
#T_PSUBSB,#T_PSUBSW,
|
||||
#T_PSUBUSB,#T_PSUBUSW,
|
||||
#T_PMULHW,
|
||||
#T_PMULLW,
|
||||
#T_PMADDWD,
|
||||
#T_PSLLW,#T_PSLLD,#T_PSLLQ,
|
||||
#T_PSRLW,#T_PSRLD,#T_PSRLQ,
|
||||
#T_PSRAW,#T_PSRAD,
|
||||
#T_PCMPEQB,#T_PCMPEQW,#T_PCMPEQD,
|
||||
#T_PCMPGTB,#T_PCMPGTW,#T_PCMPGTD,
|
||||
#T_PAND,
|
||||
#T_PANDN,
|
||||
#T_POR,
|
||||
#T_PXOR,
|
||||
#T_EMMS};
|
||||
|
||||
|
630
programs/develop/c--/trunk/parser.h--
Normal file
630
programs/develop/c--/trunk/parser.h--
Normal file
@ -0,0 +1,630 @@
|
||||
// ---- ƒ¥¥à æ¨ï ¢ëà ¦¥¨ï
|
||||
DoExpr(dword var,vtok,vtype,mnem)
|
||||
byte varName[2*IDLENGTH];
|
||||
{
|
||||
IF(tok2notstopper()){
|
||||
IF(vtok==tk_var)Expression("eax",tk_reg,tk_dword);
|
||||
ELSE{
|
||||
Expression(var,vtok,vtype);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else{ // Ž¤¨ ®¯¥à ¤
|
||||
tok=GetVarname(#varName);
|
||||
IF(tok==tk_reg)wsprintfA(#mapstr,"%s %s,%s",mnem,var,#varName);
|
||||
else IF(tok==tk_var){
|
||||
IF(vtok==tk_var)Expression("eax",tk_reg,tk_dword);
|
||||
ELSE wsprintfA(#mapstr,"%s %s,%s",mnem,var,#varName);
|
||||
}
|
||||
else IF(tok==tk_number)wsprintfA(#mapstr,"%s %s,%d",mnem,var,DoConstMath());
|
||||
ELSE IF(tok==tk_postnumber)wsprintfA(#mapstr,"%s %s#%s",mnem,var,#varName);
|
||||
ELSE IF(tok==tk_locnumber){
|
||||
wsprintfA(#mapstr,"lea ebx,%s",#varName);
|
||||
wsprintfA(#mapstr,"%s %s,ebx",mnem,var);
|
||||
return;
|
||||
}
|
||||
Asm(#mapstr);
|
||||
RETURN;
|
||||
}
|
||||
IF(vtype==tk_byte)||(vtype==tk_char)wsprintfA(#mapstr,"%s %s,al",mnem,var);
|
||||
ELSE IF(vtype==tk_word)||(vtype==tk_short)wsprintfA(#mapstr,"%s %s,ax",mnem,var);
|
||||
ELSE IF(vtype==tk_dword)||(vtype==tk_int)wsprintfA(#mapstr,"%s %s,eax",mnem,var);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
|
||||
// ---- <20> §¡®àª ¨ âà á«ïæ¨ï ¢ëà ¦¥¨©
|
||||
dword Expression(dword dest,dtok,dtype)
|
||||
byte s[IDLENGTH];
|
||||
{
|
||||
GetInto(dest,dtok,dtype);
|
||||
for(;;){
|
||||
Term(#s,dtype);
|
||||
IF(tok==tk_plus){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"add %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_minus){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"sub %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_or){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"or %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_xor){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"xor %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_assign)||(tok==tk_equalto){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"cmp %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
Asm("sete al");
|
||||
SE:
|
||||
wsprintfA(#mapstr,"movzx %s,al",dest);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_notequal){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"cmp %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
Asm("setne al");
|
||||
GOTO SE;
|
||||
}
|
||||
else IF(tok==tk_greater){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"cmp %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
Asm("setg al");
|
||||
$JMP SE;
|
||||
}
|
||||
else IF(tok==tk_greaterequal){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"cmp %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
Asm("setge al");
|
||||
$JMP SE;
|
||||
}
|
||||
else IF(tok==tk_less){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"cmp %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
Asm("setl al");
|
||||
$JMP SE;
|
||||
}
|
||||
ELSE IF(tok==tk_lessequal){
|
||||
Term(#s,dtype);
|
||||
wsprintfA(#mapstr,"cmp %s,%s",dest,#s);
|
||||
Asm(#mapstr);
|
||||
Asm("setle al");
|
||||
$JMP SE;
|
||||
}
|
||||
ELSE BREAK;
|
||||
}
|
||||
return(relation);
|
||||
}
|
||||
|
||||
// ---- —⥨¥ ®ç¥à¥¤®£® í«¥¬¥â ¢ëà ¦¥¨ï
|
||||
Factor(dword f,ftype)
|
||||
{
|
||||
NextTok();
|
||||
IF(tok==tk_openbracket){
|
||||
NextTok();
|
||||
PushEAX();
|
||||
Expression("eax",tk_reg,ftype);
|
||||
Asm("pop ebx; xchg eax,ebx");
|
||||
wsprintfA(f,"%s","ebx");
|
||||
}
|
||||
else IF(tok==tk_number)wsprintfA(f,"%#x",DoConstMath());
|
||||
else IF(tok==tk_postnumber)wsprintfA(f,"#%s",#string);
|
||||
else IF(tok==tk_proc){
|
||||
PushEAX();
|
||||
DoAnyProc();
|
||||
Asm("pop ebx; xchg eax,ebx");
|
||||
wsprintfA(f,"%s","ebx");
|
||||
}
|
||||
ELSE IF(tok==tk_API){
|
||||
PushEAX();
|
||||
doAPI();
|
||||
Asm("pop ebx; xchg eax,ebx");
|
||||
wsprintfA(f,"%s","ebx");
|
||||
}
|
||||
ELSE IF(tok==tk_var)||(tok==tk_param)||(tok==tk_local)||(tok==tk_openblock)||
|
||||
(tok==tk_reg)GetVarname(f);
|
||||
}
|
||||
|
||||
// ----
|
||||
GetInto(dword dest,dtok,dtype)
|
||||
dword tk;
|
||||
{
|
||||
tk=0;
|
||||
DOCASE:
|
||||
IF(tok==tk_minus){
|
||||
F_0:
|
||||
tk=tok;
|
||||
NextTok();
|
||||
GOTO DOCASE;
|
||||
}
|
||||
else IF(tok==tk_not){
|
||||
relation^=1;
|
||||
GOTO F_0;
|
||||
}
|
||||
else IF(tok==tk_openbracket){
|
||||
NextTok();
|
||||
Expression(dest,dtok,dtype);
|
||||
}
|
||||
else IF(tok==tk_number){
|
||||
IF(tk)wsprintfA(#mapstr,"mov %s,-%#x",dest,DoConstMath());
|
||||
ELSE wsprintfA(#mapstr,"mov %s,%#x",dest,DoConstMath());
|
||||
Asm(#mapstr);
|
||||
tk=0;
|
||||
}
|
||||
else IF(tok==tk_postnumber){
|
||||
wsprintfA(#mapstr,"mov %s,#%s",dest,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_locnumber){
|
||||
wsprintfA(#mapstr,"lea ebx,%s",#string);
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"mov %s,ebx",dest);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(tok==tk_proc)DoAnyProc();
|
||||
ELSE IF(tok==tk_API)doAPI();
|
||||
ELSE IF(tok==tk_var)||(tok==tk_local)||(tok==tk_param)||(tok==tk_reg)||
|
||||
(tok==tk_openblock)GetIntoVar(dest,dtok,dtype);
|
||||
ELSE preerror("Wrong expression member");
|
||||
// wsprintfA(#string,dest,"mov %s,%s",#mapstr);
|
||||
// ESP+=16; Asm(#mapstr);
|
||||
IF(tk==tk_minus){
|
||||
wsprintfA(#mapstr,"neg %s",dest);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
IF(tk==tk_not){
|
||||
wsprintfA(#mapstr,"not %s",dest);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
GetIntoVar(dword dName,dTok,dType)
|
||||
byte varName[2*IDLENGTH];
|
||||
dword vtype,vtok;
|
||||
{
|
||||
if(dTok==tk_reg){
|
||||
if(tok==tk_reg){ // Reg = Reg
|
||||
IF(dType==tk_dword){// Reg32=Reg
|
||||
IF(type==tk_dword){
|
||||
wsprintfA(#mapstr,"mov %s,%s",dName,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(type==tk_word)||(type==tk_byte){
|
||||
RDW:
|
||||
wsprintfA(#mapstr,"movzx %s,%s",dName,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
}
|
||||
else IF(dType==tk_word){ // Reg=Reg
|
||||
IF(type==tk_dword){
|
||||
GERR:
|
||||
warning("Not same size\n");
|
||||
}
|
||||
ELSE IF(type==tk_word){
|
||||
wsprintfA(#mapstr,"mov %s,%s",dName,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(type==tk_byte)GOTO RDW;
|
||||
}
|
||||
ELSE IF(dType==tk_byte){ // Reg=Reg
|
||||
IF(type==tk_dword)||(type==tk_word)GOTO GERR;
|
||||
IF(type==tk_byte){
|
||||
wsprintfA(#mapstr,"mov %s,%s",dName,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(tok==tk_var)||(tok==tk_param)||(tok==tk_local)||(tok==tk_openblock){ // Reg = Var
|
||||
vtype=type; vtok=GetVarname(#varName);
|
||||
IF(vtype==tk_dword)||(vtype==tk_int)||(dType==vtype){
|
||||
wsprintfA(#mapstr,"mov %s,%s",dName,#varName);
|
||||
}
|
||||
ELSE IF(vtype==tk_word)||(vtype==tk_byte){
|
||||
wsprintfA(#mapstr,"movzx %s,%s",dName,#varName);
|
||||
}
|
||||
ELSE IF(vtype==tk_short)||(vtype==tk_char){
|
||||
wsprintfA(#mapstr,"movsx %s,%s",dName,#varName);
|
||||
}
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_number){ // Reg = Const
|
||||
wsprintfA(#mapstr,"mov %s,%d",dName,DoConstMath());
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_postnumber){ // Reg = #Var
|
||||
GetVarname(#varName);
|
||||
wsprintfA(#mapstr,"mov %s,#%s",dName,#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(tok==tk_locnumber){ // Reg = #locVar
|
||||
vtype=type; vtok=GetVarname(#varName);
|
||||
wsprintfA(#mapstr,"lea %s,%s",dName,#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
}
|
||||
else if(dTok==tk_var){
|
||||
if(tok==tk_reg){ // Var = Reg;
|
||||
IF(type==tk_dword){
|
||||
wsprintfA(#mapstr,"mov dword %s,%s",dName,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(type==tk_word){
|
||||
wsprintfA(#mapstr,"mov word %s,%s",dName,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(type==tk_byte){
|
||||
wsprintfA(#mapstr,"mov byte %s,%s",dName,#string);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
}
|
||||
else if(tok==tk_var){ // Var = Var;
|
||||
vtype=type;
|
||||
vtok=GetVarname(#varName);
|
||||
IF(dType==tk_byte)||(dType==tk_char){
|
||||
wsprintfA(#mapstr,"mov al,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"mov %s,al",dName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else if(dType==tk_word)||(dType==tk_short){
|
||||
IF(vtype==tk_byte){
|
||||
wsprintfA(#mapstr,"movzx ax,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(vtype==tk_char){
|
||||
wsprintfA(#mapstr,"movsx ax,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(vtype==tk_word)||(vtype==tk_short){
|
||||
wsprintfA(#mapstr,"mov ax,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(vtype==tk_dword)||(vtype==tk_int){
|
||||
wsprintfA(#mapstr,"mov ax,word %s",#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
wsprintfA(#mapstr,"mov %s,ax",dName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else if(dType==tk_dword)||(dType==tk_int){
|
||||
IF(vtype==tk_byte)||(vtype==tk_word){
|
||||
wsprintfA(#mapstr,"movzx eax,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(vtype==tk_char)||(vtype==tk_short){
|
||||
wsprintfA(#mapstr,"movsx eax,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(vtype==tk_dword)||(vtype==tk_int){
|
||||
wsprintfA(#mapstr,"mov eax,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
wsprintfA(#mapstr,"mov %s,eax",dName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
}
|
||||
else IF(tok==tk_number){ // Var = Const;
|
||||
wsprintfA(#mapstr,"mov %s,%d",dName,DoConstMath());
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_postnumber){ // Var = #Var;
|
||||
vtype=type; vtok=GetVarname(#varName);
|
||||
wsprintfA(#mapstr,"mov %s,#%s",dName,#varName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(tok==tk_locnumber){ // Var = #locVar;
|
||||
vtype=type; vtok=GetVarname(#varName);
|
||||
wsprintfA(#mapstr,"lea ebx,%s",#varName);
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"mov %s,ebx",dName);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- —⥨¥ ¯¥à¥¬¥®©: VarName[reg+reg*Scale+disp]
|
||||
dword GetVarname(dword varName)
|
||||
dword vtok;
|
||||
{
|
||||
IF(tok==tk_openblock)GOTO G0;
|
||||
lstrcpyA(varName,#string);
|
||||
vtok=tok;
|
||||
IF(vtok==tk_local)vtok=tk_var;
|
||||
ELSE IF(vtok==tk_param)vtok=tk_var;
|
||||
if(tok2==tk_openblock){
|
||||
NextTok();
|
||||
G0:
|
||||
vtok=tk_var;
|
||||
lstrcatA(varName,"[");
|
||||
for(;;){
|
||||
NextTok();
|
||||
IF(tok==tk_reg)lstrcatA(varName,#string);
|
||||
else IF(tok==tk_plus)lstrcatA(varName,"+");
|
||||
else IF(tok==tk_mult)lstrcatA(varName,"*");
|
||||
ELSE IF(tok==tk_number){
|
||||
wsprintfA(#mapstr,"%d",DoConstMath());
|
||||
lstrcatA(varName,#mapstr);
|
||||
}
|
||||
ELSE IF(tok==tk_postnumber){
|
||||
lstrcatA(varName,"#");
|
||||
lstrcatA(varName,#string);
|
||||
}
|
||||
ELSE IF(tok==tk_closeblock){
|
||||
lstrcatA(varName,"]");
|
||||
BREAK;
|
||||
}
|
||||
ELSE preerror("Illegal index expression in []");
|
||||
}
|
||||
}
|
||||
return(vtok);
|
||||
}
|
||||
|
||||
// ----
|
||||
Term(dword t,ttype)
|
||||
{
|
||||
for(;;){
|
||||
Factor(t,ttype);
|
||||
IF(tok==tk_mult){
|
||||
Factor(t,ttype);
|
||||
IF(tok==tk_number){
|
||||
wsprintfA(#mapstr,"mov ebx,%d",DoConstMath());
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"mul %s","ebx");
|
||||
}
|
||||
ELSE wsprintfA(#mapstr,"mul %s",t);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_div){
|
||||
Factor(t,ttype);
|
||||
IF(tok==tk_number){
|
||||
wsprintfA(#mapstr,"mov ebx,%d",DoConstMath());
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"div %s","ebx");
|
||||
}
|
||||
ELSE wsprintfA(#mapstr,"div %s",t);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
else IF(tok==tk_mod){
|
||||
Factor(t,ttype);
|
||||
IF(tok==tk_number){
|
||||
wsprintfA(#mapstr,"mov ebx,%d",DoConstMath());
|
||||
Asm(#mapstr);
|
||||
wsprintfA(#mapstr,"div %s","ebx");
|
||||
}
|
||||
ELSE wsprintfA(#mapstr,"div %s",t);
|
||||
Asm(#mapstr);
|
||||
Asm("xchg eax,edx");
|
||||
}
|
||||
ELSE IF(tok==tk_and){
|
||||
Factor(t,ttype);
|
||||
IF(tok==tk_number)wsprintfA(#mapstr,"and ebx,%d",DoConstMath());
|
||||
ELSE wsprintfA(#mapstr,"and eax,%s",t);
|
||||
Asm(#mapstr);
|
||||
}
|
||||
ELSE IF(tok==tk_not)Asm("not eax");
|
||||
ELSE BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- ‘®åà ¥¨¥ EAX ¢ á⥪¥
|
||||
PushEAX()
|
||||
{
|
||||
Asm("push eax");
|
||||
}
|
||||
|
||||
// ---- ‘®åà ¥¨¥ EAX ¢ á⥪¥
|
||||
/*PopEAX()
|
||||
{
|
||||
Asm("pop eax");
|
||||
} */
|
||||
|
||||
// ---- Ž¡à ¡®âª áâப¨-¯ à ¬¥âà : proc("string")
|
||||
dword AddPoststring()
|
||||
dword returnvalue;
|
||||
{
|
||||
IF(posts >= MAXPOSTS){
|
||||
preerror("cannot add post string, post queue full");
|
||||
ExitProcess(-1);
|
||||
}
|
||||
EBX=posts<<2+posttype;
|
||||
DSDWORD[EBX] = POST_STR;
|
||||
EBX=posts<<2+postloc;
|
||||
DSDWORD[EBX] = outptr;
|
||||
posts++;
|
||||
returnvalue = MAXDATA-1-poststrptr;
|
||||
ESI=#string;
|
||||
EBX><poststrptr;
|
||||
do{
|
||||
$LODSB;
|
||||
EDI=output+EBX;
|
||||
DSBYTE[EDI]=AL;
|
||||
EBX--;
|
||||
}while(AL!=0);
|
||||
EBX><poststrptr;
|
||||
EAX=returnvalue;
|
||||
}
|
||||
|
||||
// ---- Ž¡à ¡®âª post-áâப ¨ ááë«®ª ¨å
|
||||
DoPoststrings()
|
||||
dword addvalue,addhold,i;
|
||||
{
|
||||
IF(poststrptr==MAXDATA-1)return;
|
||||
addvalue = OptImageBase + OptBaseOfCode+outptr-output ;
|
||||
EDI><outptr;
|
||||
EBX=MAXDATA-1;
|
||||
D0:
|
||||
ESI=output+EBX;
|
||||
AL=DSBYTE[ESI];
|
||||
$STOSB
|
||||
EBX--;
|
||||
$CMP EBX,poststrptr;
|
||||
$JA D0;
|
||||
EDI><outptr;
|
||||
i=0;
|
||||
while(i<posts){
|
||||
EBX=i<<2+posttype;
|
||||
if(DSDWORD[EBX]==POST_STR){
|
||||
EBX=i<<2+postloc;
|
||||
addhold = GetDword(DSDWORD[EBX])+addvalue;
|
||||
SetDword(DSDWORD[EBX],addhold);
|
||||
posts--;
|
||||
EBX=i<<2+postloc;
|
||||
ECX=posts<<2+postloc;
|
||||
DSDWORD[EBX]=DSDWORD[ECX];
|
||||
EBX=i<<2+posttype;
|
||||
ECX=posts<<2+posttype;
|
||||
DSDWORD[EBX]=DSDWORD[ECX];
|
||||
EBX=i<<2+postnum;
|
||||
ECX=posts<<2+postnum;
|
||||
DSDWORD[EBX]=DSDWORD[ECX];
|
||||
i--;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
poststrptr = MAXDATA-1;
|
||||
}
|
||||
|
||||
// ---- —⥨¥ ®¤®£® ¯ à ¬¥âà ¯à¨ ¢ë§®¢¥ ¯à®æ¥¤ãàë
|
||||
GetParam(dword p)
|
||||
dword count; // áç¥â稪 ᪮¡®ª ¢ ¯ à ¬¥âà¥
|
||||
{
|
||||
count=0;
|
||||
for(;;){
|
||||
EAX=0;
|
||||
ESI><inptr2;
|
||||
$LODSB;
|
||||
ESI><inptr2;
|
||||
cha2=AL;
|
||||
EDI><p;
|
||||
$STOSB EDI><p;
|
||||
IF(AL==0)BREAK;
|
||||
IF(AL==')'){
|
||||
IF(count==0){
|
||||
EDI><p;
|
||||
AL=0;
|
||||
EDI--;
|
||||
$STOSB;
|
||||
EDI><p;
|
||||
BREAK;
|
||||
}
|
||||
count--;
|
||||
}
|
||||
ELSE IF(AL==','){
|
||||
IF(count==0){
|
||||
EDI><p;
|
||||
EDI--;
|
||||
AL=0;
|
||||
$STOSB;
|
||||
EDI><p;
|
||||
DoParam();
|
||||
BREAK;
|
||||
}
|
||||
}
|
||||
ELSE IF(AL=='(')count++;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Ž¡à ¡®âª ®¤®£® ¯ à ¬¥âà ¯à¨ ¢ë§®¢¥ ¯à®æ¥¤ãàë
|
||||
DoParam()
|
||||
dword vtok;
|
||||
byte p[250]; // ¬¥áâ® ¯®¤ ª®¯¨î ¯ à ¬¥âà
|
||||
byte holdcha;
|
||||
byte s[STRLEN],s2[STRLEN];
|
||||
byte varName[2*IDLENGTH];
|
||||
{
|
||||
GetParam(#p);
|
||||
holdcha=cha2;
|
||||
$PUSH linenum2,inptr2,number,tok2,tok,input,inptr,currmod,linenumber,
|
||||
endoffile,displaytokerrors;
|
||||
lstrcpyA(#s,#string); lstrcpyA(#s2,#string2);
|
||||
input=#p;
|
||||
inptr = input;
|
||||
inptr2 = input;
|
||||
endoffile = 0; // <20> ç «¥ ä ©«
|
||||
NextChar();
|
||||
cha2 = cha;
|
||||
inptr2=inptr;
|
||||
linenum2 = 1;
|
||||
NextTok();
|
||||
for(;;){
|
||||
IF(tok==tk_eof)||(tok==tk_closebracket)break;
|
||||
IF(tok==tk_comma)NextTok();
|
||||
else IF(tok==tk_string){
|
||||
OP(byte 0x68);
|
||||
OUTDWORD(AddPoststring());
|
||||
IF(list){
|
||||
wsprintfA(#mapstr,"\t//\tpush #\"%s\"\n",#string);
|
||||
fprint(mapfile,#mapstr);
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
else IF(tok2isopperand()){
|
||||
Expression("eax",tk_reg,tk_dword);
|
||||
PushEAX();
|
||||
}
|
||||
else{ // ¥ ¢ëà ¦¥¨¥
|
||||
IF(tok==tk_number){
|
||||
wsprintfA(#mapstr,"push %#x",DoConstMath());
|
||||
Asm(#mapstr);
|
||||
NextTok();
|
||||
}
|
||||
else IF(tok==tk_postnumber){
|
||||
wsprintfA(#mapstr,"push #%s",#string);
|
||||
Asm(#mapstr);
|
||||
NextTok();
|
||||
}
|
||||
else if(tok==tk_reg){
|
||||
IF(type==tk_dword){
|
||||
wsprintfA(#mapstr,"push %s",#string);
|
||||
Asm(#mapstr);
|
||||
NextTok();
|
||||
}
|
||||
ELSE IF(type==tk_word){
|
||||
wsprintfA(#mapstr,"movsx e%s,%s;push e%s",#string,#string,#string);
|
||||
Asm(#mapstr);
|
||||
NextTok();
|
||||
}
|
||||
ELSE IF(tok==tk_byte){
|
||||
wsprintfA(#mapstr,"movsx e%cx,%s;push e%cx",string[0],#string,string[0]);
|
||||
Asm(#mapstr);
|
||||
NextTok();
|
||||
}
|
||||
}
|
||||
else IF(tok==tk_var)||(tok==tk_local)||(tok==tk_param){
|
||||
vtok=GetVarname(#varName);
|
||||
IF(type==tk_dword){
|
||||
D0: wsprintfA(#mapstr,"push %s",#varName);
|
||||
Asm(#mapstr);
|
||||
NextTok();
|
||||
}
|
||||
ELSE GOTO D1;
|
||||
IF(type==tk_int){ //????
|
||||
vtok=GetVarname(#varName);
|
||||
GOTO D0;
|
||||
}
|
||||
}
|
||||
ELSE{
|
||||
D1: Expression("eax",tk_reg,tk_dword);
|
||||
PushEAX();
|
||||
}
|
||||
}
|
||||
}
|
||||
lstrcpyA(#string,#s);
|
||||
lstrcpyA(#string2,#s2);
|
||||
$POP displaytokerrors,endoffile,linenumber,currmod,inptr,input,tok,tok2;
|
||||
$POP number,inptr2,linenum2;
|
||||
cha2=holdcha;
|
||||
}
|
529
programs/develop/c--/trunk/readme_ru.txt
Normal file
529
programs/develop/c--/trunk/readme_ru.txt
Normal file
@ -0,0 +1,529 @@
|
||||
"‘®¢¥àè¨â¥ ¢ë ¬ ááã ®âªàë⨩,
|
||||
¨®£¤ ¥ ¦¥« ï ⮣®..."
|
||||
<20>¥ ¯®¬î ¢â®à , ® ¯¥«
|
||||
€¤à¥© Œ¨à®®¢.
|
||||
|
||||
<20>।¨á«®¢¨¥.
|
||||
|
||||
ˆ¤¥ï ¯¨á âì ª®¬¯¨«ïâ®à ¤«ï Win32 த¨« áì ¯à¨ ¬®¥¬ ¯¥à¢®¬
|
||||
§ ª®¬á⢥ á ª®¬¯¨«ïâ®à®¬ Sphinx C-- <20>¨â¥à ‘¥««¨ª (Peter Cellik)
|
||||
¢ 1996 £®¤ã, ® ॠ«¨§®¢ âì ¥¥ 㤠«®áì «¨èì ¥¤ ¢®, ª®£¤
|
||||
¯®ï¢¨« áì ¢®§¬®¦®áâì ç¥à¥§ ˆâ¥à¥â ©â¨ ¨áå®¤ë¥ â¥ªáâë ¤«ï C--,
|
||||
¯®áª®«ìªã ç¨ âì á ã«ï ¦¥« ¨ï ¥ ¡ë«®.
|
||||
ˆâ ª, ª®à®âª® ® £« ¢®¬. Žá®¢®© ¯à¨æ¨¯ ¯®áâ஥¨ï ¯à¨«®¦¥¨©
|
||||
¤«ï 32-à §à冷© á¨á⥬ë, ¯à¥¤« £ ¥¬ë© ¢ à §«¨çëå ª®¬¯¨«ïâ®à å,
|
||||
§ ª«îç ¥âáï ¢ à §¤¥«¥¨¨ ª®¤ ¥áª®«ìª® ᥪ権: .text, .data,
|
||||
.idata, .reloc, .rsrc ¨ â.¤., ª®â®àë¥ áâà®ïâáï ¨§ á ¬¨å ¨á室ëå
|
||||
⥪á⮢ ¨ à §«¨çëå ä ©«®¢ ®¯¨á ¨© ¨ à¥áãàᮢ áâ ¤¨¨ ᡮન
|
||||
¯à®£à ¬¬®©-«¨ª®¢é¨ª®¬ (link). <20>® áã⨠¤¥« ®áâ « áì áâ à ï á奬
|
||||
¯®áâ஥¨ï: compiler + linker -> exe-file. Šà®¬¥ ⮣®, ¡®«ì让 ¡®à
|
||||
à §«¨çëå ¡¨¡«¨®â¥ª... ª®â®àë¥ ª ⮬㠦¥ áãé¥á⢥® ¬¥ïîâáï ®â
|
||||
¢¥àᨨ ª ¢¥àᨨ, ç⮠ᮢᥬ ¥ à ¤ã¥â. ˆ ¥á«¨ ¢ë ¯¥à¥å®¤¨â¥ ®¢ãî,
|
||||
¡®«¥¥ ¯à®¤¢¨ãâãî ¢¥àá¨î ª®¬¯¨«ïâ®à , â® ¥â ¨ª ª®© £ à ⨨, çâ®
|
||||
¢ë ᬮ¦¥â¥ ¥¬ ¯¥à¥ª®¬¯¨«¨à®¢ âì ᢮¨ áâ àë¥ ¯à®£à ¬¬ë - ¯à¨¬¥à®¬
|
||||
á«ã¦¨â DDK ®â MicroSoft.
|
||||
Sphinx C-- ¨§ ç «ì® ¡ë« § ¤ã¬ ¨ ॠ«¨§®¢ ¤«ï ᮧ¤ ¨ï
|
||||
ª®¬¯ ªâëå ¯® à §¬¥àã COM-ä ©«®¢ ¨ ¯®í⮬㠢¯®«¥ ¯®¤å®¤¨â ¤«ï
|
||||
£¥¥à 樨 32-à §àï¤ëå ¯à¨«®¦¥¨ï ¢ ¬®¤¥«¨ ¯«®áª®© (flat) ¯ ¬ïâ¨.
|
||||
<EFBFBD>®¬¨¬® í⮣® ¡®«ì訬 ¯«îᮬ ï¥âáï ¨¤¥ï ®âªàë⮣® ª®¤ ¤«ï ¢á¥å
|
||||
¢ë§ë¢ ¥¬ëå ¢ ¯à®£à ¬¬¥ ¡¨¡«¨®â¥çëå äãªæ¨©, ॠ«¨§®¢ ï ¯®á।á⢮¬
|
||||
*.h-- ä ©«®¢.
|
||||
…é¥ ®¤ ¨¤¥ï ¨§ ª®¬¯¨«ïâ®à Sphinx C--, § á«ã¦¨¢ îé ï ¢¨¬ ¨ï, - íâ®
|
||||
¤¨ ¬¨ç¥áª¨¥ ¯à®æ¥¤ãàë, â.¥. ¯à®æ¥¤ãàë, ª®â®àë¥ ¬®£ãâ ¡ëâì ¯®¬¥é¥ë ¢ ⥫®
|
||||
ª®¬¯¨«¨à㥬®© ¯à®£à ¬¬ë ⮫쪮 ⮣¤ , ª®£¤ ª ¨¬ ¥áâì ®¡à 饨¥. ’ ª¨¬
|
||||
®¡à §®¬, ¢ ¯à®æ¥áᥠ¯¨á ¨ï ¯à®£à ¬¬ë á ¨á¯®«ì§®¢ ¨¥¬ ¤¨ ¬¨ç¥áª¨å
|
||||
¯à®æ¥¤ãà £ à â¨àã¥âáï ¢ª«î票¥ ¢ ⥫® ¯à®£à ¬¬ë ⮫쪮 ⮣® ª®¤ ,
|
||||
ª®â®àë© ¤¥©áâ¢¨â¥«ì® ¥®¡å®¤¨¬.
|
||||
‚ ¯à®æ¥áá¥ à ¡®âë ¯® ¯¥à¥¢®¤ã ª®¬¯¨«ïâ®à Sphinx C-- ¯« âä®à¬ã Win32
|
||||
¯à®¨§¢¥¤¥ë ¢¥áì¬ áãé¥áâ¢¥ë¥ ¨§¬¥¥¨ï ª ª ¢ á ¬®¬ ª®¬¯¨«ïâ®à¥, â ª ¨ ¢
|
||||
¨¤¥ïå, ª®â®àëå ® ॠ«¨§®¢ . Ÿ ¥ ¡ã¤ã §¤¥áì ¢ë¤¥«ïâì ¢á¥ ®â«¨ç¨ï
|
||||
áâ®ï饣® ª®¬¯¨«ïâ®à ®â ¥£® ¯à த¨â¥«ï ¯® ⮩ ¯à®á⮩ ¯à¨ç¨¥, çâ® â¥, ªâ®
|
||||
á ¨¬ § ª®¬, ¨å ᬮ£ãâ 㢨¤¥âì á ¬¨, ⥬, ªâ® ¥ ¨¬¥« ¤¥« á ‘--, ¥â 㦤ë
|
||||
¢¨ª âì ¢ í⨠¤¥â «¨.
|
||||
Žâ¬¥çã, ®¤ ª®, çâ® ¯à¨æ¨¯ £¥¥à 樨 ª®¤ , ¨á¯®«ì§®¢ ¢è¨©áï ¢ ‘--, § ¬¥¥
|
||||
¯à¨æ¨¯, ¨á¯®«ì§ã¥¬ë© ¢ ¬ ªà® áᥬ¡«¥à¥ TMA ‘¢¥ Š«®§¥ (TMA macro assembler
|
||||
Sven Klose), á ¯à®¢¥¤¥¨¥¬ ¥£® ¤ ¯â 樨 ª 㦤 ¬ ‘--.
|
||||
‚ १ã«ìâ ⥠¯®ï¢¨«áï ¤ ë© ª®¬¯¨«ïâ®à, 楫ìî ª®â®à®£® ï¥âáï § ¯®«¥¨¥
|
||||
¨è¨ ¬¥¦¤ã ï§ëª®¬ áᥬ¡«¥à ¨ ï§ëª®¬ ‘.
|
||||
|
||||
Ž¯¨á ¨¥ ï§ëª .
|
||||
|
||||
ˆ¤¥â¨ä¨ª â®àë.
|
||||
|
||||
ˆ¤¥â¨ä¨ª â®àë ¤®«¦ë ç¨ âìáï á ¡ãª¢ë ¨«¨ § ª ¯®¤ç¥àª¨¢ ¨ï, ¥á«¨
|
||||
ïîâáï £«®¡ «ì묨, ¨«¨ ¦¥ ¤®«¦ë ç¨ âìáï á ᨬ¢®« @, ¥á«¨ ®¨ «®ª «ìë¥.
|
||||
„ «¥¥ ¬®¦¥â ¨¤â¨ «î¡ ï ª®¬¡¨ æ¨ï æ¨äà, ¡ãª¢ ¨«¨ § ª®¢ ¯®¤ç¥àª¨¢ ¨ï ¤«¨®©
|
||||
¥ ¡®«¥¥ 63 ᨬ¢®«®¢. <20>ãª¢ë ¬®£ãâ ¡ëâì ª ª ¨§ « â¨áª®£®, â ª ¨ ¨§ 樮 «ì®£®
|
||||
«ä ¢¨â . <20>¥áª®«ìª® ¯à¨¬¥à®¢:
|
||||
GoHome
|
||||
_1234
|
||||
<20>ਬ¥àˆ¤¥â¨ä¨ª â®à
|
||||
@LocalLabel2
|
||||
|
||||
‚ᥠ¨¤¥â¨ä¨ª â®àë, ªà®¬¥ § १¥à¢¨à®¢ ëå, ïîâáï çã¢á⢨⥫ì묨 ª
|
||||
ॣ¨áâàã, â.¥. ¨¤¥â¨ä¨ª â®àë: ToDo ¨ Todo ª®¬¯¨«ïâ®à ¢®á¯à¨¬¥â ª ª à §ë¥.
|
||||
|
||||
‡ १¥à¢¨à®¢ ë¥ ¨¤¥â¨ä¨ª â®àë
|
||||
|
||||
<20>¨¦¥ ¯à¨¢®¤¨âáï ᯨ᮪ § १¥à¢¨à®¢ ëå ¨¤¥â¨ä¨ª â®à®¢ ï§ëª , ª®â®àë¥
|
||||
¥ ¬®£ãâ ¡ëâì ¨á¯®«ì§®¢ ë ¯à¨ á®§¤ ¨¨ ¯à®£à ¬¬ë ¨ ç¥, ª ª íâ® ®¯à¥¤¥«¥®
|
||||
¢ ï§ëª¥:
|
||||
byte char word short dword int
|
||||
if else cycle do while return
|
||||
docase case continue break extract from
|
||||
enum struct
|
||||
carryflag overflow zeroflag
|
||||
notcarryflag notoverflow notzeroflag
|
||||
â ª¦¥ §¢ ¨ï ॣ¨áâ஢ ¨ ¬¥¬®¨ª¨ ª®¬ ¤ áᥬ¡«¥à .
|
||||
|
||||
…é¥ à § ¯®¤ç¥àªã, çâ® § १¥à¢¨à® ë¥ á«®¢ ¥ § ¢¨áïâ ®â ॣ¨áâà , â.¥.
|
||||
Enum ¨ eNuM ª®¬¯¨«ïâ®à ¢®á¯à¨¬¥â ¢ «î¡®¬ ¨§ ¢ ਠ⮢, ª ª ç «® ᯨáª
|
||||
㬥஢ ëå ª®áâ â.
|
||||
|
||||
Š®áâ âë
|
||||
|
||||
—¨á«®¢ë¥ ª®áâ âë ¬®£ãâ ¡ëâì § ¤ ë ¢ ®¤®© ¨§ ç¥âëà¥å á¨á⥬ áç¨á«¥¨ï:
|
||||
¤¥áïâ¨ç®©, è¥áâ ¤æ â¨à¨ç®©, ¢®á¬¥à¨ç®© ¨«¨ ¤¢®¨ç®©.
|
||||
„¥áïâ¨çë¥ ç¨á«®¢ë¥ ª®áâ âë § ¤ îâáï ®¡ëçë¬ ®¡à §®¬: 444 ¨«¨ 007.
|
||||
˜¥áâ ¤æ â¨à¨ç®¥ ¯à¥¤áâ ¢«¥¨¥ ª®áâ â ç¨ ¥âáï á ª®¬¡¨ 樨 0x: 0xFFF
|
||||
¨«¨ 0x088.
|
||||
‚®á¬¥à¨ç®¥ ¯à¥¤áâ ¢«¥¨¥ ª®áâ â ç¨ ¥âáï á ª®¬¡¨ 樨 0o: 0o777 ¨«¨
|
||||
0o10.
|
||||
„¢®¨ç®¥ ¯à¥¤áâ ¢«¥¨¥ ª®áâ â ç¨ ¥âáï á ª®¬¡¨ 樨 0b: 0b111101 ¨«¨
|
||||
0b11101010.
|
||||
|
||||
‘¨¬¢®«ë ¢ ª®áâ â å § ª«îç îâáï ¢ ®¤¨®çë¥ ª ¢ë窨 ('). ’ ª ¦¥ ª ª ¨ ¢ ‘
|
||||
ᨬ¢®«ë ¬®£ãâ § ¤ ë á ¯®¬®éìî 㪠§ ¨ï ¨å ª®¤ ¯®á«¥ ᨬ¢®« '\'. ‘¯¨á®ª
|
||||
ᯥæᨬ¢®«®¢:
|
||||
'\a', '\b', '\f', '\l', '\n', '\r', '\t' - ¤«ï ä®à¬ â¨à®¢ ¨ï ¢ë¢®¤
|
||||
'\x??' ¨«¨ '\???' - ASCII-ᨬ¢®«. Š®¤ ᨬ¢®« § ¤ «¨¡® ¢ 16, 10 § 票¥¬.
|
||||
‹î¡ë¥ ᨬ¢®«ë ¯®á«¥ '\' ¯à®áâ® ¯à¨¨¬ îâáï ª®¬¯¨«ïâ®à®¬, â ª¨¬ ®¡à §®¬
|
||||
®¤¨®çãî ª ¢ëçªã ¬®¦® 㪠§ âì ª ª '\''.
|
||||
|
||||
‘âப®¢ë¥ ª®áâ âë § ¤ îâáï ¯ã⥬ § ª«îç¥¨ï ¨å ¢ ¤¢®©ë¥ ª ¢ë窨 (").
|
||||
‚ãâਠáâப®¢®© ª®áâ âë ¤®¯ã᪠¥âáï 㪠§ ¨¥ ᯥæᨬ¢®«®¢ ¢ ®¤¨®çëå
|
||||
ª ¢ëçª å. <20>ਬ¥àë áâப®¢ëå ª®áâ â:
|
||||
"<22>ਬ¥à áâப®¢®© ª®áâ âë\n"
|
||||
"Need '\"'word'\"' in data declaration" -> Need "word" in data declaration
|
||||
|
||||
<20>ਠ®¯à¥¤¥«¥¨¨ ç¨á«®¢ëå ¨ ᨬ¢®«ìëå ª®áâ â ¤®¯ã᪠¥âáï ¨á¯®«ì§®¢ ¨¥
|
||||
¢ëà ¦¥¨©, ª®â®àë¥ ¢ëç¨á«ïîâáï ¢ ¯à®æ¥áᥠª®¬¯¨«ï樨. ‡ 票¥¬ ª®áâ âë
|
||||
¡ã¤¥â १ã«ìâ â ¢ëç¨á«¥¨ï ¢ëà ¦¥¨ï:
|
||||
1*2*3/2+4 ¤ áâ § 票¥ ª®áâ âë 7.
|
||||
‚ëç¨á«¥¨ï ¯à®¢®¤ïâáï á«¥¢ - ¯à ¢® ¡¥§ ãç¥â ¯à¨®à¨â¥â ®¯¥à 権.
|
||||
|
||||
‘â ¤ àâë¥ â¨¯ë ¤ ëå
|
||||
|
||||
ˆ¬¥¥âáï è¥áâì áâ ¤ àâëå ⨯®¢ ¤ ëå: byte, char, word, short, dword
|
||||
¨ int. ‚ â ¡«¨æ¥ ¯à¨¢¥¤¥ë à §¬¥à ¨ ¤¨ ¯ §® § 票© ¤«ï ª ¦¤®£® ⨯ :
|
||||
-------------------------------------------------------------------
|
||||
’¨¯ | <20> §¬¥à | „¨ ¯ §® § 票©
|
||||
¯¥à¥¬¥®© | ¢ ¡ ©â å | (¤¥áïâ¨ç.) | (hex)
|
||||
-------------------------------------------------------------------
|
||||
byte | 1 | 0...255 | 0...0xFF
|
||||
char | 1 | -127...127 | 0x80...0x7F
|
||||
word | 2 | 0...65535 | 0...0xFFFF
|
||||
short | 2 | -32768...32767 | 0x8000...0x7FFF
|
||||
dword | 4 | 0...4294967295 | 0...0xFFFFFFFF
|
||||
int | 4 | -2147483648... | 0x80000000 ...
|
||||
| | 2147483647 | 0x7FFFFFFF
|
||||
-------------------------------------------------------------------
|
||||
|
||||
ƒ«®¡ «ìë¥ ¯¥à¥¬¥ë¥
|
||||
|
||||
Ž¡ê¥¨¥ ¯¥à¥¬¥ëå ¨¬¥¥â ®¡ëçë© ¤«ï ‘ á¨â ªá¨á:
|
||||
|
||||
<⨯> <ᯨ᮪ ¨¤¥â¨ä¨ª â®à®¢>;
|
||||
|
||||
‘¯¨á®ª ¨¤¥â¨ä¨ª â®à®¢ á®á⮨⠨§ ®¤®£® ¨«¨ ¡®«¥¥ ¨¤¥â¨ä¨ª â®à®¢,
|
||||
à §¤¥«¥ëå § ¯ïâ묨. ‚ ᯨ᪥ â ª¦¥ ¬®£ãâ ¯à¨áãâ᢮¢ âì ®¤®¬¥àë¥ ¬ áᨢë,
|
||||
®¡êï¢«ï¥¬ë¥ ¢ ¢¨¤¥:
|
||||
<¨¤¥â¨ä¨ª â®à>[<à §¬¥à®áâì>].
|
||||
|
||||
<20>ਬ¥àë ®¡ê¥¨© ¯¥à¥¬¥ëå:
|
||||
dword i,j; // i ¨ j ⨯ dword
|
||||
byte Tab='\t'; // ¯¥à¥¬¥ ï Tab ⨯ byte á ç «ìë¬ § 票¥¬
|
||||
char string[]="This is a string\n";
|
||||
int z,b[6]; // z ⨯ int ¨ ¬ áᨢ 楫ëå - b
|
||||
|
||||
‚ëà ¦¥¨ï
|
||||
|
||||
‚ëà ¦¥¨ï á®áâ®ïâ ¨§ «¥¢®© ¨ ¯à ¢®© ç á⥩, à §¤¥«¥ëå «¨¡® ®¯¥à 樥©
|
||||
¯à¨á¢ ¨¢ ¨ï, «¨¡® ®¯¥à 樥© áà ¢¥¨ï. ‹¥¢ ï ç áâì ¢ëà ¦¥¨ï ¬®¦¥â ¡ëâì
|
||||
«¨¡® ¯¥à¥¬¥®©, «¨¡® ॣ¨áâ஬. ‚ ¯à ¢®© ç á⨠¢ëà ¦¥¨ï ¬®¦¥â 室¨âìáï
|
||||
¯à®¨§¢®«ì®¥ ª®«¨ç¥á⢮ ¯¥à¥¬¥ëå, äãªæ¨©, ª®áâ â, ᪮¡®ª ¨ § ª®¢ ®¯¥à 権.
|
||||
<EFBFBD>¨¦¥ ¯à¨¢®¤¨âáï â ¡«¨æ ¢á¥å ¤®¯ãá⨬ëå ®¯¥à 権:
|
||||
-------------------------------------------------------------------------
|
||||
Ž¯¥à æ¨ï | ‡ 票¥ | <20>ਬ¥à
|
||||
-------------------------------------------------------------------------
|
||||
= | ¯à¨á¢®¨âì ¨«¨ | edi = 33;
|
||||
| ¯à®¢¥à¨âì à ¢¥á⢮ | while(ch = 'a')
|
||||
+ | á«®¦¨âì | eax = Count + 5;
|
||||
- | ¢ëç¥áâì | Count = eax - edi;
|
||||
* | 㬮¦¨âì | x = y * 3;
|
||||
/ | à §¤¥«¨âì | y = ecx / x;
|
||||
% | ®áâ ⮪ ¤¥«¥¨ï | y = edi / 7;
|
||||
& | «®£¨ç¥áª®¥ AND | a = B & c;
|
||||
| | «®£¨ç¥áª®¥ OR | a = B | c;
|
||||
^ | «®£¨ç¥áª®¥ XOR | a = B ^ c;
|
||||
<< | ᤢ¨£ ¡¨â ¢«¥¢® | x = y << 5;
|
||||
>> | ᤢ¨£ ¡¨â ¢¯à ¢® | x = y >> 6;
|
||||
+= | 㢥«¨ç¨âì | a += 6; // a = a + 6;
|
||||
-= | 㬥ìè¨âì | a -= 5; // a = a - 5;
|
||||
&= | ¯®¡¨âë© AND | a &= 0xF; // a = a & 0xF;
|
||||
|= | ¯®¡¨âë© OR | a |= 0o77; // a = a | 0o77;
|
||||
^= | ¯®¡¨âë© XOR | a ^= 0b1101; // a = a ^ 0b1101;
|
||||
<<= | ᤢ¨£ ¡¨â ¢«¥¢® | a <<= 7; // a = a << 7;
|
||||
>>= | ᤢ¨£ ¡¨â ¢¯à ¢® | a >>= 3; // a = a >> 3;
|
||||
>< | ®¡¬¥(swap) | x >< y; // temp=y; y=x; x=temp;
|
||||
== | ¯à®¢¥à¨âì à ¢¥á⢮ | if( x=='7' ) // ¤«ï â¥å, ª®¬ã â ª ¯à¨¢ë祥
|
||||
> | ¡®«ìè¥ ç¥¬ | case( x > y )
|
||||
< | ¬¥ìè¥ ç¥¬ | if( a < 0 )
|
||||
>= | ¡®«ìè¥ ¨«¨ à ¢® | while(( b >= a ) & ( x >= ( y - 7 )))
|
||||
<= | ¬¥ìè¥ ¨«¨ à ¢® | if( y <= ( a + b - 30 ))
|
||||
!= ¨«¨ <>| ¥ à ¢® | case( a != b) ¨«¨ ¦¥ case( a <> b)
|
||||
# | ¤à¥á ¯¥à¥¬¥®© | esi = #Count; // esi= ¤à¥á ¯¥à¥¬¥®© Count
|
||||
|
||||
”ãªæ¨¨
|
||||
|
||||
Ž¡ê¥¨¥ äãªæ¨© ¨¬¥¥â ¢¨¤:
|
||||
|
||||
<⨯> <¨¤¥â¨ä¨ª â®à>(<ᯨ᮪ ¯ à ¬¥â஢>)
|
||||
|
||||
‘¯¨á®ª ¯ à ¬¥â஢ § ¤ ¥â â¨¯ë ¨ ¨¬¥ ä®à¬ «ìëå ¯ à ¬¥â஢, ¨á¯®«ì§ã¥¬ëå ¯à¨
|
||||
¢ë§®¢¥ äãªæ¨¨. Š®¬¯¨«ïâ®à ¥ ®áãé¥á⢫ï¥â ¯à®¢¥àªã ᮮ⢥âá⢨ï ᯨáª
|
||||
ä®à¬ «ìëå ¯ à ¬¥â஢ äãªæ¨¨ ä ªâ¨ç¥áª¨¬, ¯®í⮬ã á«¥¤ã¥â ¢¨¬ â¥«ì® á«¥¤¨âì
|
||||
§ ª®à४â®áâìî ¢ë§®¢ äãªæ¨©.
|
||||
’¨¯ ¢®§¢à é ¥¬®£® ¨§ äãªæ¨¨ § ç¥¨ï ¬®¦® ¥ 㪠§ë¢ âì. ‚ í⮬ á«ãç ¥
|
||||
¯® 㬮«ç ¨î áç¨â ¥âáï, çâ® äãªæ¨ï ¢®§¢à é ¥â § 票¥ ⨯ dword. ‡ 票¥
|
||||
¯®¬¥é ¥âáï ¯à¨ ¢®§¢à ⥠¨§ äãªæ¨¨ ¢ ॣ¨áâà eax ¤«ï ⨯®¢ dword ¨ int, ¢
|
||||
ॣ¨áâà ax ¤«ï ⨯®¢ word ¨ short ¨ ¢ ॣ¨áâà al ¤«ï ⨯®¢ byte ¨ char.
|
||||
‚ ᯨ᪥ ¯ à ¬¥â஢ ¤«ï ª ¦¤®£® ¯ à ¬¥âà 㪠§ë¢ ¥âáï ¥£® ⨯. <20> à ¬¥âàë
|
||||
®¤®£® ⨯ , ¨¤ã騥 ¯®¤àï¤, à §¤¥«ïîâáï § ¯ïâ묨. ”®à¬ «ìë¥ ¯ à ¬¥âàë à §®£®
|
||||
⨯ ¢ ®¡ê¥¨¨ äãªæ¨¨ à §¤¥«ïîâáï ᨬ¢®«®¬ ;. …᫨ ⨯ ¯ à ¬¥âà ¥ § ¤ ,
|
||||
â® áç¨â ¥âáï, çâ® ¯ à ¬¥âà ¨¬¥¥â ⨯ dword. <20>¥ § ¢¨á¨¬® ®â ⨯ ¯ à ¬¥âà ¯à¨
|
||||
¢ë§®¢¥ äãªæ¨¨ ¤«ï ª ¦¤®£® ¯ à ¬¥âà ¢ë¤¥«ï¥âáï 4 ¡ ©â (dword). <20>â® á¢ï§ ®
|
||||
á ⥬, çâ® ¢ Win32 á⥪ ¢á¥£¤ ¤®«¦¥ ¨¬¥âì ¢ëà ¢¨¢ ¨¥ (alignment) £à ¨æã
|
||||
¤¢®©®£® á«®¢ .
|
||||
<20>ਬ¥àë ®¡ê¥¨ï äãªæ¨© ¨ ¨å ¢ë§®¢®¢.
|
||||
Ž¡ê¥¨¥ <20>ਬ¥à ¢ë§®¢
|
||||
char ToUpper(char ch) upChar = ToUpper('i');
|
||||
MergeStrings(dword dest,str1,str2) MergeStrings(#str,"One","+Two");
|
||||
¯®«ã稬 str="One+Two"
|
||||
Convert(dword str; int number,base) Convert(#num, -567, 16);
|
||||
|
||||
<20>ਠ¢ë§®¢¥ äãªæ¨¨ ¯¥à¢ë© ¯ à ¬¥âà ¯®¬¥é ¥âáï ¢ á⥪ ¯®á«¥¤¨¬. <20>ਬ¥à:
|
||||
WriteFile(handle,"Hello World!\n",14,#dWriteFileCount,0);
|
||||
¡ã¤¥â ॠ«¨§®¢ :
|
||||
push 0
|
||||
push #dWriteFileCount
|
||||
push 14
|
||||
push #"Hello World!"
|
||||
push handle
|
||||
call WriteFile
|
||||
<20>ਠ¢®§¢à ⥠¨§ äãªæ¨¨ á⥪ ®ç¨é ¥âáï ®â ¯ à ¬¥â஢ ª®¬ ¤®©: ret number.
|
||||
|
||||
‚ᥠ®¡êï¢«ï¥¬ë¥ ¢ ¯à®£à ¬¬¥ äãªæ¨¨ ïîâáï ¤¨ ¬¨ç¥áª¨¬¨. <20>â® § ç¨â,
|
||||
çâ® ª®¤ äãªæ¨¨ ¢áâ ¢«ï¥âáï ¢ ¯à®£à ¬¬ã «¨èì ⮫쪮 ¢ á«ãç ¥ ®¡à é¥¨ï ª ¥©.
|
||||
’® ¦¥ á ¬®¥ ®â®á¨âáï ¨ ª «î¡ë¬ £«®¡ «ìë¬ ¯¥à¥¬¥ë¬ ¢ ¯à®£à ¬¬¥.
|
||||
|
||||
‘âàãªâãàë¥ ®¯¥à â®àë
|
||||
|
||||
<20>ਬ¥¥¨¥ áâàãªâãàëå ®¯¥à â®à®¢ ¢ ¯à®£à ¬¬¥ ¤¥« ¥â ¥¥ ¡®«¥¥ 㤮¡®© ¤«ï
|
||||
çâ¥¨ï ¨ «¨§ . Šà®¬¥ ⮣®, ¯¨á âì ¥áª®«ìª® áâàãªâãàëå ®¯¥à â®à®¢ ¯à®é¥,
|
||||
祬 ¯ãâ âìáï ¢ ¯®å®¦¨å ¨¬¥ å ¡®«ì讣® ç¨á« ¬¥â®ª ¨ ¬ãç¨âìáï, ¯à¨¤ã¬ë¢ ï
|
||||
㨪 «ì®¥ ¨¬ï ¤«ï ª ¦¤®© ®¢®© ¬¥âª¨. ‚ â® ¦¥ ¢à¥¬ï ¥ § ¯à¥é ¥âáï ¨á¯®«ì§®¢ âì
|
||||
¨ ¬¥âª¨ ¢ «î¡®¬ ¬¥á⥠¯à®£à ¬¬ë. •®à®è® ¯®áâ ¢«¥ ï ¬¥âª ᯮᮡ §¤®à®¢®
|
||||
®¡«¥£ç¨âì ¯¨á ¨¥ ¨ «¨§ ¯à®£à ¬¬ë.
|
||||
|
||||
Ž¯¥à â®à if.
|
||||
|
||||
‚ ®¡é¥¬ ¢¨¤¥ ãá«®¢ë© ®¯¥à â®à ¬®¦® § ¯¨á âì â ª:
|
||||
|
||||
if(<ãá«®¢¨¥>)
|
||||
<£à㯯 ®¯¥à â®à®¢1>
|
||||
else
|
||||
<£à㯯 ®¯¥à â®à®¢2>
|
||||
|
||||
€«£®à¨â¬ ¢ë¯®«¥¨ï ãá«®¢®£® ®¯¥à â®à á®á⮨⠢ á«¥¤ãî饬:
|
||||
¯à®¢¥àï¥âáï <ãá«®¢¨¥>, ¨ ¥á«¨ ®® ¨á⨮, â® ¢ë¯®«ï¥âáï <£à㯯 ®¯¥à â®à®¢1>,
|
||||
á«¥¤ãîé ï § if, ¯®á«¥ 祣® ã¯à ¢«¥¨¥ ¯¥à¥¤ ¥âáï § ª®¥æ ãá«®¢®£® ®¯¥à â®à .
|
||||
…᫨ ãá«®¢¨¥ «®¦®, â® ã¯à ¢«¥¨¥ ¯¥à¥¤ ¥âáï <£à㯯㠮¯¥à â®à®¢2>, á«¥¤ãîéãî
|
||||
§ else. <20>®à冷ª ¢ë¯®«¥¨ï ãá«®¢®£® ®¯¥à â®à ¢ á«ãç ¥ ®âáãâá⢨ï else
|
||||
®ç¥¢¨¤¥. ‚ ª ç¥á⢥ £àã¯¯ë ®¯¥à â®à®¢ ¬®¦¥â ¡ëâì «¨¡® ®¤¨ ®¯¥à â®à, «¨¡® ¡«®ª
|
||||
¨§ ¥áª®«ìª¨å ®¯¥à â®à®¢ ¢ {} ᪮¡ª å. ‚®â ¥áª®«ìª® ¯à¨¬¥à®¢:
|
||||
if(edx<=2){
|
||||
WriteStr("Equal or less two\n");
|
||||
return();
|
||||
}
|
||||
else{
|
||||
WriteStr("Greater than two\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
if((x<>0)&(y<>0))
|
||||
return(x/y);
|
||||
|
||||
Ž¯¥à â®à cycle
|
||||
|
||||
Ž¯¥à â®à 横« cycle ¨¬¥¥â ¢¨¤:
|
||||
|
||||
cycle(<áç¥â稪>) <£à㯯 ®¯¥à â®à®¢>
|
||||
|
||||
–¨ª« ¢ë¯®«ï¥âáï ¤® â¥å ¯®à ¯®ª § 票¥ áç¥â稪 ¥ ¡ã¤¥â à ¢® ã«î.
|
||||
<EFBFBD>஢¥àª áç¥â稪 à ¢¥á⢮ ã«î ¨ ¥£® 㬥ì襨¥ ¥¤¨¨æ㠯ந§¢®¤¨âáï
|
||||
¢ ª®æ¥ £àã¯¯ë ®¯¥à â®à®¢ 横« . „®¯ã᪠¥âáï ¢ãâਠ横« ¨á¯®«ì§®¢ âì ¨ ¬¥ïâì
|
||||
§ 票¥ áç¥â稪 . …᫨ áç¥â稪 ¥ 㪠§ , ⮠横« ¡ã¤¥â ¡¥áª®¥çë¬. <20>ਬ¥à:
|
||||
#import "kernel32.dll"
|
||||
#import "user32.dll"
|
||||
dword Count;
|
||||
dword dWriteFileCount;
|
||||
dword handle;
|
||||
byte s[20]=0;
|
||||
main(){
|
||||
handle=GetStdHandle(-11);
|
||||
Count=4;
|
||||
cycle(Count){
|
||||
if(Count=2)
|
||||
Count--;
|
||||
wsprintfA(#s,"Count=%d\n",Count); ESP+=12;
|
||||
WriteFile(handle,#s,lstrlenA(#s),#dWriteFileCount,0);
|
||||
}
|
||||
}
|
||||
<20>ਠ¢ë¯®«¥¨¨ ¡ã¤¥â ¢ë¢¥¤¥®:
|
||||
Count=4
|
||||
Count=3
|
||||
Count=1
|
||||
|
||||
Ž¯¥à â®à while
|
||||
|
||||
Ž¯¥à â®à 横« while ¨¬¥¥â ¢¨¤:
|
||||
|
||||
while(<ãá«®¢¨¥>)
|
||||
<£à㯯 ®¯¥à â®à®¢>
|
||||
|
||||
ƒà㯯 ®¯¥à â®à®¢ ¢ 横«¥ while ¢ë¯®«ï¥âáï ¯®ª <ãá«®¢¨¥> ®áâ ¥âáï
|
||||
¨áâ¨ë¬. <20>ਬ¥à ¨§ ®¯¨á ¨ï ®¯¥à â®à cycle ¬®¦¥â ¡ëâì ॠ«¨§®¢ á ¯®¬®éìî
|
||||
while á«¥¤ãî騬 ®¡à §®¬:
|
||||
Count=4;
|
||||
while(Count){
|
||||
if(Count=2)
|
||||
Count--;
|
||||
wsprintfA(#s,"Count=%d\n",Count); ESP+=12;
|
||||
WriteFile(handle,#s,lstrlenA(#s),#dWriteFileCount,0);
|
||||
Count--;
|
||||
}
|
||||
}
|
||||
|
||||
Ž¯¥à â®à do ... while
|
||||
|
||||
Ž¯¥à â®à 横« do ... while ¨¬¥¥â ¢¨¤:
|
||||
|
||||
do
|
||||
<£à㯯 ®¯¥à â®à®¢>
|
||||
while(<ãá«®¢¨¥>)
|
||||
|
||||
ƒà㯯 ®¯¥à â®à®¢ ¢ 横«¥ do ... while ¢ë¯®«ï¥âáï ¯®ª <ãá«®¢¨¥> ®áâ ¥âáï
|
||||
¨áâ¨ë¬. <20>ਬ¥à ¨§ ®¯¨á ¨ï ®¯¥à â®à cycle ¬®¦¥â ¡ëâì ॠ«¨§®¢ á ¯®¬®éìî
|
||||
do ... while á«¥¤ãî騬 ®¡à §®¬:
|
||||
Count=4;
|
||||
do{
|
||||
if(Count=2)
|
||||
Count--;
|
||||
wsprintfA(#s,"Count=%d\n",Count); ESP+=12;
|
||||
WriteFile(handle,#s,lstrlenA(#s),#dWriteFileCount,0);
|
||||
Count--;
|
||||
} while(Count)
|
||||
}
|
||||
Žá®¡¥®áâìî ®¯¥à â®à do ... while ï¥âáï â®, çâ® <£à㯯 ®¯¥à â®à®¢>
|
||||
¢ 横«¥ ¢á¥£¤ ¢ë¯®«ï¥âáï ¥ ¬¥¥¥ ®¤®£® à § .
|
||||
|
||||
Ž¯¥à â®à docase
|
||||
|
||||
Ž¯¥à â®à ¢¥â¢«¥¨ï docase ¨¬¥¥â ¢¨¤:
|
||||
|
||||
docase
|
||||
<£à㯯 ®¯¥à â®à®¢ 0>
|
||||
case(<ãá«®¢¨¥1>)
|
||||
<£à㯯 ®¯¥à â®à®¢ 1>
|
||||
...
|
||||
case(<ãá«®¢¨¥N>)
|
||||
<£à㯯 ®¯¥à â®à®¢ N>
|
||||
default
|
||||
<£à㯯 ®¯¥à â®à®¢ N1>
|
||||
|
||||
Ž¯¥à â®à docase ¯®§¢®«ï¥â § ¬¥¨âì ¢«®¦¥ë¥ £àã¯¯ë ¨§ if ... else if ...
|
||||
else ... . Šà®¬¥ ⮣® ¤ «¥¥ ¡ã¤¥â ¯®ª § ¯à¨¬¥à¥ 㨢¥àá «ì®áâì í⮣®
|
||||
®¯¥à â®à . <20>ਬ¥à ¨§ ®¯¨á ¨ï ®¯¥à â®à cycle ¬®¦¥â ¡ëâì ॠ«¨§®¢ á ¯®¬®éìî
|
||||
docase á«¥¤ãî騬 ®¡à §®¬:
|
||||
Count=4;
|
||||
docase{
|
||||
if(Count=2)
|
||||
Count--;
|
||||
wsprintfA(#s,"Count=%d\n",Count); ESP+=12;
|
||||
WriteFile(handle,#s,lstrlenA(#s),#dWriteFileCount,0);
|
||||
Count--;
|
||||
case(Count=0)
|
||||
break;
|
||||
default
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Ž¯¥à â®àë continue ¨ break
|
||||
|
||||
<20>⨠®¯¥à â®àë ¨á¯®«ì§ãîâáï ¢ãâਠ¢ëè¥ ®¯¨á ëå ®¯¥à â®à®¢ 横« cycle,
|
||||
while, do...while ¨ ®¯¥à â®à¥ docase ¤«ï ¯¥à¥å®¤ ç «® 横« ¨«¨ docase
|
||||
¯® ®¯¥à â®àã continue ¨ ¢ë室 § ª®¥æ ®¯¥à â®à ¯® break. <20>ਬ¥à:
|
||||
while(cond1){<--Ô
|
||||
... |
|
||||
if(cond2) |
|
||||
continue; --+
|
||||
... |
|
||||
if(cond3) |
|
||||
break; ---+ |
|
||||
... | |
|
||||
} ----------|-+
|
||||
<----------+
|
||||
|
||||
Ž¯¥à â®à enum
|
||||
|
||||
<20> § 票¥ ®¯¥à â®à § ª«îç ¥âáï ¢ ᮧ¤ ¨¨ £à㯯 㬥஢ ëå ª®áâ â.
|
||||
<EFBFBD>ਬ¥à:
|
||||
enum { ab, ac=2, ad, ae=6}; ¯à¨ í⮬ ¡ã¤¥â: ab=0, ac=2, ad=3, ae=6.
|
||||
|
||||
Ž¯¥à â®à struc
|
||||
|
||||
‘«ã¦¨â ¤«ï ®¯¨á ¨ï áâàãªâãà¨à®¢ ëå ¤ ëå, «®£¨ç® ‘.
|
||||
<EFBFBD>®ª ¥ ॠ«¨§®¢ . Œ®¦®, ¨á¯®«ì§ãï enum, ¡¥§ ¢áïª¨å ¯à®¡«¥¬ à ¡®â âì á
|
||||
¤ 묨 «î¡®© áâàãªâãàë. <20>ਬ¥à:
|
||||
„«ï ¨á¯®«ì§®¢ ¨ï áâàãªâãàë:
|
||||
struct localrec{
|
||||
struct localrec *next;
|
||||
char localid[IDLENGTH];
|
||||
int localtok;
|
||||
int localnumber;
|
||||
};
|
||||
ᮧ¤ ¤¨¬:
|
||||
// ---- ‘âàãªâãà localrec - ®¯¨á ¨¥ «®ª «ì®© ¯¥à¥¬¥®©
|
||||
enum{ localnext=0, // “ª § ⥫ì á«¥¤ãîéãî localrec
|
||||
localid=4, // ˆ¬ï «®ª «ì®© ¯¥à¥¬¥®©
|
||||
localtok=localid+IDLENGTH, // ‡ 票¥ token
|
||||
localtype=localtok+4, // ⨯ ¯¥à¥¬¥®©
|
||||
localnumber=localtype+4, // <20>®§¨æ¨ï ¢ á⥪¥
|
||||
local_size=localnumber+4}; // <20> §¬¥à áâàãªâãàë
|
||||
ˆ ⥯¥àì ¢ ¯à®£à ¬¬¥ ¬®¦® ¨á¯®«ì§®¢ âì 㬥஢ ë¥ ª®áâ âë ¤«ï ®¡à 饨ï
|
||||
ª í«¥¬¥â ¬ áâàãªâãàë localrec:
|
||||
// ---- „®¡ ¢¨âì «®ª «ìãî ¯¥à¥¬¥ãî ¢ ᯨ᮪
|
||||
AddLocalvar(dword str,tk,ltype,num)
|
||||
dword ptr,newptr;
|
||||
{
|
||||
newptr=LocalAlloc(0x40, local_size);
|
||||
if(newptr==NULL){
|
||||
preerror("Compiler out of memory for local symbol linked list");
|
||||
ExitProcess(e_outofmemory);
|
||||
}
|
||||
if(locallist==NULL)
|
||||
locallist = newptr;
|
||||
else{
|
||||
ptr = locallist; EBX=ptr;
|
||||
docase{
|
||||
EAX=[EBX+localnext];
|
||||
case(EAX!=0){
|
||||
EBX=EAX; continue;
|
||||
}
|
||||
}
|
||||
[EBX+localnext]=newptr;
|
||||
}
|
||||
EBX=newptr; lstrcpyA(EBX+localid, str);
|
||||
EBX=newptr; [EBX+localtok] = tk; [EBX+localtype] = ltype;
|
||||
[EBX+localnumber] = num; [EBX+localnext] = NULL; localptr = EBX;
|
||||
}
|
||||
|
||||
Œ¥âª¨
|
||||
|
||||
’ॡ®¢ ¨ï ª ¨¬¥ ¬ ¬¥â®ª ⥠¦¥, çâ® ¨ ª ¨¤¥â¨ä¨ª â®à ¬. ˆáª«î票¥¬
|
||||
ïîâáï «®ª «ìë¥ ¬¥âª¨ - ®¨ ¤®«¦ë ç¨ âìáï á ᨬ¢®« '@'. ‹®ª «ìë¥
|
||||
¬¥âª¨ ¤®áâã¯ë ⮫쪮 ¢ ¯à¥¤¥« å ⮩ äãªæ¨¨, ¢ ª®â®à®© ®¨ ®¯à¥¤¥«¥ë,
|
||||
£«®¡ «ìë¥ - ¯® ¢á¥© ¯à®£à ¬¬¥. <20>ਠᮧ¤ ¨¨ ¨¬¥ «®ª «ìëå ¬¥â®ª á«¥¤ã¥â
|
||||
ãç¨âë¢ âì, çâ® ª®¬¯¨«ïâ®à ¯à¨ ॠ«¨§ 樨 áâàãªâãàëå ®¯¥à â®à®¢ £¥¥à¨àã¥â
|
||||
¬¥âª¨ ¢¨¤ : @l<ç¨á«®>. —â®¡ë ¨§¡¥¦ âì ª®««¨§¨©, á«¥¤ã¥â ¤«ï ᢮¨å ¬¥â®ª ¥
|
||||
¯à¨¬¥ïâì â ª®£® ¢¨¤ . ‹î¡ ï ¬¥âª § ¢¥àè ¥âáï ᨬ¢®«®¬ ¤¢®¥â®ç¨ï (:).
|
||||
<EFBFBD>ਬ¥àë ¬¥â®ª:
|
||||
NotUpperCase: // íâ® £«®¡ «ì ï ¬¥âª
|
||||
@NotUpperCase: // íâ® «®ª «ì ï ¬¥âª
|
||||
|
||||
ˆ¤¥ªá æ¨ï ¬ áᨢ®¢
|
||||
|
||||
<20>«¥¬¥âë ¬ áᨢ «î¡®£® ⨯ ¨¤¥ªá¨àãîâáï ¢ ¡ ©â®¢ëå ¥¤¨¨æ å, ¥§ ¢¨á¨¬®
|
||||
®â ⨯ ¤ ëå. <20>â® ‚‘…ƒ„€ á«¥¤ã¥â ¯®¬¨âì ¯à¨ à ¡®â¥. ˆ¤¥ªáë ¨¬¥îâ ¢¨¤,
|
||||
¯à¨ïâë© ¢ áᥬ¡«¥à¥ ¤«ï 386 CPU:
|
||||
|
||||
<¯¥à¥¬¥ ï>[<¡ §®¢ë© ॣ¨áâà>+<¬ áèâ ¡>*<¨¤¥ªáë© à¥£¨áâà>+<¨¤¥ªá>]
|
||||
|
||||
‚®â ¥áª®«ìª® ¯à¨¬¥à®¢:
|
||||
Str[7]; // ᥤ쬮© ¡ ©â ¨§ ¬ áᨢ Str
|
||||
IntArray[4*ebx]; // ebx í«¥¬¥â ¨§ ¬ áᨢ 楫ëå - IntArray
|
||||
ByteArray[esi+8*ecx+300];
|
||||
|
||||
‘¯¥æ¨ «ìë¥ ãá«®¢ë¥ ¢ëà ¦¥¨ï
|
||||
|
||||
ˆ¬¥¥âáï è¥áâì á¯¥æ¨ «ìëå ãá«®¢ëå ¢ëà ¦¥¨©:
|
||||
CarryFlag, NotCarryFlag, Overflow, NotOverflow, ZeroFlag, NotZeroFlag. Ž¨
|
||||
á«ã¦ â ¤«ï £¥¥à 樨 ª®¤ ¯à®¢¥àïî饣® á®áâ®ï¨¥ ä« £®¢ CPU.
|
||||
|
||||
Š®¬¬¥â ਨ
|
||||
|
||||
Š®¬¬¥â ਨ § ¤ îâáï «®£¨ç® ‘.
|
||||
|
||||
„¨à¥ªâ¨¢ë ª®¬¯¨«ïâ®à
|
||||
|
||||
‚ᥠ¤¨à¥ªâ¨¢ë ª®¬¯¨«ïâ®à ç¨ îâáï á ᨬ¢®« '#'. ‘¯¨á®ª ¤¨à¥ªâ¨¢ ¨ ¨å
|
||||
§ 票¥ ¯à¨¢®¤ïâáï ¨¦¥:
|
||||
#debug // 㪠§ë¢ ¥â ª®¬¯¨«ïâ®àã ¥®¡å®¤¨¬®áâì £¥¥à 樨
|
||||
// ®â« ¤®ç®© ¨ä®à¬ 樨 ¤«ï ª®¬¯¨«¨à㥬®© ¯à®£à ¬¬ë
|
||||
#define // ®¯à¥¤¥«¨âì ª®áâ âã ¨«¨ ¨¤¥â¨ä¨ª â®à. <20>ਬ¥à:
|
||||
// #define MAXLINES 400
|
||||
// #define less <
|
||||
// #define SetTrue "eax=1"
|
||||
// if(lines less MAXLINES) --> if(lines<400)
|
||||
// SetTrue; --> eax=1;
|
||||
#dll // 㪠§ë¢ ¥â ª®¬¯¨«ïâ®àã £¥¥à æ¨î DLL-ä ©« . Ž¡ëç® - exe.
|
||||
#include // ¯®¤ª«î票¥ ä ©« á ¨áå®¤ë¬ â¥ªá⮬. € «®£¨ç® ‘.
|
||||
#import // ¨¬¯®àâ äãªæ¨© ¨§ DLL-ä ©« ¯® ¨¬¥¨.
|
||||
#importN // ¨¬¯®àâ äãªæ¨© ¨§ DLL-ä ©« ¯® ®¬¥àã. <20>ਬ¥à ᬮâà¨â¥ ¢
|
||||
// ®¯¨á ¨¨ áâàãªâãàëå ®¯¥à â®à®¢ cycle, while ¨ â.¤.
|
||||
#list // 㪠§ë¢ ¥â ª®¬¯¨«ïâ®àã £¥¥à æ¨î ä ©« á «¨á⨣®¬ (.lst)
|
||||
#map // 㪠§ë¢ ¥â ª®¬¯¨«ïâ®àã £¥¥à æ¨î map-ä ©« (.map)
|
||||
|
||||
‚áâà®¥ë© áᥬ¡«¥à
|
||||
|
||||
€áᥬ¡«¥à ¯®¤¤¥à¦¨¢ ¥â ¡®«ìèãî ç áâì ¨áâàãªæ¨© ¨§ ¡®à 386, 486 ¨ 586
|
||||
¯à®æ¥áá®à®¢. Œ¥¬®¨ª¨ áᥬ¡«¥à ¬®£ãâ ¡ëâì ¯®¬¥é¥ë ¢ãâਠ⥫ «î¡®© äãªæ¨¨
|
||||
¡¥§ ª ª¨å-«¨¡® ®£à ¨ç¥¨©. <20>ਬ¥à:
|
||||
// ‚뤥«¥¨¥ á«®¢ ¢ Dest ¨§ áâப¨ ᨬ¢®«®¢ Source
|
||||
dword GetWord(dword Source,Dest){
|
||||
push esi; push edi; esi=Source; edi=Dest;
|
||||
// ˆé¥¬ ¯¥à¢ë© ¥¯ãá⮩ ᨬ¢®«
|
||||
@up: lodsb; cmp al,' '; jz @up; // <20>஡¥«
|
||||
cmp al,0; jz @down // Š®¥æ áâப¨ Source
|
||||
// Š®¯¨à㥬 á«®¢® ¢ Dest
|
||||
@up1: stosb; cmp al,0; jz @down; // Š®¥æ áâப¨ Source
|
||||
lodsb; cmp al,' '; jnz @up1; // <20>¥ ¯à®¡¥«
|
||||
al=0; jmp @up1 // Žâ¬¥â¨¬ ª®¥æ á«®¢
|
||||
@down:
|
||||
// ‘«®¢® ¢ë¤¥«¥® ¨ ᪮¯¨à®¢ ® ¢ Dest
|
||||
eax=esi-Source; eax--; // ‚ëç¨á«¨¬ ¤«¨ã á«®¢
|
||||
pop edi; pop esi // ‚®ááâ ®¢¨¬ esi ¨ edi
|
||||
}
|
||||
|
||||
‡ ª«î票¥
|
||||
|
||||
<20>¥ ¢á¥ ¨§ ¢ë襮¯¨á ®£® ॠ«¨§®¢ ®. <20>â® ®¡ãá«®¢«¥® ¢ ¯¥à¢ãî ®ç¥à¥¤ì ⥬,
|
||||
çâ® ¤ ï ¢¥àá¨ï ï¥âáï ¯à¥¤¢ à¨â¥«ì®© ¨ ®á®¢®© ¥¥ 楫ìî ï¥âáï
|
||||
¢ë¥¨¥ ¨â¥à¥á ª®¬¯ìîâ¥à®© ®¡é¥á⢥®á⨠ª â ª®¬ã ª®¬¯¨«ïâ®àã.
|
||||
…᫨ ‚ë § ¨â¥à¥á®¢ «¨áì í⨬ ¯à®¤ãªâ®¬ ¨«¨ ã ‚ á ¢®§¨ª«¨ ª ª¨¥-«¨¡®
|
||||
¢®¯à®áë, ¨¤¥¨ ¨«¨ ¯à¥¤«®¦¥¨ï, â® ¯à®èã ® ¨å á®®¡é¨âì ¬¥ ¯® ¤à¥áã:
|
||||
halimovskiy@usa.net.
|
||||
|
||||
‘ 㢠¦¥¨¥¬ €.• «¨¬®¢áª¨© E-mail: halimovskiy@usa.net
|
666
programs/develop/c--/trunk/tokscan.h--
Normal file
666
programs/develop/c--/trunk/tokscan.h--
Normal file
@ -0,0 +1,666 @@
|
||||
// ---- <20>८¡à §®¢ ¨¥ ⥪ã饣® ᨬ¢®« ¤«ï ª®áâãªæ¨© ⨯ : \n, \x00, â.¯.
|
||||
byte ConvertChar()
|
||||
dword hold;
|
||||
{
|
||||
IF(cha!='\\')return(cha);
|
||||
NextChar(); // Ž¡à ¡®âª á«¥¤ãî饣® § \
|
||||
IF(AL>='0')&&(AL<='9'){
|
||||
// „¥áïâ¨ç ï ª®áâ â
|
||||
EDX=0;
|
||||
AL-='0';
|
||||
EAX=AL;
|
||||
EDX+=EAX;
|
||||
ECX=2;
|
||||
loop(ECX){
|
||||
EBX=EDX;
|
||||
EDX<<=1;
|
||||
EBX<<=3;
|
||||
EDX+=EBX;
|
||||
NextChar();
|
||||
EAX=AL;
|
||||
IF(AL<'0')||(AL>'9')GOTO ERR;
|
||||
AL-='0';
|
||||
EDX+=EAX;
|
||||
}
|
||||
return(DL);
|
||||
ERR:
|
||||
expectederror("decimal digit");
|
||||
return(0);
|
||||
}
|
||||
IF(cha=='a')return('\a');
|
||||
IF(cha=='b') return('\b');
|
||||
IF(cha=='f') return('\f');
|
||||
IF(cha=='l') return(10);
|
||||
IF(cha=='n') return(13);
|
||||
IF(cha=='p') return('_');
|
||||
IF(cha=='r') return(13);
|
||||
IF(cha=='t') return('\t');
|
||||
IF(cha=='v') return('\v');
|
||||
IF(cha=='x'){ // HEX ª®áâ â
|
||||
ECX=2;
|
||||
hold=0;
|
||||
loop(ECX){
|
||||
$PUSH ECX;
|
||||
NextChar();
|
||||
CharUpperA(AL);
|
||||
EBX=AL;
|
||||
IF(AL>='0')&&(AL<='9')GOTO LX1;
|
||||
IF(AL<'A')&&(AL>'F')GOTO ERR1;
|
||||
LX1:
|
||||
EDX=hold;
|
||||
EDX<<=4;
|
||||
IF(BL>='A')BL-='A'-10-'0';
|
||||
BL-='0';
|
||||
EDX+=EBX;
|
||||
hold=EDX;
|
||||
$POP ECX;
|
||||
}
|
||||
return(hold);
|
||||
ERR1:
|
||||
$POP ECX;
|
||||
expectederror("hexdecimal digit");
|
||||
return(0);
|
||||
}
|
||||
return(cha);
|
||||
}
|
||||
|
||||
// ---- <20> §¤¥«¨â¥«¨
|
||||
byte Delim1={'#','\"','\'','-','+','*','/','%','|','&','!','^','=','>','<','@',0};
|
||||
byte Delim2={':',';','(',')','{','}','[',']',',','.','$','?','~',0};
|
||||
// ---- Ž¯à¥¤¥«¥¨¥ ⨯ token
|
||||
TokScan(dword tok4,type4,src4,post4,string4,number4)
|
||||
dword useme,strptr;
|
||||
dword next;
|
||||
dword dirPrefix,locPrefix;// ”« £¨ ®¡ à㦥¨ï #directive ¨«¨ @LocalLabel
|
||||
{
|
||||
dirPrefix=0;
|
||||
locPrefix=0;
|
||||
SC_0:
|
||||
strptr=string4;
|
||||
next=1;
|
||||
EAX=number4;
|
||||
DSDWORD[EAX] = 0;
|
||||
EAX=type4;
|
||||
DSDWORD[EAX] = 0;
|
||||
EAX=src4;
|
||||
DSDWORD[EAX] = 0;
|
||||
EAX=post4;
|
||||
DSDWORD[EAX] = 0;
|
||||
WhiteSpaces();
|
||||
ESI=string4;
|
||||
DSBYTE[ESI]=0;
|
||||
ECX=17;
|
||||
EDI=#Delim1;
|
||||
AL=cha;
|
||||
$REPNZ $SCASB;
|
||||
$JCXZ SC00 // <20>¥ ¯¥à¢ ï £à㯯 à §¤¥«¨â¥«¥
|
||||
EDI=EDI-#Delim1-1<<2+#Jmp_Delim1;
|
||||
$JMP NEAR DSDWORD[EDI];
|
||||
SC00:
|
||||
ECX=14;
|
||||
EDI=#Delim2;
|
||||
AL=cha;
|
||||
$REPNZ $SCASB;
|
||||
$JCXZ SC01 // <20>¥ ¢â®à ï £à㯯 à §¤¥«¨â¥«¥
|
||||
EDI=EDI-#Delim2-1+#tk_delim2;
|
||||
EAX=DSBYTE[EDI];
|
||||
EBX=tok4;
|
||||
DSDWORD[EBX]=EAX;
|
||||
$JMP ScEx
|
||||
SC01:
|
||||
IF(locPrefix){
|
||||
EDI><strptr;
|
||||
AL='@';
|
||||
$STOSB;
|
||||
strptr><EDI;
|
||||
}
|
||||
IF(cha==0){ // Š®¥æ ¢å®¤®£® ¡ãä¥à
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_eof;
|
||||
next=0;
|
||||
}
|
||||
else if(IsCharAlphaA(cha))||(cha=='_'){ // ˆ¤¥â¨ä¨ª â®à ç¨ ¥âáï á ¡ãª¢ë
|
||||
do{
|
||||
do{ // Š®¯¨à㥬 ¨¤¥â¨ä¨ª â®à ¢ string4
|
||||
UP:
|
||||
EDI><strptr;
|
||||
AL=cha;
|
||||
$STOSB;
|
||||
strptr><EDI;
|
||||
NextChar();
|
||||
}while(IsCharAlphaNumericA(cha));
|
||||
}while(cha=='_');
|
||||
EAX=strptr-string4;
|
||||
IF(EAX>=IDLENGTH){
|
||||
preerror("Maximum length for an identifier exceeded");
|
||||
strptr = string4 + IDLENGTH - 1;
|
||||
}
|
||||
EDI=strptr;
|
||||
AL=0;
|
||||
$STOSB
|
||||
EBX=tok4;
|
||||
DSDWORD[EBX]=tk_id;
|
||||
IF(locPrefix)goto FL;
|
||||
FastSearch(string4,#St_Directives); // <20>â® § १¥à¢¨à®¢ ®¥ á«®¢®?
|
||||
IF(CARRYFLAG){ // Š®¬ ¤ ®¡ à㦥 ¢ ᯨ᪥
|
||||
EBX=number4; DSDWORD[EBX]=EAX; // ‡ ¯®¬¨¬ ¯®à浪®¢ë© ®¬¥à
|
||||
EBX=tok4; // “ª ¦¥¬ ᮮ⢥âáâ¢ãî騩 token
|
||||
IF(dirPrefix)DSDWORD[EBX]=tk_directive;
|
||||
ELSE DSDWORD[EBX]=tk_command;
|
||||
dirPrefix=0;
|
||||
next=0;
|
||||
$JMP ScEx
|
||||
}
|
||||
FastSearch(string4,#St_Mnemonics); // <20>â® ¬¥¬®¨ª ?
|
||||
IF(CARRYFLAG){ // Œ¥¬®¨ª áᥬ¡«¥à
|
||||
EBX=number4;
|
||||
DSDWORD[EBX]=EAX; // ‡ ¯®¬¨¬ ®¬¥à ¬¥¬®¨ª¨
|
||||
EBX=tok4;
|
||||
DSDWORD[EBX]=tk_mnemonics;
|
||||
next=0;
|
||||
$JMP ScEx
|
||||
}
|
||||
FastSearch(string4,#St_Registers); // <20>â® ¨¬ï ॣ¨áâà ?
|
||||
IF(CARRYFLAG){ // <20>¥£¨áâà
|
||||
EBX=number4;
|
||||
DSDWORD[EBX]=EAX; // ‡ ¯®¬¨¬ ®¬¥à ॣ¨áâ
|
||||
EAX>>=3;
|
||||
$CMP EAX,2;
|
||||
$JG R0 // “¯à ¢«ïî騥 ॣ¨áâàë?
|
||||
EBX=tok4;
|
||||
DSDWORD[EBX]=tk_reg;
|
||||
EBX=type4;
|
||||
EAX<<=1;
|
||||
DSDWORD[EBX] = EAX + tk_byte;
|
||||
GOTO R1;
|
||||
R0:
|
||||
EBX=tok4;
|
||||
EAX-=3;
|
||||
DSDWORD[EBX]=EAX+tk_controlreg;
|
||||
R1:
|
||||
next=0;
|
||||
$JMP ScEx
|
||||
}
|
||||
FL:
|
||||
EAX=tok4;
|
||||
EAX=DSDWORD[EAX];
|
||||
IF(AL==tk_id){
|
||||
SearchLocals(tok4,type4,string4,number4); // …áâì ¢ ᯨ᪥ «®ª «ìëå?
|
||||
EAX=tok4;
|
||||
EAX=DSDWORD[EAX];
|
||||
IF(AL==tk_id){
|
||||
IF(locPrefix){ // @label
|
||||
EBX=tok4;
|
||||
DSDWORD[EBX]=tk_locallabel;
|
||||
IF(displaytokerrors)AddLocalvar(#string,tk_locallabel,0,0);
|
||||
locPrefix=0;
|
||||
GOTO FL;
|
||||
}
|
||||
SearchTree(tok4,type4,src4,post4,string4,number4);
|
||||
}
|
||||
}
|
||||
IF(dirPrefix){ // Š®áâàãªæ¨ï: #ident
|
||||
dirPrefix=0;
|
||||
EBX=tok4;
|
||||
EAX=DSDWORD[EBX];
|
||||
IF(AL==tk_id){ // …áâì ¢ ᯨ᪥?
|
||||
IF(displaytokerrors){
|
||||
EAX=post4;
|
||||
DSDWORD[EAX] = 1; // „®¡ ¢¨¬ ¢ ᯨ᮪
|
||||
EBX=tok4;
|
||||
DSDWORD[EBX]=tk_undefproc;
|
||||
AddToTree(string4);
|
||||
}
|
||||
}
|
||||
// ˆ¤¥â¨ä¨ª â®à ¥áâì ¢ ᯨ᪥
|
||||
EAX=post4;
|
||||
EAX=DSDWORD[EAX];
|
||||
EBX=tok4;
|
||||
IF(EAX){ // …é¥ ¥ ®¡à ¡®â ë© ¨¤¥â¨ä¨ª â®à?
|
||||
DSDWORD[EBX] = tk_postnumber;
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
EAX=DSDWORD[EAX];
|
||||
IF(EAX==tk_param)DSDWORD[EBX] = tk_locnumber;
|
||||
ELSE IF(EAX==tk_local)DSDWORD[EBX] = tk_locnumber;
|
||||
ELSE DSDWORD[EBX] = tk_number;
|
||||
}
|
||||
}
|
||||
next=0;
|
||||
$JMP ScEx
|
||||
}
|
||||
else if(IsNumber(cha)){ // ˆ¤¥â¨ä¨ª â®à ç¨ ¥âáï á æ¨äàë
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tokens; // <20>®ª ¥¨§¢¥áâë© token
|
||||
if(cha=='0'){
|
||||
NextChar();
|
||||
IF(cha=='X')||(cha=='x'){ // hex - ç¨á«®
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_number;
|
||||
HEX:
|
||||
NextChar();
|
||||
CharUpperA(AL);
|
||||
$CMP AL,'0';
|
||||
$JL EHEX;
|
||||
$CMP AL,'9';
|
||||
$JA HEXAF
|
||||
AL-='0';
|
||||
for(;;){
|
||||
EBX=number4;
|
||||
ECX=DSDWORD[EBX];
|
||||
ECX<<=4;
|
||||
EAX+=ECX;
|
||||
DSDWORD[EBX]=EAX;
|
||||
GOTO HEX;
|
||||
HEXAF:
|
||||
IF(AL<'A')||(AL>'F')BREAK;
|
||||
AL-='7';
|
||||
}
|
||||
EHEX:
|
||||
}
|
||||
ELSE IF(cha=='B')||(cha=='b'){ // binary ç¨á«®
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_number;
|
||||
for(;;){
|
||||
NextChar();
|
||||
IF(AL!='0')||(AL!='1')BREAK;
|
||||
AL-='0';
|
||||
EBX=number4;
|
||||
ECX=DSDWORD[EBX];
|
||||
ECX<<=1;
|
||||
EAX+=ECX;
|
||||
DSDWORD[EBX]=EAX;
|
||||
}
|
||||
EBIN:
|
||||
}
|
||||
ELSE IF(cha=='O')||(cha=='o'){ // octal ç¨á«®
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_number;
|
||||
for(;;){
|
||||
NextChar();
|
||||
IF(AL<'0')||(AL>'7')BREAK;
|
||||
AL-='0';
|
||||
EBX=number4;
|
||||
ECX=DSDWORD[EBX];
|
||||
ECX<<=3;
|
||||
EAX+=ECX;
|
||||
DSDWORD[EBX]=EAX;
|
||||
}
|
||||
EOCT:
|
||||
}
|
||||
}
|
||||
EAX=tok4;
|
||||
EAX=DSDWORD[EAX];
|
||||
IF(EAX!=tk_number){ // decimal ç¨á«®
|
||||
for(;;){
|
||||
EAX=cha;
|
||||
IF(AL<'0')||(AL>'9')BREAK;
|
||||
AL-='0';
|
||||
EBX=number4;
|
||||
EDX=DSDWORD[EBX];
|
||||
ECX=EDX;
|
||||
EDX<<=1;
|
||||
ECX<<=3;
|
||||
EDX+=ECX;
|
||||
EAX+=EDX;
|
||||
DSDWORD[EBX]=EAX;
|
||||
NextChar();
|
||||
}
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_number;
|
||||
}
|
||||
next=0;
|
||||
}
|
||||
ELSE{
|
||||
IF(displaytokerrors)preerror("tokenizer: bad character value");
|
||||
NextChar();
|
||||
TokScan(tok4,type4,src4,post4,string4,number4);
|
||||
next=0;
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Number: // #directive || #identifier
|
||||
NextChar();
|
||||
dirPrefix=1;
|
||||
$JMP SC_0
|
||||
Jmp_Local: // @LocalLabel
|
||||
NextChar();
|
||||
locPrefix=1;
|
||||
$JMP SC01
|
||||
Jmp_String: // ‘âப ᨬ¢®«®¢ ¢ ""
|
||||
do{
|
||||
NextChar();
|
||||
IF(cha=='\"') // ‡ ªàë¢ îé ï ª ¢ëçª
|
||||
BREAK;
|
||||
EAX=strptr-string4;
|
||||
IF(EAX<STRLEN-1 ){
|
||||
AL=ConvertChar();
|
||||
EDI=strptr;
|
||||
$STOSB;
|
||||
IF(AL==13)&&(cha=='n'){
|
||||
AL=10;
|
||||
$STOSB
|
||||
} // „®¡ ¢¨¬ char 10 ¤«ï \n
|
||||
strptr=EDI;
|
||||
}
|
||||
ELSE{
|
||||
IF(displaytokerrors)preerror("Maximum String Length Exceeded");
|
||||
WHILE(cha!='\"'){ // <20>®¨áª § ªàë¢ î饩 ª ¢ë窨
|
||||
IF(endoffile)BREAK;
|
||||
NextChar();
|
||||
}
|
||||
BREAK;
|
||||
}
|
||||
}while(cha==0);
|
||||
EDI=strptr;
|
||||
DSBYTE[EDI]=0;
|
||||
EDI-=string4;
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_string;
|
||||
EAX=number4;
|
||||
DSDWORD[EAX] = EDI; // ‡ ¯®¬¨¬ ¤«¨ã áâப
|
||||
IF(cha!='\"')expected('\"');
|
||||
$JMP ScEx
|
||||
Jmp_Const: // ‘¨¬¢®«ì ï ª®áâ â : 'AbCD'
|
||||
NextChar();
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_number;
|
||||
EAX=number4;
|
||||
DSDWORD[EAX] = 0;
|
||||
WHILE(cha != '\''){
|
||||
IF(endoffile)BREAK;
|
||||
EAX=ConvertChar();
|
||||
EBX=number4;
|
||||
ECX=DSDWORD[EBX];
|
||||
ECX<<=8;
|
||||
EAX+=ECX;
|
||||
DSDWORD[EBX]=EAX;
|
||||
NextChar();
|
||||
}
|
||||
IF(cha != '\''){
|
||||
IF(displaytokerrors)
|
||||
expected(0x27/*'\''*/);
|
||||
}
|
||||
ELSE NextChar();
|
||||
next = 0;
|
||||
$JMP ScEx
|
||||
Jmp_Minus: // -
|
||||
NextChar();
|
||||
EBX=tok4;
|
||||
IF(cha=='=') DSDWORD[EBX]=tk_minusequals; // -=
|
||||
ELSE IF(cha=='-') DSDWORD[EBX]=tk_minusminus; // --
|
||||
ELSE{
|
||||
DSDWORD[EBX]=tk_minus;
|
||||
next = 0;
|
||||
} // -
|
||||
$JMP ScEx
|
||||
Jmp_Plus: // +
|
||||
NextChar();
|
||||
EBX=tok4;
|
||||
IF(cha=='=')DSDWORD[EBX]=tk_plusequals; // +=
|
||||
ELSE IF(cha=='+') DSDWORD[EBX]=tk_plusplus; // ++
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
EBX=tok4; // ¢®§¬®¦® «¨ç¨¥ ¯à®¡¥«®¢
|
||||
IF(cha=='-')DSDWORD[EBX]=tk_minus; // ®¯â¨¬¨§ æ¨ï + -
|
||||
ELSE{
|
||||
DSDWORD[EBX]=tk_plus;
|
||||
next = 0;
|
||||
}
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Mul: // *
|
||||
NextChar();
|
||||
WhiteSpaces();
|
||||
EBX=tok4;
|
||||
IF(cha == '-')DSDWORD[EBX] = tk_multminus; // *-
|
||||
ELSE{
|
||||
DSDWORD[EBX] = tk_mult;
|
||||
next=0; // *
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Div: // /
|
||||
NextChar();
|
||||
if(cha=='*'){ // Š®¬¬¥â ਩
|
||||
NextChar();
|
||||
useme = 1; // ‚ useme - áç¥â稪 ¢«®¦¥ëå ª®¬¬¥â ਥ¢
|
||||
WHILE(useme>0){
|
||||
WhiteSpaces();
|
||||
IF( cha == '*' ){
|
||||
NextChar();
|
||||
IF(cha == '/' ){ // ‡ ªàë⨥ ª®¬¬¥â à¨ï
|
||||
IF(useme > 0)useme--; // “¬¥¨è¨¬ áç¥â稪
|
||||
NextChar();
|
||||
}
|
||||
}
|
||||
ELSE{
|
||||
IF( cha == '/' ){
|
||||
NextChar();
|
||||
IF( cha == '*' ){ // ‚«®¦¥ë© ª®¬¬¥â ਩
|
||||
useme++;
|
||||
NextChar();
|
||||
}
|
||||
}
|
||||
ELSE // <20>¥ ®£à ¨ç¨â¥«¨ ª®¬¬¥â à¨ï
|
||||
NextChar();
|
||||
}
|
||||
}
|
||||
IF(endoffile){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_eof;
|
||||
IF(useme > 0)&&(displaytokerrors)unexpectedeof();
|
||||
}
|
||||
ELSE TokScan(tok4,type4,src4,post4,string4,number4);
|
||||
}
|
||||
ELSE IF(cha=='/'){ // Š®¬¬¥â ਩ ¤® ª®æ áâப¨ //
|
||||
do{
|
||||
NextChar();
|
||||
IF(endoffile)BREAK;
|
||||
} while(cha!=10 );
|
||||
IF(endoffile){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_eof;
|
||||
}
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
TokScan(tok4,type4,src4,post4,string4,number4);
|
||||
}
|
||||
}
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
IF(cha=='-'){
|
||||
EAX=tok4; DSDWORD[EAX]=tk_divminus; // /-
|
||||
NextChar();
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_div; // /
|
||||
}
|
||||
}
|
||||
next = 0;
|
||||
$JMP ScEx
|
||||
Jmp_Mod: // %
|
||||
NextChar();
|
||||
WhiteSpaces();
|
||||
IF(cha == '-'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX] = tk_modminus; // %-
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_mod; next=0;
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Or: // |
|
||||
NextChar();
|
||||
IF(cha=='='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_orequals; // |=
|
||||
}
|
||||
ELSE IF(cha=='|'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_oror; // ||
|
||||
}
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
IF(cha=='-'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_orminus; // |-
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_or;
|
||||
next=0; // |
|
||||
}
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_And: // &
|
||||
NextChar();
|
||||
IF(cha=='='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_andequals; // &=
|
||||
}
|
||||
ELSE IF(cha=='&'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_andand; // &&
|
||||
}
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
IF(cha == '-'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_andminus; // &-
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_and;
|
||||
next=0;// &
|
||||
}
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Not: // !
|
||||
NextChar();
|
||||
IF(cha == '='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_notequal; // !=
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_not;
|
||||
next=0; // !
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Xor: // ^
|
||||
NextChar();
|
||||
IF(cha == '='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_xorequals; // ^=
|
||||
}
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
IF(cha == '-'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_xorminus; // ^-
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_xor;
|
||||
next=0; // ^
|
||||
}
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Equal: // =
|
||||
NextChar();
|
||||
IF(cha == '='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_equalto; // ==
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_assign;
|
||||
next=0; // =
|
||||
}
|
||||
$JMP ScEx
|
||||
Jmp_Great: // >
|
||||
NextChar();
|
||||
IF(cha=='>'){
|
||||
NextChar();
|
||||
IF( cha == '=' ){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_rrequals; // >>=
|
||||
}
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
IF(cha == '-'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_rrminus; // >>-
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_rr;
|
||||
next=0;// >>
|
||||
}
|
||||
}
|
||||
}
|
||||
ELSE IF(cha=='<'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_swap; // ><
|
||||
}
|
||||
ELSE IF(cha=='='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_greaterequal; // >=
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_greater;
|
||||
next= 0; // >
|
||||
}
|
||||
GOTO ScEx;
|
||||
Jmp_Less: // <
|
||||
NextChar();
|
||||
IF(cha=='<'){
|
||||
NextChar();
|
||||
IF(cha=='='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_llequals; // <<=
|
||||
}
|
||||
ELSE{
|
||||
WhiteSpaces();
|
||||
IF(cha == '-'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_llminus; // <<-
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_ll;
|
||||
next=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
ELSE IF(cha=='>'){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_notequal; // <>
|
||||
}
|
||||
ELSE IF(cha=='='){
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_lessequal; // <=
|
||||
}
|
||||
ELSE{
|
||||
EAX=tok4;
|
||||
DSDWORD[EAX]=tk_less;
|
||||
next=0; // <
|
||||
}
|
||||
ScEx:
|
||||
IF(next)NextChar();
|
||||
}
|
||||
|
||||
// '#','\"','\'','-','+','*','/','%','|','&','!','^','=','>','<','@'
|
||||
dword Jmp_Delim1={#Jmp_Number,#Jmp_String,#Jmp_Const,#Jmp_Minus,
|
||||
#Jmp_Plus,#Jmp_Mul,#Jmp_Div,#Jmp_Mod,#Jmp_Or,#Jmp_And,
|
||||
#Jmp_Not,#Jmp_Xor,#Jmp_Equal,#Jmp_Great,#Jmp_Less,#Jmp_Local};
|
||||
|
||||
// ':', ';', '(', ')',
|
||||
byte tk_delim2={tk_colon,tk_semicolon,tk_openbracket,tk_closebracket,
|
||||
// '{', '}', '[', ']', ',',
|
||||
tk_openbrace,tk_closebrace,tk_openblock,tk_closeblock,tk_comma,
|
||||
//'.', '$', '?', '~'
|
||||
tk_period,tk_dollar,tk_question,tk_tilda};
|
461
programs/develop/c--/trunk/tree.h--
Normal file
461
programs/develop/c--/trunk/tree.h--
Normal file
@ -0,0 +1,461 @@
|
||||
// ---- ‡ ¥á¥¨¥ ¯®¨¬¥®¢ ®© ª®áâ âë ¢ ᯨ᮪
|
||||
AddConstToTree(dword keystring,constvalue)
|
||||
dword ptr,newptr; // idrec structure
|
||||
{
|
||||
newptr=LocalAlloc(0x40,recsize);
|
||||
IF(EAX==NULL){
|
||||
preerror("Compiler out of memory for identifier tree");
|
||||
ExitProcess(e_outofmemory);
|
||||
}
|
||||
ptr=treestart;
|
||||
IF(EAX == NULL ) // <20>ãá⮩ ᯨ᮪?
|
||||
treestart = newptr;
|
||||
ELSE{
|
||||
for(;;){
|
||||
// <20>®¨áª ᢮¡®¤®© áá뫪¨
|
||||
ESI=ptr;
|
||||
EAX=lstrcmpA(DSDWORD[ESI+recid],keystring);
|
||||
ESI=ptr;
|
||||
IF(long EAX<0){
|
||||
// ptr.left
|
||||
IF(DSDWORD[ESI+left]==0){ // <20> 諨 ¯ãá⮩ «¥¢ë© - ¤®¡ ¢¨¬
|
||||
DSDWORD[ESI+left]=newptr;
|
||||
BREAK; // ptr.left=newptr
|
||||
}
|
||||
ptr=DSDWORD[ESI+left];
|
||||
}
|
||||
ELSE IF(EAX!=0){
|
||||
// ptr.right
|
||||
IF(DSDWORD[ESI+right]==0){ // <20> 諨 ¯ãá⮩ ¯à ¢ë© - ¤®¡ ¢¨¬
|
||||
DSDWORD[ESI+right]=newptr;
|
||||
BREAK;
|
||||
}
|
||||
ptr=DSDWORD[ESI+right];
|
||||
}
|
||||
ELSE internalerror("string found in tree when trying to add to it");
|
||||
}
|
||||
}
|
||||
// ”®à¬¨à㥬 ®¢ãî § ¯¨áì ¢ ᯨ᪥
|
||||
ESI=newptr;
|
||||
DSDWORD[ESI+recid]=LocalAlloc(0x40,lstrlenA(keystring)+1);
|
||||
lstrcpyA(DSDWORD[ESI+recid],keystring);
|
||||
ESI=newptr;
|
||||
DSDWORD[ESI+newid]= NULL;
|
||||
DSDWORD[ESI+rectok]=tk_number;
|
||||
DSDWORD[ESI+recnumber]=constvalue;
|
||||
DSDWORD[ESI+recpost]=0;
|
||||
DSDWORD[ESI+left]=NULL;
|
||||
DSDWORD[ESI+right]=NULL;
|
||||
DSDWORD[ESI+recmodline] = currmod<<16+linenumber;
|
||||
}
|
||||
|
||||
// ---- „®¡ ¢¨âì «®ª «ìãî ¯¥à¥¬¥ãî ¢ ᯨ᮪
|
||||
AddLocalvar(dword str,tk,ltype,num)
|
||||
dword newptr;
|
||||
{
|
||||
newptr=LocalAlloc(0x40,local_size);
|
||||
IF(EAX==NULL){
|
||||
preerror("Compiler out of memory for local symbol linked list");
|
||||
ExitProcess(e_outofmemory);
|
||||
}
|
||||
IF(locallist==NULL)locallist = newptr;
|
||||
ELSE{
|
||||
EAX=locallist;
|
||||
EBX><EAX; //ptr;
|
||||
for(;;){
|
||||
EAX=DSDWORD[EBX+localnext];
|
||||
IF(EAX==0)BREAK;
|
||||
EBX><EAX;
|
||||
}
|
||||
DSDWORD[EBX+localnext]=newptr;
|
||||
}
|
||||
EBX=newptr;
|
||||
lstrcpyA(EBX+localid,str);
|
||||
EBX=newptr;
|
||||
DSDWORD[EBX+localtok] = tk;
|
||||
DSDWORD[EBX+localtype] = ltype;
|
||||
DSDWORD[EBX+localnumber] = num;
|
||||
DSDWORD[EBX+localnext] = NULL;
|
||||
localptr=EBX;
|
||||
}
|
||||
|
||||
// ---- „®¡ ¢¨âì ¨¤¥â¨ä¨ª â®à ¢ ᯨ᮪
|
||||
AddToTree(dword keystring)
|
||||
dword ptr,newptr;
|
||||
{
|
||||
newptr=LocalAlloc(0x40,recsize);
|
||||
IF(EAX==NULL)outofmemory();
|
||||
ptr = treestart;
|
||||
//WRITESTR(keystring);WRITESTR("\n");
|
||||
IF(EAX==NULL)treestart = newptr;
|
||||
ELSE{
|
||||
for(;;){
|
||||
// <20>®¨áª ᢮¡®¤®© áá뫪¨
|
||||
ESI=ptr;
|
||||
EAX=lstrcmpA(DSDWORD[ESI+recid],keystring);
|
||||
ESI=ptr;
|
||||
IF(long EAX<0){
|
||||
// ptr.left
|
||||
IF(DSDWORD[ESI+left]==0){ // <20> 諨 ¯ãá⮩ «¥¢ë© - ¤®¡ ¢¨¬
|
||||
DSDWORD[ESI+left]=newptr;
|
||||
BREAK; // ptr.left=newptr
|
||||
}
|
||||
ptr=DSDWORD[ESI+left];
|
||||
}
|
||||
ELSE IF(EAX!=0){
|
||||
// ptr.right
|
||||
IF(DSDWORD[ESI+right]==0){ // <20> 諨 ¯ãá⮩ ¯à ¢ë© - ¤®¡ ¢¨¬
|
||||
DSDWORD[ESI+right]=newptr;
|
||||
BREAK;
|
||||
}
|
||||
ptr=DSDWORD[ESI+right];
|
||||
}
|
||||
ELSE internalerror("string found in tree when trying to add to it");
|
||||
}
|
||||
}
|
||||
ESI=newptr;
|
||||
DSDWORD[ESI+recid]=LocalAlloc(0x40,lstrlenA(keystring)+1);
|
||||
lstrcpyA(EAX,keystring);
|
||||
IF(tok == tk_string){
|
||||
ESI=newptr;
|
||||
DSDWORD[ESI+newid] = LocalAlloc(0x40,number+1);
|
||||
IF( EAX == NULL )outofmemory();
|
||||
ECX=number;
|
||||
EDI=EAX;
|
||||
ESI=#string;
|
||||
$REP $MOVSB
|
||||
}
|
||||
ELSE{
|
||||
IF( lstrlenA(#string) == 0 ){
|
||||
ESI=newptr;
|
||||
DSDWORD[ESI+newid]=NULL;
|
||||
}
|
||||
ELSE{
|
||||
ESI=newptr;
|
||||
DSDWORD[ESI+newid]=LocalAlloc(0x40,lstrlenA(#string)+1);
|
||||
IF( EAX == NULL )outofmemory();
|
||||
lstrcpyA(EAX,#string);
|
||||
}
|
||||
}
|
||||
ESI=newptr;
|
||||
DSDWORD[ESI+rectok] = tok;
|
||||
DSDWORD[ESI+recnumber] = number;
|
||||
DSDWORD[ESI+rectype] = type;
|
||||
DSDWORD[ESI+recsrc] = src;
|
||||
DSDWORD[ESI+recpost] = post;
|
||||
DSDWORD[ESI+left] = NULL;
|
||||
DSDWORD[ESI+right] = NULL;
|
||||
DSDWORD[ESI+recmodline] = modline;
|
||||
treeptr = newptr;
|
||||
}
|
||||
|
||||
// ---- ‚뢮¤ ¢á¥å ¨¤¥â¨ä¨ª â®à®¢
|
||||
void DisplayTree ()
|
||||
{ // dump all identifiers to MAP file
|
||||
fprint(mapfile,"ALL GLOBAL IDENTIFIERS LIST:\n");
|
||||
fprint(mapfile,"tok type number post\tIDENTIFIER\n");
|
||||
numberofids = 0;
|
||||
DisplayTreeAll(treestart);
|
||||
wsprintfA(#mapstr,"\n %u Unique Global Identifiers.\n\n",numberofids);
|
||||
fprint(mapfile,#mapstr);
|
||||
fprint(mapfile,"GLOBAL CONSTANT IDENTIFIER LIST:\n");
|
||||
numberofids = 0;
|
||||
DisplayTreeConstants(treestart);
|
||||
wsprintfA(#mapstr,"\n %u Unique Global Constant Value Identifiers.\n\n",numberofids);
|
||||
fprint(mapfile,#mapstr);
|
||||
}
|
||||
|
||||
// ---- ‚뢮¤ ¢á¥£® ᯨ᪠¨¤¥â¨ä¨ ªâ®à®¢
|
||||
DisplayTreeAll(dword ptr)
|
||||
{
|
||||
if( ptr != NULL ){
|
||||
ESI=ptr;
|
||||
DisplayTreeAll(DSDWORD[ESI+right]);
|
||||
ESI=ptr;
|
||||
if(DSDWORD[ESI+rectok]-DSDWORD[ESI+recpost]!=tk_API){
|
||||
wsprintfA(#mapstr,"%3d %8lXh %8lXh %6Xh\t%s\n",DSDWORD[ESI+rectok],
|
||||
DSDWORD[ESI+rectype],DSDWORD[ESI+recnumber],DSDWORD[ESI+recpost],
|
||||
DSDWORD[ESI+recid]);
|
||||
fprint(mapfile,#mapstr);
|
||||
EAX=DSDWORD[ESI+newid];
|
||||
IF(EAX!=0){
|
||||
IF(lstrcmpA(DSDWORD[ESI+recid],EAX) != 0 ){
|
||||
ESI=ptr;
|
||||
wsprintfA(#mapstr,"Alias=%s\n",DSDWORD[ESI+newid]);
|
||||
fprint(mapfile,#mapstr);
|
||||
}
|
||||
}
|
||||
IF(list){
|
||||
ESI=ptr;
|
||||
EAX=DSDWORD[ESI+recsrc];
|
||||
IF(EAX!=0){
|
||||
EBX=DSDWORD[ESI+recmodline]>>16;
|
||||
EAX=FILENAMESIZE*EBX+#modules;
|
||||
EBX=EAX;
|
||||
wsprintfA(#mapstr,"File:%s, line=%-d:\n%s\n",EBX,
|
||||
DSDWORD[ESI+recmodline]&0xFFFF,DSDWORD[ESI+recsrc]);
|
||||
fprint(mapfile,#mapstr);
|
||||
ESI=ptr; LocalFree(DSDWORD[ESI+recsrc]); // Žá¢®¡®¤¨¬ ¯ ¬ïâì
|
||||
DSDWORD[ESI+recsrc]=0;
|
||||
}
|
||||
}
|
||||
numberofids++;
|
||||
}
|
||||
ESI=ptr;
|
||||
DisplayTreeAll(DSDWORD[ESI+left]);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- ‚뢮¤ ᯨ᪠£«®¡ «ìëå ª®áâ â
|
||||
DisplayTreeConstants(dword ptr)
|
||||
{
|
||||
IF( ptr != NULL ){
|
||||
ESI=ptr;
|
||||
DisplayTreeConstants(DSDWORD[ESI+right]);
|
||||
ESI=ptr;
|
||||
EAX=DSDWORD[ESI+rectok];
|
||||
IF(EAX == tk_number){
|
||||
wsprintfA(#mapstr,"#define %10ld /* %8lX hex */ %s\n",
|
||||
DSDWORD[ESI+recnumber],DSDWORD[ESI+recnumber],DSDWORD[ESI+recid]);
|
||||
fprint(mapfile,#mapstr);
|
||||
numberofids++;
|
||||
}
|
||||
ESI=ptr;
|
||||
DisplayTreeConstants(DSDWORD[ESI+left]);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- ‚ëç¨á«¥¨¥ § ç¥¨ï ¡¥§§ ª®¢® ª®áâ âë
|
||||
dword DoConstDwordMath()
|
||||
dword value;
|
||||
{
|
||||
IF(tok == tk_minus){
|
||||
NextTok();
|
||||
IF(tok != tk_number){
|
||||
numexpected();
|
||||
return(0);
|
||||
}
|
||||
number = -number;
|
||||
}
|
||||
IF(tok != tk_number){
|
||||
numexpected();
|
||||
return(0);
|
||||
}
|
||||
value = number;
|
||||
while(tok2isopperand()){
|
||||
NextTok();
|
||||
IF(tok2!=tk_number)return(value);
|
||||
switch(tok){
|
||||
case tk_minus: value -= number2; break;
|
||||
case tk_plus: value += number2; break;
|
||||
case tk_xor: value ^= number2; break;
|
||||
case tk_and: value &= number2; break;
|
||||
case tk_or: value |= number2; break;
|
||||
case tk_mod: value = value % number2; BREAK;
|
||||
case tk_div: value = value / number2; BREAK;
|
||||
case tk_mult: value = value * number2; BREAK;
|
||||
case tk_rr: value >>= number2; BREAK;
|
||||
case tk_ll: value <<= number2; BREAK;
|
||||
case tk_xorminus: value ^= -number2; BREAK;
|
||||
case tk_andminus: value &= -number2; BREAK;
|
||||
case tk_orminus: value |= -number2; BREAK;
|
||||
/* case(tok==tk_modminus) value %= -number2;
|
||||
case(tok==tk_divminus) value /= -number2;
|
||||
case(tok==tk_multminus) value *= -number2; */
|
||||
case tk_rrminus: value >>= -number2; BREAK;
|
||||
case tk_llminus: value <<= -number2; BREAK;
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
return(value);
|
||||
}
|
||||
|
||||
// ---- ‚ëç¨á«¥¨¥ § ç¥¨ï § ª®¢®© ª®áâ âë
|
||||
long DoConstMath()
|
||||
long value;
|
||||
{
|
||||
IF(tok == tk_minus){
|
||||
NextTok();
|
||||
IF(tok != tk_number){
|
||||
numexpected();
|
||||
return(0);
|
||||
}
|
||||
number = -number;
|
||||
}
|
||||
IF(tok != tk_number){
|
||||
numexpected();
|
||||
return(0);
|
||||
}
|
||||
value = number;
|
||||
while(tok2isopperand()){
|
||||
NextTok();
|
||||
IF(tok2 != tk_number) return(value);
|
||||
switch(tok){
|
||||
case tk_minus: value -= number2; break;
|
||||
case tk_plus: value += number2; break;
|
||||
case tk_xor: value ^= number2; break;
|
||||
case tk_and: value &= number2; break;
|
||||
case tk_or: value |= number2; break;
|
||||
case tk_mod: value = value % number2; BREAK;
|
||||
case tk_div: value = value / number2; BREAK;
|
||||
case tk_mult: value = value * number2; BREAK;
|
||||
case tk_rr: value >>= number2; BREAK;
|
||||
case tk_ll: value <<= number2; BREAK;
|
||||
case tk_xorminus: value ^= -number2; BREAK;
|
||||
case tk_andminus: value &= -number2; BREAK;
|
||||
case tk_orminus: value |= -number2; BREAK;
|
||||
/* case(tok==tk_modminus) value %= -number2;
|
||||
case(tok==tk_divminus) value /= -number2;
|
||||
case(tok==tk_multminus) value *= -number2; */
|
||||
case tk_rrminus: value >>= -number2; BREAK;
|
||||
case tk_llminus: value <<= -number2; BREAK;
|
||||
}
|
||||
NextTok();
|
||||
}
|
||||
return(value);
|
||||
}
|
||||
|
||||
// ---- ‚ëç¨á«¥¨¥ § ç¥¨ï § ª®¢®© ª®áâ âë
|
||||
long DoConstLongMath()
|
||||
long value;
|
||||
{
|
||||
value=DoConstMath();
|
||||
NextTok();
|
||||
return(value);
|
||||
}
|
||||
|
||||
// ---- ‘«¥¤ãî騩 token - ®¯¥à æ¨ï?
|
||||
dword tok2isopperand()
|
||||
{
|
||||
EAX=tok2;
|
||||
IF(EAX==tk_plus)||(EAX==tk_minus)||(EAX==tk_mult)||(EAX==tk_div)||(EAX==tk_mod)||
|
||||
(EAX==tk_rr)||(EAX==tk_ll)||(EAX==tk_or)||(EAX==tk_and)||(EAX==tk_xor)||
|
||||
(EAX==tk_divminus)||(EAX==tk_modminus)||(EAX==tk_multminus)||(EAX==tk_xorminus)||
|
||||
(EAX==tk_orminus)||(EAX==tk_andminus)||(EAX==tk_llminus)||(EAX==tk_rrminus)return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
// ---- ‘«¥¤ãî騩 token § ªàë¢ ¥â ¢ëà ¦¥¨¥?
|
||||
dword tok2notstopper ()
|
||||
{
|
||||
EAX=tok2;
|
||||
IF(EAX==tk_semicolon)||(EAX==tk_comma)||(EAX==tk_closebracket)||
|
||||
(EAX==tk_openblock)EAX=0;
|
||||
ELSE EAX=1;
|
||||
}
|
||||
|
||||
// ---- <20>®¨áª ¢ ᯨ᪥ «®ª «ìëå ¯¥à¥¬¥ëå
|
||||
SearchLocals(dword tok4,type4,string4,number4)
|
||||
{
|
||||
if( locallist != NULL ){
|
||||
localptr = locallist;
|
||||
S00:
|
||||
ESI=EAX; //localptr;
|
||||
lstrcmpA(string4,ESI+localid);
|
||||
ESI=localptr;
|
||||
IF(EAX==0){ // <20>¥à¥¬¥ ï ©¤¥
|
||||
EBX=number4;
|
||||
DSDWORD[EBX]=DSDWORD[ESI+localnumber];
|
||||
EBX=type4;
|
||||
DSDWORD[EBX]=DSDWORD[ESI+localtype];
|
||||
EBX=tok4;
|
||||
EAX=DSDWORD[ESI+localtok];
|
||||
DSDWORD[EBX]=EAX;
|
||||
IF(EAX==tk_local){
|
||||
EBX=number4;
|
||||
DSDWORD[EBX]-=localsize;
|
||||
}
|
||||
ELSE IF(EAX==tk_param){
|
||||
EBX=number4;
|
||||
EAX=DSDWORD[EBX]+4;
|
||||
DSDWORD[EBX]=EAX;
|
||||
IF(current_proc_type==cpt_far)DSDWORD[EBX]+=4; // move over seg on stack
|
||||
}
|
||||
ELSE IF(EAX!=tk_locallabel)&&(EAX!=tk_number)internalerror("Bad *tok4 value in SearchLocals");
|
||||
}
|
||||
ELSE{
|
||||
IF(DSDWORD[ESI+localnext]!=NULL){
|
||||
localptr=DSDWORD[ESI+localnext];
|
||||
$JMP S00
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- <20>®¨áª ¢ ᯨ᪥ £«®¡ «ìëå ¨¤¥â¨ä¨ª â®à®¢
|
||||
dword SearchTree(dword tok4,type4,src4,post4,string4,number4)
|
||||
dword ptr;
|
||||
long cmpresult;
|
||||
{
|
||||
cmpresult=123;
|
||||
ptr = treestart;
|
||||
// <20>®¨áª ᢮¡®¤®© áá뫪¨
|
||||
for(;;){
|
||||
ESI=EAX;
|
||||
IF(ESI==0){
|
||||
treeptr=NULL;
|
||||
return(0); // Not found
|
||||
}
|
||||
cmpresult = lstrcmpA(DSDWORD[ESI+recid],string4);
|
||||
ESI=ptr;
|
||||
IF(cmpresult<0)ptr=DSDWORD[ESI+left];
|
||||
ELSE IF(cmpresult>0)ptr=DSDWORD[ESI+right];
|
||||
ELSE BREAK;
|
||||
}
|
||||
EBX=number4; DSDWORD[EBX]=DSDWORD[ESI+recnumber];
|
||||
EBX=type4; DSDWORD[EBX]=DSDWORD[ESI+rectype];
|
||||
EBX=src4; DSDWORD[EBX]=DSDWORD[ESI+recsrc];
|
||||
EBX=post4; DSDWORD[EBX]=DSDWORD[ESI+recpost];
|
||||
EBX=tok4; EAX=DSDWORD[ESI+rectok]; DSDWORD[EBX]=EAX;
|
||||
IF(EAX==tk_string ){
|
||||
EBX=number4; ECX=DSDWORD[EBX]; EDI=string4;
|
||||
ESI=DSDWORD[ESI+newid]; $REP $MOVSB
|
||||
}
|
||||
ELSE{
|
||||
IF(DSDWORD[ESI+newid])lstrcpyA(string4,DSDWORD[ESI+newid]);
|
||||
}
|
||||
ESI=ptr;
|
||||
IF(lstrcmpA(DSDWORD[ESI+recid],string4)!=0) // <20>஢¥à¨¬: ¬¥ï«®áì «¨ ¨¬ï ¨¤¥â¨ä¨ª â®à
|
||||
SearchTree(tok4,type4,src4,post4,string4,number4); // „ - ¯®¢â®à¨¬ ¯®¨áª
|
||||
treeptr = ptr;
|
||||
return(1);
|
||||
}
|
||||
|
||||
// ---- <20>®¨áª ¥®âª®¬¯¨«¨à®¢ ëå ¥é¥ ááë«®ª
|
||||
dword SeekToDo(dword ptr)
|
||||
{
|
||||
IF(ptr!=NULL){
|
||||
ESI=ptr;
|
||||
IF(SeekToDo(DSDWORD[ESI+right]))RETURN(1);
|
||||
ESI=ptr; EAX=DSDWORD[ESI+recpost];
|
||||
IF(EAX>1){
|
||||
treeptr=ptr; ESI=ptr;
|
||||
number=DSDWORD[ESI+recnumber];
|
||||
type=DSDWORD[ESI+rectype]; modline=DSDWORD[ESI+recmodline];
|
||||
src=DSDWORD[ESI+recsrc];
|
||||
post=DSDWORD[ESI+recpost];
|
||||
tok=DSDWORD[ESI+rectok]; RETURN(1);
|
||||
}
|
||||
ESI=ptr;
|
||||
IF(SeekToDo(DSDWORD[ESI+left]))RETURN(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
// ---- <20>®¨áª ¥§ ªàëâëå ááë«®ª
|
||||
SeekUndefined(dword ptr)
|
||||
{
|
||||
IF( ptr != NULL ){
|
||||
ESI=ptr;
|
||||
SeekUndefined(DSDWORD[ESI+right]);
|
||||
ESI=ptr; EAX=DSDWORD[ESI+rectok];
|
||||
IF(EAX==tk_undefproc){
|
||||
wsprintfA(#mapstr,"'%s' undefined\n",DSDWORD[ESI+recid]);
|
||||
IF( makemapfile )fprint(mapfile,#mapstr);
|
||||
WRITESTR(#mapstr);
|
||||
}
|
||||
ESI=ptr;
|
||||
SeekUndefined(DSDWORD[ESI+left]);
|
||||
}
|
||||
}
|
||||
|
36
programs/develop/c--/trunk/wapi.h--
Normal file
36
programs/develop/c--/trunk/wapi.h--
Normal file
@ -0,0 +1,36 @@
|
||||
extern WINAPI "user32.dll"
|
||||
{
|
||||
cdecl long wsprintfA();
|
||||
dword IsCharAlphaA();
|
||||
dword IsCharAlphaNumericA();
|
||||
dword CharUpperA();
|
||||
dword CharToOemA();
|
||||
|
||||
}
|
||||
|
||||
extern WINAPI "kernel32.dll"
|
||||
{
|
||||
long lstrlenA();
|
||||
long lstrcmpA();
|
||||
dword lstrcpyA();
|
||||
dword lstrcpynA();
|
||||
dword lstrcatA();
|
||||
long _lopen();
|
||||
dword _lread();
|
||||
dword _lwrite();
|
||||
long _llseek();
|
||||
long _lclose();
|
||||
long _lcreat();
|
||||
dword LocalAlloc();
|
||||
dword LocalFree();
|
||||
dword LocalUnlock();
|
||||
dword GetSystemDirectoryA();
|
||||
dword GlobalFree();
|
||||
dword GetStdHandle();
|
||||
dword GetLastError();
|
||||
dword GetFileSize();
|
||||
dword GetCommandLineA();
|
||||
void ExitProcess();
|
||||
dword CloseHandle();
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user