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

Merge branch 'master' of gitlab.control.lth.se:anders_blomdell/labcomm

parents 4366700d 98cb774e
......@@ -283,6 +283,9 @@ aspect C_Type {
getType().C_emitType(env, env.prefix + getName());
env.println(";");
env.println("#endif");
env.println("extern const struct labcomm"+env.verStr+"_signature " +
"*labcomm"+env.verStr+"_signature_" + env.prefix + getName() +
";");
}
public void Type.C_emitType(C_env env, String name) {
......@@ -295,6 +298,10 @@ aspect C_Type {
env.print("char " + name);
}
public void SampleRefType.C_emitType(C_env env, String name) {
env.print("const struct labcomm_signature *" + name);
}
public void PrimType.C_emitType(C_env env, String name) {
switch (getToken()) {
case LABCOMM_BOOLEAN: { env.print("uint8_t"); } break;
......@@ -516,6 +523,10 @@ aspect C_Decoder {
public void VoidType.C_emitDecoder(C_env env) {
}
public void SampleRefType.C_emitDecoder(C_env env) {
env.println(env.qualid + " = labcomm_internal_decoder_index_to_signature(" +
"r->decoder, labcomm"+env.verStr+"_read_int(r));");
}
public void PrimType.C_emitDecoder(C_env env) {
env.println(env.qualid + " = labcomm"+env.verStr+"_read_" + getName() + "(r);");
}
......@@ -593,6 +604,9 @@ aspect C_Decoder {
" not declared");
}
public void SampleRefType.C_emitDecoderDeallocation(C_env env) {
}
public void PrimType.C_emitDecoderDeallocation(C_env env) {
if (C_isDynamic()) {
env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " +
......@@ -677,7 +691,7 @@ aspect C_Decoder {
env.println("return labcomm"+env.verStr+"_internal_decoder_register(");
env.indent();
env.println("d,");
env.println("&labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ",");
env.println("&signature_" + env.prefix + getName() + ",");
env.println("(labcomm"+env.verStr+"_decoder_function)decode_" + env.prefix + getName() + ",");
env.println("(labcomm"+env.verStr+"_handler_function)handler,");
env.println("context");
......@@ -745,6 +759,12 @@ aspect C_copy {
public void VoidType.C_emitCopy(C_env env_src, C_env env_dst) {
}
public void SampleRefType.C_emitCopy(C_env env_src, C_env env_dst) {
env_src.println(env_dst.accessor() + env_dst.qualid + " = " +
env_src.accessor() + env_src.qualid + ";");
}
public void PrimType.C_emitCopy(C_env env_src, C_env env_dst) {
if (C_isDynamic()) {
env_src.println(String.format(
......@@ -888,6 +908,9 @@ aspect C_copy {
public void VoidType.C_emitCopyDeallocation(C_env env) {
}
public void SampleRefType.C_emitCopyDeallocation(C_env env) {
}
public void PrimType.C_emitCopyDeallocation(C_env env) {
if (C_isDynamic()) {
env.println("labcomm" + env.verStr + "_memory_free(mem, 1, " +
......@@ -972,7 +995,7 @@ aspect C_DecoderIoctl {
env.println("va_start(va, ioctl_action);");
env.println("result = labcomm"+env.verStr+"_internal_decoder_ioctl(");
env.indent();
env.println("d, &labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ", ");
env.println("d, &signature_" + env.prefix + getName() + ", ");
env.println("ioctl_action, va);");
env.unindent();
env.println("va_end(va);");
......@@ -1023,7 +1046,7 @@ aspect C_Encoder {
env.println(")");
env.println("{");
env.indent();
env.println("return labcomm"+env.verStr+"_internal_encode(e, &labcomm"+env.verStr+"_signature_" +
env.println("return labcomm"+env.verStr+"_internal_encode(e, &signature_" +
env.prefix + getName() +
", (labcomm"+env.verStr+"_encoder_function)encode_" +
env.prefix + getName() +
......@@ -1042,6 +1065,13 @@ aspect C_Encoder {
env.println("result = 0;");
}
public void SampleRefType.C_emitEncoder(C_env env) {
env.println("result = labcomm"+env.verStr+"_write_int(w, " +
"labcomm_internal_encoder_signature_to_index(w->encoder, " +
env.qualid + "));");
env.println("if (result != 0) { return result; }");
}
public void PrimType.C_emitEncoder(C_env env) {
env.println("result = labcomm"+env.verStr+"_write_" + getName() +
"(w, " + env.qualid + ");");
......@@ -1124,7 +1154,7 @@ aspect C_Encoder {
env.println("return labcomm"+env.verStr+"_internal_encoder_register(");
env.indent();
env.println("e,");
env.println("&labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ",");
env.println("&signature_" + env.prefix + getName() + ",");
env.println("(labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName());
env.unindent();
env.println(");");
......@@ -1160,7 +1190,7 @@ aspect C_EncoderIoctl {
env.println("va_start(va, ioctl_action);");
env.println("result = labcomm"+env.verStr+"_internal_encoder_ioctl(");
env.indent();
env.println("e, &labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ", ");
env.println("e, &signature_" + env.prefix + getName() + ", ");
env.println("ioctl_action, va);");
env.unindent();
env.println("va_end(va);");
......@@ -1272,8 +1302,8 @@ aspect C_Signature {
env.println("};");
C_emitSizeofValue(env);
env.println("struct labcomm"+env.verStr+"_signature labcomm"+env.verStr+"_signature_" +
env.prefix + getName() + " = {");
env.println("static struct labcomm"+env.verStr+"_signature " +
"signature_" + env.prefix + getName() + " = {");
env.indent();
env.println("\"" + getName() + "\",");
env.println("sizeof_" + env.prefix + getName() + ",");
......@@ -1282,6 +1312,9 @@ aspect C_Signature {
env.println("0");
env.unindent();
env.println(" };");
env.println("const struct labcomm"+env.verStr+"_signature " +
"*labcomm"+env.verStr+"_signature_" + env.prefix + getName() +
" = &signature_" + env.prefix + getName() + ";");
}
public void Signature.C_emitSignature(C_env env, boolean decl){
......@@ -1407,7 +1440,7 @@ aspect C_Constructor {
}
//XXX
public void SampleDecl.C_emitConstructor(C_env env) {
env.println("labcomm"+env.verStr+"_set_local_index(&labcomm"+env.verStr+"_signature_" +
env.println("labcomm"+env.verStr+"_set_local_index(&signature_" +
env.prefix + getName() + ");");
}
......@@ -1447,7 +1480,7 @@ aspect C_Sizeof {
env.println("{");
env.indent();
env.println("return labcomm"+env.verStr+"_internal_sizeof(" +
"&labcomm" + env.verStr+"_signature_" + env.prefix + getName() +
"&signature_" + env.prefix + getName() +
", v);");
env.unindent();
env.println("}");
......@@ -1463,6 +1496,10 @@ aspect C_Sizeof {
return 0;
}
public int SampleRefType.C_fixedSizeof() {
return 4;
}
public int PrimType.C_fixedSizeof() {
switch (getToken()) {
case LABCOMM_BOOLEAN: { return 1; }
......
......@@ -21,6 +21,10 @@ aspect FlatSignature {
getType().flatSignature(list);
}
public void SampleRefType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_SAMPLE_REF, "sample");
}
public void VoidType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_STRUCT, "void");
list.addInt(0, null);
......@@ -92,6 +96,10 @@ aspect FlatSignature {
return getType().signatureComment() + " '" + getName() +"'";
}
public String SampleRefType.signatureComment() {
return "sample";
}
public String PrimType.signatureComment() {
return getName();
}
......
......@@ -23,6 +23,7 @@ Field ::= Type <Name:String>;
abstract Type;
VoidType : Type;
SampleRefType : Type;
PrimType : Type ::= <Name:String> <Token:int>;
UserType : Type ::= <Name:String>;
StructType : Type ::= Field*;
......
......@@ -33,7 +33,7 @@ public class LabComm {
println("[ RAPID options ]");
println(" --rapid Generates RAPID code in FILE.sys");
println("[ Misc options ]");
println(" --pretty Pretty prints on standard output");
println(" --pretty=PFILE Pretty prints to PFILE");
println(" --typeinfo=TIFILE Generates typeinfo in TIFILE");
}
......
......@@ -77,6 +77,7 @@ Type type =
| user_type.u {: return u; :}
| struct_type.s {: return s; :}
| void_type.v {: return v; :}
| sample_ref_type.s {: return s; :}
;
PrimType prim_type =
......@@ -110,6 +111,10 @@ VoidType void_type =
VOID {: return new VoidType(); :}
;
SampleRefType sample_ref_type =
SAMPLE {: return new SampleRefType(); :}
;
List dim_list =
dim.d {: return new List().add(d); :}
| dim_list.l dim.d {: return l.add(d); :}
......
aspect LabCommTokens {
public static final int ASTNode.LABCOMM_VERSION = 0x01;
public static final int ASTNode.LABCOMM_SAMPLE = 0x02; // The flat signature
public static final int ASTNode.LABCOMM_TYPE_DEF = 0x03; // and type declarations, hierarchically
public static final int ASTNode.LABCOMM_VERSION = 0x01;
public static final int ASTNode.LABCOMM_SAMPLE_DEF = 0x02; // The flat signature
public static final int ASTNode.LABCOMM_SAMPLE_REF = 0x03;
public static final int ASTNode.LABCOMM_TYPE_DEF = 0x04; // and type declarations, hierarchically
public static final int ASTNode.LABCOMM_ARRAY = 0x10;
public static final int ASTNode.LABCOMM_STRUCT = 0x11;
......
......@@ -68,8 +68,8 @@ aspect PrettyPrint {
out.print("void");
}
public String PrimType.toString() {
return getName();
public void SampleRefType.ppPrefix(PrintStream out) {
out.print("sample");
}
public void PrimType.ppPrefix(PrintStream out) {
......
......@@ -176,6 +176,9 @@ aspect Signature {
list.addInt(0, null);
}
public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl) {
list.addInt(LABCOMM_SAMPLE_REF, "sample");
}
public void PrimType.genSigLineForDecl(SignatureList list, boolean decl) {
list.addInt(getToken(), null);
}
......@@ -229,4 +232,5 @@ aspect Signature {
public void VariableSize.genSigLineForDecl(SignatureList list, boolean decl) {
list.addInt(0, null);
}
}
aspect Version {
/* An auxilliary class for handling naming and prefixes connected
* to the LabComm version
*/
class LabCommVersion {
public static String versionString(int version) {
return (version == 2006) ? "2006" : "";
}
public static boolean versionHasPragma(int version) {
return version != 2006;
}
}
}
......@@ -20,7 +20,7 @@
<!-- "jflex" is an ant task class for the scanner generator in JFlex.jar -->
<taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="tools/JFlex.jar"/>
<!-- "beaver" is an ant task class for the parser generator in beaver.jar -->
<taskdef name="beaver" classname="beaver.comp.run.AntTask" classpath="tools/beaver.jar"/>
<taskdef name="beaver" classname="beaver.comp.run.AntTask" classpath="tools/beaver-ant.jar"/>
<!-- "jastadd" is an ant task class in jastadd2.jar -->
<taskdef name="jastadd" classname="jastadd.JastAddTask"
classpath="tools/jastadd2.jar"/>
......
......@@ -106,7 +106,7 @@ static void enqueue_decimation(struct decimating_private *decimating,
static int wrap_reader_start(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index, struct labcomm_signature *signature,
int local_index, int remote_index, const struct labcomm_signature *signature,
void *value)
{
struct decimating_private *decimating = action_context->context;
......@@ -133,7 +133,7 @@ static int wrap_reader_ioctl(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index,
struct labcomm_signature *signature,
const struct labcomm_signature *signature,
uint32_t action, va_list args)
{
struct decimating_private *decimating = action_context->context;
......@@ -197,7 +197,7 @@ static int wrap_writer_alloc(
static int wrap_writer_start(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, struct labcomm_signature *signature,
int index, const struct labcomm_signature *signature,
void *value)
{
struct decimating_private *decimating = action_context->context;
......
......@@ -44,13 +44,13 @@ struct introspecting_private {
LABCOMM_SIGNATURE_ARRAY_DEF(local,
struct local {
enum introspecting_status status;
struct labcomm_signature *signature;
const struct labcomm_signature *signature;
});
};
static struct local *get_local(struct introspecting_private *introspecting,
int index,
struct labcomm_signature *signature)
const struct labcomm_signature *signature)
{
/* Called with data_lock held */
struct local *local;
......@@ -137,7 +137,7 @@ static int wrap_reader_alloc(
struct handles_signature {
struct introspecting_private *introspecting;
int index;
struct labcomm_signature *signature;
const struct labcomm_signature *signature;
};
static void send_handles_signature(void *arg)
......@@ -156,7 +156,7 @@ static void send_handles_signature(void *arg)
static int wrap_reader_start(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index, struct labcomm_signature *signature,
int local_index, int remote_index, const struct labcomm_signature *signature,
void *value)
{
struct introspecting_private *introspecting = action_context->context;
......@@ -180,7 +180,7 @@ static int wrap_reader_start(
struct labcomm_encoder *encoder,
void *context)
{
struct labcomm_signature *signature = context;
const struct labcomm_signature *signature = context;
introspecting_messages_handles_signature handles_signature;
int index = 0;
......@@ -224,7 +224,7 @@ static int wrap_writer_alloc(
static int wrap_writer_start(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, struct labcomm_signature *signature,
int index, const struct labcomm_signature *signature,
void *value)
{
struct introspecting_private *introspecting = action_context->context;
......@@ -243,7 +243,7 @@ static int wrap_writer_start(
static int wrap_writer_ioctl(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, struct labcomm_signature *signature,
int index, const struct labcomm_signature *signature,
uint32_t ioctl_action, va_list args)
{
struct introspecting_private *introspecting = action_context->context;
......
......@@ -64,7 +64,7 @@ int labcomm_reader_free(struct labcomm_reader *r,
int labcomm_reader_start(struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index,
struct labcomm_signature *signature,
const struct labcomm_signature *signature,
void *value)
{
UNWRAP(start, r, action_context, local_index, remote_index, signature, value);
......@@ -85,7 +85,7 @@ int labcomm_reader_fill(struct labcomm_reader *r,
int labcomm_reader_ioctl(struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index,
struct labcomm_signature *signature,
const struct labcomm_signature *signature,
uint32_t ioctl_action, va_list args)
{
UNWRAP(ioctl, r, action_context,
......@@ -106,7 +106,7 @@ int labcomm_writer_free(struct labcomm_writer *w,
int labcomm_writer_start(struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, struct labcomm_signature *signature,
int index, const struct labcomm_signature *signature,
void *value)
{
UNWRAP(start, w, action_context, index, signature, value);
......@@ -127,7 +127,7 @@ int labcomm_writer_flush(struct labcomm_writer *w,
int labcomm_writer_ioctl(struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index,
struct labcomm_signature *signature,
const struct labcomm_signature *signature,
uint32_t ioctl_action, va_list args)
{
UNWRAP(ioctl, w, action_context, index, signature, ioctl_action, args);
......@@ -250,7 +250,7 @@ void labcomm_set_local_index(struct labcomm_signature *signature)
local_index++;
}
int labcomm_get_local_index(struct labcomm_signature *signature)
int labcomm_get_local_index(const struct labcomm_signature *signature)
{
if (signature->index == 0) {
labcomm_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET,
......@@ -259,7 +259,7 @@ int labcomm_get_local_index(struct labcomm_signature *signature)
return signature->index;
}
int labcomm_internal_sizeof(struct labcomm_signature *signature,
int labcomm_internal_sizeof(const struct labcomm_signature *signature,
void *v)
{
int length = signature->encoded_size(v);
......
......@@ -119,6 +119,9 @@ int labcomm_decoder_decode_one(
struct labcomm_decoder *decoder);
void labcomm_decoder_run(
struct labcomm_decoder *decoder);
int labcomm_decoder_sample_ref_register(
struct labcomm_decoder *decoder,
const struct labcomm_signature *signature);
/* See labcomm_ioctl.h for predefined ioctl_action values */
int labcomm_decoder_ioctl(struct labcomm_decoder *decoder,
......@@ -137,6 +140,9 @@ struct labcomm_encoder *labcomm_encoder_new(
struct labcomm_scheduler *scheduler);
void labcomm_encoder_free(
struct labcomm_encoder *encoder);
int labcomm_encoder_sample_ref_register(
struct labcomm_encoder *encoder,
const struct labcomm_signature *signature);
/* See labcomm_ioctl.h for predefined ioctl_action values */
int labcomm_encoder_ioctl(struct labcomm_encoder *encoder,
......
......@@ -28,7 +28,7 @@
struct sample_entry {
int remote_index;
struct labcomm_signature *signature;
const struct labcomm_signature *signature;
labcomm_decoder_function decode;
labcomm_handler_function handler;
void *context;
......@@ -45,6 +45,8 @@ struct labcomm_decoder {
labcomm_handle_new_datatype_callback on_new_datatype;
LABCOMM_SIGNATURE_ARRAY_DEF(local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_DEF(remote_to_local, int);
LABCOMM_SIGNATURE_ARRAY_DEF(local_ref, const struct labcomm_signature *);
LABCOMM_SIGNATURE_ARRAY_DEF(remote_to_local_ref, int);
};
struct labcomm_decoder *labcomm_decoder_new(
......@@ -72,6 +74,9 @@ struct labcomm_decoder *labcomm_decoder_new(
result->on_error = on_error_fprintf;
LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local, int);
LABCOMM_SIGNATURE_ARRAY_INIT(result->local_ref,
const struct labcomm_signature*);
LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local_ref, int);
}
return result;
}
......@@ -83,17 +88,91 @@ void labcomm_decoder_free(struct labcomm_decoder* d)
labcomm_reader_free(d->reader, d->reader->action_context);
LABCOMM_SIGNATURE_ARRAY_FREE(memory, d->local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_FREE(memory, d->remote_to_local, int);
LABCOMM_SIGNATURE_ARRAY_FREE(memory, d->local_ref,
const struct labcomm_signature*);
LABCOMM_SIGNATURE_ARRAY_FREE(memory, d->remote_to_local_ref, int);
labcomm_memory_free(memory, 0, d);
}
static int decode_sample(struct labcomm_decoder *d, int kind)
static int handle_sample_def(struct labcomm_decoder *d, int remote_index,
const struct labcomm_signature *signature)
{
int result;
struct labcomm_signature signature, *local_signature;
int remote_index, local_index, i;
local_signature = NULL;
local_index = 0;
int i;
const struct labcomm_signature *local_signature = NULL;
int local_index = 0;
labcomm_scheduler_data_lock(d->scheduler);
LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local, struct sample_entry, i) {
struct sample_entry *s;
int *remote_to_local;
result = -ENOENT;
s = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry, i);
if (s->signature &&
s->signature->size == signature->size &&
strcmp(s->signature->name, signature->name) == 0 &&
memcmp((void*)s->signature->signature, (void*)signature->signature,
signature->size) == 0) {
s->remote_index = remote_index;
local_signature = s->signature;
local_index = i;
remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
*remote_to_local = i;
result = remote_index;
break;
}
}
labcomm_scheduler_data_unlock(d->scheduler);
if (local_signature) {
labcomm_reader_start(d->reader, d->reader->action_context,
local_index, remote_index, local_signature,
NULL);
labcomm_reader_end(d->reader, d->reader->action_context);
}
return result;
}
static int handle_sample_ref(struct labcomm_decoder *d, int remote_index,
const struct labcomm_signature *signature)
{
int result;
int i;
labcomm_scheduler_data_lock(d->scheduler);
LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local_ref, const struct labcomm_signature *, i) {
const struct labcomm_signature *s;
int *remote_to_local_ref;
result = -ENOENT;
s = LABCOMM_SIGNATURE_ARRAY_GET(d->local_ref, const struct labcomm_signature *, i, 0);
if (s &&
s->signature &&
s->size == signature->size &&
strcmp(s->name, signature->name) == 0 &&
memcmp((void*)s->signature, (void*)signature->signature, signature->size) == 0) {
remote_to_local_ref = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local_ref, int,
remote_index);
*remote_to_local_ref = i;
result = remote_index;
break;
}
}
labcomm_scheduler_data_unlock(d->scheduler);
return result;
}
static int decode_sample_def_or_ref(struct labcomm_decoder *d, int kind)
{
int result;
struct labcomm_signature signature;
int i, remote_index;
remote_index = labcomm_read_packed32(d->reader);
if (d->reader->error < 0) {
result = d->reader->error;
......@@ -121,36 +200,16 @@ static int decode_sample(struct labcomm_decoder *d, int kind)
goto free_signature_signature;
}
}
labcomm_scheduler_data_lock(d->scheduler);
LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local, struct sample_entry, i) {
struct sample_entry *s;
int *remote_to_local;
result = -ENOENT;
s = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry, i);
if (s->signature &&
s->signature->size == signature.size &&
strcmp(s->signature->name, signature.name) == 0 &&
memcmp((void*)s->signature->signature, (void*)signature.signature,
signature.size) == 0) {
s->remote_index = remote_index;
local_signature = s->signature;
local_index = i;
remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
*remote_to_local = i;
result = remote_index;
break;
if (kind == LABCOMM_SAMPLE_DEF) {
result = handle_sample_def(d, remote_index, &signature);
} else if (kind == LABCOMM_SAMPLE_REF) {
result = handle_sample_ref(d, remote_index, &signature);
if (result == -ENOENT) {
/* Dummy value to silently continue */
result = LABCOMM_SAMPLE_REF;
}
}
labcomm_scheduler_data_unlock(d->scheduler);
if (local_signature) {
labcomm_reader_start(d->reader, d->reader->action_context,