1-- Mcode back-end for ortho - common definitions. 2-- Copyright (C) 2006 Tristan Gingold 3-- 4-- This program is free software: you can redistribute it and/or modify 5-- it under the terms of the GNU General Public License as published by 6-- the Free Software Foundation, either version 2 of the License, or 7-- (at your option) any later version. 8-- 9-- This program is distributed in the hope that it will be useful, 10-- but WITHOUT ANY WARRANTY; without even the implied warranty of 11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12-- GNU General Public License for more details. 13-- 14-- You should have received a copy of the GNU General Public License 15-- along with this program. If not, see <gnu.org/licenses>. 16with Ada.Unchecked_Conversion; 17 18package Ortho_Code is 19 type Int32 is range -(2 ** 31) .. (2 ** 31) - 1; 20 21 type Uns32 is mod 2 ** 32; 22 23 type Uns64 is mod 2 ** 64; 24 25 function Shift_Right (L : Uns64; R : Natural) return Uns64; 26 function Shift_Right (L : Uns32; R : Natural) return Uns32; 27 pragma Import (Intrinsic, Shift_Right); 28 29 function Shift_Right_Arithmetic (L : Uns32; R : Natural) return Uns32; 30 pragma Import (Intrinsic, Shift_Right_Arithmetic); 31 32 function Shift_Left (L : Uns32; R : Natural) return Uns32; 33 pragma Import (Intrinsic, Shift_Left); 34 35 type O_Tnode is new Int32; 36 for O_Tnode'Size use 32; 37 O_Tnode_Null : constant O_Tnode := 0; 38 O_Tnode_First : constant O_Tnode := 2; 39 40 -- A generic pointer. 41 -- This is used by static chains. 42 O_Tnode_Ptr : constant O_Tnode := 2; 43 44 type O_Cnode is new Int32; 45 for O_Cnode'Size use 32; 46 O_Cnode_Null : constant O_Cnode := 0; 47 48 type O_Dnode is new Int32; 49 for O_Dnode'Size use 32; 50 O_Dnode_Null : constant O_Dnode := 0; 51 O_Dnode_First : constant O_Dnode := 2; 52 53 type O_Enode is new Int32; 54 for O_Enode'Size use 32; 55 O_Enode_Null : constant O_Enode := 0; 56 O_Enode_Err : constant O_Enode := 1; 57 58 type O_Fnode is new Int32; 59 for O_Fnode'Size use 32; 60 O_Fnode_Null : constant O_Fnode := 0; 61 62 type O_Lnode is new Int32; 63 for O_Lnode'Size use 32; 64 O_Lnode_Null : constant O_Lnode := 0; 65 66 type O_Gnode is new Int32; 67 for O_Gnode'Size use 32; 68 O_Gnode_Null : constant O_Gnode := 0; 69 70 type O_Ident is new Int32; 71 O_Ident_Nul : constant O_Ident := 0; 72 73 function To_Int32 is new Ada.Unchecked_Conversion 74 (Source => Uns32, Target => Int32); 75 76 function To_Uns32 is new Ada.Unchecked_Conversion 77 (Source => Int32, Target => Uns32); 78 79 80 -- Specifies the storage kind of a declaration. 81 -- O_STORAGE_EXTERNAL: 82 -- The declaration do not either reserve memory nor generate code, and 83 -- is imported either from an other file or from a later place in the 84 -- current file. 85 -- O_STORAGE_PUBLIC, O_STORAGE_PRIVATE: 86 -- The declaration reserves memory or generates code. 87 -- With O_STORAGE_PUBLIC, the declaration is exported outside of the 88 -- file while with O_STORAGE_PRIVATE, the declaration is local to the 89 -- file. 90 type O_Storage is (O_Storage_External, 91 O_Storage_Public, 92 O_Storage_Private, 93 O_Storage_Local); 94 95 -- Depth of a declaration. 96 -- 0 for top-level, 97 -- 1 for declared in a top-level subprogram 98 type O_Depth is range 0 .. (2 ** 16) - 1; 99 O_Toplevel : constant O_Depth := 0; 100 101 -- BE representation of a register. 102 type O_Reg is mod 256; 103 R_Nil : constant O_Reg := 0; 104 105 type Mode_Type is (Mode_U8, Mode_U16, Mode_U32, Mode_U64, 106 Mode_I8, Mode_I16, Mode_I32, Mode_I64, 107 Mode_X1, Mode_Nil, Mode_F32, Mode_F64, 108 Mode_B2, Mode_Blk, Mode_P32, Mode_P64); 109 110 subtype Mode_Uns is Mode_Type range Mode_U8 .. Mode_U64; 111 subtype Mode_Int is Mode_Type range Mode_I8 .. Mode_I64; 112 subtype Mode_Fp is Mode_Type range Mode_F32 .. Mode_F64; 113 -- Mode_Ptr : constant Mode_Type := Mode_P32; 114 115 type ON_Op_Kind is 116 ( 117 -- Not an operation; invalid. 118 ON_Nil, 119 120 -- Dyadic operations. 121 ON_Add_Ov, -- ON_Dyadic_Op_Kind 122 ON_Sub_Ov, -- ON_Dyadic_Op_Kind 123 ON_Mul_Ov, -- ON_Dyadic_Op_Kind 124 ON_Div_Ov, -- ON_Dyadic_Op_Kind 125 ON_Rem_Ov, -- ON_Dyadic_Op_Kind 126 ON_Mod_Ov, -- ON_Dyadic_Op_Kind 127 128 -- Binary operations. 129 ON_And, -- ON_Dyadic_Op_Kind 130 ON_Or, -- ON_Dyadic_Op_Kind 131 ON_Xor, -- ON_Dyadic_Op_Kind 132 133 -- Monadic operations. 134 ON_Not, -- ON_Monadic_Op_Kind 135 ON_Neg_Ov, -- ON_Monadic_Op_Kind 136 ON_Abs_Ov, -- ON_Monadic_Op_Kind 137 138 -- Comparaisons 139 ON_Eq, -- ON_Compare_Op_Kind 140 ON_Neq, -- ON_Compare_Op_Kind 141 ON_Le, -- ON_Compare_Op_Kind 142 ON_Lt, -- ON_Compare_Op_Kind 143 ON_Ge, -- ON_Compare_Op_Kind 144 ON_Gt -- ON_Compare_Op_Kind 145 ); 146 147 subtype ON_Dyadic_Op_Kind is ON_Op_Kind range ON_Add_Ov .. ON_Xor; 148 subtype ON_Monadic_Op_Kind is ON_Op_Kind range ON_Not .. ON_Abs_Ov; 149 subtype ON_Compare_Op_Kind is ON_Op_Kind range ON_Eq .. ON_Gt; 150 151 Syntax_Error : exception; 152end Ortho_Code; 153