Skip to content
Snippets Groups Projects
Commit 588a5ccc authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

Java version 2006 working for simple example

parent 6e6d9700
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ aspect Java_CodeGenEnv {
public class Java_env {
public final int version; //labcomm version to generate code for
public final String verStr;
private int indent;
private int depth;
private Java_printer printer;
......@@ -78,6 +79,7 @@ aspect Java_CodeGenEnv {
private Java_env(int version, int indent) {
this.version = version;
this.verStr = (version == 2006) ? "2006" : "";
this.indent = indent;
}
......@@ -337,9 +339,9 @@ aspect Java_Class {
}
env.println("import java.io.IOException;");
env.println("import se.lth.control.labcomm.LabCommType;");
env.println("import se.lth.control.labcomm.LabCommEncoder;");
env.println("import se.lth.control.labcomm.LabCommDecoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommType;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommEncoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommDecoder;");
env.println();
env.println("public class " + getName() + " implements LabCommType {");
env.println();
......@@ -377,11 +379,11 @@ aspect Java_Class {
}
env.println("import java.io.IOException;");
env.println("import se.lth.control.labcomm.LabCommDecoder;");
env.println("import se.lth.control.labcomm.LabCommDispatcher;");
env.println("import se.lth.control.labcomm.LabCommEncoder;");
env.println("import se.lth.control.labcomm.LabCommHandler;");
env.println("import se.lth.control.labcomm.LabCommSample;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommDecoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommDispatcher;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommEncoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommHandler;");
env.println("import se.lth.control.labcomm"+env.verStr+".LabCommSample;");
env.println();
env.print("public class " + getName());
// if(getType().isUserType()) {
......
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import se.lth.control.labcomm2006.LabCommDecoderChannel;
public class Decoder06
implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler
{
LabCommDecoderChannel decoder;
public Decoder06(InputStream in)
throws Exception
{
decoder = new LabCommDecoderChannel(in);
theTwoInts.register(decoder, this);
anotherTwoInts.register(decoder, this);
IntString.register(decoder, this);
TwoArrays.register(decoder, this);
TwoFixedArrays.register(decoder, this);
try {
System.out.println("Running decoder.");
decoder.run();
} catch (java.io.EOFException e) {
System.out.println("Decoder reached end of file.");
}
}
public void printTwoInts(TwoInts d) throws java.io.IOException {
System.out.println("a="+d.a+", b="+d.b);
}
public void handle_theTwoInts(TwoInts d) throws java.io.IOException {
System.out.print("Got theTwoInts: ");
printTwoInts(d);
}
public void handle_anotherTwoInts(TwoInts d) throws java.io.IOException {
System.out.print("Got anotherheTwoInts: ");
printTwoInts(d);
}
public void handle_IntString(IntString d) throws java.io.IOException {
System.out.println("Got IntString, x="+d.x+", s="+d.s);
}
public void handle_TwoArrays(TwoArrays d) throws java.io.IOException {
System.out.println("Got TwoArrays:");
for(int i=0; i<d.fixed.length; i++) {
System.out.print(d.fixed[i]+" ");
}
System.out.println();
for(int i=0; i<d.variable[0].length; i++) {
System.out.print(d.variable[0][i]+" ");
System.out.print(d.variable[1][i]+" ");
}
System.out.println();
}
public void handle_TwoFixedArrays(TwoFixedArrays d) throws java.io.IOException {
System.out.println("Got TwoFixedArrays:");
for(int i=0; i<d.a.length; i++) {
System.out.print(d.a[i]+" ");
}
System.out.println();
for(int i=0; i<d.b[0].length; i++) {
System.out.print(d.b[0][i]+" ");
System.out.print(d.b[1][i]+" ");
}
System.out.println();
}
public static void main(String[] arg) throws Exception {
Decoder06 example = new Decoder06(
new FileInputStream(new File(arg[0]))
);
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import se.lth.control.labcomm2006.LabCommEncoderChannel;
/**
* Simple encoder
*/
public class Encoder06
{
LabCommEncoderChannel encoder;
public Encoder06(OutputStream out)
throws Exception
{
encoder = new LabCommEncoderChannel(out);
theTwoInts.register(encoder);
IntString.register(encoder);
TwoArrays.register(encoder);
}
public void doEncode() throws java.io.IOException {
TwoInts x = new TwoInts();
x.a = 17;
x.b = 42;
IntString y = new IntString();
y.x = 37;
y.s = "Testing, testing";
TwoArrays ta = new TwoArrays();
ta.fixed = new int[] {14, 25};
// ta.variable = new int[][] {{1,2},{0x11,0x12},{0x21,0x22},{0x31,0x32}};
ta.variable = new int[][] {{1,2, 3, 4},{0x21,0x22,0x23,0x24}};
System.out.println("Encoding theTwoInts, a="+x.a+", b="+x.b);
theTwoInts.encode(encoder, x);
System.out.println("Encoding IntString, x="+y.x+", s="+y.s);
IntString.encode(encoder, y);
System.out.println("Encoding TwoArrays");
for(int i = 0; i < ta.variable.length; i++) {
for(int j=0; j < ta.variable[0].length; j++)
System.out.println(ta.variable[i][j]);
System.out.println("---");
}
TwoArrays.encode(encoder, ta);
}
public static void main(String[] arg) throws Exception {
FileOutputStream fos = new FileOutputStream(arg[0]);
Encoder06 example = new Encoder06(fos);
example.doEncode();
fos.close();
}
}
......@@ -3,7 +3,7 @@
mkdir -p gen
java -jar ../../compiler/labComm.jar --ver=2006 --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc
javac -cp ../../lib/java:. gen/*.java Encoder.java Decoder.java
javac -cp ../../lib/java:. gen/*.java Encoder06.java Decoder06.java
# gcc -Wall -Werror -I. -I../../lib/c -L../../lib/c \
# -o example_encoder example_encoder.c gen/simple.c \
......
......@@ -24,7 +24,7 @@ public class LabCommEncoderChannel implements LabCommEncoder {
}
public LabCommEncoderChannel(LabCommWriter writer) throws IOException {
this(writer, true);
this(writer, false);
}
public LabCommEncoderChannel(OutputStream writer,
......@@ -33,7 +33,7 @@ public class LabCommEncoderChannel implements LabCommEncoder {
}
public LabCommEncoderChannel(OutputStream writer) throws IOException {
this(new WriterWrapper(writer), true);
this(new WriterWrapper(writer), false);
}
public void register(LabCommDispatcher dispatcher) throws IOException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment