Predator  [unstable] git snapshot
Data Structures | Typedefs | Enumerations | Functions | Variables
code_listener.h File Reference

code listener interface - useful to write compiler plug-ins, etc. More...

#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  cl_loc
 generic location info. More...
struct  cl_init_data
 collection of call-backs for writing various types of messages More...
struct  cl_type_item
 used for nesting types into another (composite) type More...
struct  cl_type
 type definition available for each operand. More...
struct  cl_accessor
 accessor definition, available for some operands. More...
struct  cl_cst
 constant, in the C language terminology: literal More...
struct  cl_var
 variable (local, global, fnc argument, register, etc.) More...
struct  cl_operand
 generic operand. More...
struct  cl_insn
 single instruction definition More...
struct  cl_initializer
 initializer, used mainly for global/static variables More...
struct  cl_code_listener
 listener object - the core part of this interface More...

Typedefs

typedef void(* cl_print_fnc_t )(const char *msg)
 type of function writing a message

Enumerations

enum  cl_scope_e {
  CL_SCOPE_GLOBAL,
  CL_SCOPE_STATIC,
  CL_SCOPE_FUNCTION
}
 symbol scope enumeration (linearly ordered) More...
enum  cl_type_e {
  CL_TYPE_VOID,
  CL_TYPE_UNKNOWN,
  CL_TYPE_PTR,
  CL_TYPE_STRUCT,
  CL_TYPE_UNION,
  CL_TYPE_ARRAY,
  CL_TYPE_FNC,
  CL_TYPE_INT,
  CL_TYPE_CHAR,
  CL_TYPE_BOOL,
  CL_TYPE_ENUM,
  CL_TYPE_REAL,
  CL_TYPE_STRING
}
 basic type enumeration More...
enum  cl_ptr_type_e {
  CL_PTR_TYPE_NOT_PTR,
  CL_PTR_TYPE_BASIC,
  CL_PTR_TYPE_LVALUE_REF,
  CL_PTR_TYPE_RVALUE_REF
}
 used for specialization of CL_TYPE_PTR, which can also represent both C++ lvalue and rvalue references. More...
enum  cl_accessor_e {
  CL_ACCESSOR_REF,
  CL_ACCESSOR_DEREF,
  CL_ACCESSOR_DEREF_ARRAY,
  CL_ACCESSOR_ITEM,
  CL_ACCESSOR_OFFSET
}
 basic accessor enumeration More...
enum  cl_operand_e {
  CL_OPERAND_VOID,
  CL_OPERAND_CST,
  CL_OPERAND_VAR
}
 generic operand kind enumeration More...
enum  cl_insn_e {
  CL_INSN_NOP,
  CL_INSN_JMP,
  CL_INSN_COND,
  CL_INSN_RET,
  CL_INSN_ABORT,
  CL_INSN_UNOP,
  CL_INSN_BINOP,
  CL_INSN_CALL,
  CL_INSN_SWITCH,
  CL_INSN_LABEL
}
 basic instruction enumeration More...
enum  cl_unop_e {
  CL_UNOP_ASSIGN,
  CL_UNOP_TRUTH_NOT,
  CL_UNOP_BIT_NOT,
  CL_UNOP_MINUS,
  CL_UNOP_ABS,
  CL_UNOP_FLOAT
}
 unary operation's enumeration More...
enum  cl_binop_e {
  CL_BINOP_EQ,
  CL_BINOP_NE,
  CL_BINOP_LT,
  CL_BINOP_GT,
  CL_BINOP_LE,
  CL_BINOP_GE,
  CL_BINOP_TRUTH_AND,
  CL_BINOP_TRUTH_OR,
  CL_BINOP_TRUTH_XOR,
  CL_BINOP_PLUS,
  CL_BINOP_MINUS,
  CL_BINOP_MULT,
  CL_BINOP_EXACT_DIV,
  CL_BINOP_TRUNC_DIV,
  CL_BINOP_TRUNC_MOD,
  CL_BINOP_RDIV,
  CL_BINOP_MIN,
  CL_BINOP_MAX,
  CL_BINOP_POINTER_PLUS,
  CL_BINOP_BIT_AND,
  CL_BINOP_BIT_IOR,
  CL_BINOP_BIT_XOR,
  CL_BINOP_LSHIFT,
  CL_BINOP_RSHIFT,
  CL_BINOP_LROTATE,
  CL_BINOP_RROTATE,
  CL_BINOP_UNKNOWN
}
 binary operation's enumeration More...

Functions

struct cl_loccl_loc_fallback (const struct cl_loc *loc, const struct cl_loc *fallback)
 return loc if it is a valid location info; return fallback otherwise
void cl_global_init (struct cl_init_data *init_data)
 global initialization - it sets message printing call-backs
void cl_global_init_defaults (const char *app_name, int debug_level)
 global initialization - it sets built-in functions to print messages
void cl_global_cleanup (void)
 free resources allocated by cl_global_init() or cl_global_init_defaults()
bool cl_is_term_insn (enum cl_insn_e code)
 return true if the given code denotes a terminal instruction
struct cl_code_listenercl_code_listener_create (const char *config_string)
 create cl_code_listener object
struct cl_code_listenercl_chain_create (void)
 create cl_code_listener object for grouping another cl_code_listener objects
void cl_chain_append (struct cl_code_listener *chain, struct cl_code_listener *listener)
 append cl_code_listener object to chain

Variables

struct cl_loc cl_loc_unknown
 nullified location info, which means "unknown location"

Detailed Description

code listener interface - useful to write compiler plug-ins, etc.

Definition in file code_listener.h.

Typedef Documentation

typedef void(* cl_print_fnc_t)(const char *msg)

type of function writing a message

Parameters
msgzero-terminated string to write

Definition at line 78 of file code_listener.h.

Enumeration Type Documentation

basic accessor enumeration

Enumerator:
CL_ACCESSOR_REF 

reference, in the C language: &

CL_ACCESSOR_DEREF 

dereference, in the C language: *

Note
operator -> is decomposed as (*ptr).item (CL_ACCESSOR_DEREF followed by CL_ACCESSOR_ITEM)
CL_ACCESSOR_DEREF_ARRAY 

array accessor, in the C language: []

CL_ACCESSOR_ITEM 

record accessor, in the C language: .

CL_ACCESSOR_OFFSET 

offset accessor, in the C language: ((char *)ptr + N)

Definition at line 300 of file code_listener.h.

enum cl_binop_e

binary operation's enumeration

Enumerator:
CL_BINOP_EQ 
CL_BINOP_NE 
CL_BINOP_LT 
CL_BINOP_GT 
CL_BINOP_LE 
CL_BINOP_GE 
CL_BINOP_TRUTH_AND 
CL_BINOP_TRUTH_OR 
CL_BINOP_TRUTH_XOR 
CL_BINOP_PLUS 
CL_BINOP_MINUS 
CL_BINOP_MULT 
CL_BINOP_EXACT_DIV 
CL_BINOP_TRUNC_DIV 
CL_BINOP_TRUNC_MOD 
CL_BINOP_RDIV 
CL_BINOP_MIN 
CL_BINOP_MAX 
CL_BINOP_POINTER_PLUS 
CL_BINOP_BIT_AND 
CL_BINOP_BIT_IOR 
CL_BINOP_BIT_XOR 
CL_BINOP_LSHIFT 
CL_BINOP_RSHIFT 
CL_BINOP_LROTATE 
CL_BINOP_RROTATE 
CL_BINOP_UNKNOWN 

Definition at line 641 of file code_listener.h.

enum cl_insn_e

basic instruction enumeration

Enumerator:
CL_INSN_NOP 

no instruction, used only internally for now

CL_INSN_JMP 

goto instruction

CL_INSN_COND 

if (EXPR) instruction

CL_INSN_RET 

return instruction

CL_INSN_ABORT 

this follows each call of a function declared with attribute noreturn

CL_INSN_UNOP 

unary (lhs + 1) operation

CL_INSN_BINOP 

binary (lhs + 2) operation

CL_INSN_CALL 

this code is never emitted by cl_insn callback

CL_INSN_SWITCH 

this code is never emitted by cl_insn callback

CL_INSN_LABEL 

label

Definition at line 544 of file code_listener.h.

generic operand kind enumeration

Enumerator:
CL_OPERAND_VOID 

there is NO operand

CL_OPERAND_CST 

constant operand, in the C language: literal

Note
this has nothing to do with the C/C++ keyword 'const'
CL_OPERAND_VAR 

variable can represent a local/global program variable, or a function argument.

Each variable has its unique ID. Optionally it has also some name, if the variable indeed exists in the analysed program (in contrast to artificial variables created by the compiler).

Definition at line 479 of file code_listener.h.

used for specialization of CL_TYPE_PTR, which can also represent both C++ lvalue and rvalue references.

Enumerator:
CL_PTR_TYPE_NOT_PTR 

to avoid accidental misuse bugs

CL_PTR_TYPE_BASIC 
CL_PTR_TYPE_LVALUE_REF 
CL_PTR_TYPE_RVALUE_REF 

used only when C++11 code is processed

Definition at line 212 of file code_listener.h.

enum cl_scope_e

symbol scope enumeration (linearly ordered)

Enumerator:
CL_SCOPE_GLOBAL 

scope is unlimited

CL_SCOPE_STATIC 

scope is limited to current source file

CL_SCOPE_FUNCTION 

scope is limited to currently processed function

Definition at line 147 of file code_listener.h.

enum cl_type_e

basic type enumeration

Enumerator:
CL_TYPE_VOID 
CL_TYPE_UNKNOWN 
CL_TYPE_PTR 
CL_TYPE_STRUCT 
CL_TYPE_UNION 
CL_TYPE_ARRAY 
CL_TYPE_FNC 
CL_TYPE_INT 
CL_TYPE_CHAR 

not used by the gcc plug-in at the moment

CL_TYPE_BOOL 
CL_TYPE_ENUM 
CL_TYPE_REAL 
CL_TYPE_STRING 

used only by cl_cst

Definition at line 167 of file code_listener.h.

enum cl_unop_e

unary operation's enumeration

Enumerator:
CL_UNOP_ASSIGN 

simple assignment

CL_UNOP_TRUTH_NOT 

truth not, in the C language: !

CL_UNOP_BIT_NOT 

bitwise not, in the C language: ~

CL_UNOP_MINUS 

unary minus

CL_UNOP_ABS 

absolute value, applicable on numbers only

CL_UNOP_FLOAT 

conversion of an integer to a real

Definition at line 604 of file code_listener.h.

Function Documentation

void cl_chain_append ( struct cl_code_listener chain,
struct cl_code_listener listener 
)

append cl_code_listener object to chain

Parameters
chainObject returned by cl_chain_create() function.
listenerObject ought to be added to the chain.
Note
Listener objects are notified in the same order as they are added.
struct cl_code_listener* cl_chain_create ( void  )
read

create cl_code_listener object for grouping another cl_code_listener objects

Returns
Returns on heap allocated cl_code_listener object which does nothing.
struct cl_code_listener* cl_code_listener_create ( const char *  config_string)
read

create cl_code_listener object

Parameters
config_stringdetermines the type and attributes of the listener.
Note
config_string is currently undocumented. You can look to slplug.c for examples or turn on verbose output to see how it is parsed.
void cl_global_cleanup ( void  )

free resources allocated by cl_global_init() or cl_global_init_defaults()

void cl_global_init ( struct cl_init_data init_data)

global initialization - it sets message printing call-backs

Parameters
init_data- collection of call-backs to set (none of them can be NULL)
Note
You should call cl_global_cleanup() to free resources before exit.
void cl_global_init_defaults ( const char *  app_name,
int  debug_level 
)

global initialization - it sets built-in functions to print messages

Parameters
app_name- name of the application which appears in all messages. If NULL is given, no application name will be printed.
debug_level- debugging level, the greater number the more output, 0 means no debugging
Note
You should call cl_global_cleanup() to free resources before exit.
bool cl_is_term_insn ( enum cl_insn_e  code)

return true if the given code denotes a terminal instruction

struct cl_loc* cl_loc_fallback ( const struct cl_loc loc,
const struct cl_loc fallback 
)
read

return loc if it is a valid location info; return fallback otherwise

Variable Documentation

struct cl_loc cl_loc_unknown

nullified location info, which means "unknown location"