Commit 176df107 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

parameterised templates, w/ command line options

parent fa2f450a
......@@ -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;
......
......@@ -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);
}
......
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
)
......
Supports Markdown
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