Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sven Gestegård Robertz
LabComm
Commits
3eb8d574
Commit
3eb8d574
authored
Apr 17, 2014
by
Tommy Olofsson
Browse files
Copying seems to work now.
parent
ba524757
Changes
3
Hide whitespace changes
Inline
Side-by-side
compiler/C_CodeGen.jrag
View file @
3eb8d574
...
...
@@ -117,9 +117,13 @@ aspect C_CodeGenEnv {
return this;
}
public String mem
e
berAccessor() {
public String memberAccessor() {
return (rootIsPointer && (nestedLevel == rootLevel)) ? "->" : ".";
}
public String accessor() {
return (rootIsPointer && (nestedLevel == rootLevel)) ? "*" : "";
}
}
public C_env ArrayType.C_Nest(C_env env) {
...
...
@@ -129,7 +133,7 @@ aspect C_CodeGenEnv {
}
public C_env FixedArrayType.C_Nest(C_env env) {
String index = env.mem
e
berAccessor() + "a";
String index = env.memberAccessor() + "a";
for (int i = 0 ; i < getNumExp() ; i++) {
index += "[i_" + env.depth + "_" + i + "]";
}
...
...
@@ -137,7 +141,7 @@ aspect C_CodeGenEnv {
}
public C_env VariableArrayType.C_Nest(C_env env) {
return env.nestArray(env.mem
e
berAccessor() + "a[i_" + env.depth + "]");
return env.nestArray(env.memberAccessor() + "a[i_" + env.depth + "]");
}
...
...
@@ -214,6 +218,7 @@ aspect C_CodeGen {
getDecl(i).C_emitDecoderDeclaration(env);
getDecl(i).C_emitEncoderDeclaration(env);
getDecl(i).C_emitSizeofDeclaration(env);
getDecl(i).C_emitCopyDeclaration(env);
env.println("");
}
C_emitConstructorDeclaration(env);
...
...
@@ -425,7 +430,7 @@ aspect C_Limit {
}
public String VariableSize.C_getLimit(C_env env, int i) {
return env.qualid + env.mem
e
berAccessor() + "n_" + i;
return env.qualid + env.memberAccessor() + "n_" + i;
}
}
...
...
@@ -675,6 +680,26 @@ aspect C_Decoder {
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) {
throw new Error(this.getClass().getName() +
".C_emitCopy(C_env env)" +
...
...
@@ -687,16 +712,11 @@ aspect C_copy {
public void SampleDecl.C_emitCopy(C_env env) {
final String dst = "dst";
final String src = "src";
C_env env_src = env.nestStruct(src).setPointer();
C_env env_dst = env.nestStruct(dst).setPointer();
env_src.println("static void 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.println(")");
C_emitCopyFunctionParam(env_src, src, dst);
env_src.println("");
env_src.println("{");
env_src.indent();
getType().C_emitCopy(env_src, env_dst);
...
...
@@ -721,7 +741,8 @@ aspect C_copy {
}
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) {
...
...
@@ -735,7 +756,7 @@ aspect C_copy {
}
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);
env_src.println("{");
env_src.indent();
...
...
@@ -760,23 +781,23 @@ aspect C_copy {
}
public void Field.C_emitCopy(C_env env_src, C_env env_dst) {
String fnam = env_src.mem
e
berAccessor() + getName();
String fnam = env_src.memberAccessor() + getName();
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,
C_env env_dst)
{
String index = ".n_" + i;
env_src.println(env_dst.qualid + index + " = " + env_src.qualid + index + ";");
public void VariableSize.C_emitCopyDecodeLimit(C_env env_src, C_env env_dst, int i) {
String src = env_src.qualid + env_src.memberAccessor() + "n_" + i;
String dst = env_dst.qualid + env_dst.memberAccessor() + "n_" + i;
env_src.println(dst + " = " + src + ";");
}
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++) {
getExp(i).C_emitCopyDecodeLimit(env, i);
getExp(i).C_emitCopyDecodeLimit(env
_src, env_dst
, i);
}
}
...
...
@@ -786,10 +807,9 @@ aspect C_copy {
public void VariableArrayType.C_emitCopyArrayAllocate(C_env env_src,
C_env env_dst)
{
String access = (env_dst.nestedLevel == 1) ? "->" : ".";
env_src.print(env_dst.qualid + env_dst.memeberAccessor() +
env_src.print(env_dst.qualid + env_dst.memberAccessor() +
"a = labcomm_memory_alloc(mem, 1, sizeof(" +
env_src.qualid + env_src.mem
e
berAccessor() + "a[0])");
env_src.qualid + env_src.memberAccessor() + "a[0])");
for (int i = 0 ; i < getNumExp() ; i++) {
env_src.print(" * " + getExp(i).C_getLimit(env_src, i));
}
...
...
lib/c/Makefile
View file @
3eb8d574
...
...
@@ -49,6 +49,7 @@ TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
test_signature_numbers
\
test_labcomm
\
test_labcomm_pthread_scheduler
\
test_labcomm_copy
#
#FIXME: test_labcomm test_labcomm_errors
TEST_DIR
=
test
...
...
@@ -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
:
$(TEST_DIR)/gen/another_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_writer.o
:
labcomm_private.h
labcomm_dynamic_buffer_writer.o
:
labcomm_private.h
lib/c/test/test_labcomm.c
View file @
3eb8d574
...
...
@@ -218,7 +218,6 @@ int main(void)
#include <labcomm_mem_reader.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, ...);
...
...
@@ -352,6 +351,7 @@ void test_decode_unreg_signature_error()
labcomm_encoder_free(encoder);
free(enc_ctx.buf);
}
int main()
{
CU_pSuite suite_decoder = NULL;
...
...
@@ -385,7 +385,7 @@ int main()
// Set verbosity.
CU_basic_set_mode(CU_BRM_VERBOSE);
/*CU_console_run_tests();*/
/*
CU_console_run_tests();
*/
// Run all test suites.
CU_basic_run_tests();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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