diff options
author | jaortega <jaortega> | 2000-12-23 02:06:26 +0000 |
---|---|---|
committer | jaortega <jaortega> | 2000-12-23 02:06:26 +0000 |
commit | 0894096cfa6391d5929738c8df424eddf8ed5277 (patch) | |
tree | 12ae3bb163923cdd75760cb1806932beadc94f65 /mixlib | |
parent | 0f5137ded00d58ba9829290031d159eea69b466e (diff) | |
download | mdk-0894096cfa6391d5929738c8df424eddf8ed5277.tar.gz mdk-0894096cfa6391d5929738c8df424eddf8ed5277.tar.bz2 |
mix_vm_clock_t and mix_time_t types definition
Diffstat (limited to 'mixlib')
-rw-r--r-- | mixlib/Makefile.am | 4 | ||||
-rw-r--r-- | mixlib/mix_vm_clock.c | 66 | ||||
-rw-r--r-- | mixlib/mix_vm_clock.h | 55 |
3 files changed, 124 insertions, 1 deletions
diff --git a/mixlib/Makefile.am b/mixlib/Makefile.am index f3b986b..fe1433d 100644 --- a/mixlib/Makefile.am +++ b/mixlib/Makefile.am @@ -26,4 +26,6 @@ libmix_a_SOURCES = mix.h mix.c \ mix_parser.h xmix_parser.h mix_parser.c mix_scanner.l \ mix_device.h mix_device.c \ mix_eval.h mix_eval.c xmix_eval.h mix_eval_scanner.l \ - mix_src_file.c mix_src_file.h + mix_src_file.c mix_src_file.h \ + mix_vm_clock.c mix_vm_clock.h + diff --git a/mixlib/mix_vm_clock.c b/mixlib/mix_vm_clock.c new file mode 100644 index 0000000..c8d1f67 --- /dev/null +++ b/mixlib/mix_vm_clock.c @@ -0,0 +1,66 @@ +/* -*-c-*- -------------- mix_vm_clock.c : + * Implementation of the functions declared in mix_vm_clock.h + * ------------------------------------------------------------------ + * Last change: Time-stamp: "00/12/22 02:19:30 jose" + * ------------------------------------------------------------------ + * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#include "mix_vm_clock.h" + +static const mix_time_t exec_times_[] = { + 1, 2, 2, 10, 12, 10, 2, 1, + 2, 2, 2, 2 , 2, 2, 2, 2, + 2, 2, 2, 2 , 2, 2, 2, 2, + 2, 2, 2, 2 , 2, 2, 2, 2, + 2, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2 , 2, 2, 2, 2 +}; + + +/* Create/delete a clock */ +mix_vm_clock_t * +mix_vm_clock_new () +{ + return g_new (mix_vm_clock_t, 1); +} + +void +mix_vm_clock_delete (mix_vm_clock_t *clock) +{ + g_return_if_fail (clock != NULL); +} + +/* Increase time with the units needed to execute ins */ +mix_time_t +mix_vm_clock_add_lapse (mix_vm_clock_t *clock, const mix_ins_t *ins) +{ + mix_time_t t = 0; + g_return_val_if_fail (clock != NULL, 0); + if (ins != NULL) + { + t = exec_times_[ins->opcode]; + if (ins->opcode == mix_MOVE) t += 2 * (ins->fspec); + } + clock->time += t; + return t; +} + diff --git a/mixlib/mix_vm_clock.h b/mixlib/mix_vm_clock.h new file mode 100644 index 0000000..c283b71 --- /dev/null +++ b/mixlib/mix_vm_clock.h @@ -0,0 +1,55 @@ +/* -*-c-*- ---------------- mix_vm_clock.h : + * Declaration of mix_vm_clock_t, a clock for the MIX virtual machine. + * ------------------------------------------------------------------ + * Last change: Time-stamp: <00/12/22 01:53:18 jose> + * ------------------------------------------------------------------ + * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef MIX_VM_CLOCK_H +#define MIX_VM_CLOCK_H + +#include "mix.h" +#include "mix_ins.h" + +/* the type of time unit */ +typedef gulong mix_time_t; + +/* the clock type */ +typedef struct mix_vm_clock_t +{ + mix_time_t time; +} mix_vm_clock_t; + +/* Create/delete a clock */ +extern mix_vm_clock_t * +mix_vm_clock_new (); + +extern void +mix_vm_clock_delete (mix_vm_clock_t *clock); + +/* Increase time with the units needed to execute ins */ +extern mix_time_t /* the added lapse */ +mix_vm_clock_add_lapse (mix_vm_clock_t *clock, const mix_ins_t *ins); + +/* Get the time since creation */ +#define mix_vm_clock_get_time(clock) (clock? clock->time:0) + +#endif /* MIX_VM_CLOCK_H */ + |