From 14f597acdd06c676532cb6b95ba83b72a8190145 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Tue, 15 Jul 2014 18:03:40 -0700 Subject: [PATCH] Add support for synthesis translate meta-comments. --- lexor.lex | 7 +++++-- parse.y | 9 +++++++++ pform.cc | 21 +++++++++++++++++++++ pform.h | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lexor.lex b/lexor.lex index dbcb6a251..b0c049307 100644 --- a/lexor.lex +++ b/lexor.lex @@ -134,9 +134,12 @@ TU [munpf] \n { yylloc.first_line += 1; } /* C++ style comments start with / / and run to the end of the - current line. These are very easy to handle. */ + current line. These are very easy to handle. The meta-comments + format is a little more tricky to handle, but do what we can. */ -"//".* { comment_enter = YY_START; BEGIN(LCOMMENT); } +"//"{W}*"synthesis"{W}*"translate_on"{W}*\n { return K_MC_TRANSLATE_ON; } +"//"{W}*"synthesis"{W}*"translate_off"{W}*\n { return K_MC_TRANSLATE_OFF; } +"//" { comment_enter = YY_START; BEGIN(LCOMMENT); } . { yymore(); } \n { yylloc.first_line += 1; BEGIN(comment_enter); } diff --git a/parse.y b/parse.y index dbbb2d799..166b08b78 100644 --- a/parse.y +++ b/parse.y @@ -532,6 +532,8 @@ static void current_function_set_statement(const YYLTYPE&loc, vector %token K_resolveto K_sin K_sinh K_slew K_split K_sqrt K_tan K_tanh %token K_timer K_transition K_units K_white_noise K_wreal %token K_zi_nd K_zi_np K_zi_zd K_zi_zp + /* Support some meta-comments as pragmas. */ +%token K_MC_TRANSLATE_ON K_MC_TRANSLATE_OFF %type from_exclude %type number pos_neg_number @@ -4246,6 +4248,13 @@ module_item /* Modules can contain further sub-module definitions. */ : module + /* The lexor detects "// synthesis translate_on/off" meta-comments, + we handle them here by turning on/off a flag. The pform uses + that flag to attach implicit attributes to "initial" and + "always" statements. */ + | K_MC_TRANSLATE_OFF { pform_mc_translate_on(false); } + | K_MC_TRANSLATE_ON { pform_mc_translate_on(true); } + | attribute_list_opt net_type data_type_or_implicit delay3_opt net_variable_list ';' { data_type_t*data_type = $3; diff --git a/pform.cc b/pform.cc index ff4114ba0..9d19cb68a 100644 --- a/pform.cc +++ b/pform.cc @@ -43,6 +43,15 @@ # include "ivl_assert.h" # include "ivl_alloc.h" +/* + * The "// synthesis translate_on/off" meta-comments cause this flag + * to be turned off or on. The pform_make_behavior and similar + * functions look at this flag and may choose to add implicit ivl + * synthesis flags. + */ +static bool pform_mc_translate_flag = true; +void pform_mc_translate_on(bool flag) { pform_mc_translate_flag = flag; } + /* * The pform_modules is a map of the modules that have been defined in * the top level. This should not contain nested modules/programs. @@ -3197,6 +3206,18 @@ PProcess* pform_make_behavior(ivl_process_type_t type, Statement*st, { PProcess*pp = new PProcess(type, st); + // If we are in a part of the code where the meta-comment + // synthesis translate_off is in effect, then implicitly add + // the ivl_synthesis_off attribute to any behavioral code that + // we run into. + if (pform_mc_translate_flag == false) { + if (attr == 0) attr = new list; + named_pexpr_t tmp; + tmp.name = perm_string::literal("ivl_synthesis_off"); + tmp.parm = 0; + attr->push_back(tmp); + } + pform_bind_attributes(pp->attributes, attr); pform_put_behavior_in_scope(pp); diff --git a/pform.h b/pform.h index ebe38395d..746258b8f 100644 --- a/pform.h +++ b/pform.h @@ -406,6 +406,7 @@ extern void pform_module_specify_path(PSpecPath*obj); */ extern PProcess* pform_make_behavior(ivl_process_type_t, Statement*, list*attr); +extern void pform_mc_translate_on(bool flag); extern std::vector* pform_make_udp_input_ports(list*);