Fixes related to handling of autowires and upto-ranges, fixes #814
authorClifford Wolf <clifford@clifford.at>
Thu, 21 Feb 2019 17:40:11 +0000 (18:40 +0100)
committerClifford Wolf <clifford@clifford.at>
Thu, 21 Feb 2019 17:40:11 +0000 (18:40 +0100)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
frontends/ast/genrtlil.cc
frontends/ast/simplify.cc

index bdc34d490cd24f01047afde7953aa125f9d1d92e..2d591b29d31b8294925afc770838437d78fb5f7d 100644 (file)
@@ -644,7 +644,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
                                while (right_at_zero_ast->simplify(true, true, false, 1, -1, false, false)) { }
                                if (left_at_zero_ast->type != AST_CONSTANT || right_at_zero_ast->type != AST_CONSTANT)
                                        log_file_error(filename, linenum, "Unsupported expression on dynamic range select on signal `%s'!\n", str.c_str());
-                               this_width = left_at_zero_ast->integer - right_at_zero_ast->integer + 1;
+                               this_width = abs(int(left_at_zero_ast->integer - right_at_zero_ast->integer)) + 1;
                                delete left_at_zero_ast;
                                delete right_at_zero_ast;
                        } else
@@ -1034,7 +1034,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint)
                                        while (right_at_zero_ast->simplify(true, true, false, 1, -1, false, false)) { }
                                        if (left_at_zero_ast->type != AST_CONSTANT || right_at_zero_ast->type != AST_CONSTANT)
                                                log_file_error(filename, linenum, "Unsupported expression on dynamic range select on signal `%s'!\n", str.c_str());
-                                       int width = left_at_zero_ast->integer - right_at_zero_ast->integer + 1;
+                                       int width = abs(int(left_at_zero_ast->integer - right_at_zero_ast->integer)) + 1;
                                        AstNode *fake_ast = new AstNode(AST_NONE, clone(), children[0]->children.size() >= 2 ?
                                                        children[0]->children[1]->clone() : children[0]->children[0]->clone());
                                        fake_ast->children[0]->delete_children();
index 6ae62ead80035b8de83697ffdef35633ea3c43bb..737fb300cc00677565440baa8be56928bbfab509 100644 (file)
@@ -934,12 +934,15 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
                        }
                }
                if (current_scope.count(str) == 0) {
-                       // log_warning("Creating auto-wire `%s' in module `%s'.\n", str.c_str(), current_ast_mod->str.c_str());
-                       AstNode *auto_wire = new AstNode(AST_AUTOWIRE);
-                       auto_wire->str = str;
-                       current_ast_mod->children.push_back(auto_wire);
-                       current_scope[str] = auto_wire;
-                       did_something = true;
+                       if (flag_autowire) {
+                               AstNode *auto_wire = new AstNode(AST_AUTOWIRE);
+                               auto_wire->str = str;
+                               current_ast_mod->children.push_back(auto_wire);
+                               current_scope[str] = auto_wire;
+                               did_something = true;
+                       } else {
+                               log_file_error(filename, linenum, "Identifier `%s' is implicitly declared and `default_nettype is set to none.\n", str.c_str());
+                       }
                }
                if (id2ast != current_scope[str]) {
                        id2ast = current_scope[str];
@@ -1689,7 +1692,7 @@ skip_dynamic_range_lvalue_expansion:;
                                while (right_at_zero_ast->simplify(true, true, false, 1, -1, false, false)) { }
                                if (left_at_zero_ast->type != AST_CONSTANT || right_at_zero_ast->type != AST_CONSTANT)
                                        log_file_error(filename, linenum, "Unsupported expression on dynamic range select on signal `%s'!\n", str.c_str());
-                               int width = left_at_zero_ast->integer - right_at_zero_ast->integer + 1;
+                               int width = abs(int(left_at_zero_ast->integer - right_at_zero_ast->integer)) + 1;
 
                                assign_data = new AstNode(AST_ASSIGN_LE, new AstNode(AST_IDENTIFIER),
                                                new AstNode(AST_SHIFT_LEFT, children[1]->clone(), offset_ast->clone()));