/* * Copyright (c) 2003-2008 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form 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 "compile.h" # include "vpi_priv.h" # include "array.h" # include "schedule.h" # include # include # include # include #ifdef HAVE_MALLOC_H # include #endif # include static void __compile_var_real(char*label, char*name, vvp_array_t array, unsigned long array_addr, int msb, int lsb) { vvp_fun_signal_real*fun = new vvp_fun_signal_real; vvp_net_t*net = new vvp_net_t; net->fun = fun; define_functor_symbol(label, net); vpiHandle obj = vpip_make_real_var(name, net); compile_vpi_symbol(label, obj); if (name) { assert(!array); vpip_attach_to_current_scope(obj); schedule_init_vector(vvp_net_ptr_t(net,0), fun->real_value()); } if (array) { assert(!name); array_attach_word(array, array_addr, obj); } free(label); if (name) free(name); } void compile_var_real(char*label, char*name, int msb, int lsb) { __compile_var_real(label, name, 0, 0, msb, lsb); } void compile_varw_real(char*label, vvp_array_t array, unsigned long addr, int msb, int lsb) { __compile_var_real(label, 0, array, addr, msb, lsb); } /* * A variable is a special functor, so we allocate that functor and * write the label into the symbol table. */ static void __compile_var(char*label, char*name, vvp_array_t array, unsigned long array_addr, int msb, int lsb, char signed_flag, bool local_flag) { unsigned wid = ((msb > lsb)? msb-lsb : lsb-msb) + 1; vvp_fun_signal*vsig = new vvp_fun_signal(wid); vvp_net_t*node = new vvp_net_t; node->fun = vsig; define_functor_symbol(label, node); vpiHandle obj = 0; if (! local_flag && !array) { /* Make the vpiHandle for the reg. */ obj = (signed_flag > 1) ? vpip_make_int(name, msb, lsb, node) : vpip_make_reg(name, msb, lsb, signed_flag!=0, node); compile_vpi_symbol(label, obj); } // If the signal has a name, then it goes into the current // scope as a signal. if (name) { assert(!array); if (obj) vpip_attach_to_current_scope(obj); schedule_init_vector(vvp_net_ptr_t(node,0), vsig->vec4_value()); } // If this is an array word, then it does not have a name, and // it is attached to the addressed array. if (array) { assert(!name); if (obj) array_attach_word(array, array_addr, obj); } free(label); if (name) free(name); } void compile_variable(char*label, char*name, int msb, int lsb, char signed_flag, bool local_flag) { __compile_var(label, name, 0, 0, msb, lsb, signed_flag, local_flag); } /* * In this case, the variable it intended to be attached to the array * as a word. The array_addr is the *canonical* address of the word in * the array. * * This function is actually used by the compile_array function, * instead of directly by the parser. */ void compile_variablew(char*label, vvp_array_t array, unsigned long array_addr, int msb, int lsb, char signed_flag) { __compile_var(label, 0, array, array_addr, msb, lsb, signed_flag, false); } /* * Here we handle .net records from the vvp source: * *