📄 cc.pas
字号:
Unit CC;
(*
** CC.H -- Symbol Definitions for Small-C compiler.
*)
Interface
type
integers=array[1..16383] of integer;
pinteger=^integers;
Const
(*
** machine dependent parameters
*)
BPW =2; { bytes per word }
LBPW =1; { log2(BPW) }
SBPC =1; { stack bytes per character }
ERRCODE =7; { op sys return code }
(*
** symbol table format
*)
sIDENT =0; (* "s" prefixed *)
sTYPE =1;
sCLASS =2;
sSIZE =3;
sOFFSET =5;
sNAME =7;
SYMAVG =12;
SYMMAX =16;
(*
** symbol table parameters
*)
NUMLOCS =25;
STARTLOC =0{symtab};
ENDLOC =({symtab+}NUMLOCS*SYMAVG);
NUMGLBS =200;
STARTGLB =ENDLOC;
ENDGLB =(ENDLOC+(NUMGLBS-1)*SYMMAX);
SYMTBSZ =3050; { (NUMLOCS*SYMAVG + NUMGLBS*SYMMAX) }
(*
** system wide name size (for symbols)
*)
NAMESIZE =9;
NAMEMAX =8;
(*
** values for "IDENT"
*)
iLABEL =0; (* "i" prefixed *)
iVARIABLE =1;
iARRAY =2;
iPOINTER =3;
iFUNCTION =4;
(*
** values for "TYPE"
** high order 14 bits give length of object
** low order 2 bits make type unique within length
*)
(* LABEL 0 *)
tCHR = ( 1 shl 2); (* "t" prefixed *)
tINT = (BPW shl 2);
tUCHR =(( 1 shl 2) + 1);
tUINT =((BPW shl 2) + 1);
tUNSIGNED= 1;
(*
** values for "CLASS"
*)
(* LABEL 0 *)
cAUTOMATIC =#1; (* "c" prefixed *)
cSTATIC =#2;
cEXTERNAL =#3;
cAUTOEXT =#4;
(*
** segment types
*)
DATASEG =1;
CODESEG =2;
(*
** "switch" table
*)
SWSIZ =(2*BPW);
SWTABSZ =(90*SWSIZ);
(*
** "while" queue
*)
WQTABSZ =30;
WQSIZ = 3;
WQMAX =({wq+}WQTABSZ-WQSIZ);
(*
** field offsets in "while" queue
*)
WQSP =0;
WQLOOP =1;
WQEXIT =2;
(*
** literal pool
*)
LITABSZ =2000;
LITMAX =(LITABSZ-1);
(*
** input line
*)
LINEMAX =127;
LINESIZE=128;
(*
** entries in staging buffer
*)
STAGESIZE=200;
(*
** macro (#define) pool
*)
MACNBR =300;
MACNSIZE =(MACNBR*(NAMESIZE+2));
MACNEND =({macn+}MACNSIZE);
MACQSIZE =(MACNBR*7);
MACMAX =(MACQSIZE-1);
(*
** statement types
*)
STIF = 1;
STWHILE = 2;
STRETURN = 3;
STBREAK = 4;
STCONT = 5;
STASM = 6;
STEXPR = 7;
STDO = 8;
STFOR = 9;
STSWITCH =10;
STCASE =11;
STDEF =12;
STGOTO =13;
STLABEL =14;
{*
** p-code symbols
**
** legend:
** 1 = primary register (pr in comments)
** 2 = secondary register (sr in comments)
** b = byte
** f = jump on false condition
** l = current literal pool label number
** m = memory reference by label
** n = numeric constant
** p = indirect reference thru pointer in sr
** r = repeated r times
** s = stack frame reference
** u = unsigned
** w = word
** _ (tail) = another p-code completes this one
*}
(* compiler-generated *)
ADD12 = 1; { add sr to pr }
ADDSP = 2; { add to stack pointer }
AND12 = 3; { AND sr to pr }
ANEG1 = 4; { arith negate pr }
ARGCNTn = 5; { pass arg count to function }
ASL12 = 6; { arith shift left sr by pr into pr }
ASR12 = 7; { arith shift right sr by pr into pr }
CALL1 = 8; { call function thru pr }
CALLm = 9; { call function directly }
BYTE_ =10; { define bytes (part 1) }
BYTEn =11; { define byte of value n }
BYTEr0 =12; { define r bytes of value 0 }
COM1 =13; { ones complement pr }
DBL1 =14; { double pr }
DBL2 =15; { double sr }
DIV12 =16; { div pr by sr }
DIV12u =17; { div pr by sr unsigned }
ENTER =18; { set stack frame on function entry }
EQ10f =19; { jump if (pr == 0) is false }
EQ12 =20; { set pr TRUE if (sr == pr) }
GE10f =21; { jump if (pr >= 0) is false }
GE12 =22; { set pr TRUE if (sr >= pr) }
GE12u =23; { set pr TRUE if (sr >= pr) unsigned }
POINT1l =24; { point pr to function's literal pool }
POINT1m =25; { point pr to mem item thru label }
GETb1m =26; { get byte into pr from mem thru label }
GETb1mu =27; { get unsigned byte into pr from mem thru label }
GETb1p =28; { get byte into pr from mem thru sr ptr }
GETb1pu =29; { get unsigned byte into pr from mem thru sr ptr }
GETw1m =30; { get word into pr from mem thru label }
GETw1n =31; { get word of value n into pr }
GETw1p =32; { get word into pr from mem thru sr ptr }
GETw2n =33; { get word of value n into sr }
GT10f =34; { jump if (pr > 0) is false }
GT12 =35; { set pr TRUE if (sr > pr) }
GT12u =36; { set pr TRUE if (sr > pr) unsigned }
WORD_ =37; { define word (part 1) }
WORDn =38; { define word of value n }
WORDr0 =39; { define r words of value 0 }
JMPm =40; { jump to label }
LABm =41; { define label m }
LE10f =42; { jump if (pr <= 0) is false }
LE12 =43; { set pr TRUE if (sr <= pr) }
LE12u =44; { set pr TRUE if (sr <= pr) unsigned }
LNEG1 =45; { logical negate pr }
LT10f =46; { jump if (pr < 0) is false }
LT12 =47; { set pr TRUE if (sr < pr) }
LT12u =48; { set pr TRUE if (sr < pr) unsigned }
MOD12 =49; { modulo pr by sr }
MOD12u =50; { modulo pr by sr unsigned }
MOVE21 =51; { move pr to sr }
MUL12 =52; { multiply pr by sr }
MUL12u =53; { multiply pr by sr unsigned }
NE10f =54; { jump if (pr != 0) is false }
NE12 =55; { set pr TRUE if (sr != pr) }
NEARm =56; { define near pointer thru label }
OR12 =57; { OR sr onto pr }
POINT1s =58; { point pr to stack item }
POP2 =59; { pop stack into sr }
PUSH1 =60; { push pr onto stack }
PUTbm1 =61; { put pr byte in mem thru label }
PUTbp1 =62; { put pr byte in mem thru sr ptr }
PUTwm1 =63; { put pr word in mem thru label }
PUTwp1 =64; { put pr word in mem thru sr ptr }
rDEC1 =65; { dec pr (may repeat) }
REFm =66; { finish instruction with label }
RETURN =67; { restore stack and return }
rINC1 =68; { inc pr (may repeat) }
SUB12 =69; { sub sr from pr }
SWAP12 =70; { swap pr and sr }
SWAP1s =71; { swap pr and top of stack }
SWITCH =72; { find switch case }
XOR12 =73; { XOR pr with sr }
(* optimizer-generated *)
ADD1n = 74; { add n to pr }
ADD21 = 75; { add pr to sr }
ADD2n = 76; { add immediate to sr }
ADDbpn = 77; { add n to mem byte thru sr ptr }
ADDwpn = 78; { add n to mem word thru sr ptr }
ADDm_ = 79; { add n to mem byte/word thru label (part 1) }
COMMAn = 80; { finish instruction with ,n }
DECbp = 81; { dec mem byte thru sr ptr }
DECwp = 82; { dec mem word thru sr ptr }
POINT2m = 83; { point sr to mem thru label }
POINT2m_= 84; { point sr to mem thru label (part 1) }
GETb1s = 85; { get byte into pr from stack }
GETb1su = 86; { get unsigned byte into pr from stack }
GETw1m_ = 87; { get word into pr from mem thru label (part 1) }
GETw1s = 88; { get word into pr from stack }
GETw2m = 89; { get word into sr from mem (label) }
GETw2p = 90; { get word into sr thru sr ptr }
GETw2s = 91; { get word into sr from stack }
INCbp = 92; { inc byte in mem thru sr ptr }
INCwp = 93; { inc word in mem thru sr ptr }
PLUSn = 94; { finish instruction with +n }
POINT2s = 95; { point sr to stack }
PUSH2 = 96; { push sr }
PUSHm = 97; { push word from mem thru label }
PUSHp = 98; { push word from mem thru sr ptr }
PUSHs = 99; { push word from stack }
PUT_m_ =100; { put byte/word into mem thru label (part 1) }
rDEC2 =101; { dec sr (may repeat) }
rINC2 =102; { inc sr (may repeat) }
SUB_m_ =103; { sub from mem byte/word thru label (part 1) }
SUB1n =104; { sub n from pr }
SUBbpn =105; { sub n from mem byte thru sr ptr }
SUBwpn =106; { sub n from mem word thru sr ptr }
PCODES =107; { size of code[] }
Implementation
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -