1 /*
2  * Copyright (c) 2008-2019, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /** \file
19  * \brief File Information Header (FIH)
20  */
21 
22 typedef struct {
23   char *dirname;  /**< directory name */
24   char *filename; /**< file name (only) */
25   char *fullname; /**< full file name */
26   char *funcname; /**< function name */
27   void *ccffinfo; /**< opaque pointer used for CCFF info */
28   int functag;    /**< integer function tag; ilm index of the function header */
29   int parent;     /**< file into which this is inlined or included */
30   int flags;      /**< file flags */
31   int lineno;     /**< line number of parent where included or inlined */
32   int srcline;    /**< line number in filename */
33   int level;      /**< count of number of parents, plus 1 */
34   int next;       /**< next inlined/included routine into same routine */
35   int child;      /**< first inlined/included routine into this routine */
36   int dirindex;   /**< used for debug line tables */
37   int findex; /**< For bottom-up auto-inlining, mapping between IFIH and FIH */
38   int funcsize; /**< For bottom-up auto-inlining, passing info to ccff_info */
39 } FIH;
40 
41 typedef struct {
42   FIH *stg_base;
43   int stg_size;
44   int stg_avail;
45   int currfindex, currftag; /**< findex/ftag for this block */
46   int nextfindex, nextftag; /**< findex/ftag for next block created */
47   int saved_avail;
48 } FIHB;
49 
50 #define FIH_INCLUDED 1
51 #define FIH_INLINED 2
52 #define FIH_IPAINLINED 4
53 #define FIH_SPLIT 8
54 #define FIH_ALTCODE 0x10
55 #define FIH_CCFF 0x20
56 #define FIH_FDONE 0x40
57 #define FIH_FINCDONE 0x80
58 #define FIH_DO_CCFF 0x100
59 /* File introduced by USE stmt in Fortran */
60 #define FIH_USE_MOD 0x200
61 
62 #define FIH_DIRNAME(i) fihb.stg_base[i].dirname
63 #define FIH_FILENAME(i) fihb.stg_base[i].filename
64 #define FIH_NAME(i) fihb.stg_base[i].fullname
65 #define FIH_FULLNAME(i) fihb.stg_base[i].fullname
66 #define FIH_FUNCNAME(i) fihb.stg_base[i].funcname
67 #define FIH_FUNCTAG(i) fihb.stg_base[i].functag
68 #define FIH_PARENT(i) fihb.stg_base[i].parent
69 #define FIH_FLAGS(i) fihb.stg_base[i].flags
70 #define FIH_LINENO(i) fihb.stg_base[i].lineno
71 #define FIH_SRCLINE(i) fihb.stg_base[i].srcline
72 #define FIH_LEVEL(i) fihb.stg_base[i].level
73 #define FIH_NEXT(i) fihb.stg_base[i].next
74 #define FIH_CHILD(i) fihb.stg_base[i].child
75 #define FIH_INC(i) (fihb.stg_base[i].flags & FIH_INCLUDED)
76 #define FIH_INL(i) (fihb.stg_base[i].flags & FIH_INLINED)
77 #define FIH_IPAINL(i) (fihb.stg_base[i].flags & FIH_IPAINLINED)
78 #define FIH_CLEARFLAG(i, f) (fihb.stg_base[i].flags &= ~(f))
79 #define FIH_SETFLAG(i, f) (fihb.stg_base[i].flags |= (f))
80 #define FIH_CHECKFLAG(i, f) (fihb.stg_base[i].flags & (f))
81 #define FIH_CLEARDONE(i) (fihb.stg_base[i].flags &= ~FIH_FDONE)
82 #define FIH_SETDONE(i) (fihb.stg_base[i].flags |= FIH_FDONE)
83 #define FIH_DONE(i) (fihb.stg_base[i].flags & FIH_FDONE)
84 #define FIH_CLEARINCDONE(i) (fihb.stg_base[i].flags &= ~FIH_FINCDONE)
85 #define FIH_SETINCDONE(i) (fihb.stg_base[i].flags |= FIH_FINCDONE)
86 #define FIH_INCDONE(i) (fihb.stg_base[i].flags & FIH_FINCDONE)
87 #define FIH_USEMOD(i) (fihb.stg_base[i].flags & FIH_USE_MOD)
88 #define FIH_CCFFINFO(i) fihb.stg_base[i].ccffinfo
89 
90 extern FIHB fihb;
91 
92 extern int addfile(char *, char *, int, int, int, int, int);
93 extern void setfile(int, char *, int);
94 
95 /*             IFIH (inline file information header)   */
96 
97 #define IFIH_DIRNAME(i) ifihb.stg_base[i].dirname
98 #define IFIH_FILENAME(i) ifihb.stg_base[i].filename
99 #define IFIH_NAME(i) ifihb.stg_base[i].fullname
100 #define IFIH_FULLNAME(i) ifihb.stg_base[i].fullname
101 #define IFIH_FUNCNAME(i) ifihb.stg_base[i].funcname
102 #define IFIH_FUNCTAG(i) ifihb.stg_base[i].functag
103 #define IFIH_PARENT(i) ifihb.stg_base[i].parent
104 #define IFIH_FLAGS(i) ifihb.stg_base[i].flags
105 #define IFIH_LINENO(i) ifihb.stg_base[i].lineno
106 #define IFIH_SRCLINE(i) ifihb.stg_base[i].srcline
107 #define IFIH_LEVEL(i) ifihb.stg_base[i].level
108 #define IFIH_NEXT(i) ifihb.stg_base[i].next
109 #define IFIH_CHILD(i) ifihb.stg_base[i].child
110 #define IFIH_INC(i) (ifihb.stg_base[i].flags & FIH_INCLUDED)
111 #define IFIH_INL(i) (ifihb.stg_base[i].flags & FIH_INLINED)
112 #define IFIH_IPAINL(i) (ifihb.stg_base[i].flags & FIH_IPAINLINED)
113 #define IFIH_CLEARFLAG(i, f) (ifihb.stg_base[i].flags &= ~(f))
114 #define IFIH_SETFLAG(i, f) (ifihb.stg_base[i].flags |= (f))
115 #define IFIH_CHECKFLAG(i, f) (ifihb.stg_base[i].flags & (f))
116 #define IFIH_CLEARDONE(i) (ifihb.stg_base[i].flags &= ~FIH_FDONE)
117 #define IFIH_SETDONE(i) (ifihb.stg_base[i].flags |= FIH_FDONE)
118 #define IFIH_DONE(i) (ifihb.stg_base[i].flags & FIH_FDONE)
119 #define IFIH_CLEARINCDONE(i) (ifihb.stg_base[i].flags &= ~FIH_FINCDONE)
120 #define IFIH_SETINCDONE(i) (ifihb.stg_base[i].flags |= FIH_FINCDONE)
121 #define IFIH_INCDONE(i) (ifihb.stg_base[i].flags & FIH_FINCDONE)
122 #define IFIH_CCFFINFO(i) ifihb.stg_base[i].ccffinfo
123 #define IFIH_FINDEX(i) ifihb.stg_base[i].findex
124 #define IFIH_FUNCSIZE(i) ifihb.stg_base[i].funcsize
125 
126 extern FIHB ifihb;
127 
128 extern int iaddfile(char *, char *, int, int, int, int, int, int, int, int,
129                     int);
130 
131 /* Moved from ccffinfo.c */
132 typedef struct ccff_message {
133   struct ccff_message *next;
134   struct ccff_message *msgchild;
135   const char *msgid;
136   char *message;
137   char *varname;
138   char *funcname;
139   struct ccff_argument *args;
140   int msgtype, fihx, lineno, order, suborder, seq, combine;
141 } MESSAGE;
142 
143 typedef struct ccff_argument {
144   struct ccff_argument *next;
145   char *argstring;
146   char *argvalue;
147 } ARGUMENT;
148