add example C program which generates (de)marshaling with ldmc

This commit is contained in:
Michael Sippel 2025-05-10 15:00:54 +02:00
parent 27ea365755
commit 1116457bcc
Signed by: senvas
GPG key ID: F96CF119C34B64A6
3 changed files with 38 additions and 0 deletions
examples/01-uint-example

1
examples/01-uint-example/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build/

View file

@ -0,0 +1,14 @@
#include "morphisms.h"
int main(int argc, char* argv[]) {
if( argc > 1 ) {
uint64_t value;
demarshal( argv[1], &value );
uint64_t result = value * value;
char buf[256];
marshal( &result, buf );
printf("%s\n", buf);
}
}

View file

@ -0,0 +1,23 @@
all: build/square
.PHONY: build clean
build:
mkdir -p build
build/morphisms.h: build
ldmc \
-m "marshal: \
~ native.UInt64 \
--> ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8>" \
\
-m "demarshal: \
~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~native.UInt8> \
--> ~ native.UInt64 " \
\
>| build/morphisms.h
build/square: build build/morphisms.h
gcc -Os -I../../morphisms/runtime/include/ -Ibuild main.c -o build/square
clean:
rm build/ -rf