//// imported
#include "../_sdk/emit.h"
#include "sizesarm.h"
//тхчфх, уфх эєцхэ ёЄЁюъют√щ ярЁрьхЄЁ, шёяюы№чєхЄё _joined
//(ъЁюьх call - Єрь _callee, ш ъЁюьх loadrg/b - Єрь _const)
//т ъюэЎх ы■сюую т√ўшёыхэш (put, call, jpiffalse) фхыры _jpflag = 0x00 (шэрўх яЁхф√фє∙хх "юяЄшьшчшЁютрээюх" ёЁртэхэшх ьюцхЄ шёяюЁЄшЄ№ эют√щ єёыютэ√щ яхЁхїюф)
//юёЄртшы Єюы№ъю т jpiffalse, Є.ъ. юёЄры№э√х эх ьюуєЄ с√Є№ "юяЄшьшчшЁютрээ√ьш"
EXPORT VAR PCHAR _callee; //эрчтрэшх т√ч√трхьющ яЁюЎхфєЁ√ (ё єў╕Єюь ьюфєы )
EXPORT VAR UINT _lencallee;
EXTERN PCHAR _joined; //ртЄюьхЄър
EXTERN UINT _lenjoined;
EXTERN PCHAR _const; //ёЄрЁр ъюэёЄрэЄр
EXTERN UINT _lenconst;
EXPORT VAR BYTE _exprlvl; //уыєсшэр т√Ёрцхэш (тхЁїэшщ єЁютхэ№ == 1)
//тэх°эшх яЁюЎхфєЁ√ (шч rgs) - todo т codegen эх шёяюы№чютрЄ№ rgs
EXTERN BYTE _rnew;
EXTERN BYTE _rold;
EXTERN BYTE _rold2;
EXTERN BYTE _rold3;
PROC getrfree FORWARD(); //чрэ Є№ ётюсюфэ√щ ЁхушёЄЁ ш тхЁэєЄ№ хую ъюф
PROC freernew FORWARD(); //юётюсюфшЄ№ ЁхушёЄЁ ё тхЁ°шэ√ ёЄхър
//rg pool
PROC getnothing FORWARD(); //ёюїЁрэшЄ№ ЁхушёЄЁ√ ш срщЄ√ т ёЄхъх ш юётюсюфшЄ№
//PROC getmainrg FORWARD(); //тч Є№ RMAIN=new ш юётюсюфшЄ№ юёЄры№э√х ЁхушёЄЁ√
PROC getmain2rgs FORWARD(); //тч Є№ RMAIN=old, RMAIN2=new ш юётюсюфшЄ№ юёЄры№э√х ЁхушёЄЁ√ //фы call2rgs
//PROC getmain3rgs FORWARD(); //фы call3rgs
PROC getmain4rgs FORWARD(); //фы call4rgs
PROC setmainrg FORWARD(); //єёЄрэютшЄ№ яЁшчэръш, ъръ сєфЄю ь√ яюыєўшыш Ёхчєы№ЄрЄ т ЁхушёЄЁх //фы call2rgs
PROC setmain2rgs FORWARD(); //єёЄрэютшЄ№ яЁшчэръш, ъръ сєфЄю ь√ яюыєўшыш Ёхчєы№ЄрЄ т ЁхушёЄЁрї //фы call4rgs
PROC rgs_initrgs FORWARD();
////
#define _RGBUFSZ (BYTE)(_NRGS+0x01)
//яЁшюЁшЄхЄ√ ЁхушёЄЁют:
CONST BYTE _RMAIN = 0x01; /**HL*/ /**ЁхушёЄЁ Ёхчєы№ЄрЄр ш яхЁтюую ярЁрьхЄЁр ёЄрэфрЁЄэ√ї ЇєэъЎшщ*/
CONST BYTE _RMAIN2= 0x02; /**DE*/ /**ЁхушёЄЁ тЄюЁюую ёыютр Ёхчєы№ЄрЄр ш тЄюЁюую ярЁрьхЄЁр ёЄрэфрЁЄэ√ї ЇєэъЎшщ*/
CONST BYTE _RMAIN3= 0x03;
CONST BYTE _RMAIN4= 0x04;
CONST PCHAR _RNAME [_RGBUFSZ] = {
"R0", //0 яєёЄющ, rtemp
"R1",
"R2",
"R3",
"R4",
// "R5",
// "R6"
};
VAR BOOL _fused;
VAR INT _funcstkdepth;
VAR BYTE _jpflag; //0=OR A:JZ, 1=JZ, 2=JNZ, 3=JNC, 4=JC
EXPORT CONST BYTE _typesz[32] = { //ЁрчьхЁ Єшяр т срщЄрї фы ЄрЁухЄр
_SZ_BYTE/**T_BYTE */, //фы тёхї ЄрЁухЄют
_SZ_REG/**T_UINT */, //фы тёхї ЄрЁухЄют
_SZ_REG/**T_INT */, //фы тёхї ЄрЁухЄют
_SZ_BOOL/**T_BOOL */,
_SZ_LONG/**T_LONG */,
_SZ_BYTE/**T_CHAR */,
_SZ_LONG/**T_FLOAT*/,
0x00/**unknown*/,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
_SZ_REG/**T_PBYTE */,
_SZ_REG/**T_PUINT */,
_SZ_REG/**T_PINT */,
_SZ_REG/**T_PBOOL */,
_SZ_REG/**T_PLONG */,
_SZ_REG/**T_PCHAR */,
_SZ_REG/**T_PFLOAT*/,
_SZ_REG/** */,
_SZ_REG, _SZ_REG, _SZ_REG, _SZ_REG, _SZ_REG, _SZ_REG, _SZ_REG, _SZ_REG //pointer to...
};
CONST BYTE _typeshift[32] = { //log ЁрчьхЁ Єшяр (n фы 2^n срщЄ) фы ЄрЁухЄр
_RL_BYTE/**T_BYTE */, //фы тёхї ЄрЁухЄют
_RL_REG/**T_UINT */, //фы тёхї ЄрЁухЄют
_RL_REG/**T_INT */, //фы тёхї ЄрЁухЄют
_RL_BOOL/**T_BOOL */,
_RL_LONG/**T_LONG */,
_RL_BYTE/**T_CHAR */,
_RL_LONG/**T_FLOAT*/,
0x00/**unknown*/,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
_RL_REG/**T_BYTE */,
_RL_REG/**T_UINT */,
_RL_REG/**T_INT */,
_RL_REG/**T_BOOL */,
_RL_REG/**T_LONG */,
_RL_REG/**T_CHAR */,
_RL_REG/**T_PFLOAT*/,
_RL_REG/** */,
_RL_REG, _RL_REG, _RL_REG, _RL_REG, _RL_REG, _RL_REG, _RL_REG, _RL_REG //pointer to...
};
//VAR CHAR _swass[_STRLEN]; //todo єсЁрЄ№?
//VAR PCHAR _wass; //todo єсЁрЄ№
//VAR UINT _lenwass; //todo єсЁрЄ№
VAR UINT constindex;
//VAR UINT wasconstindex; //todo єсЁрЄ№
VAR UINT asmcmds; //ёъюы№ъю ъюьрэф яЁю°ыю ё ьюьхэЄр яюёыхфэхщ т√уЁєчъш ьхЄюъ
PROC initrgs FORWARD(); //юўшёЄшЄ№ ёюёЄю эш ЁхушёЄЁют ш срщЄют (шёяюы№чєхЄё т cemitfunc)
VAR CHAR asmlblbuf[65536];
VAR UINT lenasmlblbuf;
PROC asm_dw FORWARD();
PROC asm_b FORWARD();
FUNC UINT mystrlen(PCHAR s) //фышэр схч ЄхЁьшэрЄюЁр!
{
VAR UINT len;
VAR CHAR c;
len = 0; //фышэр схч ЄхЁьшэрЄюЁр!
loop:
c = *(PCHAR)s;
IF (c == '\0') goto endloop; //BREAK;
INC s;
INC len;
goto loop;
endloop:
RETURN len; //фышэр схч ЄхЁьшэрЄюЁр!
}
FUNC UINT mystrcopy(PCHAR from, PCHAR to)
{
VAR UINT len;
VAR CHAR c;
len = 0; //фышэр схч ЄхЁьшэрЄюЁр!
loop:
c = from[len];
to[len] = c;
IF (c == '\0') goto endloop; //BREAK;
INC len;
goto loop;
endloop:
RETURN len; //фышэр схч ЄхЁьшэрЄюЁр!
}
PROC varmangledstr(PCHAR s)
{
VAR CHAR c;
IF (*(PCHAR)s == '\'') { //'c'
varstr(s);
}ELSE {
loop:
c = *(PCHAR)s;
IF (c == '\0') goto quit;
IF ((c == '.')||(c == '/')) {
varstr("__");
}ELSE varc(c);
INC s;
goto loop;
quit:
}
}
PROC asmmangledstr(PCHAR s)
{
VAR CHAR c;
IF (*(PCHAR)s == '\'') { //'c'
asmstr(s);
}ELSE {
loop:
c = *(PCHAR)s;
IF (c == '\0') goto quit;
IF ((c == '.')||(c == '/')) {
asmstr("__");
}ELSE asmc(c);
INC s;
goto loop;
quit:
}
}
PROC asm_pc4_eol()
{
asmstr("__"); asmuint(constindex); asmmangledstr(_fn); endasm(); //fn эєцхэ, ўЄюс√ ртЄюьхЄъш фы Ёрчэ√ї ьюфєыхщ эх ёютярыш
}
PROC asm_endpc4()
{
asmstr("__"); asmuint(constindex); asmmangledstr(_fn); endasm(); //fn эєцхэ, ўЄюс√ ртЄюьхЄъш фы Ёрчэ√ї ьюфєыхщ эх ёютярыш
INC constindex;
}
PROC asm_align4b()
{
asmstr("\tALIGN 4"); endasm();
}
EXPORT PROC emitasmlabel(PCHAR s)
{
asmmangledstr(s); /**asmc( ':' );*/ endasm();
}
EXPORT PROC emitfunclabel(PCHAR s)
{
asmmangledstr(s); asmstr("\tEQU $+1"); endasm();
}
EXPORT PROC emitvarlabel(PCHAR s)
{
varmangledstr(s); /**varc( ':' );*/ endvar();
}
PROC asmaddlabel(PCHAR s, UINT constindex)
{
VAR UINT len;
POKE *(PUINT)(&asmlblbuf[lenasmlblbuf]) = constindex;
lenasmlblbuf = lenasmlblbuf + +sizeof(UINT);
len = mystrcopy(s, &asmlblbuf[lenasmlblbuf]);
lenasmlblbuf = lenasmlblbuf + len + 1;
asmstr("__"); asmuint(constindex); asmmangledstr(_fn); //fn эєцхэ, ўЄюс√ ртЄюьхЄъш фы Ёрчэ√ї ьюфєыхщ эх ёютярыш
asmstr("__"); asmmangledstr(s); //фы эруы фэюёЄш
// IF (high) {asmstr( ">>32"/**WORDBITS*/ ); }; //todo long
}
PROC asmflushlabels()
{
VAR UINT i;
VAR UINT len;
IF (lenasmlblbuf != 0) asm_align4b();
i = 0;
WHILE (i != lenasmlblbuf) {
asmstr("__"); asmuint(*(PUINT)(&asmlblbuf[i])); asmmangledstr(_fn); //fn эєцхэ, ўЄюс√ ртЄюьхЄъш фы Ёрчэ√ї ьюфєыхщ эх ёютярыш
i = i + +sizeof(UINT);
asmstr("__"); emitasmlabel(&asmlblbuf[i]); //фы эруы фэюёЄш
//len = mystrcopy(&asmlblbuf[i], _wass);
asm_dw(); asmmangledstr(&asmlblbuf[i]); endasm();
i = i + mystrlen(&asmlblbuf[i]) + 1;
};
lenasmlblbuf = 0;
asmcmds = 0;
}
PROC asmjpflushlabels()
{
asm_b();
asm_pc4_eol();
asmflushlabels(); //эх ЄЁюурхЄ constindex
asm_endpc4();
}
//////////// ьхыъшх яЁюЎхфєЁ√ фы ёюъЁр∙хэш ўшёыр ъюэёЄрэЄ
PROC endasmcmd()
{
endasm();
INC asmcmds;
IF (asmcmds >= 250) asmjpflushlabels();
}
PROC asm_direct()
{
asmc('#');
}
PROC asm_comma()
{
asmc(',');
}
PROC asm_open()
{
asmc('[');
}
PROC asm_close()
{
asmc(']');
}
PROC asm_opcurl()
{
asmc('{');
}
PROC asm_clcurl()
{
asmc('}');
}
PROC asm_rname(BYTE r)
{
asmstr( _RNAME[(UINT)r] );
}
PROC asm_mrname(BYTE r)
{
asm_open(); asm_rname(r); asm_close();
}
PROC asm_rtemp()
{
asmstr("R0");
}
PROC asm_mrtemp()
{
asmstr("[R0]");
}
PROC asm_rzero()
{
asmstr("R8");
}
PROC asm_rff()
{
asmstr("R7");
}
PROC asm_rmain()
{
asm_rname(_RMAIN);
}
PROC asm_close_eol()
{
asm_close(); endasmcmd();
}
PROC var_alignwsz()
{
varstr("\tALIGN 4"); endvar();
}
EXPORT PROC var_db() //фюёЄєяэю шч compile!
{
varstr( "\tDCB " );
}
EXPORT PROC asm_db() //ъюёЄ√ы№ фы ъюэёЄрэЄэ√ї ьрёёштют ёЄЁюъ TODO
{
asmstr( "\tDCB " );
}
EXPORT PROC var_dw() //фюёЄєяэю шч compile!
{
// var_align4b();
varstr( "\tDCD " );
}
EXPORT PROC asm_dw() //ъюёЄ√ы№ фы ртЄюухэхЁшЁєхь√ї ъюэёЄрэЄ
{
// asm_align4b();
asmstr( "\tDCD " );
}
PROC var_dl()
{
// var_align4b();
varstr( "\tDCQ " );
}
EXPORT PROC var_ds() //фюёЄєяэю шч compile!
{
varstr( "\tSPACE " );
}
PROC asm_ands() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tANDS " );
}
PROC asm_ors() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tORRS " );
}
PROC asm_eors() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tEORS " );
}
PROC asm_rsbs() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tRSBS " );
}
PROC asm_subs() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tSUBS " );
}
PROC asm_sbcs() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tSBCS " );
}
PROC asm_adds() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tADDS " );
}
PROC asm_adcs() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tADCS " );
}
PROC asm_ldr()
{
asmstr( "\tLDR " );
}
PROC asm_ldrb()
{
asmstr( "\tLDRB " );
}
PROC asm_str()
{
asmstr( "\tSTR " );
}
PROC asm_strb()
{
asmstr( "\tSTRB " );
}
PROC asm_mov() //┴┼╟ єёЄрэютъш Їыруют
{
asmstr( "\tMOV " );
}
PROC asm_movs() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tMOVS " );
}
PROC asm_mvns() //ё єёЄрэютъющ Їыруют
{
asmstr( "\tMVNS " );
}
PROC asm_b() //jr
{
asmstr( "\tB " );
}
PROC asm_bl() //jp/call
{
asmstr( "\tBL " );
INC asmcmds; //long cmd
}
PROC asm_beq() //jp z
{
asmstr( "\tBEQ " );
}
PROC asm_bne() //jp nz
{
asmstr( "\tBNE " );
}
PROC asm_bcs() //jp c
{
asmstr( "\tBCS " );
}
PROC asm_bcc() //jp nc
{
asmstr( "\tBCC " );
}
PROC asm_bpl() //jp p
{
asmstr( "\tBPL " );
}
PROC asm_bvc() //jp pe? (no overflow)
{
asmstr( "\tBVC " );
}
PROC asm_bvs() //jp po? (overflow)
{
asmstr( "\tBVS " );
}
PROC asm_blt() //< (чэръютюх ёЁртэхэшх)
{
asmstr( "\tBLT " );
}
PROC asm_bgt() //> (чэръютюх ёЁртэхэшх)
{
asmstr( "\tBGT " );
}
PROC asm_bx() //jp reg
{
asmstr( "\tBX " );
}
PROC asm_blx() //call reg???
{
asmstr( "\tBLX " );
}
PROC asm_nop_eol()
{
asmstr("\tNOP"); endasmcmd();
}
PROC asm_push()
{
asmstr( "\tPUSH " );
}
PROC asm_pop()
{
asmstr( "\tPOP " );
}
PROC emit0(BYTE reg) //схч єёЄрэютъш Їыруют
{
asm_mov(); asm_rname(reg); asm_comma(); asm_rzero(); endasmcmd();
//asm_mov(); asm_rname(reg); asm_comma(); asm_direct(); asmc('0'); endasmcmd();
//asm_sub(); asm_rname(reg); asm_comma(); asm_rname(reg); endasmcmd();
}
PROC emitmaskb(BYTE reg)
{
asm_ands(); asm_rname(reg); asm_comma(); asm_rff(); endasmcmd();
}
PROC asm_call_eol(PCHAR s)
{
asm_bl(); asmmangledstr(s); endasmcmd();
}
///////////////////////////////////
//фюёЄєяэ√ шч commands
PROC unproxy()
{
}
PROC proxy(BYTE r)
{
}
///////////////////////////////////////////////////////////
//яЁюЎхфєЁ√ ё ьр°шээ√ь ъюфюь фы rgs
PROC emitpushrg(BYTE rnew)
{
asm_push(); asm_opcurl(); asm_rname(rnew); asm_clcurl(); endasmcmd();
INC _funcstkdepth;
}
PROC emitpoprg(BYTE rnew) //ЁхушёЄЁ єцх яюьхўхэ т getrfree/getrg
{
asm_pop(); asm_opcurl(); asm_rname(rnew); asm_clcurl(); endasmcmd();
DEC _funcstkdepth;
}
PROC emitmovrg(BYTE rsrc, BYTE rdest) //эх чрърч√трхЄ ш эх юётюсюцфрхЄ (ёь. emitmoverg)
{
asm_movs(); asm_rname(rdest); asm_comma(); asm_rname(rsrc); endasmcmd(); //эх mov, яюЄюьє ўЄю юср ЁхушёЄЁр r0..r7
}
///////////////////////////////////////////////////////////////////////////////////////
//¤Єш яЁюЎхфєЁ√ ухэхЁшЁє■Є ъюф
//эхфюёЄєяэ√ шч ъюьяшы ЄюЁр, фюёЄєяэ√ шч commands
EXPORT PROC emitexport(PCHAR s)
{
asmstr("\tEXPORT "); asmmangledstr(s); endasmcmd();
}
EXPORT PROC emitvarpreequ(PCHAR s)
{
// varstr("\tIF :LNOT: :DEF: "); varmangledstr(s); endvar(); //todo єсЁрЄ№ (Keil)
}
EXPORT PROC emitvarpostequ()
{
// varstr("\tENDIF"); endvar(); //todo єсЁрЄ№ (Keil)
}
EXPORT PROC varequ(PCHAR s)
{
varmangledstr(s); varstr("\tEQU ");
}
EXPORT FUNC UINT varshift(UINT shift, UINT sz)
{
IF (sz >= 4) shift = (shift+3)&(UINT)(-4);
//asmstr(_joined); asmc('='); asmuint(shift); endasm();
varequ(_joined); /**varstr(_joined); varc('=');*/ varuint(shift); endvar();
RETURN shift;
}
PROC emitjpmainrg() //"jp (hl)"
{
//эр ¤ЄюЄ ьюьхэЄ фы яЁхфёърчєхьюёЄш тёх ЁхушёЄЁ√ фюыцэ√ с√Є№ ётюсюфэ√
//(ёхщўрё ¤Єю яюыєўшЄё ртЄюьрЄшўхёъш, эю схч storergs ш ё ЁхчхЁтшЁютрэшхь ЁхушёЄЁют эрфю юётюсюцфрЄ№ тЁєўэє■)
getnothing(); //getnothingword();
asm_bx(); asm_rmain(); endasmcmd();
}
PROC emitcallmainrg() //"call (hl)"
{
//эр ¤ЄюЄ ьюьхэЄ фы яЁхфёърчєхьюёЄш тёх ЁхушёЄЁ√ фюыцэ√ с√Є№ ётюсюфэ√
//(ёхщўрё ¤Єю яюыєўшЄё ртЄюьрЄшўхёъш, эю схч storergs ш ё ЁхчхЁтшЁютрэшхь ЁхушёЄЁют эрфю юётюсюцфрЄ№ тЁєўэє■)
getnothing(); //getnothingword();
/** //asm_blx(); asm_rmain(); endasmcmd();
asm_add(); asm_rtemp(); asm_comma(); asmstr("PC"); asm_comma(); asmstr("#8"); endasmcmd();
asm_mov(); asmstr("LR"); asm_comma(); asm_rtemp(); endasmcmd();
asm_bx(); asm_rmain(); endasmcmd();
asm_nop_eol();
*/
asm_call_eol("_JPHL.");
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitjp()
{
//эр ¤ЄюЄ ьюьхэЄ фы яЁхфёърчєхьюёЄш тёх ЁхушёЄЁ√ фюыцэ√ с√Є№ ётюсюфэ√
//(ёхщўрё ¤Єю яюыєўшЄё ртЄюьрЄшўхёъш, эю схч storergs ш ё ЁхчхЁтшЁютрэшхь ЁхушёЄЁют эрфю юётюсюцфрЄ№ тЁєўэє■)
unproxy();
getnothing(); //getnothingword();
asm_b(); asmmangledstr(_joined); endasmcmd();
}
PROC emitbtoz() //яхЁхф jp!
{
//ёЁрчє яюёых ёЁртэхэш эх эрфю, эю тфЁєу ь√ ўшЄрхь BOOL
//IF (_jpflag == 0x00) {
IF (!_fused) { //Ёхчєы№ЄрЄр эхЄ тю Їырурї
asm_ors(); asm_rname(_rnew); asm_comma(); asm_rname(_rnew); endasmcmd();
};
}
PROC emitjpiffalse()
{
//эр ¤ЄюЄ ьюьхэЄ фы яЁхфёърчєхьюёЄш тёх ЁхушёЄЁ√ фюыцэ√ с√Є№ ётюсюфэ√
//(ёхщўрё ¤Єю яюыєўшЄё ртЄюьрЄшўхёъш, эю схч storergs ш ё ЁхчхЁтшЁютрэшхь ЁхушёЄЁют эрфю юётюсюцфрЄ№ тЁєўэє■)
getnothing(); //getnothingword();
IF (_jpflag == 0x02) {asm_beq(); //asm_bne();
}ELSE IF (_jpflag == 0x03) {asm_bcc(); //asm_bcs();
}ELSE IF (_jpflag == 0x04) {asm_bcs(); //asm_bcc();
}ELSE {asm_bne(); //asm_beq();
};
asm_pc4_eol();
asm_bl(); //long jp
asmmangledstr(_joined);
endasmcmd();
asm_endpc4();
_fused = +FALSE;
_jpflag = 0x00;
}
PROC emitret()
{
asm_pop(); asmstr( "{PC}" ); endasmcmd();
asmflushlabels();
}
PROC emitcall2rgs(PCHAR s)
{
unproxy();
getmain2rgs();
initrgs();
asm_call_eol(s);
setmainrg(); //Ёхчєы№ЄрЄ т RMAIN
}
/**
PROC emitcall3rgs(PCHAR s) //todo яЁютхЁшЄ№
{
unproxy();
getmain3rgs();
initrgs();
asm_call_eol(s);
//ёхщўрё тёх ЁхушёЄЁ√ юЄьхўхэ√ ъръ ётюсюфэ√х
//setwordcontext();
setmain2rgs(); //Ёхчєы№ЄрЄ т RMAIN,RMAIN2
}
*/
PROC emitcall4rgs(PCHAR s) //todo яЁютхЁшЄ№
{
unproxy();
getmain4rgs();
initrgs();
asm_call_eol(s);
//ёхщўрё тёх ЁхушёЄЁ√ юЄьхўхэ√ ъръ ётюсюфэ√х
//setwordcontext();
setmain2rgs(); //Ёхчєы№ЄрЄ т RMAIN,RMAIN2
}
PROC emitcallproc()
{
//_jpflag = 0x00;
asm_call_eol(_callee);
}
PROC emitloadrtemp(BYTE r, PCHAR s)
{
asm_ldr(); asm_rname(r); asm_comma();
//asmc('L'); asmstr(s); //todo яюфяЁюуЁрььр ё т√фхыхэшхь ъюэёЄрэЄ√, ё шёъы■ўхэшхь яютЄюЁэюую яЁшётрштрэш (rtemp яЁшётрштрхЄё Єюы№ъю чфхё№ ш т inc/dec)
asmaddlabel(s, constindex);
INC constindex;
endasmcmd();
}
PROC emitloadrg(BOOL high) //ЁхушёЄЁ єцх чрэ Є ўхЁхч getrfree
{
emitloadrtemp(_rnew,_const);
// asm_ldr(); asm_rname(_rnew); asm_comma(); asm_mrtemp(); endasmcmd(); //todo long
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitloadrg0() //ЁхушёЄЁ єцх чрэ Є ўхЁхч getrfree
{
emit0(_rnew); //Їыруш эх трцэ√
}
PROC emitloadb() //ръъєьєы ЄюЁ єцх чрэ Є ўхЁхч getfreea
{
asm_movs(); asm_rname(_rnew); asm_comma(); asm_direct(); asmmangledstr(_const); endasmcmd();
}
PROC emitgetrg(BOOL high) //ЁхушёЄЁ єцх чрэ Є ўхЁхч getrfree
{
emitloadrtemp(0x00,_joined);
asm_ldr(); asm_rname(_rnew); asm_comma(); asm_mrtemp(); endasmcmd(); //todo long
}
PROC emitgetb() //ръъєьєы ЄюЁ єцх чрэ Є ўхЁхч getfreea
{
emitloadrtemp(0x00,_joined);
asm_ldrb(); asm_rname(_rnew); asm_comma(); asm_mrtemp(); endasmcmd();
}
PROC emitputrg(BOOL high) //ld [],new
{
//_jpflag = 0x00;
emitloadrtemp(0x00,_joined);
asm_str(); asm_rname(_rnew); asm_comma(); asm_mrtemp(); endasmcmd(); //todo long
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitputb()
{
//_jpflag = 0x00;
emitloadrtemp(0x00,_joined);
asm_strb(); asm_rname(_rnew); asm_comma(); asm_mrtemp(); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitshl1rg()
{
asm_adds(); asm_rname(_rnew); asm_comma(); asm_rname(_rnew); endasmcmd();
}
PROC emitshl1b()
{
asm_adds(); asm_rname(_rnew); asm_comma(); asm_rname(_rnew); endasmcmd();
emitmaskb(_rnew);
}
/**
PROC emitshr1rg(BYTE rnew)
{
asmstr( "\tSRL " ); asm_rhigh(rnew); endasmcmd();
asmstr( "\tRR " ); asm_rlow(rnew); endasmcmd();
}
PROC emitshr1signedrg(BYTE rnew)
{
asmstr( "\tSRA " ); asm_rhigh(rnew); endasmcmd();
asmstr( "\tRR " ); asm_rlow(rnew); endasmcmd();
}
*/
//PROC emitshr1b(BYTE anew)
//{
// asmstr( "\tSRL " ); /**rganame*/asm_rlow(anew] ); endasmcmd();
//}
PROC emitinvb() //~A -> A
{
asm_eors(); asm_rname(_rnew); asm_comma(); asm_rff(); endasmcmd();
}
PROC emitinvrg()
{
asm_mvns(); asm_rname(_rnew); asm_comma(); asm_rname(_rnew); endasmcmd();
}
PROC emitnegrg()
{
asm_rsbs(); asm_rname(_rnew); asm_comma(); asm_rname(_rnew); asm_comma(); asm_direct(); asmc('0'); endasmcmd();
}
PROC emitSxorVtob() //яюёых subflags (less), ЁрчЁхчхЁтшЁєхЄ A
{ //todo яЁютхЁшЄ№
emit0(_rnew); //схч єёЄрэютъш Їыруют
asm_bgt(); asm_pc4_eol();
asm_eors(); asm_rname(_rnew); asm_comma(); asm_rff(); endasmcmd();
asm_endpc4();
}
PROC emitinvSxorVtob() //яюёых subflags (moreeq), ЁрчЁхчхЁтшЁєхЄ A
{ //todo яЁютхЁшЄ№
//emit0(_rnew); //схч єёЄрэютъш Їыруют
//asm_blt(); asm_pc4_eol();
//asm_eors(); asm_rname(_rnew); asm_comma(); asm_rff(); endasmcmd();
asm_mov(); asm_rname(_rnew); asm_comma(); asm_rff(); endasmcmd();
asm_bgt(); asm_pc4_eol();
asm_eors(); asm_rname(_rnew); asm_comma(); asm_rff(); endasmcmd();
asm_endpc4();
}
PROC emitxorrg() //old^new => old
{
asm_eors(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE; //^^
}
PROC getxorb() //RGA^RGA2 -> RGA
{
asm_eors(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE; //^^
}
PROC emitorrg() //old|new => old
{
asm_ors(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE; //||
}
PROC getorb() //RGA|RGA2 -> RGA
{
asm_ors(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE; //||
}
PROC emitandrg() //old&new => old
{
asm_ands(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE; //&&
}
PROC getandb() //RGA&RGA2 -> RGA
{
asm_ands(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE; //&&
}
PROC emitaddrg() //old+new => old
{
asm_adds(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
}
PROC emitadcrg() //old+new => old
{
asm_adcs(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
}
PROC emitaddb() //old+new
{
asm_adds(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
emitmaskb(_rold);
}
PROC emitaddbconst() //new8+<const>
{
asm_adds(); asm_rname(_rnew); asm_comma(); asm_direct(); asmmangledstr(_const); endasmcmd();
emitmaskb(_rnew);
}
PROC emitsubrg() //old-new => old
{
asm_subs(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
}
PROC emitsbcrg() //old-new => old
{
asm_sbcs(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
}
PROC emitsubb() //old-new
{
asm_subs(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
emitmaskb(_rold);
}
PROC emitsubbconst() //new8-<const>
{
asm_subs(); asm_rname(_rnew); asm_comma(); asm_direct(); asmmangledstr(_const); endasmcmd();
emitmaskb(_rnew);
}
PROC emitsubflags(BYTE rnew, BYTE rold) //r2-r1 => CY,sign,overflow
{
asm_subs(); asm_rname(rold); asm_comma(); asm_rname(rnew); endasmcmd();
_fused = +TRUE;
}
PROC emitsubbflags(BYTE anew, BYTE aold) //a2-a1 => CY
{ //sign,overflow эх эєцхэ!
asm_subs(); asm_rname(aold); asm_comma(); asm_rname(anew); endasmcmd();
_fused = +TRUE;
}
PROC emitsubz() //old-new => Z
{
asm_subs(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE;
}
PROC emitsubbz() //old-new => Z
{
asm_subs(); asm_rname(_rold); asm_comma(); asm_rname(_rnew); endasmcmd();
_fused = +TRUE;
}
PROC emitsubbzconst() //new-<const> => Z
{
asm_subs(); asm_rname(_rnew); asm_comma(); asm_direct(); asmmangledstr(_const); endasmcmd();
_fused = +TRUE;
}
PROC emitsublongz() //old2-new, old3-old => Z
{ //todo
_fused = +TRUE;
}
PROC emitpokerg() //эютюх чряшё√трхь т ёЄрЁє■ ыюърЎш■ ярь Єш
{
asm_str(); asm_rname(_rnew); asm_comma(); asm_mrname(_rold); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitpokeb() //эютюх чряшё√трхь т ёЄрЁє■ ыюърЎш■ ярь Єш
{
asm_strb(); asm_rname(_rnew); asm_comma(); asm_mrname(_rold); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitpokelong() //old2(addr), old(high), new(low)
{
asm_str(); asm_rname(_rnew); asm_comma(); asm_mrname(_rold2); endasmcmd();
asm_adds(); asm_rname(_rold2); asm_comma(); asmstr("#4"); endasmcmd();
asm_str(); asm_rname(_rold); asm_comma(); asm_mrname(_rold2); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitpeekrg() //[new] => new
{
asm_ldr(); asm_rname(_rnew); asm_comma(); asm_mrname(_rnew); endasmcmd();
}
PROC emitpeekb()
{
asm_ldrb(); asm_rname(_rnew); asm_comma(); asm_mrname(_rnew); endasmcmd();
}
PROC emitpeeklong() //[old] => old(high),new(low)
{
asm_ldr(); asm_rname(_rnew); asm_comma(); asm_mrname(_rold); endasmcmd();
asm_adds(); asm_rname(_rold); asm_comma(); asmstr("#4"); endasmcmd();
asm_ldr(); asm_rname(_rold); asm_comma(); asm_mrname(_rold); endasmcmd();
}
PROC emitztob()
{
//asmstr(";emitztoa exprlvl="); asmuint(_exprlvl); endasmcmd();
IF (_exprlvl != 0x01) { //if (a == b)
emit0(_rnew); //схч єёЄрэютъш Їыруют
asm_bne(); asm_pc4_eol();
emitinvb();
asm_endpc4();
_fused = +FALSE; //шэрўх уы■ъ яЁш if ((a==b))
//_jpflag = 0x00;
}ELSE {
//_fused = +TRUE;
_jpflag = 0x02;
};
}
PROC emitinvztob()
{
//asmstr(";emitinvztoa exprlvl="); asmuint(_exprlvl); endasmcmd();
IF (_exprlvl != 0x01) { //if (a != b)
emit0(_rnew); //схч єёЄрэютъш Їыруют
asm_beq(); asm_pc4_eol();
emitinvb();
asm_endpc4();
_fused = +FALSE; //шэрўх уы■ъ яЁш if ((a!=b))? todo test //тючьюцхэ уы■ъ ifnot ((a!=b))
//_jpflag = 0x00;
}ELSE {
//_fused = +TRUE;
_jpflag = 0x01;
};
}
PROC emitcytob()
{
//asmstr(";emitcytoa exprlvl="); asmuint(_exprlvl); endasmcmd();
IF (_exprlvl != 0x01) { //if (a < b)
asm_sbcs(); asm_rname(_rnew); asm_comma(); asm_rname(_rnew); endasmcmd();
//_fused = +FALSE;
//_jpflag = 0x00;
}ELSE {
//_fused = +TRUE;
_jpflag = 0x03;
};
}
PROC emitinvcytob()
{
//asmstr(";emitinvcytoa exprlvl="); asmuint(_exprlvl); endasmcmd();
IF (_exprlvl != 0x01) { //if (a >= b)
asm_sbcs(); asm_rname(_rnew); asm_comma(); asm_rname(_rnew); endasmcmd();
asm_eors(); asm_rname(_rnew); asm_comma(); asm_rff(); endasmcmd();
//_fused = +FALSE;
//_jpflag = 0x00;
}ELSE {
//_fused = +TRUE;
_jpflag = 0x04;
};
}
PROC emitrgtob() //эхы№ч єсшЁрЄ№ - ёяхЎшЇшўэю
{
emitmaskb(_rnew); //todo эрюсюЁюЄ, шуэюЁшЁютрЄ№ ёЄ.ўрёЄ№ ёыютр, ъЁюьх ёЁртэхэшщ
}
PROC emitbtorg()
{
}
PROC emitincrg_byname()
{
emitloadrtemp(_rnew,_joined);
asm_ldr(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
asm_adds(); asm_rtemp(); asm_comma(); asmstr("#1"); endasmcmd();
asm_str(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
//asm_adds(); asm_rname(_rnew); asm_comma(); asm_direct(); asmc('1'); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitincb_bypoi()
{
asm_ldrb(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
asm_adds(); asm_rtemp(); asm_comma(); asmstr("#1"); endasmcmd();
asm_strb(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
/**
PROC emitinclong() //todo
{
asm_inc(); asm_open(); asm_rname(_rnew); asm_close(); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
*/
PROC emitdecrg_byname()
{
emitloadrtemp(_rnew,_joined);
asm_ldr(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
asm_subs(); asm_rtemp(); asm_comma(); asmstr("#1"); endasmcmd();
asm_str(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
//asm_subs(); asm_rname(_rnew); asm_comma(); asmstr("#1"); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitdecb_bypoi()
{
asm_ldrb(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
asm_subs(); asm_rtemp(); asm_comma(); asmstr("#1"); endasmcmd();
asm_strb(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
/**
PROC emitdeclong() //todo
{
asm_dec(); asm_open(); asm_rname(_rnew); asm_close(); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
*/
PROC emitincrg_bypoi() //[old], new free
{
asm_ldr(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
asm_adds(); asm_rtemp(); asm_comma(); asmstr("#1"); endasmcmd();
asm_str(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
PROC emitdecrg_bypoi() //[old], new free
{
asm_ldr(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
asm_subs(); asm_rtemp(); asm_comma(); asmstr("#1"); endasmcmd();
asm_str(); asm_rtemp(); asm_comma(); asm_mrname(_rnew); endasmcmd();
_fused = +FALSE; //ъюэхЎ т√ўшёыхэш
}
/////////////
EXPORT PROC initcode()
{
// _wass = (PCHAR)_swass;
_jpflag = 0x00;
constindex = 0;
asmcmds = 0;
asmstr("\tALIGN 2"); endasm();
}
EXPORT PROC endcode()
{
asmflushlabels();
asmstr("\tEND"); endasmcmd();
varstr("\tEND"); endvar();
}
PROC initrgs()
{
rgs_initrgs();
_fused = +FALSE; //ьюцэю ёфхырЄ№ юфэє яЁюЎхфєЁє initif фы ¤Єюую (т√ч√трЄ№ т эрўрых if, while, until)
}
PROC emitfunchead()
{
asm_push(); asmstr( "{LR}" ); endasmcmd();
initrgs();
}
PROC setmainb()
{
setmainrg(); //Ёхчєы№ЄрЄ т RMAIN
}
PROC prefernoregs()
{
}