Skip to content
Snippets Groups Projects
Commit 3eb8d574 authored by Tommy Olofsson's avatar Tommy Olofsson
Browse files

Copying seems to work now.

parent ba524757
No related branches found
No related tags found
No related merge requests found
...@@ -117,9 +117,13 @@ aspect C_CodeGenEnv { ...@@ -117,9 +117,13 @@ aspect C_CodeGenEnv {
return this; return this;
} }
public String memeberAccessor() { public String memberAccessor() {
return (rootIsPointer && (nestedLevel == rootLevel)) ? "->" : "."; return (rootIsPointer && (nestedLevel == rootLevel)) ? "->" : ".";
} }
public String accessor() {
return (rootIsPointer && (nestedLevel == rootLevel)) ? "*" : "";
}
} }
public C_env ArrayType.C_Nest(C_env env) { public C_env ArrayType.C_Nest(C_env env) {
...@@ -129,7 +133,7 @@ aspect C_CodeGenEnv { ...@@ -129,7 +133,7 @@ aspect C_CodeGenEnv {
} }
public C_env FixedArrayType.C_Nest(C_env env) { public C_env FixedArrayType.C_Nest(C_env env) {
String index = env.memeberAccessor() + "a"; String index = env.memberAccessor() + "a";
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
index += "[i_" + env.depth + "_" + i + "]"; index += "[i_" + env.depth + "_" + i + "]";
} }
...@@ -137,7 +141,7 @@ aspect C_CodeGenEnv { ...@@ -137,7 +141,7 @@ aspect C_CodeGenEnv {
} }
public C_env VariableArrayType.C_Nest(C_env env) { public C_env VariableArrayType.C_Nest(C_env env) {
return env.nestArray(env.memeberAccessor() + "a[i_" + env.depth + "]"); return env.nestArray(env.memberAccessor() + "a[i_" + env.depth + "]");
} }
...@@ -214,6 +218,7 @@ aspect C_CodeGen { ...@@ -214,6 +218,7 @@ aspect C_CodeGen {
getDecl(i).C_emitDecoderDeclaration(env); getDecl(i).C_emitDecoderDeclaration(env);
getDecl(i).C_emitEncoderDeclaration(env); getDecl(i).C_emitEncoderDeclaration(env);
getDecl(i).C_emitSizeofDeclaration(env); getDecl(i).C_emitSizeofDeclaration(env);
getDecl(i).C_emitCopyDeclaration(env);
env.println(""); env.println("");
} }
C_emitConstructorDeclaration(env); C_emitConstructorDeclaration(env);
...@@ -425,7 +430,7 @@ aspect C_Limit { ...@@ -425,7 +430,7 @@ aspect C_Limit {
} }
public String VariableSize.C_getLimit(C_env env, int i) { public String VariableSize.C_getLimit(C_env env, int i) {
return env.qualid + env.memeberAccessor() + "n_" + i; return env.qualid + env.memberAccessor() + "n_" + i;
} }
} }
...@@ -675,6 +680,26 @@ aspect C_Decoder { ...@@ -675,6 +680,26 @@ aspect C_Decoder {
aspect C_copy { aspect C_copy {
private void SampleDecl.C_emitCopyFunctionParam(C_env env_src, String src,
String dst)
{
env_src.println("void labcomm_copy_" + env_src.prefix + getName() + "(");
env_src.indent();
env_src.println("struct labcomm_memory *mem,");
env_src.println(env_src.prefix + getName() + " *" + dst + ",");
env_src.println(env_src.prefix + getName() + " *" + src);
env_src.unindent();
env_src.print(")");
}
public void Decl.C_emitCopyDeclaration(C_env env) {
}
public void SampleDecl.C_emitCopyDeclaration(C_env env) {
C_emitCopyFunctionParam(env, "src", "dst");
env.println(";");
}
public void Decl.C_emitCopy(C_env env) { public void Decl.C_emitCopy(C_env env) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".C_emitCopy(C_env env)" + ".C_emitCopy(C_env env)" +
...@@ -687,16 +712,11 @@ aspect C_copy { ...@@ -687,16 +712,11 @@ aspect C_copy {
public void SampleDecl.C_emitCopy(C_env env) { public void SampleDecl.C_emitCopy(C_env env) {
final String dst = "dst"; final String dst = "dst";
final String src = "src"; final String src = "src";
C_env env_src = env.nestStruct(src).setPointer(); C_env env_src = env.nestStruct(src).setPointer();
C_env env_dst = env.nestStruct(dst).setPointer(); C_env env_dst = env.nestStruct(dst).setPointer();
env_src.println("static void copy_" + env_src.prefix + getName() + "(");
env_src.indent(); C_emitCopyFunctionParam(env_src, src, dst);
env_src.println("struct labcomm_memory *mem ,"); env_src.println("");
env_src.println(env_src.prefix + getName() + " *" + dst + ",");
env_src.println(env_src.prefix + getName() + " *" + src);
env_src.unindent();
env_src.println(")");
env_src.println("{"); env_src.println("{");
env_src.indent(); env_src.indent();
getType().C_emitCopy(env_src, env_dst); getType().C_emitCopy(env_src, env_dst);
...@@ -721,7 +741,8 @@ aspect C_copy { ...@@ -721,7 +741,8 @@ aspect C_copy {
} }
public void PrimType.C_emitCopy(C_env env_src, C_env env_dst) { public void PrimType.C_emitCopy(C_env env_src, C_env env_dst) {
env_src.println(env_dst.qualid + " = " + env_src.qualid + ";"); env_src.println(env_dst.accessor() + env_dst.qualid + " = " +
env_src.accessor() + env_src.qualid + ";");
} }
public void UserType.C_emitCopy(C_env env_src, C_env env_dst) { public void UserType.C_emitCopy(C_env env_src, C_env env_dst) {
...@@ -735,7 +756,7 @@ aspect C_copy { ...@@ -735,7 +756,7 @@ aspect C_copy {
} }
public void ArrayType.C_emitCopy(C_env env_src, C_env env_dst) { public void ArrayType.C_emitCopy(C_env env_src, C_env env_dst) {
C_emitCopyDecodeLimit(env_src); C_emitCopyDecodeLimit(env_src, env_dst);
C_emitCopyArrayAllocate(env_src, env_dst); C_emitCopyArrayAllocate(env_src, env_dst);
env_src.println("{"); env_src.println("{");
env_src.indent(); env_src.indent();
...@@ -760,23 +781,23 @@ aspect C_copy { ...@@ -760,23 +781,23 @@ aspect C_copy {
} }
public void Field.C_emitCopy(C_env env_src, C_env env_dst) { public void Field.C_emitCopy(C_env env_src, C_env env_dst) {
String fnam = env_src.memeberAccessor() + getName(); String fnam = env_src.memberAccessor() + getName();
getType().C_emitCopy(env_src.nestStruct(fnam), env_dst.nestStruct(fnam)); getType().C_emitCopy(env_src.nestStruct(fnam), env_dst.nestStruct(fnam));
} }
public void Exp.C_emitCopyDecodeLimit(C_env env, int i) { public void Exp.C_emitCopyDecodeLimit(C_env env_src, C_env env_dst, int i) {
// Ordinary array has no length-member.
} }
public void VariableSize.C_emitCopyDecodeLimit(C_env env_src, int i, public void VariableSize.C_emitCopyDecodeLimit(C_env env_src, C_env env_dst, int i) {
C_env env_dst) String src = env_src.qualid + env_src.memberAccessor() + "n_" + i;
{ String dst = env_dst.qualid + env_dst.memberAccessor() + "n_" + i;
String index = ".n_" + i; env_src.println(dst + " = " + src + ";");
env_src.println(env_dst.qualid + index + " = " + env_src.qualid + index + ";");
} }
public void ArrayType.C_emitCopyDecodeLimit(C_env env) { public void ArrayType.C_emitCopyDecodeLimit(C_env env_src, C_env env_dst) {
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
getExp(i).C_emitCopyDecodeLimit(env, i); getExp(i).C_emitCopyDecodeLimit(env_src, env_dst, i);
} }
} }
...@@ -786,10 +807,9 @@ aspect C_copy { ...@@ -786,10 +807,9 @@ aspect C_copy {
public void VariableArrayType.C_emitCopyArrayAllocate(C_env env_src, public void VariableArrayType.C_emitCopyArrayAllocate(C_env env_src,
C_env env_dst) C_env env_dst)
{ {
String access = (env_dst.nestedLevel == 1) ? "->" : "."; env_src.print(env_dst.qualid + env_dst.memberAccessor() +
env_src.print(env_dst.qualid + env_dst.memeberAccessor() +
"a = labcomm_memory_alloc(mem, 1, sizeof(" + "a = labcomm_memory_alloc(mem, 1, sizeof(" +
env_src.qualid + env_src.memeberAccessor() + "a[0])"); env_src.qualid + env_src.memberAccessor() + "a[0])");
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
env_src.print(" * " + getExp(i).C_getLimit(env_src, i)); env_src.print(" * " + getExp(i).C_getLimit(env_src, i));
} }
......
...@@ -49,6 +49,7 @@ TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \ ...@@ -49,6 +49,7 @@ TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
test_signature_numbers \ test_signature_numbers \
test_labcomm \ test_labcomm \
test_labcomm_pthread_scheduler \ test_labcomm_pthread_scheduler \
test_labcomm_copy
# #
#FIXME: test_labcomm test_labcomm_errors #FIXME: test_labcomm test_labcomm_errors
TEST_DIR=test TEST_DIR=test
...@@ -150,6 +151,7 @@ $(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h ...@@ -150,6 +151,7 @@ $(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h $(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o $(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o $(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/test_labcomm_copy: $(TEST_DIR)/gen/generated_encoding.o
labcomm_fd_reader.o: labcomm_private.h labcomm_fd_reader.o: labcomm_private.h
labcomm_fd_writer.o: labcomm_private.h labcomm_fd_writer.o: labcomm_private.h
labcomm_dynamic_buffer_writer.o: labcomm_private.h labcomm_dynamic_buffer_writer.o: labcomm_private.h
...@@ -218,7 +218,6 @@ int main(void) ...@@ -218,7 +218,6 @@ int main(void)
#include <labcomm_mem_reader.h> #include <labcomm_mem_reader.h>
#include "test/testdata/gen/test_sample.h" #include "test/testdata/gen/test_sample.h"
#define TEST_BUFFER_SIZE (50)
void test_error_handler(enum labcomm_error error_id, size_t nbr_va_args, ...); void test_error_handler(enum labcomm_error error_id, size_t nbr_va_args, ...);
...@@ -352,6 +351,7 @@ void test_decode_unreg_signature_error() ...@@ -352,6 +351,7 @@ void test_decode_unreg_signature_error()
labcomm_encoder_free(encoder); labcomm_encoder_free(encoder);
free(enc_ctx.buf); free(enc_ctx.buf);
} }
int main() int main()
{ {
CU_pSuite suite_decoder = NULL; CU_pSuite suite_decoder = NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment