Commit ea3b8d65 authored by Frédéric Pétrot's avatar Frédéric Pétrot
Browse files

Initial commit

parents
BasedOnStyle: llvm
IndentWidth: 8
UseTab: ForIndentation
Standard: Cpp03
AccessModifierOffset: -8
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
#include "Add8bits.h"
Add8bits::Add8bits(sc_module_name name) : sc_core::sc_module(name)
{
SC_METHOD(calcul);
sensitive << a << b;
}
void Add8bits::calcul()
{
c.write(a.read() + b.read());
}
#include <systemc>
SC_MODULE(Add8bits)
{
sc_core::sc_in<sc_core::sc_uint<8> > a, b;
sc_core::sc_out<sc_core::sc_uint<8> > c;
SC_CTOR(Add8bits);
void calcul();
};
# Makefile SystemC
# by Jerome Cornet
# Only one variable needed: SYSTEMCROOT, pointing
# to the systemc install and source tree
SYSTEMC = $(SYSTEMCROOT)
TLM = $(TLMROOT)
# guess target os name used by systemc's configure
ARCH = $(shell uname -m | sed -e 's/x86_64.*/linux64/' -e 's/i.86.*/linux/')
INCLUDES = -I. -I$(SYSTEMC)/include
CC = g++
CPPFLAGS = $(INCLUDES)
CXXFLAGS = -Wno-deprecated -O0
LD = $(CC)
LDFLAGS =
LDLIBS = -L. -L$(SYSTEMC)/lib-$(ARCH) -Xlinker -Bstatic -lsystemc -Xlinker -Bdynamic -lm -pthread
SRCS = $(wildcard *.cpp)
DEPS = $(SRCS:%.cpp=%.d)
OBJS = $(SRCS:%.cpp=%.o)
PROGRAM = run.x
all: $(PROGRAM)
clean: FORCE
-rm -f *.d *.o *.out core $(PROGRAM) trace.vcd
$(PROGRAM): $(DEPS) $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $(PROGRAM) 2>&1 | c++filt
%.d: %.cpp
@ echo Making dependencies for $<
@ $(CC) -MM $(INCLUDES) $< | sed 's#: # $*.d : #1' > $@
%.o: %.cpp %.d
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Include dependency files
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
FORCE: ;
#include "Testbench.h"
Testbench::Testbench(sc_module_name name) : sc_module(name)
{
SC_THREAD(test);
}
void Testbench::test()
{
while (true)
{
for (int i=0; i<16; i++)
{
for (int j=0; j<16; j++)
{
a.write(sc_uint<8>(i));
b.write(sc_uint<8>(j));
wait(5, SC_NS);
}
}
}
}
#include <systemc>
SC_MODULE(Testbench)
{
sc_core::sc_out<sc_uint<8> > a, b;
sc_core::sc_in<sc_uint<8> > c;
SC_CTOR(Testbench);
void test();
};
#include <systemc>
#include "Add8bits.h"
#include "Testbench.h"
using namespace std;
int sc_main(int, char**)
{
Add8bits add("Add");
Testbench testbench("Testbench");
sc_core::sc_signal<sc_core::sc_uint<8> > sa, sb, sc;
testbench.a(sa);
testbench.b(sb);
testbench.c(sc);
add.a(sa);
add.b(sb);
add.c(sc);
sc_trace_file *trace;
trace = sc_create_vcd_trace_file("trace");
sc_trace(trace, sa, "a");
sc_trace(trace, sb, "b");
sc_trace(trace, sc, "c");
sc_start(500, SC_NS);
sc_close_vcd_trace_file(trace);
return 0;
}
all: chainage
%: %.cpp
g++ -g $< -o $@ -Wall -Wextra
clean: chainage
rm -f $<
/********************************************************************
* Copyright (C) 2012 by Verimag *
* Initial author: Matthieu Moy *
********************************************************************/
#include <iostream>
using namespace std;
class Base {
public:
Base(const char *name)
/*
* Chainage sur le constructeur d'un champ.
* Ici, m_name n'est pas un objet, mais on peut quand
* même chainer dessus.
*/
: m_name(name) {
/*
* On ne peut pas écrire « m_name = name; » parce que
* m_name est const (error: assignment of read-only
* member ‘Base::m_name’).
*/
}
void print() {
cout << "My name is " << m_name << endl;
}
private:
const char * const m_name;
};
class Derived : public Base {
public:
/* Constructeur par défaut : celui qui n'a pas d'argument */
Derived()
/* Chainage sur le constructeur de la classe de base */
: Base("default name") {}
Derived(const char *name) : Base(name) {}
};
int main() {
Base b("b");
b.print();
Derived d_named("d_named");
d_named.print();
Derived d_anonymous; /* Appelle le constructeur par défaut */
d_anonymous.print();
}
#include "Compteur.h"
Compteur::Compteur(sc_module_name name) : sc_module(name)
{
SC_METHOD(calcul);
sensitive << clk.pos();
sensitive << reset;
}
void Compteur::calcul()
{
if (reset.read() == true)
count.write(0);
else if (clk.posedge())
{
count.write(count.read() + 1);
}
}
#include <systemc>
SC_MODULE(Compteur)
{
sc_in<bool> clk;
sc_in<bool> reset;
sc_out<sc_uint<8> > count;
SC_CTOR(Compteur);
void calcul();
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment