summaryrefslogtreecommitdiff
path: root/ortho
diff options
context:
space:
mode:
Diffstat (limited to 'ortho')
-rw-r--r--ortho/mcode/Makefile2
-rw-r--r--ortho/mcode/binary_file.adb1
-rw-r--r--ortho/mcode/elf_common.ads1
-rw-r--r--ortho/mcode/memsegs_c.c19
-rw-r--r--ortho/mcode/ortho_code-exprs.adb1
-rw-r--r--ortho/mcode/ortho_code-exprs.ads2
-rw-r--r--ortho/mcode/ortho_code-opts.adb1
-rw-r--r--ortho/mcode/ortho_code-types.adb1
-rw-r--r--ortho/mcode/ortho_code-x86-abi.adb2
-rw-r--r--ortho/mcode/ortho_code-x86-abi.ads2
-rw-r--r--ortho/mcode/ortho_code-x86-emits.adb30
-rw-r--r--ortho/mcode/ortho_code-x86-flags.ads2
-rw-r--r--ortho/mcode/ortho_code-x86-insns.adb104
-rw-r--r--ortho/mcode/ortho_code.ads3
14 files changed, 113 insertions, 58 deletions
diff --git a/ortho/mcode/Makefile b/ortho/mcode/Makefile
index cdec5c4..182397a 100644
--- a/ortho/mcode/Makefile
+++ b/ortho/mcode/Makefile
@@ -11,7 +11,7 @@ memsegs_c.o: $(ortho_srcdir)/mcode/memsegs_c.c
$(CC) -c $(CFLAGS) -o $@ $<
oread: force
- gnatmake -m -o $@ -g $(GNAT_FLAGS) -aI../oread ortho_code_main -aI..
+ gnatmake -m -o $@ -g $(GNAT_FLAGS) -aI../oread ortho_code_main -aI.. -largs memsegs_c.o
elfdump: force
gnatmake -m -g $(GNAT_FLAGS) $@
diff --git a/ortho/mcode/binary_file.adb b/ortho/mcode/binary_file.adb
index 58c5a79..488aac8 100644
--- a/ortho/mcode/binary_file.adb
+++ b/ortho/mcode/binary_file.adb
@@ -111,6 +111,7 @@ package body Binary_File is
begin
return Get_Scope (Sym) /= Sym_Undef;
end S_Defined;
+ pragma Unreferenced (S_Defined);
function S_Local (Sym : Symbol) return Boolean is
begin
diff --git a/ortho/mcode/elf_common.ads b/ortho/mcode/elf_common.ads
index c53cd48..28186d0 100644
--- a/ortho/mcode/elf_common.ads
+++ b/ortho/mcode/elf_common.ads
@@ -16,7 +16,6 @@
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-- 02111-1307, USA.
with Interfaces; use Interfaces;
-with System;
package Elf_Common is
subtype Elf_Half is Unsigned_16;
diff --git a/ortho/mcode/memsegs_c.c b/ortho/mcode/memsegs_c.c
index a35d695..c311423 100644
--- a/ortho/mcode/memsegs_c.c
+++ b/ortho/mcode/memsegs_c.c
@@ -28,17 +28,21 @@
set rights.
*/
+#ifdef __APPLE__
+#define MAP_ANONYMOUS MAP_ANON
+#else
+#define HAVE_MREMAP
+#endif
+
void *
mmap_malloc (int size)
{
void *res;
res = mmap (NULL, size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
/* printf ("mmap (%d) = %p\n", size, res); */
-#if 0
if (res == MAP_FAILED)
return NULL;
-#endif
return res;
}
@@ -46,7 +50,16 @@ void *
mmap_realloc (void *ptr, int old_size, int size)
{
void *res;
+#ifdef HAVE_MREMAP
res = mremap (ptr, old_size, size, MREMAP_MAYMOVE);
+#else
+ res = mmap (NULL, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (res == MAP_FAILED)
+ return NULL;
+ memcpy (res, ptr, old_size);
+ munmap (ptr, old_size);
+#endif
/* printf ("mremap (%p, %d, %d) = %p\n", ptr, old_size, size, res); */
#if 0
if (res == MAP_FAILED)
diff --git a/ortho/mcode/ortho_code-exprs.adb b/ortho/mcode/ortho_code-exprs.adb
index b8da44c..0724bcc 100644
--- a/ortho/mcode/ortho_code-exprs.adb
+++ b/ortho/mcode/ortho_code-exprs.adb
@@ -251,6 +251,7 @@ package body Ortho_Code.Exprs is
begin
return Enodes.Table (Stmt).Arg1;
end Get_BB_Next;
+ pragma Unreferenced (Get_BB_Next);
procedure Set_BB_Next (Stmt : O_Enode; Next : O_Enode) is
begin
diff --git a/ortho/mcode/ortho_code-exprs.ads b/ortho/mcode/ortho_code-exprs.ads
index ffff28e..0ac6cee 100644
--- a/ortho/mcode/ortho_code-exprs.ads
+++ b/ortho/mcode/ortho_code-exprs.ads
@@ -111,6 +111,8 @@ package Ortho_Code.Exprs is
-- ARG1 is subprogram
-- ARG2 is arguments.
OE_Call,
+ -- ARG1 is the subprogram.
+ OE_Setup_Frame,
-- ARG1 is intrinsic operation.
OE_Intrinsic,
diff --git a/ortho/mcode/ortho_code-opts.adb b/ortho/mcode/ortho_code-opts.adb
index 75fedd0..83071b4 100644
--- a/ortho/mcode/ortho_code-opts.adb
+++ b/ortho/mcode/ortho_code-opts.adb
@@ -120,6 +120,7 @@ package body Ortho_Code.Opts is
end case;
end loop;
end Get_Fall_Stmt;
+ pragma Unreferenced (Get_Fall_Stmt);
procedure Thread_Jump (Subprg : Subprogram_Data_Acc)
is
diff --git a/ortho/mcode/ortho_code-types.adb b/ortho/mcode/ortho_code-types.adb
index 446fde6..fda7a21 100644
--- a/ortho/mcode/ortho_code-types.adb
+++ b/ortho/mcode/ortho_code-types.adb
@@ -645,6 +645,7 @@ package body Ortho_Code.Types is
null;
end case;
end Disp_Type;
+ pragma Unreferenced (Disp_Type);
procedure Mark (M : out Mark_Type) is
begin
diff --git a/ortho/mcode/ortho_code-x86-abi.adb b/ortho/mcode/ortho_code-x86-abi.adb
index 0087bb1..5456235 100644
--- a/ortho/mcode/ortho_code-x86-abi.adb
+++ b/ortho/mcode/ortho_code-x86-abi.adb
@@ -36,6 +36,7 @@ package body Ortho_Code.X86.Abi is
is
pragma Unreferenced (Subprg);
begin
+ -- First argument is at %ebp + 8
Abi.Offset := 8;
end Start_Subprogram;
@@ -59,6 +60,7 @@ package body Ortho_Code.X86.Abi is
begin
Set_Decl_Info (Subprg,
To_Int32 (Create_Symbol (Get_Decl_Ident (Subprg))));
+ -- Offset is 8 biased.
Set_Subprg_Stack (Subprg, Abi.Offset - 8);
end Finish_Subprogram;
diff --git a/ortho/mcode/ortho_code-x86-abi.ads b/ortho/mcode/ortho_code-x86-abi.ads
index 613e37b..d130042 100644
--- a/ortho/mcode/ortho_code-x86-abi.ads
+++ b/ortho/mcode/ortho_code-x86-abi.ads
@@ -34,7 +34,7 @@ package Ortho_Code.X86.Abi is
Mode_B2 => 0);
Mode_Ptr : constant Mode_Type := Mode_P32;
-
+
-- Procedures to layout a subprogram declaration.
procedure Start_Subprogram (Subprg : O_Dnode; Abi : out O_Abi_Subprg);
procedure New_Interface (Inter : O_Dnode; Abi : in out O_Abi_Subprg);
diff --git a/ortho/mcode/ortho_code-x86-emits.adb b/ortho/mcode/ortho_code-x86-emits.adb
index 85327fd..3f71f87 100644
--- a/ortho/mcode/ortho_code-x86-emits.adb
+++ b/ortho/mcode/ortho_code-x86-emits.adb
@@ -767,17 +767,39 @@ package body Ortho_Code.X86.Emits is
End_Insn;
end Gen_Call;
+ procedure Emit_Setup_Frame (Stmt : O_Enode)
+ is
+ use Ortho_Code.Decls;
+ Subprg : O_Dnode;
+ Val : Unsigned_32;
+ begin
+ Subprg := Get_Call_Subprg (Stmt);
+ Val := Unsigned_32 (Get_Subprg_Stack (Subprg));
+ -- Pad the stack if necessary.
+ Val := Val and (Flags.Stack_Boundary - 1);
+ if Val /= 0 then
+ Start_Insn;
+ -- subl esp, val
+ Gen_B8 (2#100000_11#);
+ Gen_B8 (2#11_101_100#);
+ Gen_B8 (Byte (Flags.Stack_Boundary - Val));
+ End_Insn;
+ end if;
+ end Emit_Setup_Frame;
+
procedure Emit_Call (Stmt : O_Enode)
is
use Ortho_Code.Decls;
Subprg : O_Dnode;
Sym : Symbol;
- Val : Int32;
+ Val : Unsigned_32;
begin
Subprg := Get_Call_Subprg (Stmt);
Sym := Get_Decl_Symbol (Subprg);
Gen_Call (Sym);
- Val := Get_Subprg_Stack (Subprg);
+ Val := Unsigned_32 (Get_Subprg_Stack (Subprg));
+ Val := (Val + Flags.Stack_Boundary - 1)
+ and not (Flags.Stack_Boundary - 1);
if Val /= 0 then
Start_Insn;
if Val <= 127 then
@@ -1819,6 +1841,10 @@ package body Ortho_Code.X86.Emits is
when others =>
Error_Emit ("emit_insn: oe_arg", Stmt);
end case;
+ when OE_Setup_Frame =>
+ if Flags.Stack_Boundary > 4 then
+ Emit_Setup_Frame (Stmt);
+ end if;
when OE_Call =>
Emit_Call (Stmt);
when OE_Intrinsic =>
diff --git a/ortho/mcode/ortho_code-x86-flags.ads b/ortho/mcode/ortho_code-x86-flags.ads
index 44179a4..699a38c 100644
--- a/ortho/mcode/ortho_code-x86-flags.ads
+++ b/ortho/mcode/ortho_code-x86-flags.ads
@@ -24,5 +24,5 @@ package Ortho_Code.X86.Flags is
-- Prefered stack alignment.
-- Must be a power of 2.
- Stack_Boundary : Unsigned_32 := 2 ** 3;
+ Stack_Boundary : Unsigned_32 := 2 ** 3; -- 4 for MacOSX, 3 for Linux
end Ortho_Code.X86.Flags;
diff --git a/ortho/mcode/ortho_code-x86-insns.adb b/ortho/mcode/ortho_code-x86-insns.adb
index cc83afa..bfd1635 100644
--- a/ortho/mcode/ortho_code-x86-insns.adb
+++ b/ortho/mcode/ortho_code-x86-insns.adb
@@ -911,6 +911,59 @@ package body Ortho_Code.X86.Insns is
-- end;
end Gen_Conv_From_Fp_Insn;
+ function Gen_Call (Stmt : O_Enode; Reg : O_Reg; Pnum : O_Inum)
+ return O_Enode
+ is
+ Left : O_Enode;
+ Reg_Res : O_Reg;
+ begin
+ Link_Stmt
+ (New_Enode (OE_Setup_Frame, Mode_Nil, O_Tnode_Null,
+ O_Enode (Get_Call_Subprg (Stmt)), O_Enode_Null));
+ Left := Get_Arg_Link (Stmt);
+ if Left /= O_Enode_Null then
+ -- Generate code for arguments.
+ Left := Gen_Insn (Left, R_None, Pnum);
+ end if;
+
+ -- Clobber registers.
+ Clobber_R32 (R_Ax);
+ Clobber_R32 (R_Dx);
+ Clobber_R32 (R_Cx);
+ -- FIXME: fp regs.
+
+ Reg_Res := Get_Call_Register (Get_Expr_Mode (Stmt));
+ Set_Expr_Reg (Stmt, Reg_Res);
+ Link_Stmt (Stmt);
+
+ case Reg is
+ when R_Any32
+ | R_Any64
+ | R_Any8
+ | R_Irm
+ | R_Rm
+ | R_Ir
+ | R_Sib
+ | R_Ax
+ | R_St0
+ | R_Edx_Eax =>
+ Reg_Res := Alloc_Reg (Reg_Res, Stmt, Pnum);
+ return Stmt;
+ when R_Any_Cc =>
+ -- Move to register.
+ -- (use the 'test' instruction).
+ Alloc_Cc (Stmt, Pnum);
+ return Insert_Move (Stmt, R_Ne);
+ when R_None =>
+ if Reg_Res /= R_None then
+ raise Program_Error;
+ end if;
+ return Stmt;
+ when others =>
+ Error_Gen_Insn (Stmt, Reg);
+ end case;
+ end Gen_Call;
+
function Gen_Insn (Stmt : O_Enode; Reg : O_Reg; Pnum : O_Inum)
return O_Enode
is
@@ -1692,48 +1745,7 @@ package body Ortho_Code.X86.Insns is
Free_Insn_Regs (Left);
return Stmt;
when OE_Call =>
- Left := Get_Arg_Link (Stmt);
- if Left /= O_Enode_Null then
- -- Generate code for arguments.
- Left := Gen_Insn (Left, R_None, Pnum);
- end if;
-
- -- Clobber registers.
- Clobber_R32 (R_Ax);
- Clobber_R32 (R_Dx);
- Clobber_R32 (R_Cx);
- -- FIXME: fp regs.
-
- Reg_Res := Get_Call_Register (Get_Expr_Mode (Stmt));
- Set_Expr_Reg (Stmt, Reg_Res);
- Link_Stmt (Stmt);
-
- case Reg is
- when R_Any32
- | R_Any64
- | R_Any8
- | R_Irm
- | R_Rm
- | R_Ir
- | R_Sib
- | R_Ax
- | R_St0
- | R_Edx_Eax =>
- Reg_Res := Alloc_Reg (Reg_Res, Stmt, Pnum);
- return Stmt;
- when R_Any_Cc =>
- -- Move to register.
- -- (use the 'test' instruction).
- Alloc_Cc (Stmt, Pnum);
- return Insert_Move (Stmt, R_Ne);
- when R_None =>
- if Reg_Res /= R_None then
- raise Program_Error;
- end if;
- return Stmt;
- when others =>
- Error_Gen_Insn (Stmt, Reg);
- end case;
+ return Gen_Call (Stmt, Reg, Pnum);
when OE_Case_Expr =>
Left := Get_Expr_Operand (Stmt);
Set_Expr_Reg (Stmt, Alloc_Reg (Get_Expr_Reg (Left), Stmt, Pnum));
@@ -1823,13 +1835,7 @@ package body Ortho_Code.X86.Insns is
when OE_Leave =>
Link_Stmt (Stmt);
when OE_Call =>
- Left := Get_Arg_Link (Stmt);
- if Left /= O_Enode_Null then
- -- Generate code for arguments.
- Left := Gen_Insn (Left, R_None, Num);
- end if;
- Set_Expr_Reg (Stmt, R_None);
- Link_Stmt (Stmt);
+ Link_Stmt (Gen_Call (Stmt, R_None, Num));
when OE_Ret =>
Left := Get_Expr_Operand (Stmt);
P_Reg := Get_Call_Register (Get_Expr_Mode (Stmt));
diff --git a/ortho/mcode/ortho_code.ads b/ortho/mcode/ortho_code.ads
index 404c9be..0657b07 100644
--- a/ortho/mcode/ortho_code.ads
+++ b/ortho/mcode/ortho_code.ads
@@ -28,6 +28,9 @@ package Ortho_Code is
function Shift_Right (L : Uns32; R : Natural) return Uns32;
pragma Import (Intrinsic, Shift_Right);
+ function Shift_Right_Arithmetic (L : Uns32; R : Natural) return Uns32;
+ pragma Import (Intrinsic, Shift_Right_Arithmetic);
+
function Shift_Left (L : Uns32; R : Natural) return Uns32;
pragma Import (Intrinsic, Shift_Left);