Commit 3e288e2d authored by Jonathan Jenkins's avatar Jonathan Jenkins

Added LP definition template to reduce boilerplate for writing LPs

parent 2a169880
......@@ -96,3 +96,16 @@ src_libcodes_base_a_SOURCES = \
src/workload/codes-workload-method.h \
src/workload/codes-bgp-io-wrkld.c \
src/workload/test-workload-method.c
# stealth testing of the template code (actual test is not run, just compiled as
# a program - Make error signifies test failure)
check_PROGRAMS += src/util/templates/lp_template_dummy_main
testlib_template = src/libcodes-base.a
src_util_templates_lp_template_dummy_main_CFLAGS = -Wno-unused-function
src_util_templates_lp_template_dummy_main_LDADD = $(testlib_template) ${ROSS_LIBS}
src_util_templates_lp_template_dummy_main_LDFLAGS = ${ROSS_LDFLAGS}
src_util_templates_lp_template_dummy_main_SOURCES = \
src/util/templates/lp_template_dummy_main.c \
src/util/templates/lp_template.c \
src/util/templates/lp_template.h
# get rid of annoying unused function in template
These contain LP definition templates, with the hope that you can copy/paste
and substitute template with your LP's name. At the moment, they are integrated
into the build system to keep them from being out of date, but aren't actually
linked into any libraries
'make tests' will compile the dummy main program along with the templates
themselves.
/*
* Copyright (C) 2014 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
/* This is meant to be a template file to use when developing new LPs.
* Roughly follows the format of the existing LPs in the CODES repos */
#include "lp_template.h"
#include "codes/codes_mapping.h"
#include "codes/lp-type-lookup.h"
#include "codes/jenkins-hash.h"
#include "codes/codes.h"
/**** BEGIN SIMULATION DATA STRUCTURES ****/
static int template_magic; /* use this as sanity check on events */
typedef struct template_state template_state;
typedef struct template_msg template_msg;
/* event types */
enum template_event
{
TEMPLATE_A,
TEMPLATE_B,
};
struct template_state {
};
struct template_msg {
enum template_event event_type;
int magic;
};
/**** END SIMULATION DATA STRUCTURES ****/
/**** BEGIN LP, EVENT PROCESSING FUNCTION DECLS ****/
/* ROSS LP processing functions */
static void template_lp_init(
template_state * ns,
tw_lp * lp);
static void template_event_handler(
template_state * ns,
tw_bf * b,
template_msg * m,
tw_lp * lp);
static void template_rev_handler(
template_state * ns,
tw_bf * b,
template_msg * m,
tw_lp * lp);
static void template_finalize(
template_state * ns,
tw_lp * lp);
/* event type handlers */
static void handle_template_a(
template_state * ns,
template_msg * m,
tw_lp * lp);
static void handle_template_b(
template_state * ns,
template_msg * m,
tw_lp * lp);
static void handle_template_a_rev(
template_state * ns,
template_msg * m,
tw_lp * lp);
static void handle_template_b_rev(
template_state * ns,
template_msg * m,
tw_lp * lp);
/* ROSS function pointer table for this LP */
tw_lptype template_lp = {
(init_f) template_init,
(event_f) template_event_handler,
(revent_f) template_rev_handler,
(final_f) template_finalize,
(map_f) codes_mapping,
sizeof(template_state),
};
/**** END LP, EVENT PROCESSING FUNCTION DECLS ****/
/**** BEGIN IMPLEMENTATIONS ****/
void template_init(){
uint32_t h1=0, h2=0;
bj_hashlittle2("template", strlen("template"), &h1, &h2);
template_magic = h1+h2;
lp_type_register("template", &template_lp);
}
void template_lp_init(
template_state * ns,
tw_lp * lp){
/* Fill me in... */
}
void template_event_handler(
template_state * ns,
tw_bf * b,
template_msg * m,
tw_lp * lp){
assert(m->magic == template_magic);
switch (m->event_type){
case TEMPLATE_A:
handle_template_a(ns, m, lp);
break;
case TEMPLATE_B:
handle_template_b(ns, m, lp);
break;
/* ... */
default:
assert(!"template event type not known");
break;
}
}
void template_rev_handler(
template_state * ns,
tw_bf * b,
template_msg * m,
tw_lp * lp){
assert(m->magic == template_magic);
switch (m->event_type){
case TEMPLATE_A:
handle_template_a_rev(ns, m, lp);
break;
case TEMPLATE_B:
handle_template_b_rev(ns, m, lp);
break;
/* ... */
default:
assert(!"template event type not known");
break;
}
}
void template_finalize(
template_state * ns,
tw_lp * lp){
/* Fill me in... */
}
/* event type handlers */
void handle_template_a(
template_state * ns,
template_msg * m,
tw_lp * lp){
}
void handle_template_b(
template_state * ns,
template_msg * m,
tw_lp * lp){
}
void handle_template_a_rev(
template_state * ns,
template_msg * m,
tw_lp * lp){
}
void handle_template_b_rev(
template_state * ns,
template_msg * m,
tw_lp * lp){
}
/**** END IMPLEMENTATIONS ****/
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ft=c ts=8 sts=4 sw=4 expandtab
*/
/*
* Copyright (C) 2014 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#ifndef LP_TEMPLATE_H
#define LP_TEMPLATE_H
#include <ross.h>
void template_init();
#endif /* end of include guard: LP_TEMPLATE_H */
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ft=c ts=8 sts=4 sw=4 expandtab
*/
/*
* Copyright (C) 2014 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include "lp_template.h"
int main(int argc, char *argv[])
{
/* won't actually be called - just here to make linker happy */
template_init();
return 0;
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*
* vim: ft=c ts=8 sts=4 sw=4 expandtab
*/
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