2012-04-13 03:08:20 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2007-11-30 23:38:21 +01:00
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Emit C++ for tree
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2007-11-30 23:38:21 +01:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2020-03-21 16:24:24 +01:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you
|
|
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 23:07:57 +02:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2007-11-30 23:38:21 +01:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2007-11-30 23:38:21 +01:00
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3EmitC.h"
|
|
|
|
|
#include "V3EmitCBase.h"
|
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
|
2018-10-14 19:43:24 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdarg>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2007-11-30 23:38:21 +01:00
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
|
|
class EmitCInlines : EmitCBaseVisitor {
|
|
|
|
|
// STATE
|
|
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
void emitInt();
|
|
|
|
|
|
|
|
|
|
// VISITORS
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstBasicDType* nodep) VL_OVERRIDE {
|
2018-10-27 16:03:28 +02:00
|
|
|
if (nodep->keyword() == AstBasicDTypeKwd::STRING) {
|
|
|
|
|
// Request #include <string> via verilated_heavy.h when we create symbol file
|
|
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
}
|
2010-01-17 21:10:37 +01:00
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstAssocArrayDType* nodep) VL_OVERRIDE {
|
2019-12-01 17:52:48 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-03-07 16:24:27 +01:00
|
|
|
virtual void visit(AstDynArrayDType* nodep) VL_OVERRIDE {
|
|
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstQueueDType* nodep) VL_OVERRIDE {
|
2019-12-01 18:35:49 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstNodeReadWriteMem* nodep) VL_OVERRIDE {
|
2020-01-14 13:01:17 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstValuePlusArgs* nodep) VL_OVERRIDE {
|
2019-02-16 00:33:52 +01:00
|
|
|
v3Global.needHeavy(true);
|
2020-03-06 04:33:31 +01:00
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstNew* nodep) VL_OVERRIDE {
|
|
|
|
|
if (v3Global.opt.savable()) v3error("Unsupported: --savable with dynamic new");
|
2019-02-16 00:33:52 +01:00
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstAtoN* nodep) VL_OVERRIDE {
|
2019-12-10 01:17:52 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-03-02 03:39:23 +01:00
|
|
|
virtual void visit(AstDumpCtl* nodep) VL_OVERRIDE {
|
|
|
|
|
if (v3Global.opt.trace()) v3Global.needTraceDumper(true);
|
|
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstPutcN* nodep) VL_OVERRIDE {
|
2019-12-15 14:09:52 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstGetcN* nodep) VL_OVERRIDE {
|
2019-12-15 14:09:52 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-26 22:38:22 +01:00
|
|
|
virtual void visit(AstGetcRefN* nodep) VL_OVERRIDE {
|
|
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstSubstrN* nodep) VL_OVERRIDE {
|
2019-12-15 14:09:52 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstCompareNN* nodep) VL_OVERRIDE {
|
2019-12-10 01:17:52 +01:00
|
|
|
v3Global.needHeavy(true);
|
|
|
|
|
iterateChildren(nodep);
|
|
|
|
|
}
|
2007-11-30 23:38:21 +01:00
|
|
|
|
|
|
|
|
// Default
|
2020-01-21 23:35:56 +01:00
|
|
|
virtual void visit(AstNode* nodep) VL_OVERRIDE {
|
2018-05-11 02:55:37 +02:00
|
|
|
iterateChildren(nodep);
|
2007-11-30 23:38:21 +01:00
|
|
|
}
|
|
|
|
|
//---------------------------------------
|
|
|
|
|
// ACCESSORS
|
|
|
|
|
public:
|
2015-10-04 04:33:06 +02:00
|
|
|
explicit EmitCInlines(AstNetlist* nodep) {
|
2018-05-11 02:55:37 +02:00
|
|
|
iterate(nodep);
|
2018-10-27 16:03:28 +02:00
|
|
|
if (v3Global.needHInlines()) {
|
|
|
|
|
emitInt();
|
|
|
|
|
}
|
2007-11-30 23:38:21 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void EmitCInlines::emitInt() {
|
|
|
|
|
string filename = v3Global.opt.makeDir()+"/"+topClassName()+"__Inlines.h";
|
|
|
|
|
newCFile(filename, false/*slow*/, false/*source*/);
|
|
|
|
|
V3OutCFile hf (filename);
|
|
|
|
|
m_ofp = &hf;
|
|
|
|
|
|
|
|
|
|
ofp()->putsHeader();
|
2019-12-24 01:00:17 +01:00
|
|
|
ofp()->putsGuard();
|
2007-11-30 23:38:21 +01:00
|
|
|
puts("\n");
|
|
|
|
|
|
|
|
|
|
puts("#include \"verilated.h\"\n");
|
|
|
|
|
|
|
|
|
|
puts("\n//======================\n\n");
|
|
|
|
|
|
2017-09-19 03:36:18 +02:00
|
|
|
// Placeholder - v3Global.needHInlines(true) currently not used
|
2007-11-30 23:38:21 +01:00
|
|
|
|
|
|
|
|
puts("//======================\n\n");
|
2019-12-24 01:00:17 +01:00
|
|
|
ofp()->putsEndGuard();
|
2007-11-30 23:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// EmitC class functions
|
|
|
|
|
|
|
|
|
|
void V3EmitC::emitcInlines() {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
|
|
|
|
EmitCInlines syms (v3Global.rootp());
|
|
|
|
|
}
|