LCOV - code coverage report
Current view: top level - monetdb5/mal - mal_instruction.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 8 8 100.0 %
Date: 2024-12-20 20:06:10 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : #ifndef _MAL_INSTR_H
      14             : #define _MAL_INSTR_H
      15             : 
      16             : #include "mal_type.h"
      17             : #include "mal_stack.h"
      18             : #include "mal_namespace.h"
      19             : 
      20             : #define isaSignature(P)  ((P)->token >=COMMANDsymbol || (P)->token == PATTERNsymbol)
      21             : 
      22             : #ifdef HAVE_SYS_TIMES_H
      23             : # include <sys/times.h>
      24             : #endif
      25             : 
      26             : #define DEBUG_MAL_INSTR
      27             : #define MAXARG 8                                /* was 4 BEWARE the code depends on this knowledge, where? */
      28             : #define STMT_INCREMENT 4
      29             : #define MAL_VAR_WINDOW  16              // was 32
      30             : #define MAXLISTING (64*1024)
      31             : 
      32             : /* Allocation of space assumes a rather exotic number of
      33             :  * arguments. Access to module and function name are cast in macros to
      34             :  * prepare for separate name space management. */
      35             : #define getModuleId(P)          ((P)->modname)
      36             : #ifdef NDEBUG
      37             : #define setModuleId(P,S)        do { (P)->modname = (S); } while (0)
      38             : #else
      39             : static inline void
      40    14780115 : setModuleId(InstrPtr p, const char *s)
      41             : {
      42    14780115 :         assert(s == getName(s));
      43    14781204 :         p->modname = s;
      44    14781204 : }
      45             : #endif
      46             : #define setModuleScope(P,S)     do {(P)->modname= (S)==NULL?NULL: (S)->name;} while (0)
      47             : 
      48             : #define getFunctionId(P)        ((P)->fcnname)
      49             : #ifdef NDEBUG
      50             : #define setFunctionId(P,S)      do { (P)->fcnname = (S); } while (0)
      51             : #else
      52             : static inline void
      53    17925549 : setFunctionId(InstrPtr p, const char *s)
      54             : {
      55    17925549 :         assert(s == getName(s));
      56    17925577 :         p->fcnname = s;
      57    17925577 : }
      58             : #endif
      59             : #define garbageControl(P)       ((P)->gc)
      60             : 
      61             : #define getInstrPtr(M,I)        (M)->stmt[I]
      62             : #define putInstrPtr(M,I,P)      (M)->stmt[I] = P
      63             : #define getSignature(S)         getInstrPtr((S)->def,0)
      64             : #define isMain(M)                       ((getInstrPtr(M,0))->fcnname == putName("main",4))
      65             : #define getFcnName(M)           getFunctionId(getInstrPtr(M,0))
      66             : #define getArgCount(M)          getInstrPtr(M,0)->argc
      67             : #define getModName(M)           getModuleId(getInstrPtr(M,0))
      68             : #define getPrgSize(M)           (M)->stop
      69             : 
      70             : #define getVar(M,I)                     (&(M)->var[I])
      71             : #define getVarType(M,I)         ((M)->var[I].type)
      72             : mal_export char *getVarNameIntoBuffer(MalBlkPtr mb, int idx, char *buf);
      73             : 
      74             : #define getVarKind(M,I)         ((M)->var[I].kind)
      75             : #define getVarGDKType(M,I)      getGDKType((M)->var[I].type)
      76             : #define setVarType(M,I,V)       ((M)->var[I].type = (V))
      77             : #define setVarKind(M,I,V)       ((M)->var[I].kind = (V))     /* either _, X, or C */
      78             : 
      79             : #define clrVarFixed(M,I)        ((M)->var[I].fixedtype = 0)
      80             : #define setVarFixed(M,I)        ((M)->var[I].fixedtype = 1)
      81             : #define isVarFixed(M,I)         ((M)->var[I].fixedtype)
      82             : 
      83             : #define clrVarCleanup(M,I)      ((M)->var[I].cleanup = 0)
      84             : #define setVarCleanup(M,I)      ((M)->var[I].cleanup = 1)
      85             : #define isVarCleanup(M,I)       ((M)->var[I].cleanup)
      86             : 
      87             : #define isTmpVar(M,I)           (getVarKind(M,I) == REFMARKER)
      88             : 
      89             : #define clrVarUsed(M,I)         ((M)->var[I].used = 0)
      90             : #define setVarUsed(M,I)         ((M)->var[I].used = 1)
      91             : #define isVarUsed(M,I)          ((M)->var[I].used)
      92             : 
      93             : #define clrVarDisabled(M,I)     ((M)->var[I].disabled = 0)
      94             : #define setVarDisabled(M,I)     ((M)->var[I].disabled = 1)
      95             : #define isVarDisabled(M,I)      ((M)->var[I].disabled)
      96             : 
      97             : #define clrVarInit(M,I)         ((M)->var[I].initialized = 0)
      98             : #define setVarInit(M,I)         ((M)->var[I].initialized = 1)
      99             : #define isVarInit(M,I)          ((M)->var[I].initialized)
     100             : 
     101             : #define clrVarTypedef(M,I)      ((M)->var[I].typevar = 0)
     102             : #define setVarTypedef(M,I)      ((M)->var[I].typevar = 1)
     103             : #define isVarTypedef(M,I)       ((M)->var[I].typevar)
     104             : 
     105             : #define clrVarConstant(M,I)     ((M)->var[I].constant = 0)
     106             : #define setVarConstant(M,I)     ((M)->var[I].constant = 1)
     107             : #define isVarConstant(M,I)      ((M)->var[I].constant)
     108             : 
     109             : #define setVarDeclared(M,I,X)   ((M)->var[I].declared = (X))
     110             : #define getVarDeclared(M,I)     ((M)->var[I].declared)
     111             : 
     112             : #define setVarUpdated(M,I,X)    ((M)->var[I].updated = (X))
     113             : #define getVarUpdated(M,I)      ((M)->var[I].updated)
     114             : 
     115             : #define setVarEolife(M,I,X)     ((M)->var[I].eolife = (X))
     116             : #define getVarEolife(M,I)       ((M)->var[I].eolife)
     117             : 
     118             : #define setVarScope(M,I,S)      ((M)->var[I].depth = (S))
     119             : #define getVarScope(M,I)        ((M)->var[I].depth)
     120             : 
     121             : #define clrVarCList(M,I)        ((M)->var[I].kind = REFMARKER)
     122             : #define setVarCList(M,I)        ((M)->var[I].kind = REFMARKERC)
     123             : #define isVarCList(M,I)         ((M)->var[I].kind == REFMARKERC)
     124             : 
     125             : #define getVarConstant(M,I)     ((M)->var[I].value)
     126             : #define getVarValue(M,I)        VALget(&(M)->var[I].value)
     127             : 
     128             : #define setRowCnt(M,I,C)        ((M)->var[I].rowcnt = (C))
     129             : #define getRowCnt(M,I)          ((M)->var[I].rowcnt)
     130             : 
     131             : #define getVarSTC(M,I)          ((M)->var[I].stc)
     132             : 
     133             : #define getDestVar(P)           ((P)->argv[0])
     134             : #define setDestVar(P,X)         ((P)->argv[0] = (X))
     135             : #define setDestType(M,P,V)      setVarType((M),getDestVar(P),V)
     136             : #define getDestType(M,P)        destinationType(M,P)
     137             : #define getArg(P,I)                     (P)->argv[I]
     138             : #define setArg(P,I,R)           ((P)->argv[I] = (R))
     139             : #define getArgName(M,P,I)       (M)->var[(P)->argv[I]].name
     140             : #define getArgNameIntoBuffer(M,P,I,B)   getVarNameIntoBuffer((M),(P)->argv[I], B)
     141             : #define getArgType(M,P,I)       getVarType((M),(P)->argv[I])
     142             : #define getArgGDKType(M,P,I) getVarGDKType((M),(P)->argv[I])
     143             : #define getGDKType(T)           ((T) <= TYPE_str ? (T) : ((T) == TYPE_any ? TYPE_void : findGDKtype(T)))
     144             : 
     145             : mal_export void addMalException(MalBlkPtr mb, str msg);
     146             : mal_export void mal_instruction_reset(void);
     147             : mal_export InstrPtr newInstruction(MalBlkPtr mb, const char *modnme,
     148             :                                                                    const char *fcnnme);
     149             : mal_export InstrPtr newInstructionArgs(MalBlkPtr mb, const char *modnme,
     150             :                                                                            const char *fcnnme, int args);
     151             : mal_export InstrPtr copyInstruction(const InstrRecord *p);
     152             : mal_export InstrPtr copyInstructionArgs(const InstrRecord *p, int args);
     153             : mal_export void clrInstruction(InstrPtr p);
     154             : mal_export void freeInstruction(InstrPtr p);
     155             : mal_export void clrFunction(InstrPtr p);
     156             : mal_export Symbol newSymbol(const char *nme, int kind);
     157             : mal_export void freeSymbol(Symbol s);
     158             : mal_export void freeSymbolList(Symbol s);
     159             : mal_export void printSignature(stream *fd, Symbol s, int flg);
     160             : 
     161             : mal_export MalBlkPtr newMalBlk(int elements);
     162             : mal_export void resetMalBlk(MalBlkPtr mb);
     163             : mal_export void resetMalTypes(MalBlkPtr mb, int stop);
     164             : mal_export int newMalBlkStmt(MalBlkPtr mb, int elements);
     165             : mal_export int resizeMalBlk(MalBlkPtr mb, int elements);
     166             : mal_export void freeMalBlk(MalBlkPtr mb);
     167             : mal_export MalBlkPtr copyMalBlk(MalBlkPtr mb);
     168             : mal_export void trimMalVariables(MalBlkPtr mb, MalStkPtr stk);
     169             : mal_export void trimMalVariables_(MalBlkPtr mb, MalStkPtr glb);
     170             : mal_export void moveInstruction(MalBlkPtr mb, int pc, int target);
     171             : mal_export void removeInstruction(MalBlkPtr mb, InstrPtr p);
     172             : mal_export void removeInstructionBlock(MalBlkPtr mb, int pc, int cnt);
     173             : mal_export str operatorName(int i);
     174             : 
     175             : mal_export int findVariable(MalBlkPtr mb, const char *name);
     176             : mal_export int findVariableLength(MalBlkPtr mb, const char *name, int len);
     177             : mal_export str getArgDefault(MalBlkPtr mb, InstrPtr p, int idx);
     178             : mal_export int newVariable(MalBlkPtr mb, const char *name, size_t len,
     179             :                                                    malType type);
     180             : mal_export int cloneVariable(MalBlkPtr dst, MalBlkPtr src, int varid);
     181             : mal_export void setVariableType(MalBlkPtr mb, const int idx, malType type);
     182             : mal_export int newTmpVariable(MalBlkPtr mb, malType type);
     183             : mal_export int newTypeVariable(MalBlkPtr mb, malType type);
     184             : mal_export void freeVariable(MalBlkPtr mb, int varid);
     185             : mal_export void clearVariable(MalBlkPtr mb, int varid);
     186             : mal_export int cpyConstant(MalBlkPtr mb, VarPtr vr);
     187             : mal_export int defConstant(MalBlkPtr mb, int type, ValPtr cst);
     188             : mal_export int fndConstant(MalBlkPtr mb, const ValRecord *cst, int depth);
     189             : mal_export str convertConstant(malType type, ValPtr vr);
     190             : 
     191             : mal_export void pushInstruction(MalBlkPtr mb, InstrPtr p);
     192             : mal_export InstrPtr pushArgument(MalBlkPtr mb, InstrPtr p, int varid);
     193             : mal_export InstrPtr setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid);
     194             : mal_export InstrPtr pushReturn(MalBlkPtr mb, InstrPtr p, int varid);
     195             : mal_export InstrPtr pushArgumentId(MalBlkPtr mb, InstrPtr p, const char *name);
     196             : mal_export void delArgument(InstrPtr p, int varid);
     197             : mal_export void setArgType(MalBlkPtr mb, InstrPtr p, int i, int tpe);
     198             : mal_export void setReturnArgument(InstrPtr p, int varid);
     199             : mal_export malType destinationType(MalBlkPtr mb, InstrPtr p);
     200             : mal_export void setPolymorphic(InstrPtr p, int tpe, int force);
     201             : /* Utility macros to inspect an instruction */
     202             : #define functionStart(X) ((X)->token == FUNCTIONsymbol || \
     203             :                                                   (X)->token == COMMANDsymbol)
     204             : #define patternStart(X)  ((X)->token == PATTERNsymbol)
     205             : #define functionExit(X)  ((X)->token == ENDsymbol)
     206             : 
     207             : #define blockStart(X)   ((X)->barrier && (((X)->barrier == BARRIERsymbol || \
     208             :                                                                                    (X)->barrier == CATCHsymbol)))
     209             : #define blockExit(X) ((X)->barrier == EXITsymbol)
     210             : #define blockReturn(X) ((X)->barrier == RETURNsymbol)
     211             : #define blockCntrl(X) ((X)->barrier== LEAVEsymbol || \
     212             :                                            (X)->barrier== REDOsymbol ||              \
     213             :                                            (X)->barrier== RETURNsymbol)
     214             : #define isLinearFlow(X)  (!(blockStart(X) || blockExit(X) || \
     215             :                                 (X)->barrier== LEAVEsymbol ||  (X)->barrier== REDOsymbol))
     216             : 
     217             : mal_export void strBeforeCall(ValPtr v, ValPtr bak);
     218             : mal_export void strAfterCall(ValPtr v, ValPtr bak);
     219             : mal_export void batBeforeCall(ValPtr v, ValPtr bak);
     220             : mal_export void batAfterCall(ValPtr v, ValPtr bak);
     221             : 
     222             : #endif /*  _MAL_INSTR_H */

Generated by: LCOV version 1.14