GNU Make & SystemC 小试

今天晚上搞搞了make,感觉比ant强大多了,总的来说,make写出来的东西很容易看懂,ant的就不是那么容易了,至少在对于我的方面。例子有点大,关于SystemC的,整个程序描述的是全加器(Full Adder)的实现。

 

half_adder.h 半加器的描述

#include "systemc.h" SC_MODULE(half_adder) { sc_in<bool> a, b; sc_out<bool> sum, carry; void prc_half_adder(); SC_CTOR(half_adder) { SC_METHOD(prc_half_adder); sensitive << a << b; } };

half_adder.cpp 半加器的实现

#include "half_adder.h" void half_adder::prc_half_adder() { sum = a ^ b; carry = a & b;

full_adder.h 全加器的描述

#include "half_adder.h" SC_MODULE(full_adder) { sc_in<bool> a, b, carry_in; sc_out<bool> sum, carry_out; sc_signal<bool> c1, s1, c2; void prc_or(); half_adder *ha1_ptr, *ha2_ptr; SC_CTOR(full_adder) { ha1_ptr = new half_adder("ha1"); ha1_ptr->a(a); ha1_ptr->b(b); ha1_ptr->sum(s1); ha1_ptr->carry(c1); ha2_ptr = new half_adder("ha2"); (*ha2_ptr)(s1, carry_in, sum, c2); SC_METHOD(prc_or); sensitive << c1 << c2; } ~full_adder() { delete ha1_ptr; delete ha2_ptr; } };

full_adeer.cpp 全加器的实现

#include "full_adder.h" void full_adder::prc_or() { carry_out = c1 | c2; }

driver.h 测试平台,每隔5ns输入一组输入信号

#include "systemc.h" SC_MODULE(driver) { sc_out<bool> d_a, d_b, d_cin; void prc_driver(); SC_CTOR(driver) { SC_THREAD(prc_driver); } };

driver.cpp 测试平台的实现

#include "driver.h" void driver::prc_driver() { sc_uint<3> pattern; pattern = 0; while(1) { d_a = pattern[0]; d_b = pattern[1]; d_cin = pattern[2]; wait(5, SC_NS); pattern++; } }

monitor.h 输出平台的描述

#include "systemc.h" SC_MODULE(monitor) { sc_in<bool> m_a, m_b, m_cin, m_sum, m_cout; void prc_monitor(); SC_CTOR(monitor) { SC_METHOD(prc_monitor); sensitive << m_a << m_b << m_cin << m_sum << m_cout; } };

monitor.cpp 输出平台的实现

#include "monitor.h" void monitor::prc_monitor() { cout << "At time" << sc_time_stamp() << "::"; cout << "(a, b, carry_in): "; cout << m_a << m_b << m_cin; cout << "(sum, carry_out): " << m_sum << m_cout << endl; }

full_adder_main.cpp 主程序,把他们都连接在一起

#include "driver.h" #include "monitor.h" #include "full_adder.h" int sc_main(int argc, char* argv[]) { sc_signal<bool> t_a, t_b, t_cin, t_sum, t_cout; full_adder f1("FullAdderWithHalfAdder"); f1 << t_a << t_b << t_cin << t_sum << t_cout; driver d1("GenerateWaveforms"); d1.d_a(t_a); d1.d_b(t_b); d1.d_cin(t_cin); monitor mo1("MonitorWaveforms"); mo1 << t_a << t_b << t_cin << t_sum << t_cout; sc_start(100, SC_NS); return (0); }

Makefile

TARGET = adder SOURCES = monitor.cpp driver.cpp full_adder_main.cpp full_adder.cpp half_adder.cpp CC = g++ OBJECTS = $(SOURCES:.cpp=.o) CFLAGS = -I /usr/local/systemc-2.2/include/ LFLAGS = -L /usr/local/systemc-2.2/lib-linux/ -l systemc all: $(TARGET) .cpp.o: $(CC) $< $(CFLAGS) -c $(TARGET): $(OBJECTS) $(CC) $(OBJECTS) $(CFLAGS) $(LFLAGS) -o $@ #The first time I wrote as follow: # $(CC) $(CFLAGS) $(LFLAGS) $(OBJECTS) -o $@ #and it was wrong... clean: rm -f $(OBJECTS) veryclean: clean rm -f $(TARGET)

Makefile写的比较郁闷,注释里面写出了郁闷的地方,如果有大侠知道为什么,希望回复一下为什么,感激不尽……

你可能感兴趣的:(GNU Make & SystemC 小试)