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
Anders Blomdell
LabComm
Commits
89cfad68
Commit
89cfad68
authored
May 22, 2015
by
Sven Gestegård Robertz
Browse files
WiP: intentions partially implemented in C, Java (typedefparser broken), and python
parent
467c8127
Changes
16
Show whitespace changes
Inline
Side-by-side
compiler/2014/Annotations.jrag
View file @
89cfad68
...
...
@@ -48,6 +48,8 @@ aspect SigAnnotations {
}
};
syn int Decl.getNumIntentions() = getTypeInstance().sortedIntentions().getNumChild();
syn List<Intention> TypeInstance.sortedIntentions() {
List<Intention> res = new List<Intention>();
...
...
compiler/2014/FlatSignature.jrag
View file @
89cfad68
...
...
@@ -78,7 +78,7 @@ aspect FlatSignature {
public void Field.flatSignature(SignatureList list) {
debugAnnotations(this.getName()+".Field.flatSignature");
list.addIntentions(intentions(), "Field: "+getIntentionString());
list.addString(getName(), signatureComment());
//
list.addString(getName(), signatureComment());
getDataType().flatSignature(list);
}
...
...
compiler/2014/Java_CodeGen.jrag
View file @
89cfad68
...
...
@@ -473,6 +473,7 @@ aspect Java_Class {
}
public void Decl.Java_emitIntentions(Java_env env){
env.println("private static int numIntentions = " +getNumIntentions() +";");
env.println("private static byte[] intentions = new byte[] {");
env.indent();
byte[] data = getIntentionBytes();
...
...
@@ -583,6 +584,28 @@ aspect Java_Class {
env.unindent();
env.println("}");
env.println();
env.println("/** return the outermost intentions. */");
env.println("public byte[] getIntentionBytes() {");
env.indent();
if(isSample) {
env.println("return intentions;");
} else {
env.println("return new byte[0];");
}
env.unindent();
env.println("}");
env.println();
env.println("/** return the number of intentions. */");
env.println("public int getNumIntentions() {");
env.indent();
if(isSample) {
env.println("return numIntentions;");
} else {
env.println("return 0;");
}
env.unindent();
env.println("}");
env.println();
// env.println("public void encodeSignature(Encoder e) throws IOException{");
// env.indent();
// env.println("emitSignature(e);");
...
...
compiler/2014/Refactoring.jrag
View file @
89cfad68
...
...
@@ -7,12 +7,12 @@ aspect Refactoring {
public Annotations Annotations.addName(String n) {
//XXX TODO: check if name already exists
addAnnotation(new
Annota
tion("",n.getBytes()));
addAnnotation(new
Inten
tion("",n.getBytes()));
return this;
}
public Field.Field(TypeInstance t) {
this(t.getDataType(), t.getAnnotations()
.addName(t.getName())
);
this(t.getDataType(), t.getAnnotations());
}
public TypeInstance.TypeInstance(DataType t, String n, Annotations a) {
...
...
compiler/2014/Signature.jrag
View file @
89cfad68
...
...
@@ -289,6 +289,7 @@ aspect Signature {
public void TypeInstance.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
// debugAnnotations(this.getName());
// list.addString(inst.getIntentionString(), "intention string");
list.addIntentions(intentionSet(), "intentions");
getDataType().genSigLineForDecl(list, decl, this);
}
...
...
@@ -351,12 +352,13 @@ aspect Signature {
list.add(null, "}");
}
public void Field.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addString(getName(), signatureComment());
super.genSigLineForDecl(list, decl, inst);
//TODOintent
//getDataType().genSigLineForDecl(list, decl, inst);
}
// public void Field.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
// //XXX make intention
// list.addString(getName(), signatureComment());
// super.genSigLineForDecl(list, decl, inst);
// //TODOintent
// //getDataType().genSigLineForDecl(list, decl, inst);
// }
public void IntegerLiteral.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
list.addInt(Integer.parseInt(getValue()), null);
...
...
compiler/2014/TypeCheck.jrag
View file @
89cfad68
...
...
@@ -44,8 +44,11 @@ aspect AnnotationCheck {
public void ASTNode.annotationCheck() {}
public void TypeDecl.annotationCheck() {
if(getTypeInstance().hasIntentions()) {
Iterator<Intention> it = getTypeInstance().intentions().iterator();;
while(it.hasNext()) {
if(!it.next().getKey().equals("")) {
error("TypeDecl " + getName() + " has intentions. (Not allowed for typedefs)");
}
}
}
}
lib/c/2014/labcomm2014_decoder.c
View file @
89cfad68
...
...
@@ -161,7 +161,7 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind)
int
numInts
=
labcomm2014_read_byte
(
d
->
reader
);
if
(
numInts
!=
1
)
{
printf
(
"WARNING! #intentions != 1, this will probably crash
\n
"
);
printf
(
"WARNING! #intentions
%d
!= 1, this will probably crash
\n
"
,
numInts
);
}
//XXX temporary kludge for intentions
//assume only one intention: the name
...
...
@@ -482,6 +482,16 @@ static void decode_raw_type_def(
struct
labcomm2014_raw_type_def
v
;
v
.
index
=
labcomm2014_read_packed32
(
r
);
if
(
r
->
error
<
0
)
{
goto
out
;
}
{
int
numInts
=
labcomm2014_read_byte
(
r
);
if
(
numInts
!=
1
)
{
printf
(
"WARNING! #intentions %d != 1, this will probably crash
\n
"
,
numInts
);
}
//XXX temporary kludge for intentions
//assume only one intention: the name
labcomm2014_read_packed32
(
r
);
// assume the empty key (i.e., name)
}
v
.
name
=
labcomm2014_read_string
(
r
);
if
(
r
->
error
<
0
)
{
goto
free_name
;
}
v
.
length
=
labcomm2014_read_packed32
(
r
);
...
...
lib/c/2014/labcomm2014_encoder.c
View file @
89cfad68
...
...
@@ -302,15 +302,15 @@ static int internal_reg_type(
if
(
err
!=
0
)
{
result
=
err
;
goto
out
;
}
int
sig_size
=
calc_sig_encoded_size
(
e
,
signature
);
int
len
=
labcomm2014_size_packed32
(
index
)
+
labcomm2014_size_string
(
signature
->
name
)
+
labcomm2014_size_packed32
(
sig
_
size
)
+
sig_size
;
int
len
=
(
labcomm2014_size_packed32
(
index
)
+
TODO_sizeof_intentions
(
signature
)
+
labcomm2014_size_packed32
(
sig
nature
->
size
)
+
sig_size
)
;
labcomm2014_write_packed32
(
e
->
writer
,
LABCOMM_TYPE_DEF
);
labcomm2014_write_packed32
(
e
->
writer
,
len
);
labcomm2014_write_packed32
(
e
->
writer
,
index
);
labcomm2014_write_string
(
e
->
writer
,
signature
->
name
);
TODO_encode_intentions
(
e
,
signature
);
labcomm2014_write_packed32
(
e
->
writer
,
sig_size
);
do_write_signature
(
e
,
signature
,
LABCOMM2014_FALSE
);
...
...
lib/c/2014/test/test_labcomm_generated_encoding.c
View file @
89cfad68
...
...
@@ -214,8 +214,8 @@ int main(void)
labcomm2014_encoder_register_generated_encoding_V
(
encoder
);
labcomm2014_encoder_register_generated_encoding_V
(
encoder
);
EXPECT
({
0x02
,
0x08
,
VARIABLE
(
0
),
0x01
,
0x00
,
0x01
,
'V'
,
0x02
,
0x11
,
0x00
,
0x04
,
0x0
8
,
VARIABLE
(
1
),
0x03
,
'v'
,
'_'
,
't'
,
0x02
,
0x11
,
0x00
,
0x04
,
0x0
5
,
VARIABLE
(
2
),
0x01
,
'V'
,
0x01
,
VARIABLE
(
1
),
0x04
,
0x0
a
,
VARIABLE
(
1
),
0x01
,
0x00
,
0x03
,
'v'
,
'_'
,
't'
,
0x02
,
0x11
,
0x00
,
0x04
,
0x0
7
,
VARIABLE
(
2
),
0x01
,
0x00
,
0x01
,
'V'
,
0x01
,
VARIABLE
(
1
),
0x05
,
0x02
,
VARIABLE
(
0
),
VARIABLE
(
2
)
});
labcomm2014_encoder_ioctl
(
encoder
,
IOCTL_WRITER_RESET
);
...
...
lib/java/se/lth/control/labcomm2014/DecoderChannel.java
View file @
89cfad68
...
...
@@ -18,6 +18,14 @@ public class DecoderChannel implements Decoder {
private
void
processSampleDef
()
throws
IOException
{
int
index
=
decodePacked32
();
int
numIntentions
=
decodePacked32
();
if
(
numIntentions
!=
1
)
{
System
.
out
.
println
(
"WARNING: #intentions == "
+
numIntentions
);
}
int
keylen
=
decodePacked32
();
if
(
keylen
!=
0
)
{
System
.
out
.
println
(
"WARNING: keylen == "
+
keylen
);
}
String
name
=
decodeString
();
int
signature_length
=
decodePacked32
();
byte
[]
signature
=
new
byte
[
signature_length
];
...
...
@@ -27,6 +35,14 @@ public class DecoderChannel implements Decoder {
private
void
processSampleRef
()
throws
IOException
{
int
index
=
decodePacked32
();
int
numIntentions
=
decodePacked32
();
if
(
numIntentions
!=
1
)
{
System
.
out
.
println
(
"WARNING: #intentions == "
+
numIntentions
);
}
int
keylen
=
decodePacked32
();
if
(
keylen
!=
0
)
{
System
.
out
.
println
(
"WARNING: keylen == "
+
keylen
);
}
String
name
=
decodeString
();
int
signature_length
=
decodePacked32
();
byte
[]
signature
=
new
byte
[
signature_length
];
...
...
@@ -39,6 +55,14 @@ public class DecoderChannel implements Decoder {
processSample
(
Constant
.
TYPE_DEF
);
}
catch
(
Exception
ex
)
{
int
idx
=
decodePacked32
();
int
numIntentions
=
decodePacked32
();
if
(
numIntentions
!=
1
)
{
System
.
out
.
println
(
"WARNING: #intentions == "
+
numIntentions
);
}
int
keylen
=
decodePacked32
();
if
(
keylen
!=
0
)
{
System
.
out
.
println
(
"WARNING: keylen == "
+
keylen
);
}
String
name
=
decodeString
();
int
siglen
=
decodePacked32
();
for
(
int
i
=
0
;
i
<
siglen
;
i
++)
{
...
...
lib/java/se/lth/control/labcomm2014/EncoderChannel.java
View file @
89cfad68
...
...
@@ -46,7 +46,15 @@ public class EncoderChannel implements Encoder {
int
index
=
sample_def_registry
.
add
(
dispatcher
);
begin
(
dispatcher
.
getTypeDeclTag
());
encodePacked32
(
index
);
//HERE BE DRAGONS! numintentions does not include name
// encodePacked32(dispatcher.getNumIntentions()+1);
encodePacked32
(
1
);
encodePacked32
(
0
);
// the empty key == name
encodeString
(
dispatcher
.
getName
());
// byte[] intentions = dispatcher.getIntentionBytes();
// for (int k = 0 ; k < intentions.length ; k++) {
// encodeByte(intentions[k]);
// }
byte
[]
signature
=
dispatcher
.
getSignature
();
encodePacked32
(
signature
.
length
);
for
(
int
i
=
0
;
i
<
signature
.
length
;
i
++)
{
...
...
@@ -92,6 +100,10 @@ public class EncoderChannel implements Encoder {
begin
(
Constant
.
TYPE_DEF
);
encodePacked32
(
index
);
//HERE BE DRAGONS! numintentions does not include name
// encodePacked32(dispatcher.getNumIntentions()+1);
encodePacked32
(
1
);
encodePacked32
(
0
);
// the empty key == name
encodeString
(
dispatcher
.
getName
());
encodePacked32
(
b
.
length
);
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++)
{
...
...
@@ -123,6 +135,10 @@ public class EncoderChannel implements Encoder {
int
index
=
sample_ref_registry
.
add
(
dispatcher
);
begin
(
Constant
.
SAMPLE_REF
);
encodePacked32
(
index
);
//HERE BE DRAGONS! numintentions does not include name
// encodePacked32(dispatcher.getNumIntentions()+1);
encodePacked32
(
1
);
encodePacked32
(
0
);
// the empty key == name
encodeString
(
dispatcher
.
getName
());
byte
[]
signature
=
dispatcher
.
getSignature
();
encodePacked32
(
signature
.
length
);
...
...
lib/java/se/lth/control/labcomm2014/SampleDispatcher.java
View file @
89cfad68
...
...
@@ -10,6 +10,10 @@ public interface SampleDispatcher <T extends SampleType>{
public
byte
[]
getSignature
();
public
int
getNumIntentions
();
public
byte
[]
getIntentionBytes
();
public
void
decodeAndHandle
(
Decoder
decoder
,
SampleHandler
handler
)
throws
Exception
;
...
...
lib/java/se/lth/control/labcomm2014/TypeBinding.java
View file @
89cfad68
...
...
@@ -77,6 +77,14 @@ public class TypeBinding implements BuiltinType {
return
null
;
// not used for matching
}
public
int
getNumIntentions
()
{
return
0
;
}
public
byte
[]
getIntentionBytes
()
{
return
null
;
// not used for matching
}
public
void
encodeTypeDef
(
Encoder
e
,
int
index
)
throws
IOException
{
throw
new
Error
(
"Should not be called"
);
}
...
...
lib/java/se/lth/control/labcomm2014/TypeDef.java
View file @
89cfad68
...
...
@@ -85,6 +85,14 @@ public class TypeDef implements BuiltinType {
return
null
;
// not used for matching
}
public
int
getNumIntentions
()
{
return
0
;
}
public
byte
[]
getIntentionBytes
()
{
return
new
byte
[
0
];
}
public
void
encodeTypeDef
(
Encoder
e
,
int
index
)
throws
IOException
{
throw
new
Error
(
"Should not be called"
);
}
...
...
@@ -119,6 +127,14 @@ public class TypeDef implements BuiltinType {
public
static
TypeDef
decode
(
Decoder
d
)
throws
IOException
{
TypeDef
result
;
int
index
=
d
.
decodePacked32
();
int
numIntentions
=
d
.
decodePacked32
();
if
(
numIntentions
!=
1
)
{
System
.
out
.
println
(
"WARNING: #intentions == "
+
numIntentions
);
}
int
keylen
=
d
.
decodePacked32
();
if
(
keylen
!=
0
)
{
System
.
out
.
println
(
"WARNING: keylen == "
+
keylen
);
}
String
name
=
d
.
decodeString
();
int
siglen
=
d
.
decodePacked32
();
byte
sig
[]
=
new
byte
[
siglen
];
...
...
lib/java/se/lth/control/labcomm2014/TypeDefParser.java
View file @
89cfad68
lib/python/labcomm2014/LabComm.py
View file @
89cfad68
...
...
@@ -401,9 +401,9 @@ class sampledef_or_sampleref_or_typedef(type_decl):
encoder
.
encode_type
(
self
.
type_index
)
with
length_encoder
(
encoder
)
as
e1
:
e1
.
encode_type
(
self
.
get_index
(
encoder
))
e1
.
encode_string
(
self
.
name
)
# XXX: temporary hack for intentions
e1
.
encode_empty_intentions
(
self
.
name
)
with
length_encoder
(
e1
)
as
e2
:
self
.
encode_empty_intentions
(
e2
)
self
.
decl
.
encode_decl
(
e2
)
def
encode
(
self
,
encoder
,
value
):
...
...
@@ -411,10 +411,11 @@ class sampledef_or_sampleref_or_typedef(type_decl):
def
decode_decl
(
self
,
decoder
):
index
=
decoder
.
decode_type_number
()
name
=
decoder
.
decode_string
()
# XXX: temporary hack for intentions
# assume the name is the only intention
name
=
decoder
.
decode_intentions
()
if
usePacketLength
(
decoder
.
version
):
length
=
decoder
.
decode_packed32
()
self
.
decode_intentions
(
decoder
)
decl
=
decoder
.
decode_decl
()
result
=
self
.
__class__
.
__new__
(
self
.
__class__
)
result
.
__init__
(
name
=
name
,
decl
=
decl
)
...
...
@@ -456,12 +457,6 @@ class sample_def(sampledef_or_sampleref_or_typedef):
def
rename
(
self
,
name
):
return
sample_def
(
name
=
name
,
decl
=
self
.
decl
)
def
decode_intentions
(
self
,
d
):
return
d
.
decode_string
()
def
encode_empty_intentions
(
self
,
e
):
e
.
encode_empty_intentions
()
class
sample_ref
(
sampledef_or_sampleref_or_typedef
):
type_index
=
i_SAMPLE_REF
type_name
=
'sample_ref'
...
...
@@ -474,12 +469,6 @@ class sample_ref(sampledef_or_sampleref_or_typedef):
else
:
self
.
sample
=
sample
def
decode_intentions
(
self
,
d
):
return
d
.
decode_string
()
def
encode_empty_intentions
(
self
,
e
):
e
.
encode_empty_intentions
()
def
get_index
(
self
,
encoder
):
return
encoder
.
ref_to_index
[
self
.
sample
]
...
...
@@ -490,12 +479,6 @@ class typedef(sampledef_or_sampleref_or_typedef):
type_index
=
i_TYPE_DEF
type_name
=
'typedef'
def
decode_intentions
(
self
,
d
):
pass
def
encode_empty_intentions
(
self
,
e
):
pass
def
encode_decl
(
self
,
encoder
):
self
.
decl
.
encode_decl
(
encoder
)
...
...
@@ -647,8 +630,7 @@ class struct(type_decl):
encoder
.
encode_type
(
i_STRUCT
)
encoder
.
encode_packed32
(
len
(
self
.
field
))
for
(
name
,
decl
)
in
self
.
field
:
encoder
.
encode_empty_intentions
()
encoder
.
encode_string
(
name
)
encoder
.
encode_empty_intentions
(
name
)
encoder
.
encode_type_number
(
decl
)
def
encode
(
self
,
encoder
,
obj
):
...
...
@@ -663,8 +645,7 @@ class struct(type_decl):
n_field
=
decoder
.
decode_packed32
()
field
=
[]
for
i
in
range
(
n_field
):
intentions
=
decoder
.
decode_intentions
()
name
=
decoder
.
decode_string
()
name
=
decoder
.
decode_intentions
()
decl
=
decoder
.
decode_decl
()
field
.
append
((
name
,
decl
))
return
struct
(
field
)
...
...
@@ -891,9 +872,11 @@ class Encoder(Codec):
self
.
encode_packed32
(
len
(
s
));
self
.
pack
(
"%ds"
%
len
(
s
),
s
)
def
encode_empty_intentions
(
self
):
def
encode_empty_intentions
(
self
,
name
):
# pass
self
.
encode_packed32
(
1
)
self
.
encode_string
(
""
)
self
.
encode_string
(
name
)
class
Decoder
(
Codec
):
def
__init__
(
self
,
reader
,
version
=
DEFAULT_VERSION
):
...
...
@@ -1027,7 +1010,14 @@ class Decoder(Codec):
return
self
.
index_to_ref
.
get
(
index
,
None
)
def
decode_intentions
(
self
):
return
self
.
decode_string
()
numIntentions
=
self
.
decode_packed32
()
name
=
""
for
i
in
range
(
numIntentions
):
key
=
self
.
decode_string
()
val
=
self
.
decode_string
()
if
key
==
""
:
name
=
val
return
name
class
signature_reader
:
def
__init__
(
self
,
signature
):
...
...
Write
Preview
Supports
Markdown
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