Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
wn2c.h
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 #ifndef wn2c_INCLUDED
00037 #define wn2c_INCLUDED
00038 /* ====================================================================
00039  * ====================================================================
00040  *
00041  *
00042  * Revision history:
00043  *  07-Oct-94 - Original Version
00044  *
00045  * Description:
00046  *
00047  *   STATUS: The status of a translation of a WN subtree into C
00048  *           is represented as a collection of flags.  Note that
00049  *           the STATUS_is_lvalue flag can only be returned in 
00050  *           response to CONTEXT_needs_lvalue request.  While
00051  *           a CONTEXT is passed down onto the processing of
00052  *           nested subtrees, the STATUS is passed up.
00053  *
00054  *   WN2C_initialize: This initializes any WN to C translation
00055  *           and must always be called prior to any WN2C_translate()
00056  *           call.
00057  *
00058  *   WN2C_finalize: This finalizes any WN to C translation
00059  *           and should be called after all procesing related
00060  *           to a whirl2c translation is complete.
00061  *
00062  *   WN2C_translate:  Translates a WN subtree into a sequence of C
00063  *           tokens, which are added to the given TOKEN_BUFFER.
00064  *
00065  *   WN2C_translate_structured_types:  Translates all struct/union/class
00066  *           types to C.  Typically, this function is called once prior
00067  *           to a sequence of calls to WN2C_translate.
00068  *
00069  *   WN2C_translate_file_scope_defs: Translates all file-level 
00070  *           variable, function and constant declarations to C.  The
00071  *           Current_Symtab must be set to the global symbol table
00072  *           prior to a call to this function.  Typically, this 
00073  *           function is called once after all calls to 
00074  *           WN2C_translate, since we then have flagged all 
00075  *           referenced entities.
00076  *
00077  *   WN2C_translate_purple_main:  A rather special translation routine,
00078  *           which ignores the body of the given PU, and translates
00079  *           parameters to become local variables.  It inserts a call
00080  *           to a purple region PU, and inserts placeholders for items
00081  *           to be inserted by purple at a later processing stage.
00082  *
00083  *   WN2C_memref_lhs: Given the necessary attributes, translate
00084  *          the lft-hand-side of an ISTORE or the address of
00085  *          an ILOAD into C.
00086  *
00087  *   WN2C_istore_lhs: Given the necessary attributes, translate
00088  *          the lft-hand-side of an STID statement into C.
00089  *
00090  * ====================================================================
00091  * ====================================================================
00092  */
00093 
00094     /* ---------- Result status of a WN to C translation ----------- */
00095 
00096 typedef mUINT32 STATUS;
00097 
00098 /* Status flags and their access macros */
00099 #define EMPTY_STATUS            0x000000000  
00100 #define STATUS_LVALUE           0x000000001
00101                                   /* Subexpression evaluated to an lvalue */
00102 #define STATUS_ARRAY_AS_ADDRESS 0x000000002
00103                                   /* Subexpression evaluated to array value */
00104 #define STATUS_BLOCK            0x000000004
00105                                   /* The last statement was a block */
00106 
00107 #define STATUS_is_lvalue(s) ((s) & STATUS_LVALUE)
00108 #define STATUS_set_lvalue(s) ((s) = (s) | STATUS_LVALUE)
00109 #define STATUS_reset_lvalue(s) ((s) = (s) & ~STATUS_LVALUE)
00110 
00111 #define STATUS_is_array_as_address(s) ((s) & STATUS_ARRAY_AS_ADDRESS)
00112 #define STATUS_set_array_as_address(s) ((s) = (s) | STATUS_ARRAY_AS_ADDRESS)
00113 #define STATUS_reset_array_as_address(s) ((s) = (s) & ~STATUS_ARRAY_AS_ADDRESS)
00114 
00115 #define STATUS_is_block(s) ((s) & STATUS_LVALUE)
00116 #define STATUS_set_block(s) ((s) = (s) | STATUS_LVALUE)
00117 #define STATUS_reset_block(s) ((s) = (s) & ~STATUS_LVALUE)
00118 
00119 
00120     /* -------- Facilities to effect a WN to C translation --------- */
00121 
00122 extern void WN2C_Append_Purple_Funcinfo(TOKEN_BUFFER tokens);
00123 extern void WN2C_initialize(void);
00124 extern void WN2C_finalize(void);
00125 extern BOOL WN2C_new_symtab(void);
00126 extern STATUS WN2C_translate(TOKEN_BUFFER tokens, const WN *wn, CONTEXT context);
00127 extern void WN2C_translate_structured_types(void);
00128 extern STATUS WN2C_translate_file_scope_defs(CONTEXT context);
00129 
00130 extern STATUS WN2C_translate_purple_main(TOKEN_BUFFER tokens, 
00131                                          const WN    *pu, 
00132                                          const char  *region_name,
00133                                          CONTEXT      context);
00134 
00135 extern void WN2C_memref_lhs(TOKEN_BUFFER tokens,
00136                             TY_IDX      *memref_typ,
00137                             const WN    *lhs,
00138                             STAB_OFFSET  memref_ofst,
00139                             TY_IDX       memref_addr_ty, 
00140                             TY_IDX       memref_object_ty, 
00141                             MTYPE        dtype,
00142                             CONTEXT      context);
00143 
00144 extern void WN2C_stid_lhs(TOKEN_BUFFER tokens,
00145                           TY_IDX      *stored_typ,
00146                           const ST    *lhs_st,
00147                           STAB_OFFSET  stid_ofst,
00148                           TY_IDX       stid_ty, 
00149                           MTYPE        dtype,
00150                           CONTEXT      context);
00151 
00152 #endif /* wn2c_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines