/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef gencode_h
#define gencode_h
#include "pcap/funcattrs.h"
/*
* pcap/bpf.h (a public header) needs u_char, u_short and u_int, which can be
* made available via either pcap-types.h (a private header) or pcap/pcap.h
* (a public header), none of which pcap/bpf.h includes. Include the private
* header to keep things simple, this way this private header should compile
* even if included early from another file.
*/
#include "pcap-types.h"
#ifndef __NetBSD__
#include "pcap/bpf.h" /* bpf_u_int32 and BPF_MEMWORDS */
#else
#include <net/bpf.h> /* bpf_u_int32 and BPF_MEMWORDS */
#endif
/*
* ATM support:
*
* Copyright (c) 1997 Yen Yen Lim and North Dakota State University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Yen Yen Lim and
* North Dakota State University
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* MTP3 field types in case of MTP2 HSL */
#define MH_SIO 5
#define MH_OPC 6
#define MH_DPC 7
#define MH_SLS 8
struct slist;
/*
* A single statement, corresponding to an instruction in a block.
*/
struct stmt {
int code; /* opcode */
struct slist *jt; /* only for relative jump in block */
struct slist *jf; /* only for relative jump in block */
bpf_u_int32 k; /* k field */
};
/*
* A bit vector to represent definition sets. We assume TOT_REGISTERS
* is smaller than 8*sizeof(atomset).
*/
typedef bpf_u_int32 atomset;
#define ATOMMASK(n) (1 << (n))
#define ATOMELEM(d, n) (d & ATOMMASK(n))
/*
* An unbounded set.
*/
typedef bpf_u_int32 *uset;
/*
* Total number of atomic entities, including accumulator (A) and index (X).
* We treat all these guys similarly during flow analysis.
*/
#define N_ATOMS (BPF_MEMWORDS+2)
/*
* Control flow graph of a program.
* This corresponds to an edge in the CFG.
* It's a directed graph, so an edge has a predecessor and a successor.
*/
struct edge {
u_int id;
int code; /* opcode for branch corresponding to this edge */
uset edom;
struct block *succ; /* successor vertex */
struct block *pred; /* predecessor vertex */
struct edge *next; /* link list of incoming edges for a node */
};
/*
* A block is a vertex in the CFG.
* It has a list of statements, with the final statement being a
* branch to successor blocks.
*/
struct block {
u_int id;
struct slist *stmts; /* side effect stmts */
struct stmt s; /* branch stmt */
int mark;
u_int longjt; /* jt branch requires long jump */
u_int longjf; /* jf branch requires long jump */
int level;
int offset;
int sense;
struct edge et; /* edge corresponding to the jt branch */
struct edge ef; /* edge corresponding to the jf branch */
struct block *head;
struct block *link; /* link field used by optimizer */
uset dom;
uset closure;
struct edge *in_edges; /* first edge in the set (linked list) of edges with this as a successor */
atomset def, kill;
atomset in_use;
atomset out_use;
int oval; /* value ID for value tested in branch stmt */
bpf_u_int32 val[N_ATOMS];
};
/*
* A value of 0 for val[i] means the value is unknown.
*/
#define VAL_UNKNOWN 0
struct arth {
struct block *b; /* protocol checks */
struct slist *s; /* stmt list */
int regno; /* virtual register number of result */
};
/*
* Representation of a program as a tree of blocks, plus current mark.
* A block is marked if only if its mark equals the current mark.
* Rather than traverse the code array, marking each item, 'cur_mark'
* is incremented. This automatically makes each element unmarked.
*/
#define isMarked(icp, p) ((p)->mark == (icp)->cur_mark)
#define unMarkAll(icp) (icp)->cur_mark += 1
#define Mark(icp, p) ((p)->mark = (icp)->cur_mark)
struct icode {
struct block *root;
int cur_mark;
};