OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [except.c] - Blame information for rev 159

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 hellwig
/*
2
 * except.c -- exception handling
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <setjmp.h>
10
 
11
#include "error.h"
12
#include "except.h"
13
 
14
 
15
#define MAX_ENV_NEST_DEPTH      10
16
 
17
 
18
static jmp_buf *environments[MAX_ENV_NEST_DEPTH];
19
static int currentEnvironment = -1;
20
 
21
 
22
void throwException(int exception) {
23
  if (currentEnvironment < 0) {
24
    error("exception %d thrown while no environment active", exception);
25
  }
26
  longjmp(*environments[currentEnvironment], exception);
27
}
28
 
29
 
30
void pushEnvironment(jmp_buf *environment) {
31
  if (currentEnvironment == MAX_ENV_NEST_DEPTH - 1) {
32
    error("too many environments active");
33
  }
34
  currentEnvironment++;
35
  environments[currentEnvironment] = environment;
36
}
37
 
38
 
39
void popEnvironment(void) {
40
  if (currentEnvironment < 0) {
41
    error("cannot pop environment - none active");
42
  }
43
  currentEnvironment--;
44
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.