dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/codegen cg_varusage.c,NONE,1.1 cg_varusa


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/codegen cg_varusage.c,NONE,1.1 cg_varusage.h,NONE,1.1 cg_gen.h,1.32,1.33 cg_nodes.tc,1.71,1.72
Date: Wed, 27 Nov 2002 06:13:38 -0500

Update of /cvsroot/dotgnu-pnet/pnet/codegen
In directory subversions:/tmp/cvs-serv2815/codegen

Modified Files:
        cg_gen.h cg_nodes.tc 
Added Files:
        cg_varusage.c cg_varusage.h 
Log Message:
support code for flow analysis


--- NEW FILE ---
/*
 * cg_varusage.c - Variable tracking functions
 *
 * Copyright (C) 2002  Free Software Foundation, Inc.
 *
 * Contributed by Gopal. V
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "cg_nodes.h"
#include "cg_varusage.h"

#ifdef  __cplusplus
extern  "C" {
#endif

ILVarUsageTable ILVarUsageTableDefault={0,{0,0,0,0,0,0,0,0},0};
                
ILVarUsageTable* ILVarUsageTableCreate(ILGenInfo *info,
                                                                                
ILVarUsageTable *previous)
{
        ILVarUsageTable* retval=(ILVarUsageTable*)(ILCalloc(1,sizeof(
                                                                                
ILVarUsageTable)));
        retval->modified__=0;
        if(previous)
        {
                ILMemCpy(retval->vars__, 
previous->vars__,sizeof(previous->vars__));
                if(previous->next__)
                {
                        
retval->next__=ILVarUsageTableCreate(info,previous->next__);
                }
                else
                {
                        retval->next__=NULL;
                }
        }
        return retval;
}

void ILVarUsageTableDestroy(ILGenInfo *info, ILVarUsageTable* table)
{
        if(!table) return;
        if(table->next__) ILVarUsageTableDestroy(info,table->next__);
        ILFree(table);
}

/* merging two branches to the same location */
ILVarUsageTable* ILVarUsageTableMerge(ILGenInfo *info,
                                        ILVarUsageTable *table1,
                                        ILVarUsageTable *table2)
{
        int i;
        ILVarUsageTable* retval;
        if(table1==NULL)return ILVarUsageTableCreate(info,table2);
        if(table2==NULL)return ILVarUsageTableCreate(info,table1);
        retval=(ILVarUsageTable*)(ILCalloc(1,sizeof(
                                                                                
ILVarUsageTable)));
        retval->modified__=0;
        for(i=0;i<IL_VAR_BLOCK_SIZE;i++)
        {
                retval->vars__[i]=(table1->vars__[i] & table2->vars__[i]);
        }
        if(table1->next__ && table2->next__)
        {
                retval->next__ = ILVarUsageTableMerge(info,table1->next__,
                                                                table2->next__);
        }
        return retval;
}

void ILVarUsageSetVariable(ILGenInfo *info,
                                        ILVarUsageTable *table,
                                        int localVar,
                                        int status)
{
        int i;
        int extra_blocks= localVar / IL_VAR_BLOCK_SIZE; 
        for(i=0;i<extra_blocks;i++)
        {
                table->next__=ILVarUsageTableCreate(info,NULL);
                table=table->next__;
        }
        table->vars__[localVar % IL_VAR_BLOCK_SIZE] |= status;  
}

int ILVarUsageGetVariable(ILGenInfo *info,
                                        ILVarUsageTable *table,
                                        int localVar)
{
        int i;
        int extra_blocks= localVar / IL_VAR_BLOCK_SIZE; 
        for(i=0;i<extra_blocks;i++)
        {
                table=table->next__;
                if(table==NULL)
                {
                        return 0;
                }
        }
        return table->vars__[localVar % IL_VAR_BLOCK_SIZE];     
}

void ILVarUsageClearVariable(ILGenInfo *info,
                                        ILVarUsageTable *table,
                                        int localVar)
{
        int i;
        int extra_blocks= localVar / IL_VAR_BLOCK_SIZE; 
        for(i=0;i<extra_blocks;i++)
        {
                table=table->next__;
                if(table==NULL)
                {
                        return;
                }
        }
        table->vars__[localVar % IL_VAR_BLOCK_SIZE] = 0;        
}



#ifdef  __cplusplus
};
#endif

--- NEW FILE ---
/*
 * cg_varusage.h - Variable tracking functions.
 * 
 * Copyright (C) 2002  Free Software Foundation, Inc.
 *
 * Contributed by Gopal. V
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _CODEGEN_CG_VARUSAGE_H
#define _CODEGEN_CG_VARUSAGE_H

#ifdef  __cplusplus
extern  "C" {
#endif

#define IL_VAR_BLOCK_SIZE 32
                
struct _tagILVarUsageTable
{
        int modified__;
        char vars__[IL_VAR_BLOCK_SIZE]; /* 8 ints */
        struct _tagILVarUsageTable *next__;
};

#define IL_VAR_STATUS_UNDEF             0
#define IL_VAR_STATUS_DECLARED          1 
#define IL_VAR_STATUS_USED                      (1 << 1)
#define IL_VAR_STATUS_MODIFIED          (1 << 2)

typedef struct _tagILVarUsageTable ILVarUsageTable;

extern ILVarUsageTable ILVarUsageTableDefault;

/* create a table cloned from the previous table , a NULL parent
 * creates a clear table */
ILVarUsageTable* ILVarUsageTableCreate(ILGenInfo *info,
                                                                                
ILVarUsageTable *previous);

/* recursively free all entries in the table */
void ILVarUsageTableDestroy(ILGenInfo *info, ILVarUsageTable* table);

/* merging two branches to the same location */
ILVarUsageTable* ILVarUsageTableMerge(ILGenInfo *info,
                                        ILVarUsageTable *table1,
                                        ILVarUsageTable *table2);

/* update variable status to the value */
void ILVarUsageSetVariable(ILGenInfo *info,
                                        ILVarUsageTable *table,
                                        int localVar,
                                        int status);

int ILVarUsageGetVariable(ILGenInfo *info,
                                        ILVarUsageTable *table,
                                        int localVar);

/* clear variable when it goes out of scope */
void ILVarUsageClearVariable(ILGenInfo *info,
                                        ILVarUsageTable *table,
                                        int localVar);
#ifdef  __cplusplus
};
#endif

#endif  /* _CODEGEN_CG_VARUSAGE_H */

Index: cg_gen.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_gen.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -r1.32 -r1.33
*** cg_gen.h    20 Nov 2002 11:36:53 -0000      1.32
--- cg_gen.h    27 Nov 2002 11:13:32 -0000      1.33
***************
*** 138,141 ****
--- 138,142 ----
        ILArrayInit    *arrayInit;                      /* Array initialization 
information */
        ILHashTable    *itemHash;                       /* Hash program items 
to nodes */
+       ILVarUsageTable *varUsage;                      /* Variable usage table 
*/
  
  };

Index: cg_nodes.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/codegen/cg_nodes.tc,v
retrieving revision 1.71
retrieving revision 1.72
diff -C2 -r1.71 -r1.72
*** cg_nodes.tc 21 Nov 2002 05:25:38 -0000      1.71
--- cg_nodes.tc 27 Nov 2002 11:13:32 -0000      1.72
***************
*** 27,30 ****
--- 27,31 ----
  
  #include <codegen/cg_defs.h>
+ #include <codegen/cg_varusage.h>
  
  typedef struct _tagILEvalValue ILEvalValue;
***************
*** 33,36 ****
--- 34,38 ----
  
  %decls %end %{
+ #include <codegen/cg_varusage.h>
  #include <codegen/cg_gen.h>
  #include <codegen/cg_output.h>
***************
*** 197,201 ****
        ILNode *expr3;
  }
! %node ILNode_Statement ILNode %abstract
  %node ILNode_List ILNode_Statement =
  {
--- 199,206 ----
        ILNode *expr3;
  }
! %node ILNode_Statement ILNode %abstract =
! {
!       %nocreate ILVarUsageTable *varUsage = {0};
! }
  %node ILNode_List ILNode_Statement =
  {
***************
*** 976,979 ****
--- 981,985 ----
                                (ILNode_LValue *node, ILGenInfo *info);
  %operation %virtual int ILNode_EndsInReturnImpl(ILNode *node);
+ 
  
  /*





reply via email to

[Prev in Thread] Current Thread [Next in Thread]