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
Erik Jansson
LabComm
Commits
588a5ccc
Commit
588a5ccc
authored
Feb 07, 2014
by
Sven Gestegård Robertz
Browse files
Java version 2006 working for simple example
parent
6e6d9700
Changes
5
Hide whitespace changes
Inline
Side-by-side
compiler/Java_CodeGen.jrag
View file @
588a5ccc
...
...
@@ -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()) {
...
...
examples/simple/Decoder06.java
0 → 100644
View file @
588a5ccc
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
]))
);
}
}
examples/simple/Encoder06.java
0 → 100644
View file @
588a5ccc
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
();
}
}
examples/simple/compile.sh
View file @
588a5ccc
...
...
@@ -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 Encoder
06
.java Decoder
06
.java
# gcc -Wall -Werror -I. -I../../lib/c -L../../lib/c \
# -o example_encoder example_encoder.c gen/simple.c \
...
...
lib/java/se/lth/control/labcomm2006/LabCommEncoderChannel.java
View file @
588a5ccc
...
...
@@ -24,7 +24,7 @@ public class LabCommEncoderChannel implements LabCommEncoder {
}
public
LabCommEncoderChannel
(
LabCommWriter
writer
)
throws
IOException
{
this
(
writer
,
tru
e
);
this
(
writer
,
fals
e
);
}
public
LabCommEncoderChannel
(
OutputStream
writer
,
...
...
@@ -33,7 +33,7 @@ public class LabCommEncoderChannel implements LabCommEncoder {
}
public
LabCommEncoderChannel
(
OutputStream
writer
)
throws
IOException
{
this
(
new
WriterWrapper
(
writer
),
tru
e
);
this
(
new
WriterWrapper
(
writer
),
fals
e
);
}
public
void
register
(
LabCommDispatcher
dispatcher
)
throws
IOException
{
...
...
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