Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Robotlab
labcomm-core
Commits
373eac7b
Commit
373eac7b
authored
Mar 04, 2015
by
Anders Blomdell
Browse files
Removed 2006 version
parent
53147edf
Changes
118
Expand all
Hide whitespace changes
Inline
Side-by-side
.bzrignore
deleted
100644 → 0
View file @
53147edf
AST
AST/*
LabComm.class
labComm.jar
lib/java/se/lth/control/labcomm/LabComm.class
lib/java/se/lth/control/labcomm/LabCommDecoderChannel.class
lib/java/se/lth/control/labcomm/LabCommDecoder.class
lib/java/se/lth/control/labcomm/LabCommDecoderRegistry.class
lib/java/se/lth/control/labcomm/LabCommDecoderRegistry$Entry.class
lib/java/se/lth/control/labcomm/LabCommDispatcher.class
lib/java/se/lth/control/labcomm/LabCommEncoderChannel.class
lib/java/se/lth/control/labcomm/LabCommEncoder.class
lib/java/se/lth/control/labcomm/LabCommEncoderRegistry.class
lib/java/se/lth/control/labcomm/LabCommEncoderRegistry$Entry.class
lib/java/se/lth/control/labcomm/LabCommHandler.class
lib/java/se/lth/control/labcomm/LabCommReader.class
lib/java/se/lth/control/labcomm/LabCommSample.class
lib/java/se/lth/control/labcomm/LabCommType.class
lib/java/se/lth/control/labcomm/LabCommWriter.class
gen
labcomm.dll
labcomm.jar
example.c
example.h
example.py
examples/wiki_example/example.encoded
example.encoded
examples/simple/*.class
examples/simple/encoded_data
examples/simple/example_decoder
examples/simple/example_encoder
lib/c/test/test_labcomm_basic_type_encoding
lib/c/test/test_labcomm_generated_encoding
lib/java/se/lth/control/labcomm/WriterWrapper.class
lib/c/liblabcomm.so.1
lib/c/test/test_labcomm_pthread_scheduler
lib/c/liblabcomm_plain_c.so.1
lib/c/test/test_signature_plain_c
test/test_signature_numbers
lib/c/test/test_signature_numbers
lib/c/test/test_labcomm
Makefile
View file @
373eac7b
SUBDIRS
=
compiler lib
test
examples packaging
export
LABCOMM_JAR
=
$(
shell
pwd
)
/compiler/labcomm_compiler.jar
export
LABCOMM_JAR
=
$(
shell
pwd
)
/compiler/labcomm
2014
_compiler.jar
export
LABCOMM
=
java
-jar
$(LABCOMM_JAR)
.PHONY
:
all
...
...
compiler/.gitignore
View file @
373eac7b
gen
labcomm2006_compiler.jar
labcomm2014_compiler.jar
labcomm_compiler.jar
labcomm
2014
_compiler.jar
compiler/2006/ArrayTypeRewrite.jrag
deleted
100644 → 0
View file @
53147edf
aspect ArrayRewrite {
syn boolean Dim.isVariable() {
for (int i = 0 ; i < getNumExp() ; i++) {
if (getExp(i) instanceof VariableSize) {
return true;
}
}
return false;
}
rewrite ParseArrayType {
when (! getDim(0).isVariable())
to FixedArrayType {
if (getNumDim() == 1) {
return new FixedArrayType(getType(),
getDim(0).getExpList());
} else {
List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i));
}
return new FixedArrayType(new ParseArrayType(getType(), l),
getDim(0).getExpList());
}
}
when (getDim(0).isVariable())
to VariableArrayType {
if (getNumDim() == 1) {
return new VariableArrayType(getType(),
getDim(0).getExpList());
} else {
List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i));
}
return new VariableArrayType(new ParseArrayType(getType(), l),
getDim(0).getExpList());
}
}
}
}
compiler/2006/CS_CodeGen.jrag
deleted
100644 → 0
View file @
53147edf
This diff is collapsed.
Click to expand it.
compiler/2006/C_CodeGen.jrag
deleted
100644 → 0
View file @
53147edf
This diff is collapsed.
Click to expand it.
compiler/2006/DeclNames.jrag
deleted
100644 → 0
View file @
53147edf
aspect DeclNames {
inh String Type.declName();
eq Decl.getType().declName() = getName();
inh String Field.declName();
eq StructType.getField(int i).declName() = declName();
//TODO: aspect should be renamed to parent-something
inh Decl Type.parentDecl();
inh Decl Field.parentDecl();
eq Decl.getType().parentDecl() = this;
eq StructType.getField(int i).parentDecl() = parentDecl();
}
compiler/2006/ErrorCheck.jrag
deleted
100644 → 0
View file @
53147edf
import java.util.Collection;
aspect ErrorCheck {
syn int ASTNode.lineNumber() = getLine(getStart());
protected String ASTNode.errors = null;
protected void ASTNode.error(String s) {
s = "Error at " + lineNumber() + ": " + s;
if(errors == null) {
errors = s;
} else {
errors = errors + "\n" + s;
}
}
protected boolean ASTNode.hasErrors() {
return errors != null;
}
public void ASTNode.errorCheck(Collection collection) {
nameCheck();
typeCheck();
if(hasErrors())
collection.add(errors);
for(int i = 0; i < getNumChild(); i++) {
getChild(i).errorCheck(collection);
}
}
}
compiler/2006/FlatSignature.jrag
deleted
100644 → 0
View file @
53147edf
import java.util.*;
aspect FlatSignature {
public SignatureList Decl.flatSignature(int version) {
SignatureList result = getSignature().getFlatSignatureList();
return result;
}
public void ASTNode.flatSignature(SignatureList list) {
throw new Error(this.getClass().getName() +
".flatSignature(SignatureList list)" +
" not declared");
}
public void TypeDecl.flatSignature(SignatureList list) {
getType().flatSignature(list);
}
public void SampleDecl.flatSignature(SignatureList list) {
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);
}
public void PrimType.flatSignature(SignatureList list) {
list.addInt(getToken(), null);
}
public void UserType.flatSignature(SignatureList list) {
lookupType(getName()).flatSignature(list);
}
public void ArrayType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_ARRAY, signatureComment());
list.indent();
list.addInt(getNumExp(), null);
for (int i = 0 ; i < getNumExp() ; i++) {
getExp(i).flatSignature(list);
}
getType().flatSignature(list);
list.unindent();
list.add(null, "}");
}
public void StructType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_STRUCT, "struct { " + getNumField() + " fields");
list.indent();
list.addInt(getNumField(), null);
for (int i = 0 ; i < getNumField() ; i++) {
getField(i).flatSignature(list);
}
list.unindent();
list.add(null, "}");
}
public void Field.flatSignature(SignatureList list) {
list.addString(getName(), signatureComment());
getType().flatSignature(list);
}
public void IntegerLiteral.flatSignature(SignatureList list) {
list.addInt(Integer.parseInt(getValue()), null);
}
public void VariableSize.flatSignature(SignatureList list) {
list.addInt(0, null);
}
public String ArrayType.signatureComment() {
StringBuffer result = new StringBuffer("array [");
for (int i = 0 ; i < getNumExp() ; i++) {
if (i > 0) {
result.append(", ");
}
result.append(getExp(i).signatureComment());
}
result.append("]");
return result.toString();
}
public String ASTNode.signatureComment() {
throw new Error(this.getClass().getName() +
".signatureComment()" +
" not declared");
}
public String Field.signatureComment() {
return getType().signatureComment() + " '" + getName() +"'";
}
public String SampleRefType.signatureComment() {
return "sample";
}
public String PrimType.signatureComment() {
return getName();
}
public String UserType.signatureComment() {
return getName();
}
public String StructType.signatureComment() {
return "struct";
}
public String IntegerLiteral.signatureComment() {
return getValue();
}
public String VariableSize.signatureComment() {
return "_";
}
}
compiler/2006/Java_CodeGen.jrag
deleted
100644 → 0
View file @
53147edf
This diff is collapsed.
Click to expand it.
compiler/2006/LabComm.ast
deleted
100644 → 0
View file @
53147edf
Program ::= Decl*;
//TODO: Add signatures to the abstract grammar, so that
//they can be extended and refined by more than one aspect.
//sketch:
Signature ::= SignatureList FlatSignatureList:SignatureList;
SignatureList ::= SignatureLine*;
abstract SignatureLine ::= <Indent:int> <Comment:String>;
abstract DataSignatureLine : SignatureLine;
ByteArraySignatureLine : DataSignatureLine ::= <Data:byte[]>;
IntSignatureLine : DataSignatureLine ::= <Data:int>;
StringSignatureLine : DataSignatureLine ::= <Data:String>;
TypeRefSignatureLine : SignatureLine ::= Decl;
//abstract Decl ::= Type <Name:String>;
// the signature list be defined as a non-terminal attribute:
abstract Decl ::= Type <Name:String> /Signature/;
TypeDecl : Decl;
SampleDecl : Decl;
Field ::= Type <Name:String>;
abstract Type;
VoidType : Type;
SampleRefType : Type;
PrimType : Type ::= <Name:String> <Token:int>;
UserType : Type ::= <Name:String>;
StructType : Type ::= Field*;
ParseArrayType : Type ::= Type Dim*;
abstract ArrayType :Type ::= Type Exp*;
VariableArrayType : ArrayType;
FixedArrayType : ArrayType;
Dim ::= Exp*;
abstract Exp;
IntegerLiteral : Exp ::= <Value:String>;
VariableSize : Exp;
compiler/2006/LabComm.java
deleted
100644 → 0
View file @
53147edf
package
se.lth.control.labcomm2006.compiler
;
import
java.io.*
;
import
java.util.*
;
public
class
LabComm
{
private
static
void
println
(
String
s
)
{
System
.
out
.
println
(
s
);
}
private
static
void
print_help
()
{
println
(
"\n Usage: java -jar labcom.jar [options*] FILE"
);
println
(
""
);
println
(
" --help Shows this help text"
);
println
(
" -v Be verbose"
);
println
(
" --ver=VERSION Generate code for labcomm VERSION (=2006 or 2013)"
);
println
(
"[ C options ]"
);
println
(
" -C Generates C/H code in FILE.[ch]"
);
println
(
" --cprefix=PREFIX Prefixes C types with PREFIX"
);
println
(
" --cinclude=FILE Include FILE in generated .c"
);
println
(
" --c=CFILE Generates C code in CFILE"
);
println
(
" --h=HFILE Generates H code in HFILE"
);
println
(
"[ C# options]"
);
println
(
" --cs Generates C# code in FILE.cs"
);
println
(
" --cs=CSFILE Generates C# code in CSFILE"
);
println
(
" --csnamespace=NAMESPACE Place C# classes in NAMESPACE"
);
println
(
"[ Java options ]"
);
println
(
" --java=JDIR Generates Java files in JDIR"
);
println
(
" --javapackage=PACKAGE Place Java classes in PACKAGE"
);
println
(
"[ Python options ]"
);
println
(
" -P Generates Python code in FILE.py"
);
println
(
" --python=PFILE Generates Python code in PFILE"
);
println
(
"[ RAPID options ]"
);
println
(
" --rapid Generates RAPID code in FILE.sys"
);
println
(
"[ Misc options ]"
);
println
(
" --pretty=PFILE Pretty prints to PFILE"
);
println
(
" --typeinfo=TIFILE Generates typeinfo in TIFILE"
);
}
/** To be cleaned up.
*/
private
static
void
checkVersion
(
int
v
)
{
if
(!
(
v
==
2006
||
v
==
2013
)
)
{
System
.
err
.
println
(
" Unknown version: "
+
v
);
System
.
err
.
println
(
" Supported versions: 2006, 2013 "
);
System
.
exit
(
2
);
}
}
private
static
void
genH
(
Program
p
,
String
hName
,
Vector
cIncludes
,
String
coreName
,
String
prefix
,
int
ver
)
{
try
{
FileOutputStream
f
;
PrintStream
out
;
f
=
new
FileOutputStream
(
hName
);
out
=
new
PrintStream
(
f
);
p
.
C_genH
(
out
,
cIncludes
,
coreName
,
prefix
,
ver
);
out
.
close
();
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
hName
+
" "
+
e
);
}
}
private
static
void
genC
(
Program
p
,
String
cName
,
Vector
cIncludes
,
String
coreName
,
String
prefix
,
int
ver
)
{
try
{
FileOutputStream
f
;
PrintStream
out
;
f
=
new
FileOutputStream
(
cName
);
out
=
new
PrintStream
(
f
);
p
.
C_genC
(
out
,
cIncludes
,
coreName
,
prefix
,
ver
);
out
.
close
();
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
cName
+
" "
+
e
);
}
}
private
static
void
genCS
(
Program
p
,
String
csName
,
String
csNamespace
,
int
ver
)
{
// throw new Error("C# generation currently disabled");
try
{
p
.
CS_gen
(
csName
,
csNamespace
,
ver
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
csName
+
" "
+
csNamespace
+
" "
+
e
);
}
}
private
static
void
genJava
(
Program
p
,
String
dirName
,
String
packageName
,
int
ver
)
{
try
{
p
.
J_gen
(
dirName
,
packageName
,
ver
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
dirName
+
" "
+
packageName
+
" "
+
e
);
}
}
private
static
void
genPython
(
Program
p
,
String
filename
,
String
prefix
,
int
ver
)
{
try
{
FileOutputStream
f
;
PrintStream
out
;
f
=
new
FileOutputStream
(
filename
);
out
=
new
PrintStream
(
f
);
p
.
Python_gen
(
out
,
prefix
,
ver
);
out
.
close
();
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
filename
+
" "
+
e
);
}
}
private
static
void
genRAPID
(
Program
p
,
String
filename
,
String
prefix
,
int
ver
)
{
try
{
p
.
RAPID_gen
(
filename
,
prefix
,
ver
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
filename
+
" "
+
e
);
}
}
/** Helper class to contain command line options
and their associated behaviour
**/
private
static
class
Opts
{
final
String
[]
args
;
String
coreName
=
null
;
String
prefix
=
null
;
boolean
verbose
=
false
;
int
ver
=
2006
;
// Version 2006 fixed
String
cFile
=
null
;
String
hFile
=
null
;
Vector
cIncludes
=
new
Vector
();
String
cPrefix
;
// gets default value (prefix) in processFilename
String
csFile
=
null
;
String
csNamespace
=
null
;
String
javaDir
=
null
;
String
javaPackage
=
""
;
String
pythonFile
=
null
;
String
prettyFile
=
null
;
String
typeinfoFile
=
null
;
String
rapidFile
=
null
;
String
fileName
=
null
;
Opts
(
String
[]
args
)
{
this
.
args
=
args
;
}
private
static
String
getCoreName
(
String
s
)
{
int
i
=
s
.
lastIndexOf
(
'.'
);
return
s
.
substring
(
0
,
i
>
0
?
i
:
s
.
length
());
}
private
static
String
getFileName
(
String
s
)
{
return
s
.
substring
(
s
.
lastIndexOf
(
'/'
)
+
1
,
s
.
length
());
}
private
static
String
getBaseName
(
String
s
)
{
s
=
getFileName
(
s
);
int
i
=
s
.
lastIndexOf
(
'.'
);
return
s
.
substring
(
0
,
i
>
0
?
i
:
s
.
length
());
}
private
static
String
getPrefix
(
String
s
)
{
return
s
.
substring
(
s
.
lastIndexOf
(
'/'
)
+
1
,
s
.
length
());
}
boolean
processFilename
(){
// Scan for first non-option
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(!
args
[
i
].
startsWith
(
"-"
))
{
fileName
=
args
[
i
];
break
;
}
}
if
(
fileName
!=
null
)
{
coreName
=
getBaseName
(
fileName
);
prefix
=
getPrefix
(
coreName
);
cPrefix
=
prefix
;
}
return
fileName
!=
null
;
}
void
processArgs
(){
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
fileName
==
null
||
args
[
i
].
equals
(
"-help"
)
||
args
[
i
].
equals
(
"-h"
)
||
args
[
i
].
equals
(
"--help"
))
{
print_help
();
System
.
exit
(
0
);
}
else
if
(
args
[
i
].
equals
(
"-v"
))
{
verbose
=
true
;
}
else
if
(
args
[
i
].
startsWith
(
"--ver="
))
{
/* ver = Integer.parseInt(args[i].substring(6));
checkVersion(ver); */
}
else
if
(
args
[
i
].
equals
(
"-C"
))
{
cFile
=
coreName
+
".c"
;
hFile
=
coreName
+
".h"
;
}
else
if
(
args
[
i
].
startsWith
(
"--cinclude="
))
{
cIncludes
.
add
(
args
[
i
].
substring
(
11
));
}
else
if
(
args
[
i
].
startsWith
(
"--cprefix="
))
{
cPrefix
=
args
[
i
].
substring
(
10
);
}
else
if
(
args
[
i
].
startsWith
(
"--c="
))
{
cFile
=
args
[
i
].
substring
(
4
);
}
else
if
(
args
[
i
].
startsWith
(
"--h="
))
{
hFile
=
args
[
i
].
substring
(
4
);
}
else
if
(
args
[
i
].
equals
(
"--cs"
))
{
csFile
=
coreName
+
".cs"
;
}
else
if
(
args
[
i
].
startsWith
(
"--cs="
))
{
csFile
=
args
[
i
].
substring
(
5
);
}
else
if
(
args
[
i
].
startsWith
(
"--csnamespace="
))
{
csNamespace
=
args
[
i
].
substring
(
14
);
}
else
if
(
args
[
i
].
startsWith
(
"--java="
))
{
javaDir
=
args
[
i
].
substring
(
7
);
}
else
if
(
args
[
i
].
startsWith
(
"--javapackage="
))
{
javaPackage
=
args
[
i
].
substring
(
14
);
}
else
if
(
args
[
i
].
equals
(
"-P"
))
{
pythonFile
=
coreName
+
".py"
;
}
else
if
(
args
[
i
].
startsWith
(
"--python="
))
{
pythonFile
=
args
[
i
].
substring
(
9
);
}
else
if
(
args
[
i
].
startsWith
(
"--pretty="
))
{
prettyFile
=
args
[
i
].
substring
(
9
);
}
else
if
(
args
[
i
].
startsWith
(
"--typeinfo="
))
{
typeinfoFile
=
args
[
i
].
substring
(
11
);
}
else
if
(
args
[
i
].
equals
(
"--rapid"
))
{
rapidFile
=
coreName
+
".sys"
;
}
else
if
(
i
==
args
.
length
-
1
)
{
fileName
=
args
[
i
];
}
else
{
System
.
err
.
println
(
" Unknown argument "
+
args
[
i
]);
print_help
();
System
.
exit
(
2
);
}
}
if
(
prefix
==
null
){
System
.
err
.
println
(
" WARNING! prefix==null"
);
prefix
=
""
;
}
}
Program
parseFile
(){
Program
ast
=
null
;
try
{
// Check for errors
LabCommScanner
scanner
=
new
LabCommScanner
(
new
FileReader
(
fileName
));
LabCommParser
parser
=
new
LabCommParser
();
Program
p
=
(
Program
)
parser
.
parse
(
scanner
);
Collection
errors
=
new
LinkedList
();
p
.
errorCheck
(
errors
);
if
(
errors
.
isEmpty
())
{
ast
=
p
;
}
else
{
for
(
Iterator
iter
=
errors
.
iterator
();
iter
.
hasNext
();
)
{
String
s
=
(
String
)
iter
.
next
();
System
.
out
.
println
(
s
);
}
}
}
catch
(
FileNotFoundException
e
)
{
System
.
err
.
println
(
"Could not find file: "
+
fileName
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"IOException: "
+
fileName
+
" "
+
e
);
}
catch
(
beaver
.
Parser
.
Exception
e
)
{
System
.
err
.
println
(
e
.
getMessage
());
}
return
ast
;
}
boolean
generateC
(
Program
ast
)
{
boolean
wroteFile
=
false
;
Vector
hIncludes
=
new
Vector
(
cIncludes
);
if
(
hFile
!=
null
)
{
cIncludes
.
add
(
hFile
);
}
if
(
cFile
!=
null
)
{
printStatus
(
"C: "
,
cFile
);
genC
(
ast
,
cFile
,
cIncludes
,
coreName
,
cPrefix
,
ver
);
wroteFile
=
true
;
}
if
(
hFile
!=
null
)
{
printStatus
(
"H: "
,
hFile
);
genH
(
ast
,
hFile
,
hIncludes
,
coreName
,
cPrefix
,
ver
);
wroteFile
=
true
;
}
return
wroteFile
;
}
boolean
generateCS
(
Program
ast
)
{
boolean
wroteFile
=
false
;
if
(
csFile
!=
null
)
{
printStatus
(
"C#: "
,
csFile
);
genCS
(
ast
,
csFile
,
csNamespace
,
ver
);
wroteFile
=
true
;
}
return
wroteFile
;
}
boolean
generateJava
(
Program
ast
)
{
boolean
wroteFile
=
false
;
if
(
javaDir
!=
null
)
{
printStatus
(
"Java: "
,
javaDir
);
genJava
(
ast
,
javaDir
,
javaPackage
,
ver
);