From fcc0a6a2031a6613a1e46fcc0b738a0b6c3d418f Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Mon, 6 Jan 2014 08:35:23 -0800 Subject: [PATCH] vec4 string literal expressions --- tgt-vvp/eval_expr.c | 2 +- tgt-vvp/eval_vec4.c | 39 +++++++++++++++++++++++++++++++++++++++ tgt-vvp/vvp_priv.h | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index 0f6988998..cfd14cc98 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -2231,7 +2231,7 @@ static struct vector_info draw_realnum_expr(ivl_expr_t expr, unsigned wid) return res; } -static char *process_octal_codes(const char *in, unsigned width) +char *process_octal_codes(const char *in, unsigned width) { unsigned idx = 0; unsigned ridx = 0; diff --git a/tgt-vvp/eval_vec4.c b/tgt-vvp/eval_vec4.c index 086e42be3..fa1bc3783 100644 --- a/tgt-vvp/eval_vec4.c +++ b/tgt-vvp/eval_vec4.c @@ -560,6 +560,41 @@ static void draw_signal_vec4(ivl_expr_t expr) clr_word(addr_index); } +static void draw_string_vec4(ivl_expr_t expr, int stuff_ok_flag) +{ + unsigned wid = ivl_expr_width(expr); + char*fp = process_octal_codes(ivl_expr_string(expr), wid); + char*p = fp; + + unsigned long tmp = 0; + unsigned tmp_wid = 0; + int push_flag = 0; + + for (unsigned idx = 0 ; idx < wid ; idx += 8) { + tmp <<= 8; + tmp |= *p; + p += 1; + tmp_wid += 8; + if (tmp_wid == 32) { + fprintf(vvp_out, " %%pushi/vec4 %lu, 0, 32;\n", tmp); + tmp = 0; + tmp_wid = 0; + if (push_flag != 0) + push_flag += 1; + else + fprintf(vvp_out, " %%concat/vec4;\n"); + } + } + + if (tmp_wid > 0) { + fprintf(vvp_out, " %%pushi/vec4 %lu, 0, %u;\n", tmp, tmp_wid); + if (push_flag != 0) + fprintf(vvp_out, " %%oncat/vec4;\n"); + } + + free(fp); +} + static void draw_ternary_vec4(ivl_expr_t expr, int stuff_ok_flag) { ivl_expr_t cond = ivl_expr_oper1(expr); @@ -734,6 +769,10 @@ void draw_eval_vec4(ivl_expr_t expr, int stuff_ok_flag) draw_signal_vec4(expr); return; + case IVL_EX_STRING: + draw_string_vec4(expr, stuff_ok_flag); + return; + case IVL_EX_TERNARY: draw_ternary_vec4(expr, stuff_ok_flag); return; diff --git a/tgt-vvp/vvp_priv.h b/tgt-vvp/vvp_priv.h index 7621a1471..60c9ede06 100644 --- a/tgt-vvp/vvp_priv.h +++ b/tgt-vvp/vvp_priv.h @@ -112,6 +112,8 @@ extern void draw_ufunc_object(ivl_expr_t expr); extern void pad_expr_in_place(ivl_expr_t expr, struct vector_info res, unsigned swid); +extern char* process_octal_codes(const char*txt, unsigned wid); + /* * modpath.c symbols. *