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
Robotlab
labcomm-core
Commits
176df107
Commit
176df107
authored
Feb 25, 2015
by
Sven Gestegård Robertz
Browse files
parameterised templates, w/ command line options
parent
fa2f450a
Changes
3
Hide whitespace changes
Inline
Side-by-side
compiler/2014/LabComm.java
View file @
176df107
...
...
@@ -36,6 +36,9 @@ public class LabComm {
println
(
"[ Misc options ]"
);
println
(
" --pretty=PFILE Pretty prints to PFILE"
);
println
(
" --typeinfo=TIFILE Generates typeinfo in TIFILE"
);
println
(
"[ Template options ]"
);
println
(
" --template=TPLFILE Generates output according to TPLFILE"
);
println
(
" --templateOpt=KEY:VAL Sets option for template"
);
}
/** To be cleaned up.
...
...
@@ -119,9 +122,9 @@ public class LabComm {
}
}
private
static
void
genTemplate
(
Program
p
,
String
filename
)
{
private
static
void
genTemplate
(
Program
p
,
String
filename
,
Map
<
String
,
String
>
opts
)
{
try
{
p
.
template_gen
(
filename
);
p
.
template_gen
(
filename
,
opts
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
filename
+
" "
+
e
);
}
...
...
@@ -150,6 +153,7 @@ public class LabComm {
String
rapidFile
=
null
;
String
fileName
=
null
;
String
stgFile
=
null
;
Map
<
String
,
String
>
templateOpts
=
new
HashMap
<
String
,
String
>();
Opts
(
String
[]
args
)
{
this
.
args
=
args
;
...
...
@@ -236,6 +240,12 @@ public class LabComm {
rapidFile
=
coreName
+
".sys"
;
}
else
if
(
args
[
i
].
startsWith
(
"--template="
))
{
stgFile
=
args
[
i
].
substring
(
11
);
}
else
if
(
args
[
i
].
startsWith
(
"--templateOpt="
))
{
String
keyval
=
args
[
i
].
substring
(
14
);
int
idx
=
keyval
.
indexOf
(
':'
);
String
key
=
keyval
.
substring
(
0
,
idx
);
String
val
=
keyval
.
substring
(
idx
+
1
);
templateOpts
.
put
(
key
,
val
);
}
else
if
(
i
==
args
.
length
-
1
)
{
fileName
=
args
[
i
];
}
else
{
...
...
@@ -376,7 +386,7 @@ public class LabComm {
boolean
wroteFile
=
false
;
if
(
stgFile
!=
null
)
{
printStatus
(
"Template: "
,
stgFile
);
genTemplate
(
ast
,
stgFile
);
genTemplate
(
ast
,
stgFile
,
templateOpts
);
wroteFile
=
true
;
}
return
wroteFile
;
...
...
compiler/2014/TestTT.jrag
View file @
176df107
...
...
@@ -4,6 +4,7 @@ import org.stringtemplate.v4.STGroupDir;
import org.stringtemplate.v4.STGroupFile;
import java.util.LinkedList;
import java.util.Map;
aspect TestTT {
...
...
@@ -11,11 +12,15 @@ aspect TestTT {
eq Decl.getTypeName() = getType().getTypeName();
eq Field.getTypeName() = getType().getTypeName();
void Program.template_gen(String filename) throws IOException {
void Program.template_gen(String filename
, Map<String,String> opts
) throws IOException {
System.out.println("Generating output from template "+filename);
STGroup group = new STGroupFile(filename, '$', '$');
ST st = group.getInstanceOf("program");
for(String opt: opts.keySet()) {
st.addAggr("opts.{key,val}", opt, opts.get(opt));
st.add(opt, opts.get(opt));
}
for(Decl d: getDecls()) {
st.add("decls",d);
}
...
...
compiler/2014/c_gen.stg
View file @
176df107
program(decls) ::= <<
program(decls, opts, lcName, prefix) ::= <<
/* template opts:
$opts;separator="\n"$
lcName=$lcName$
prefix=$prefix$
*/
#include "labcomm.h"
#include "labcomm_private.h"
#include "
minimal.h" //TODO: send
lcName
#include "
$
lcName
$.h"
//TODO gen dependency signatures
...
...
@@ -18,26 +24,26 @@ $([TMPL,obj.TemplateType])(obj,name, data)$
>>
processSampleDecl(decl) ::= <<
static int sizeof_
minimal
_$decl.Name$(void *vv) //TODO: send lcName
static int sizeof_
$lcName$
_$decl.Name$(void *vv) //TODO: send lcName
{
int result = 0;
result += 32 //TODO: calc size;
return result;
}
static struct labcomm_signature signature_
minimal
_$decl.Name$ = {
static struct labcomm_signature signature_
$lcName$
_$decl.Name$ = {
"$decl.Name$",
sizeof_
minimal
_$decl.Name$,
sizeof(signature_bytes_
minimal
_$decl.Name$),
signature_bytes_
minimal
_$decl.Name$,
sizeof_
$lcName$
_$decl.Name$,
sizeof(signature_bytes_
$lcName$
_$decl.Name$),
signature_bytes_
$lcName$
_$decl.Name$,
0,
sizeof(signature_tree_
minimal
_$decl.Name$),
signature_tree_
minimal
_$decl.Name$
sizeof(signature_tree_
$lcName$
_$decl.Name$),
signature_tree_
$lcName$
_$decl.Name$
};
const struct labcomm_signature *labcomm_signature_
minimal
_$decl.Name$ = &signature_
minimal
_$decl.Name$;
const struct labcomm_signature *labcomm_signature_
$lcName$
_$decl.Name$ = &signature_
$lcName$
_$decl.Name$;
static void decode_
minimal
_$decl.Name$(
static void decode_
$lcName$
_$decl.Name$(
struct labcomm_reader *r,
void (*handle)(
minimal_$decl.Name$ *v,
...
...
@@ -51,7 +57,7 @@ static void decode_minimal_$decl.Name$(
handle(&v, context);
}
int labcomm_decoder_register_
minimal
_$decl.Name$(
int labcomm_decoder_register_
$lcName$
_$decl.Name$(
struct labcomm_decoder *d,
void (*handler)(
minimal_$decl.Name$ *v,
...
...
@@ -62,13 +68,13 @@ int labcomm_decoder_register_minimal_$decl.Name$(
{
return labcomm_internal_decoder_register(
d,
&signature_
minimal
_$decl.Name$,
(labcomm_decoder_function)decode_
minimal
_$decl.Name$,
&signature_
$lcName$
_$decl.Name$,
(labcomm_decoder_function)decode_
$lcName$
_$decl.Name$,
(labcomm_handler_function)handler,
context
);
}
int labcomm_decoder_ioctl_
minimal
_$decl.Name$(
int labcomm_decoder_ioctl_
$lcName$
_$decl.Name$(
struct labcomm_decoder *d,
int ioctl_action,
...
...
...
@@ -78,13 +84,13 @@ int labcomm_decoder_ioctl_minimal_$decl.Name$(
va_list va;
va_start(va, ioctl_action);
result = labcomm_internal_decoder_ioctl(
d, &signature_
minimal
_$decl.Name$,
d, &signature_
$lcName$
_$decl.Name$,
ioctl_action, va);
va_end(va);
return result;
}
static int encode_
minimal
_$decl.Name$(
static int encode_
$lcName$
_$decl.Name$(
struct labcomm_writer *w
, minimal_$decl.Name$ *v
)
...
...
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