/** * evaluate one initializer, add data to table * @param symbol_name * @param type * @param identity * @param dim * @param tag * @return * returns size of initializer, or 0 for none (a null string is size 1) * */ int init(char *symbol_name, int type, int identity, int *dim, TAG_SYMBOL *tag) { int value, n; /* A pointer is initialized as a word holding the address of the struct or string etc that directly follows */ if(identity == POINTER) { int x = getlabel(); gen_def_word(); print_label(x); newline(); print_label(x); output_label_terminator(); newline(); } /* FIXME: may need to distinguish const string v data in future */ if(quoted_string(&n, NULL)) { if((identity == VARIABLE) || !(type & CCHAR)) error("found string: must assign to char pointer or array"); *dim = *dim - n; /* ??? FIXME arrays of char only */ return n; } if (type & CCHAR) gen_def_byte(); else gen_def_word(); if (!number(&value) && !quoted_char(&value)) return 0; *dim = *dim - 1; output_number(value); newline(); return (type & CCHAR) ? 1 : 2; }
int constant(int val[]) { if (number (val)) gen_immediate (); else if (quoted_char (val)) gen_immediate (); else if (quoted_string (val)) { gen_immediate (); print_label (litlab); output_byte ('+'); } else return (0); output_number (val[0]); newline (); return (1); }
char* sbbs_cmdstr(const char* src ,char* buf ,size_t buflen /* includes '\0' terminator */ ,scfg_t* scfg ,user_t* user ,int node_num ,int minutes ,int rows ,int timeleft ,SOCKET socket_descriptor ,char* protocol ,char* ip_address ,char* fpath ,char* fspec ) { const char* nulstr = ""; char alias_buf[LEN_ALIAS+1]; char fpath_buf[MAX_PATH+1]; char fspec_buf[MAX_PATH+1]; char sysop_buf[sizeof(scfg->sys_op)]; keyed_string_t str_list[] = { /* user alias */ { 'a', user!=NULL ? quoted_string(user->alias, alias_buf, sizeof(alias_buf)) : nulstr }, { 'A', user!=NULL ? user->alias : nulstr }, /* connection */ { 'c', protocol }, { 'C', protocol }, /* file path */ { 'f', quoted_string(fpath, fpath_buf, sizeof(fpath_buf)) }, { 'F', fpath }, /* temp dir */ { 'g', scfg->temp_dir }, { 'G', scfg->temp_dir }, /* IP address */ { 'h', ip_address }, { 'H', ip_address }, /* data dir */ { 'j', scfg->data_dir }, { 'J', scfg->data_dir }, /* ctrl dir */ { 'k', scfg->ctrl_dir }, { 'K', scfg->ctrl_dir }, /* node dir */ { 'n', scfg->node_dir }, { 'N', scfg->node_dir }, /* sysop */ { 'o', quoted_string(scfg->sys_op, sysop_buf, sizeof(sysop_buf)) }, { 'O', scfg->sys_op }, /* protocol */ { 'p', protocol }, { 'P', protocol }, /* system QWK-ID */ { 'q', scfg->sys_id }, { 'Q', scfg->sys_id }, /* file spec */ { 's', quoted_string(fspec, fspec_buf, sizeof(fspec_buf)) }, { 'S', fspec }, /* UART I/O Address (in hex) 'f' for FOSSIL */ { 'u', "f" }, { 'U', "f" }, /* text dir */ { 'z', scfg->text_dir }, { 'Z', scfg->text_dir }, /* exec dir */ { '!', scfg->exec_dir }, { '@', #ifndef __unix__ scfg->exec_dir #else nulstr #endif }, /* .exe (on Windows) */ { '.', #ifndef __unix__ ".exe" #else nulstr #endif }, /* terminator */ { 0 } }; keyed_int_t int_list[] = { /* node number */ { '#', node_num }, /* DTE rate */ { 'b', 38400 }, { 'B', 38400 }, /* DCE rate */ { 'd', 30000 }, { 'D', 30000 }, /* Estimated Rate (cps) */ { 'e', 3000 }, { 'E', 3000 }, { 'h', socket_descriptor }, { 'H', socket_descriptor }, { 'l', user==NULL ? 0 : scfg->level_linespermsg[user->level] }, { 'L', user==NULL ? 0 : scfg->level_linespermsg[user->level] }, { 'm', minutes }, { 'M', minutes }, { 'r', rows }, { 'R', rows }, /* Time left in seconds */ { 't', timeleft }, { 'T', timeleft }, /* Credits */ { '$', user==NULL ? 0 : (user->cdt+user->freecdt) }, /* terminator */ { 0 } }; return replace_keyed_values(src, buf, buflen, '%', str_list, int_list, TRUE); }
// Build the design hierarchy. int build_hierarchy(ivl_scope_t scope, void* cd) { int return_code; unsigned i, j; indent(); fprintf(output, "(scope "); quoted_string(ivl_scope_tname(scope)); fprintf(output, " "); quoted_string(ivl_scope_basename(scope)); fprintf(output, " (\n"); // Constants (root scope only) if (! level) for (i = 0; i < ivl_design_consts(design); i++) { ivl_net_const_t constant = ivl_design_const(design, i); const char* bits = ivl_const_bits(constant); unsigned pins = ivl_const_pins(constant); unsigned id = new_id(); indent(); fprintf(output, " (const %i \"", id); for (j = pins - 1; j < pins; j--) fprintf(output, "%c", bits[j]); fprintf(output, "\")\n"); for (j = 0; j < pins; j++) create_bit_select(id_of_nexus(ivl_const_pin(constant, j), 1), pins, j, id); } // Parameters for (i = 0; i < ivl_scope_params(scope); i++) { ivl_parameter_t param = ivl_scope_param(scope, i); ivl_expr_t param_value = ivl_parameter_expr(param); unsigned width = ivl_expr_width(param_value); const char* bits; unsigned id = new_id(); indent(); fprintf(output, " (const %i \"", id); switch (ivl_expr_type(param_value)) { case IVL_EX_STRING : bits = ivl_expr_string(param_value); break; case IVL_EX_NUMBER : bits = ivl_expr_bits(param_value); break; default : fprintf(output, "** ERROR: Unknown parameter type."); return -1; } for (j = width - 1; j < width; j--) fprintf(output, "%c", bits[j]); fprintf(output, "\")\n"); indent(); fprintf(output, " (name %i ", new_id()); quoted_string(ivl_parameter_basename(param)); fprintf(output, " %i %i)\n", width, id); } // Signals for (i = 0; i < ivl_scope_sigs(scope); i++) { ivl_signal_t sig = ivl_scope_sig(scope, i); unsigned pins = ivl_signal_pins(sig); ivl_signal_port_t type = ivl_signal_port(sig); const char* name = ivl_signal_basename(sig); unsigned id; if (! level && type == IVL_SIP_INPUT) { id = new_id(); fprintf(output, " (input %i \"%s\" %i)\n", id, name, pins); for (j = 0; j < pins; j++) create_bit_select(id_of_nexus(ivl_signal_pin(sig, j), 1), pins, j, id); } else if (! level && type == IVL_SIP_INOUT) { printf("** ERROR: Inout ports not supported.\n"); } else if (! level && type == IVL_SIP_OUTPUT) { id = id_of_nexus(ivl_signal_pin(sig, 0), 0); for (j = 1; j < pins; j++) { id = create_bit_concat(id, j, ivl_signal_pin(sig, j)); } fprintf(output, " (output %i \"%s\" %i %i)\n", new_id(), name, pins, id); } else { id = id_of_nexus(ivl_signal_pin(sig, 0), 0); for (j = 1; j < pins; j++) { id = create_bit_concat(id, j, ivl_signal_pin(sig, j)); } indent(); fprintf(output, " (name %i ", new_id()); //XXX Why is "_s22" getting named? quoted_string(name); fprintf(output, " %i %i)\n", pins, id); } } // Logic for (i = 0; i < ivl_scope_logs(scope); i++) { unsigned id; ivl_net_logic_t log = ivl_scope_log(scope, i); switch (ivl_logic_type(log)) { case IVL_LO_BUF: indent(); fprintf(output, " (buf %i 1 %i)\n", id_of_nexus(ivl_logic_pin(log, 0), 1), id_of_nexus(ivl_logic_pin(log, 1), 0)); break; case IVL_LO_NOT: indent(); fprintf(output, " (not %i 1 %i)\n", id_of_nexus(ivl_logic_pin(log, 0), 1), id_of_nexus(ivl_logic_pin(log, 1), 0)); break; case IVL_LO_AND: indent(); create_multi_gate("and ", id_of_nexus(ivl_logic_pin(log, 0), 1), log); break; case IVL_LO_NAND: id = new_id(); indent(); create_multi_gate("and ", id, log); indent(); fprintf(output, " (not %i 1 %i)\n", id_of_nexus(ivl_logic_pin(log, 0), 1), id); break; case IVL_LO_XOR: indent(); create_multi_gate("xor ", id_of_nexus(ivl_logic_pin(log, 0), 1), log); break; case IVL_LO_XNOR: id = new_id(); indent(); create_multi_gate("xor ", id, log); indent(); fprintf(output, " (not %i 1 %i)\n", id_of_nexus(ivl_logic_pin(log, 0), 1), id); break; case IVL_LO_OR: indent(); create_multi_gate("or ", id_of_nexus(ivl_logic_pin(log, 0), 1), log); break; case IVL_LO_NOR: id = new_id(); indent(); create_multi_gate("or ", id, log); indent(); fprintf(output, " (not %i 1 %i)\n", id_of_nexus(ivl_logic_pin(log, 0), 1), id); break; default: printf("** ERROR: Unsupported logic type: %i.\n", ivl_logic_type(log)); return -1; } } // LPMs for (i = 0; i < ivl_scope_lpms(scope); i++) { ivl_lpm_t lpm = ivl_scope_lpm(scope, i); ivl_lpm_type_t lpm_t = ivl_lpm_type(lpm); unsigned width = ivl_lpm_width(lpm); unsigned selects; unsigned size; unsigned id, id1, id2, id3; switch (lpm_t) { case IVL_LPM_ADD: id = new_id(); id1 = create_concat_lpm_data(lpm); id2 = create_concat_lpm_datab(lpm); indent(); fprintf(output, " (add %i %i %i %i)\n", id, width, id1, id2); create_split_lpm_q(lpm, id); break; case IVL_LPM_SUB: id = new_id(); id1 = create_concat_lpm_data(lpm); id2 = create_concat_lpm_datab(lpm); indent(); fprintf(output, " (sub %i %i %i %i)\n", id, width, id1, id2); create_split_lpm_q(lpm, id); break; case IVL_LPM_MULT: id = new_id(); id1 = create_concat_lpm_data(lpm); id2 = create_concat_lpm_datab(lpm); indent(); fprintf(output, " (mul %i %i %i %i)\n", id, width, id1, id2); create_split_lpm_q(lpm, id); break; case IVL_LPM_CMP_EQ: id1 = create_concat_lpm_data(lpm); id2 = create_concat_lpm_datab(lpm); indent(); fprintf(output, " (eq %i %i %i %i)\n", id_of_nexus(ivl_lpm_q(lpm, 0), 1), width, id1, id2); break; case IVL_LPM_CMP_NE: id1 = create_concat_lpm_data(lpm); id2 = create_concat_lpm_datab(lpm); id = new_id(); indent(); fprintf(output, " (eq %i %i %i %i)\n", id, width, id1, id2); indent(); fprintf(output, " (not %i 1 %i)\n", id_of_nexus(ivl_lpm_q(lpm, 0), 1), id); break; case IVL_LPM_CMP_GT: // XXX Check for signed. id1 = create_concat_lpm_data(lpm); id2 = create_concat_lpm_datab(lpm); indent(); fprintf(output, " (lt %i %i %i %i)\n", id_of_nexus(ivl_lpm_q(lpm, 0), 1), width, id2, id1); break; case IVL_LPM_CMP_GE: // XXX Check for signed. id1 = create_concat_lpm_data(lpm); id2 = create_concat_lpm_datab(lpm); id = new_id(); indent(); fprintf(output, " (lt %i %i %i %i)\n", id, width, id1, id2); indent(); fprintf(output, " (not %i 1 %i)\n", id_of_nexus(ivl_lpm_q(lpm, 0), 1), id); break; case IVL_LPM_FF: { ivl_nexus_t async_clr = ivl_lpm_async_clr(lpm); ivl_nexus_t async_set = ivl_lpm_async_set(lpm); ivl_nexus_t sync_clr = ivl_lpm_sync_clr(lpm); ivl_nexus_t sync_set = ivl_lpm_sync_set(lpm); ivl_nexus_t clk = ivl_lpm_clk(lpm); ivl_nexus_t enable = ivl_lpm_enable(lpm); if (async_set || sync_set) { perror("** ERROR: Does not support registers with async or sync sets.\n"); return -1; } id = new_id(); id1 = create_concat_lpm_data(lpm); if (enable) { id2 = new_id(); indent(); fprintf(output, " (mux %i %i %i %i %i)\n", id2, width, id_of_nexus(enable, 0), id, id1); id1 = id2; } if (sync_clr) { id2 = new_id(); id3 = new_id(); indent(); fprintf(output, " (const %i \"", id3); for (j = 0; j < width; j++) fprintf(output, "0"); fprintf(output, "\")\n"); indent(); fprintf(output, " (mux %i %i %i %i %i)\n", id2, width, id_of_nexus(sync_clr, 0), id1, id3); id1 = id2; } // XXX Default to posedge sensitivity. if (async_clr) { indent(); fprintf(output, " (ffc %i %i %i %i %i)\n", id, width, id_of_nexus(async_clr, 0), id_of_nexus(clk, 0), id1); } else { indent(); fprintf(output, " (ff %i %i %i %i)\n", id, width, id_of_nexus(clk, 0), id1); } create_split_lpm_q(lpm, id); } break; case IVL_LPM_MUX: { unsigned t = 1; selects = ivl_lpm_selects(lpm); size = ivl_lpm_size(lpm); for (j = 0; j < selects; j++) t = t * 2; assert(t == size); // General case. id = create_mux(lpm, selects, 0); create_split_lpm_q(lpm, id); } break; default: perror("** ERROR: Unsupported LPM type.\n"); return -1; } } level = level + 1; return_code = ivl_scope_children(scope, build_hierarchy, 0); level = level - 1; if (! level) delete_nexus_table(nexus_table); indent(); fprintf(output, "))\n"); return return_code; }