FoxIntermediateCode.SymU 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. MODULE FoxIntermediateCode;
  2. IMPORT Sections := FoxSections, Basic := FoxBasic, SyntaxTree := FoxSyntaxTree, BinaryCode := FoxBinaryCode, Backend := FoxBackend, Streams, Global := FoxGlobal, D := Debugging, ObjectFile;
  3. CONST
  4. Undefined* = 0;
  5. ModeRegister* = 1;
  6. ModeMemory* = 2;
  7. ModeImmediate* = 3;
  8. ModeNumber* = 4;
  9. ModeString* = 5;
  10. ModeRule* = 6;
  11. Undef* = {Undefined};
  12. Imm* = {ModeImmediate};
  13. Reg* = {ModeRegister};
  14. RegMem* = {ModeRegister, ModeMemory};
  15. RegMemImm* = {ModeRegister, ModeMemory, ModeImmediate};
  16. UndefReg* = {Undefined, ModeRegister};
  17. UndefRegMem* = {Undefined, ModeRegister, ModeMemory};
  18. UndefRule* = {Undefined, ModeRule};
  19. Num* = {ModeNumber};
  20. Str* = {ModeString};
  21. Any = {Undefined, ModeRegister, ModeMemory, ModeImmediate};
  22. SignedInteger* = 1;
  23. UnsignedInteger* = 2;
  24. Integer* = {SignedInteger, UnsignedInteger};
  25. Float* = 3;
  26. SameType12* = 0;
  27. SameType23* = 1;
  28. Op1IsDestination* = 2;
  29. Commute23* = 3;
  30. SameSize12* = 4;
  31. Bits8* = 8;
  32. Bits16* = 16;
  33. Bits32* = 32;
  34. Bits64* = 64;
  35. Bits128* = 128;
  36. GeneralPurpose* = 0;
  37. Parameter* = 1;
  38. None* = -1;
  39. SP* = -2;
  40. FP* = -3;
  41. AP* = -4;
  42. LR* = -5;
  43. HwRegister* = -32;
  44. nop* = 0;
  45. mov* = 1;
  46. conv* = 2;
  47. call* = 3;
  48. enter* = 4;
  49. exit* = 5;
  50. leave* = 6;
  51. return* = 7;
  52. result* = 8;
  53. trap* = 9;
  54. br* = 10;
  55. breq* = 11;
  56. brne* = 12;
  57. brge* = 13;
  58. brlt* = 14;
  59. pop* = 15;
  60. push* = 16;
  61. neg* = 17;
  62. not* = 18;
  63. abs* = 19;
  64. mul* = 20;
  65. div* = 21;
  66. mod* = 22;
  67. sub* = 23;
  68. add* = 24;
  69. and* = 25;
  70. or* = 26;
  71. xor* = 27;
  72. shl* = 28;
  73. shr* = 29;
  74. rol* = 30;
  75. ror* = 31;
  76. cas* = 32;
  77. copy* = 33;
  78. fill* = 34;
  79. asm* = 35;
  80. data* = 36;
  81. reserve* = 37;
  82. label* = 38;
  83. special* = 39;
  84. NofOpcodes* = 40;
  85. NotYetCalculatedSize = -2;
  86. TYPE
  87. Type* = RECORD
  88. form-: SHORTINT;
  89. sizeInBits-: INTEGER;
  90. length-: LONGINT;
  91. END;
  92. RegisterClass* = RECORD
  93. class-: SHORTINT;
  94. number-: INTEGER;
  95. END;
  96. Rules* = POINTER TO ARRAY OF Operand;
  97. RegisterMap* = RECORD
  98. register*: LONGINT;
  99. name*: SyntaxTree.SourceCode;
  100. END;
  101. BackendRules* = POINTER TO ARRAY OF RegisterMap;
  102. Operand* = RECORD
  103. mode-: SHORTINT;
  104. type-: Type;
  105. register-: LONGINT;
  106. registerClass-: RegisterClass;
  107. offset-: LONGINT;
  108. intValue-: HUGEINT;
  109. floatValue-: LONGREAL;
  110. symbol-: ObjectFile.Identifier;
  111. symbolOffset-: LONGINT;
  112. resolved*: Sections.Section;
  113. string-: SyntaxTree.SourceCode;
  114. rule-: Rules;
  115. END;
  116. Instruction* = POINTER TO RECORD
  117. opcode-: SHORTINT;
  118. subtype-: SHORTINT;
  119. textPosition-: Basic.Position;
  120. pc-: LONGINT;
  121. scope-: SyntaxTree.Scope;
  122. op1*, op2*, op3*: Operand;
  123. END;
  124. InstructionFormat* = RECORD
  125. name-: ARRAY 16 OF CHAR;
  126. op1-, op2-, op3-: SET;
  127. flags-: SET;
  128. END;
  129. Instructions* = POINTER TO ARRAY OF Instruction;
  130. Section* = OBJECT (Sections.Section)
  131. VAR
  132. instructions-: Instructions;
  133. pc-: LONGINT;
  134. finally-: LONGINT;
  135. resolved-, alias-: BinaryCode.Section;
  136. aliasOffset-: LONGINT;
  137. comments-: Sections.CommentWriter;
  138. sizeInUnits: LONGINT;
  139. exported-: BOOLEAN;
  140. PROCEDURE ^ GetPC(): LONGINT;
  141. PROCEDURE ^ & InitIntermediateSection*(type: SHORTINT; CONST n: Basic.SegmentedName; symbol: SyntaxTree.Symbol; comment: BOOLEAN);
  142. PROCEDURE ^ SetExported*(e: BOOLEAN);
  143. PROCEDURE ^ EnableComments*(enabled: BOOLEAN);
  144. PROCEDURE ^ DeleteComments*;
  145. PROCEDURE ^ SetResolved*(section: BinaryCode.Section);
  146. PROCEDURE ^ SetAlias*(section: BinaryCode.Section; offset: LONGINT);
  147. PROCEDURE ^ SetFinally*(atPc: LONGINT);
  148. PROCEDURE ^ GetSize*(): LONGINT;
  149. PROCEDURE ^ Emit*(instruction: Instruction);
  150. PROCEDURE ^ EmitAt*(at: LONGINT; instruction: Instruction);
  151. PROCEDURE ^ Reset*;
  152. PROCEDURE ^ PatchOperands*(pc: LONGINT; op1, op2, op3: Operand);
  153. PROCEDURE ^ PatchAddress*(pc: LONGINT; symbolOffset: LONGINT);
  154. PROCEDURE ^ SetPC*(at: LONGINT; pc: LONGINT);
  155. PROCEDURE ^ DumpCode*(w: Streams.Writer; from, to: LONGINT);
  156. PROCEDURE ^ Dump*(w: Streams.Writer);
  157. PROCEDURE ^ WriteRaw*(w: Streams.Writer);
  158. END Section;
  159. IntermediateBackend* = OBJECT (Backend.Backend)
  160. VAR
  161. builtinsModuleName-: SyntaxTree.IdentifierString;
  162. PROCEDURE ^ SupportedInstruction*(CONST instr: Instruction; VAR moduleName, procedureName: ARRAY OF CHAR): BOOLEAN;
  163. PROCEDURE ^ SetBuiltinsModuleName*(CONST name: ARRAY OF CHAR);
  164. END IntermediateBackend;
  165. VAR
  166. instructionFormat-: ARRAY NofOpcodes OF InstructionFormat;
  167. int8-, int16-, int32-, int64-, uint8-, uint16-, uint32-, uint64-, float32-, float64-, undef-: Type;
  168. GeneralPurposeRegister-: RegisterClass;
  169. empty: Operand;
  170. PROCEDURE ^ Assert(condition: BOOLEAN; CONST reason: ARRAY OF CHAR);
  171. PROCEDURE ^ NewSection*(list: Sections.SectionList; type: SHORTINT; CONST name: Basic.SegmentedName; syntaxTreeSymbol: SyntaxTree.Symbol; dump: BOOLEAN): Section;
  172. PROCEDURE ^ SameOperand*(CONST left, right: Operand): BOOLEAN;
  173. PROCEDURE ^ CheckOperand*(operand: Operand; opCode, location: LONGINT; VAR message: ARRAY OF CHAR): BOOLEAN;
  174. PROCEDURE ^ CheckInstruction*(instruction: Instruction; VAR message: ARRAY OF CHAR): BOOLEAN;
  175. PROCEDURE ^ DumpRegister*(w: Streams.Writer; registerNumber: LONGINT; CONST registerClass: RegisterClass);
  176. PROCEDURE ^ DumpType*(w: Streams.Writer; type: Type);
  177. PROCEDURE ^ DumpOperand*(w: Streams.Writer; CONST operand: Operand);
  178. PROCEDURE ^ WriteRawOperand*(w: Streams.Writer; CONST operand: Operand);
  179. PROCEDURE ^ TypeEquals*(CONST s1, s2: Type): BOOLEAN;
  180. PROCEDURE ^ OperandEquals*(CONST s1, s2: Operand): BOOLEAN;
  181. PROCEDURE ^ Equals*(CONST i1, i2: Instruction): BOOLEAN;
  182. PROCEDURE ^ WriteRawInstruction*(w: Streams.Writer; CONST instr: Instruction);
  183. PROCEDURE ^ DumpInstruction*(w: Streams.Writer; CONST instr: Instruction);
  184. PROCEDURE ^ InitInstructions;
  185. PROCEDURE ^ InitInstruction*(VAR instr: Instruction; textPosition: Basic.Position; opcode: SHORTINT; CONST op1, op2, op3: Operand);
  186. PROCEDURE ^ InitInstruction2*(VAR instr: Instruction; textPosition: Basic.Position; opcode: SHORTINT; op1, op2: Operand);
  187. PROCEDURE ^ InitInstruction1*(VAR instr: Instruction; textPosition: Basic.Position; opcode: SHORTINT; op1: Operand);
  188. PROCEDURE ^ InitInstruction0*(VAR instr: Instruction; textPosition: Basic.Position; opcode: SHORTINT);
  189. PROCEDURE ^ SetSubType*(VAR instr: Instruction; subType: SHORTINT);
  190. PROCEDURE ^ InitOperand*(VAR op: Operand);
  191. PROCEDURE ^ InitRegister*(VAR op: Operand; type: Type; registerClass: RegisterClass; register: LONGINT);
  192. PROCEDURE ^ Register*(type: Type; registerClass: RegisterClass; register: LONGINT): Operand;
  193. PROCEDURE ^ RegisterOffset*(type: Type; registerClass: RegisterClass; register, offset: LONGINT): Operand;
  194. PROCEDURE ^ AddOffset*(VAR op: Operand; offset: LONGINT);
  195. PROCEDURE ^ SetOffset*(VAR op: Operand; offset: LONGINT);
  196. PROCEDURE ^ SetSymbol*(VAR op: Operand; symbol: Sections.SectionName; fp: Basic.Fingerprint);
  197. PROCEDURE ^ SetScope*(VAR instr: Instruction; scope: SyntaxTree.Scope);
  198. PROCEDURE ^ SetIntValue*(VAR op: Operand; intValue: HUGEINT);
  199. PROCEDURE ^ MakeMemory*(VAR op: Operand; type: Type);
  200. PROCEDURE ^ MakeAddress*(VAR op: Operand; CONST type: Type);
  201. PROCEDURE ^ InitAddress*(VAR op: Operand; type: Type; symbol: Sections.SectionName; fp: Basic.Fingerprint; symbolOffset: LONGINT);
  202. PROCEDURE ^ Address*(type: Type; symbol: Sections.SectionName; fp: Basic.Fingerprint; offset: LONGINT): Operand;
  203. PROCEDURE ^ InitMemory*(VAR op: Operand; type: Type; base: Operand; offset: LONGINT);
  204. PROCEDURE ^ Memory*(type: Type; base: Operand; offset: LONGINT): Operand;
  205. PROCEDURE ^ IsConstantInteger*(CONST op: Operand; VAR value: HUGEINT): BOOLEAN;
  206. PROCEDURE ^ InitImmediate*(VAR op: Operand; type: Type; value: HUGEINT);
  207. PROCEDURE ^ Immediate*(type: Type; value: HUGEINT): Operand;
  208. PROCEDURE ^ InitFloatImmediate*(VAR op: Operand; type: Type; value: LONGREAL);
  209. PROCEDURE ^ FloatImmediate*(type: Type; value: LONGREAL): Operand;
  210. PROCEDURE ^ InitNumber*(VAR op: Operand; value: HUGEINT);
  211. PROCEDURE ^ Number*(value: HUGEINT): Operand;
  212. PROCEDURE ^ InitRule*(VAR op: Operand; rules: Rules);
  213. PROCEDURE ^ InitString*(VAR op: Operand; string: SyntaxTree.SourceCode);
  214. PROCEDURE ^ SetString*(VAR op: Operand; string: POINTER TO ARRAY OF CHAR);
  215. PROCEDURE ^ String*(string: SyntaxTree.SourceCode): Operand;
  216. PROCEDURE ^ InitType*(VAR type: Type; form: SHORTINT; sizeInBits: INTEGER);
  217. PROCEDURE ^ ToVectorType*(VAR type: Type; length: LONGINT);
  218. PROCEDURE ^ IsVectorRegister*(CONST op: Operand): BOOLEAN;
  219. PROCEDURE ^ InitRegisterClass*(VAR registerClass: RegisterClass; class: SHORTINT; number: LONGINT);
  220. PROCEDURE ^ InitParameterRegisterClass*(VAR registerClass: RegisterClass; number: LONGINT);
  221. PROCEDURE ^ NewType*(form: SHORTINT; sizeInBits: INTEGER): Type;
  222. PROCEDURE ^ SetType*(VAR op: Operand; CONST type: Type);
  223. PROCEDURE ^ FindMnemonic*(CONST name: ARRAY OF CHAR): SHORTINT;
  224. PROCEDURE ^ SetRegister*(VAR op: Operand; reg: LONGINT);
  225. PROCEDURE ^ DecimalNumber(ch: CHAR; VAR nr: LONGINT): BOOLEAN;
  226. PROCEDURE ^ Numbers(CONST name: ARRAY OF CHAR; VAR pos: LONGINT; VAR number: LONGINT): BOOLEAN;
  227. PROCEDURE ^ Character(CONST name: ARRAY OF CHAR; VAR pos: LONGINT; char: CHAR): BOOLEAN;
  228. PROCEDURE ^ DenotesRegister*(CONST name: ARRAY OF CHAR; VAR registerClass: RegisterClass; VAR register: LONGINT): BOOLEAN;
  229. PROCEDURE ^ UnsignedIntegerType*(bits: LONGINT): Type;
  230. PROCEDURE ^ SignedIntegerType*(bits: LONGINT): Type;
  231. PROCEDURE ^ FloatType*(bits: LONGINT): Type;
  232. PROCEDURE ^ ToUnsigned*(operand: Operand): Operand;
  233. PROCEDURE ^ DenotesType*(CONST name: ARRAY OF CHAR; VAR type: Type): BOOLEAN;
  234. PROCEDURE ^ GetType*(system: Global.System; type: SyntaxTree.Type): Type;
  235. BEGIN
  236. END FoxIntermediateCode.