Merge pull request #591 from hzeller/virtual-override
[yosys.git] / frontends / ast / ast.h
index 18064626715e6a795aa02aa33ef6d4e1359e1a52..d94199643ccb37ddb93bc7cb99d3f3464a35adfa 100644 (file)
@@ -1,12 +1,12 @@
-/*
+/* -*- c++ -*-
  *  yosys -- Yosys Open SYnthesis Suite
  *
  *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at>
- *  
+ *
  *  Permission to use, copy, modify, and/or distribute this software for any
  *  purpose with or without fee is hereby granted, provided that the above
  *  copyright notice and this permission notice appear in all copies.
- *  
+ *
  *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@@ -64,6 +64,10 @@ namespace AST
                AST_IDENTIFIER,
                AST_PREFIX,
                AST_ASSERT,
+               AST_ASSUME,
+               AST_LIVE,
+               AST_FAIR,
+               AST_COVER,
 
                AST_FCALL,
                AST_TO_BITS,
@@ -107,6 +111,7 @@ namespace AST
                AST_TERNARY,
                AST_MEMRD,
                AST_MEMWR,
+               AST_MEMINIT,
 
                AST_TCALL,
                AST_ASSIGN,
@@ -120,6 +125,8 @@ namespace AST
                AST_ASSIGN_LE,
                AST_CASE,
                AST_COND,
+               AST_CONDX,
+               AST_CONDZ,
                AST_DEFAULT,
                AST_FOR,
                AST_WHILE,
@@ -133,7 +140,9 @@ namespace AST
 
                AST_POSEDGE,
                AST_NEGEDGE,
-               AST_EDGE
+               AST_EDGE,
+
+               AST_PACKAGE
        };
 
        // convert an node type to a string (e.g. for debug output)
@@ -159,7 +168,7 @@ namespace AST
                // node content - most of it is unused in most node types
                std::string str;
                std::vector<RTLIL::State> bits;
-               bool is_input, is_output, is_reg, is_signed, is_string, range_valid, range_swapped;
+               bool is_input, is_output, is_reg, is_logic, is_signed, is_string, range_valid, range_swapped, was_checked;
                int port_id, range_left, range_right;
                uint32_t integer;
                double realvalue;
@@ -180,9 +189,9 @@ namespace AST
                int linenum;
 
                // creating and deleting nodes
-               AstNode(AstNodeType type = AST_NONE, AstNode *child1 = NULL, AstNode *child2 = NULL);
-               AstNode *clone();
-               void cloneInto(AstNode *other);
+               AstNode(AstNodeType type = AST_NONE, AstNode *child1 = NULL, AstNode *child2 = NULL, AstNode *child3 = NULL);
+               AstNode *clone() const;
+               void cloneInto(AstNode *other) const;
                void delete_children();
                ~AstNode();
 
@@ -208,13 +217,14 @@ namespace AST
                // simplify() creates a simpler AST by unrolling for-loops, expanding generate blocks, etc.
                // it also sets the id2ast pointers so that identifier lookups are fast in genRTLIL()
                bool simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, int width_hint, bool sign_hint, bool in_param);
-               AstNode *readmem(bool is_readmemh, std::string mem_filename, AstNode *memory, int start_addr, int finish_addr);
+               AstNode *readmem(bool is_readmemh, std::string mem_filename, AstNode *memory, int start_addr, int finish_addr, bool unconditional_init);
                void expand_genblock(std::string index_var, std::string prefix, std::map<std::string, std::string> &name_map);
                void replace_ids(const std::string &prefix, const std::map<std::string, std::string> &rules);
                void mem2reg_as_needed_pass1(dict<AstNode*, pool<std::string>> &mem2reg_places,
                                dict<AstNode*, uint32_t> &mem2reg_flags, dict<AstNode*, uint32_t> &proc_flags, uint32_t &status_flags);
-               void mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block);
+               bool mem2reg_as_needed_pass2(pool<AstNode*> &mem2reg_set, AstNode *mod, AstNode *block, AstNode *&async_block);
                bool mem2reg_check(pool<AstNode*> &mem2reg_set);
+               void mem2reg_remove(pool<AstNode*> &mem2reg_set, vector<AstNode*> &delnodes);
                void meminfo(int &mem_width, int &mem_size, int &addr_bits);
 
                // additional functionality for evaluating constant functions
@@ -224,8 +234,8 @@ namespace AST
                AstNode *eval_const_function(AstNode *fcall);
 
                // create a human-readable text representation of the AST (for debugging)
-               void dumpAst(FILE *f, std::string indent);
-               void dumpVlog(FILE *f, std::string indent);
+               void dumpAst(FILE *f, std::string indent) const;
+               void dumpVlog(FILE *f, std::string indent) const;
 
                // used by genRTLIL() for detecting expression width and sign
                void detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *found_real = NULL);
@@ -254,26 +264,27 @@ namespace AST
                RTLIL::Const asAttrConst();
                RTLIL::Const asParaConst();
                uint64_t asInt(bool is_signed);
-               bool bits_only_01();
-               bool asBool();
+               bool bits_only_01() const;
+               bool asBool() const;
 
                // helper functions for real valued const eval
-               int isConst(); // return '1' for AST_CONSTANT and '2' for AST_REALVALUE
+               int isConst() const; // return '1' for AST_CONSTANT and '2' for AST_REALVALUE
                double asReal(bool is_signed);
                RTLIL::Const realAsConst(int width);
        };
 
        // process an AST tree (ast must point to an AST_DESIGN node) and generate RTLIL code
-       void process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump_ast2, bool dump_vlog, bool nolatches, bool nomem2reg, bool mem2reg, bool lib, bool noopt, bool icells, bool ignore_redef, bool defer, bool autowire);
+       void process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump_ast2, bool dump_vlog, bool dump_rtlil, bool nolatches, bool nomeminit,
+                       bool nomem2reg, bool mem2reg, bool lib, bool noopt, bool icells, bool nooverwrite, bool overwrite, bool defer, bool autowire);
 
        // parametric modules are supported directly by the AST library
-       // therfore we need our own derivate of RTLIL::Module with overloaded virtual functions
+       // therefore we need our own derivate of RTLIL::Module with overloaded virtual functions
        struct AstModule : RTLIL::Module {
                AstNode *ast;
-               bool nolatches, nomem2reg, mem2reg, lib, noopt, icells, autowire;
-               virtual ~AstModule();
-               virtual RTLIL::IdString derive(RTLIL::Design *design, dict<RTLIL::IdString, RTLIL::Const> parameters);
-               virtual RTLIL::Module *clone() const;
+               bool nolatches, nomeminit, nomem2reg, mem2reg, lib, noopt, icells, autowire;
+               ~AstModule() YS_OVERRIDE;
+               RTLIL::IdString derive(RTLIL::Design *design, dict<RTLIL::IdString, RTLIL::Const> parameters, bool mayfail) YS_OVERRIDE;
+               RTLIL::Module *clone() const YS_OVERRIDE;
        };
 
        // this must be set by the language frontend before parsing the sources
@@ -294,13 +305,15 @@ namespace AST
 namespace AST_INTERNAL
 {
        // internal state variables
-       extern bool flag_dump_ast1, flag_dump_ast2, flag_nolatches, flag_nomem2reg, flag_mem2reg, flag_lib, flag_noopt, flag_icells, flag_autowire;
+       extern bool flag_dump_ast1, flag_dump_ast2, flag_dump_rtlil, flag_nolatches, flag_nomeminit;
+       extern bool flag_nomem2reg, flag_mem2reg, flag_lib, flag_noopt, flag_icells, flag_autowire;
        extern AST::AstNode *current_ast, *current_ast_mod;
        extern std::map<std::string, AST::AstNode*> current_scope;
        extern const dict<RTLIL::SigBit, RTLIL::SigBit> *genRTLIL_subst_ptr;
        extern RTLIL::SigSpec ignoreThisSignalsInInitial;
-       extern AST::AstNode *current_top_block, *current_block, *current_block_child;
+       extern AST::AstNode *current_always, *current_top_block, *current_block, *current_block_child;
        extern AST::AstModule *current_module;
+       extern bool current_always_clocked;
        struct ProcessGenerator;
 }