How to use MessageCallBackHandler Class
From Verific Design Automation FAQ
This is a small example showing how to use MessageCallBackHandler Class:
In C++:
#include <iostream> #include "veri_file.h" #include "Message.h" #include "Strings.h" #ifdef VERIFIC_NAMESPACE using namespace Verific ; #endif class MyMsgCallBack : public MessageCallBackHandler { public: MyMsgCallBack() : MessageCallBackHandler(), _msg_string(0) { } virtual ~MyMsgCallBack() { Strings::free(_msg_string) ; _msg_string = 0 ; } private: MyMsgCallBack(const MyMsgCallBack &) ; MyMsgCallBack& operator=(const MyMsgCallBack &) ; public: virtual void Msg(msg_type_t msg_type, const char *message_id, linefile_type linefile, const char *msg_str) ; const char * GetMessageString() const { return _msg_string ; } private: char *_msg_string ; } ; // class MyMsgCallBack void MyMsgCallBack::Msg(msg_type_t /*msg_type*/, const char * /*message_id*/, linefile_type /*linefile*/, const char *msg_str) { if (!_msg_string) { _msg_string = Strings::save(msg_str) ; } else { char *tmp = _msg_string ; _msg_string = Strings::save(_msg_string, "\n", msg_str) ; Strings::free(tmp) ; } } int main(int argc, const char **argv) { MyMsgCallBack mmcb ; Message::RegisterCallBackMsg(&mmcb) ; const char *in_file = (argc > 1) ? argv[1] : "test.v" ; if (!veri_file::Analyze(in_file)) return 1 ; const char *msg_str = mmcb.GetMessageString() ; std::cout << "\nAccumulated messages: \n" << msg_str << std::endl ; return 0 ; }
test.v:
module test (output [3:0] out) ; assign out = {1} ; endmodule
Run:
[moh@awing0 15065]$ ./test-linux -- Analyzing Verilog file 'test.v' (VERI-1482) test.v(2): WARNING: concatenation with an unsized literal will be treated as 32 bits (VERI-1320) Accumulated messages: Analyzing Verilog file 'test.v' concatenation with an unsized literal will be treated as 32 bits [moh@awing0 15065]$
In Python:
#!/usr/bin/python import sys sys.path.append('../py') import Verific class MyMessageCallBack(Verific.MessageCallBackHandler,object): _msg_string = "\nAccumulated message:\n" def __init__(obj): if not obj: return super(MyMessageCallBack,obj).__init__() def Msg(self, msg_type, message_id, linefile, msg_str): self._msg_string = self._msg_string + "\t" + self.GetLinefile(linefile) + self.GetMsgType(msg_type) + msg_str + " (" + message_id + ")\n" def GetLinefile(self, linefile): if not linefile: return "" return Verific.LineFile_GetFileName(linefile) + "(" + str(Verific.LineFile_GetLineNo(linefile)) + "): " def GetMsgType(self, msg_type): if (msg_type==Verific.VERIFIC_INFO): return "INFO: " elif (msg_type==Verific.VERIFIC_WARNING): return "WARNING: " elif (msg_type==Verific.VERIFIC_ERROR): return "ERROR: " return "-- " def GetMessageString(self): return self._msg_string mc = MyMessageCallBack() Verific.Message_RegisterCallBackMsg(mc) if (not Verific.veri_file_Analyze("test.v")): print("Error during analysis. Exiting.") sys.exit(1) print mc.GetMessageString() sys.exit(0)
Run:
[moh@awing0 15065]$ ./test.py -- Analyzing Verilog file 'test.v' (VERI-1482) test.v(2): WARNING: concatenation with an unsized literal will be treated as 32 bits (VERI-1320) Accumulated message: -- Analyzing Verilog file 'test.v' (VERI-1482) test.v(2): WARNING: concatenation with an unsized literal will be treated as 32 bits (VERI-1320) [moh@awing0 15065]$
In Perl:
#!/usr/bin/perl -w use strict ; use warnings ; use lib "../pm" ; require "Verific.pm" ; use Verific ; { package MyMessageCallBack ; use base 'Verific::MessageCallBackHandler' ; my $msg_string = "\nAccumulated message:\n" ; sub Msg { my ($class, $msg_type, $message_id, $linefile, $msg_str) = (@_) ; $msg_string .= "\t" . GetLinefile($linefile) . GetMsgType($msg_type) . "$msg_str ($message_id)\n" ; } sub GetLinefile { my ($linefile) = (@_) ; if (!$linefile) { return "" ; } ; return Verific::LineFile::GetFileName($linefile) . "(" . Verific::LineFile::GetLineNo($linefile) . "): " ; } sub GetMsgType { my ($msg_type) = (@_) ; if ($msg_type == $Verific::VERIFIC_INFO) { return "INFO: "; } elsif ($msg_type == $Verific::VERIFIC_WARNING) { return "WARNING: "; } elsif ($msg_type == $Verific::VERIFIC_ERROR) { return "ERROR: "; } return "-- "; } sub GetMessageString { return "$msg_string" ; } } my $mc = MyMessageCallBack->new() ; Verific::Message::RegisterCallBackMsg($mc) ; if (!Verific::veri_file::Analyze("test.v")) { print "Error during analysis. Exiting.\n" ; exit(1) ; } print $mc->GetMessageString() ; exit(0) ;
Run:
-- Analyzing Verilog file 'test.v' (VERI-1482) test.v(2): WARNING: concatenation with an unsized literal will be treated as 32 bits (VERI-1320) Accumulated message: -- Analyzing Verilog file 'test.v' (VERI-1482) test.v(2): WARNING: concatenation with an unsized literal will be treated as 32 bits (VERI-1320) [moh@awing0 15065]$