Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
codes
codes
Commits
3e288e2d
Commit
3e288e2d
authored
Jan 09, 2014
by
Jonathan Jenkins
Browse files
Added LP definition template to reduce boilerplate for writing LPs
parent
2a169880
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/Makefile.subdir
View file @
3e288e2d
...
...
@@ -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
src/util/templates/README.txt
0 → 100644
View file @
3e288e2d
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.
src/util/templates/lp_template.c
0 → 100644
View file @
3e288e2d
/*
* 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
*/
src/util/templates/lp_template.h
0 → 100644
View file @
3e288e2d
/*
* 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
*/
src/util/templates/lp_template_dummy_main.c
0 → 100644
View file @
3e288e2d
/*
* 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
*/
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment