File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,8 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
6969        return ;
7070    case  OP_read :
7171    case  OP_write :
72+     case  OP_push :
73+     case  OP_pop :
7274    case  OP_jump :
7375    case  OP_call :
7476    case  OP_load_func :
@@ -284,6 +286,12 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
284286        else 
285287            abort ();
286288        return ;
289+     case  OP_push :
290+         emit (__stmdb (__AL , 1 , __sp , rn ));
291+         return ;
292+     case  OP_pop :
293+         emit (__add_i (__AL , __sp , __sp , rn  *  4 ));
294+         return ;
287295    case  OP_branch :
288296        emit (__teq (rn ));
289297        if  (ph2_ir -> is_branch_detached ) {
Original file line number Diff line number Diff line change @@ -268,6 +268,7 @@ typedef enum {
268268    OP_call ,     /* function call */ 
269269    OP_indirect , /* indirect call with function pointer */ 
270270    OP_return ,   /* explicit return */ 
271+     OP_pop ,      /* eliminate arguments */ 
271272
272273    OP_allocat , /* allocate space on stack */ 
273274    OP_assign ,
Original file line number Diff line number Diff line change @@ -768,12 +768,29 @@ void reg_alloc(void)
768768                    if  (!callee_func -> num_params )
769769                        spill_alive (bb , insn );
770770
771-                     if  (dynlink )
771+                     if  (dynlink ) { 
772772                        callee_func -> is_used  =  true;
773+                         /* Push args to stack for Arm output */ 
774+                         if  (!callee_func -> bbs  &&  args  >  4 ) {
775+                             int  regs  =  0 ;
776+                             for  (int  i  =  4 ; i  <  args ; i ++ )
777+                                 regs  |= (1  << i );
778+                             ir  =  bb_add_ph2_ir (bb , OP_push );
779+                             ir -> src0  =  regs ;
780+                         }
781+                     }
773782
774783                    ir  =  bb_add_ph2_ir (bb , OP_call );
775784                    strcpy (ir -> func_name , insn -> str );
776785
786+                     if  (dynlink ) {
787+                         /* Pop args from stack for Arm output */ 
788+                         if  (!callee_func -> bbs  &&  args  >  4 ) {
789+                             ir  =  bb_add_ph2_ir (bb , OP_pop );
790+                             ir -> src0  =  args  -  4 ;
791+                         }
792+                     }
793+ 
777794                    is_pushing_args  =  false;
778795                    args  =  0 ;
779796
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments