Logo Search packages:      
Sourcecode: fauhdlc version File versions

libfauhdli.h

/* $Id: libfauhdli.h 4321 2009-01-27 13:02:52Z potyra $
 * Interpreter library, internal API.
 *
 * Copyright (C) 2008-2009 FAUmachine Team <info@faumachine.org>.
 * This program is free software. You can redistribute it and/or modify it
 * under the terms of the GNU General Public License, either version 2 of
 * the License, or (at your option) any later version. See COPYING.
 */

#ifndef __LIB_FAUHDLI_H_INCLUDED
#define __LIB_FAUHDLI_H_INCLUDED

#include "fauhdli.h"
#include <stdbool.h>
#include <stdlib.h>     /* for size_t */
#include "list.h"
#include "slset.h"
#include "vhdl_sched.h"
#include "basetypes.h"
#include "glue-vhdl.h"

/* ********************* types  *********************** */

enum opcode_kind {
      OPCODE_MOV,       /* 0 */
      OPCODE_ADD,
      OPCODE_SUB,
      OPCODE_IMUL,
      OPCODE_DIV,
      OPCODE_CALL,      /* 5 */
      OPCODE_PROC,
      OPCODE_RETURN,
      OPCODE_BEGINTRANS,
      OPCODE_ENDTRANS,
      OPCODE_SETPARAM, /* 10 */
      OPCODE_GETPARAM,
      OPCODE_UPDATE,
      OPCODE_GETSIG,
      OPCODE_JMP,
      OPCODE_JE,  /* 15 */
      OPCODE_JB,
      OPCODE_JNE,
      OPCODE_JBE,
      OPCODE_AOFFSET,
      OPCODE_ROFFSET,   /* 20 */
      OPCODE_LABEL,
      OPCODE_SUSPEND,
      OPCODE_CONNECT,
      OPCODE_WAKEAT,
      OPCODE_WAKEON,    /* 25 */
      OPCODE_LOG,
      OPCODE_ABORT
};

/** kind of operand */
enum operand_kind {
      /** register operand */
      OPERAND_REGISTER,
      /** indirect memory access via register */
      OPERAND_INDIRECT,
      /** immediate operand */
      OPERAND_IMMEDIATE,
      /** reference to a data object. (= pointer to data) */
      OPERAND_REFERENCE,
      /** reference to a label */
      OPERAND_TARGET
};

/** basic type enumeration */
enum type_kind {
      /** integral type */
      TYPE_INT,
      /** float type */
      TYPE_FLOAT,
      /** pointer type */
      TYPE_POINTER,
};

/** storage kinds of data elements */
enum storage_kind {
      /** plain storage, only the value is stored. */
      STORAGE_VARIABLE,
      /** signal storage, defining a signal */
      STORAGE_SIGNAL,
      /** driver storage, a driver to a signal */
      STORAGE_DRIVER
};

/** code container */
00090 struct code_container {
      /** name of the container */
00092       char *name;
      /** architecture segment */
00094       struct slist *transfer_segment;
      /** stack segment */
00096       struct slist *stack_segment;
      /** nested code containers */
00098       struct slist *sub_containers;
      /** data size of stack segment */
00100       size_t stack_size;
      /** data size of transfer segment */
00102       size_t transfer_size;
      /** text segment */
00104       struct slist *text_segment;
      /** nesting level of container */
00106       unsigned int nesting_level;
};

/** one intermediate code operand */
00110 struct operand {
      /** kind of operand */
00112       enum operand_kind kind;
      /** type of operand */
00114       enum type_kind type;
      /** union by kind of operand */
      union {
            /** register for register and indirect operands */
00118             unsigned int reg;
            /** immediate value */
00120             union fauhdli_value immediate;
            /** reference to a label */
            struct {
                  /** name of the label */
00124                   char *name;
                  /** resolved reference or NULL if unresolved */
00126                   const struct slist_entry *ref;
            } target;
            /** reference to a data object, or a code container */
            struct {
                  /** name of the reference */
                  char *name;
                  /** resolved reference or NULL if unresolved */
00133                   const struct data_definition *ref;
                  /** for setparam, begintrans, endtrans: 
                   *  reference to the code container 
                   */
00137                   const struct code_container *container;
            } data;
      } bytype;
};

struct opcode {
      /** kind of opcode */
      enum opcode_kind kind;
      /** first operand (if any) */
      struct operand *op1;
      /** second operand (if any) */
      struct operand *op2;
      /** third operand (if any) */
      struct operand *op3;
      /** label, in case it's no opcode but a label. */
      char *label;
      /** type element referring to the indexed type in caes of 
       *  aoffset/roffset opcodes */
      struct type_element *indexed_type;
      /** line number in parsed file */
      int lineno;
      /** list of annotations (optional) */
      struct slist *annotations;
};

/** generic annotation specification */
00163 struct annotation_spec {
      /** name of the annotation specification */
00165       char *name;
      /** string value */
00167       char *string_value;
      /** int value */
00169       int int_value;
};

/** Element of a type.
 *  
 *  A type_element represents one element of a possibly composite type.
 *  It can represent an array of either a basic type or another composite
 *  type.
 *  A basic type would be universal_integer or universal_real, or a driver
 *  of it, or a signal of it.
 *  
 *  elem_count represents the number of basic types that this type_element
 *  refers to.
 *  offset means the number of basic type elements in a composite type 
 *  that reside before this type.
 *
 *  Example:
 *  type t is { a: u[10], b: v }
 *  type u is { c: universal_integer[5] }
 *  type v is { d: universal_real, e: universal_integer }
 *
 *  type_element d has offset 0 and elem_count 1
 *  type_element e has offset 1 and elem_count 1
 *  type v has elem_count 2
 *
 *  type_element c has offset 0 and elem_count 5
 *  type u has elem_count 5
 *
 *  type_elment a has offset 0 and elem_count 10 * 5 = 50 (and elements = 10)
 *  type_element b has offset 50 and elem_count 2 (and elements = 1)
 *  type t has elem_count 52
 */
00201 struct type_element {
      /** name of the referred to type */
00203       char *name;
      /** referred to type */
00205       const struct type_declaration *type;
      /** number of elements of an array */
00207       universal_integer elements;
      /** initial value (if any, must be an immediate) */
00209       struct operand *initial;
      /** number of basic subelements. -1 means unset. */
00211       int elem_count;
      /** element offset from beginning of type (not a size!) */
00213       int offset;
      /** annotations (optional) */
00215       struct slist *annotations;
};

struct type_declaration {
      /** name of the type */
      char *name;
      /** subelements of the type */
      struct slist *elements;
      /** number of basic subelements. -1 means unset. */
      int elem_count;
};

enum segment_kind {
      SEGMENT_TRANSFER,
      SEGMENT_STACK
};

struct data_definition {
      /** name of the definition */
      char *name;
      /** type of the definition (local type_element) */
      struct type_element *type;
      /** storage kind of the data definition */
      enum storage_kind storage;
      /** location of the data. */
      enum segment_kind loc;
      /** nesting level, 0=current stack seg., 1=parent stack seg..) */
      unsigned int nesting_level;
      /** offset of data in segment (bytes) */
      size_t offset;
      /** storage size in byte of the resulting data */
      size_t storage_size;
      /** annotations (optional) */
      struct slist *annotations;
};

enum declaration_kind {
      DECLARATION_TYPE,
      DECLARATION_DATA,
};

struct declaration_element {
      enum declaration_kind kind;
      union {
            struct type_declaration type_decl;
            struct data_definition data_def;
      } bytype;
};


/** value of a virtual register */
00266 struct reg_value {
      /** actual value */
00268       union fauhdli_value value;
      /** type of register (mainly useful for debugging */
00270       enum type_kind kind;
      /** was the register written to already? 
       *  (only useful to debug intermediate code) */
00273       bool initialized;
};

/** main instance of vhdl interpreter */
00277 struct fauhdli {
      /** top code container. */
00279       struct code_container *container;
      /** set containing various allocated pointers that should get free'd
       *  on exit. (order must not be relevant!)
       */
00283       struct slset *cleanup_ptrs;

      /** virtual registers...
       *  Registers 0-9 have a special meaning (cf. 
       *  intermediate/operands/RegisterFactory.cpp).
       *  0: integer return register.
       *  1: float return register.
       *  2: pointer return register.
       *  3: integer containing the current simulation time.
       *  4-9: reserved.
       */
00294       struct reg_value registers[50000];
      /** scheduler instance */
00296       struct vhdl_sched *scheduler;

      /** set of created signals */
00299       struct slset *signals;
      /** set of created, but not free'd stack_frames */
00301       struct slset *pending_stack_frames;
      /** all vhdl processes */
00303       struct slset *processes;
      /** current simulation time */
00305       universal_integer sim_time;
      /** tracer instance (NULL if no tracing is desired) */
00307       struct trace_t *tracer;
      /** debugging enabled/disabled? */
00309       bool debug;
      /** glue_vhdl instance */
00311       struct glue_vhdl *glue_vhdl;
      /** set containing all (non-foreign) drivers */
00313       struct slset *drivers;
      /** set of all "foreign" drivers. A foreign driver means that the
       *  signal of a process is written to from VHDL but the signal itself
       *  is foreign. */
00317       struct slset *foreign_drivers;
};

/* ********************* functions *********************** */

/** allocate memory for an opcode an initialize the members.
 *  @param kind kind of opcode.
 *  @return opcode with kind set, and pointers set to 0.
 */
extern 
__attribute__((__malloc__, __visibility__("internal")))
struct opcode *
fauhdli_alloc_opcode(enum opcode_kind kind);

/** find the annotation with name in the list of annotations.
 *  @param name name tag of the annotation
 *  @param annotations list of annotations
 *  @return the spec in question or NULL if not found.
 */
extern
__attribute__((__visibility__("internal")))
const struct annotation_spec *
fauhdli_find_annotation(const char *name, const struct slist *annotations);

#endif /* __LIB_FAUHDLI_H_INCLUDED */

Generated by  Doxygen 1.6.0   Back to index