-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: adopt new embedding method and simplify code
- Loading branch information
Showing
18 changed files
with
288 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
path="$1" | ||
parent=`dirname ${1}` | ||
name=${2:-`basename ${1}`} | ||
pathname=`basename ${1}` | ||
dst=src/embed_${name}.c | ||
|
||
[ -r src/embedded.h ] || { | ||
>&2 echo "Build must generate src/embedded.h first" | ||
exit 1 | ||
} | ||
|
||
[ -r src/embedded.c ] || { | ||
>&2 echo "Build must generate src/embedded.c first" | ||
exit 1 | ||
} | ||
|
||
command -v xxd > /dev/null || { | ||
>&2 echo "Error not found: xxd binary not installed" | ||
exit 1 | ||
} | ||
|
||
>&2 echo "parent: $parent" | ||
>&2 echo "name: $name" | ||
>&2 echo "pathname: $pathname" | ||
>&2 echo "dest: $dst" | ||
|
||
rm -f ${name}.tar.gz | ||
prevpwd=`pwd` | ||
cd ${parent} | ||
[ "$pathname" != "$name" ] && cp -ra "$pathname" "$name" | ||
tar --format ustar -czf ${prevpwd}/${name}.tar.gz "$name" | ||
[ "$pathname" != "$name" ] && rm -rf "$name" | ||
cd - | ||
|
||
echo "// Embedded: $path" > $dst | ||
echo "// source generated by cjit/build/embed-path.sh" >> $dst | ||
echo "// `date`" >> $dst | ||
echo "// ${name}" >> $dst | ||
mv ${name}.tar.gz ${name} | ||
xxd -i ${name} >> $dst | ||
rm -f ${name} | ||
# must be constant variables in stack | ||
# sed inplace is not portable | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
sed -i'' -e 's/unsigned char/const char/' $dst | ||
sed -i'' -e 's/unsigned int/const unsigned int/' $dst | ||
else | ||
sed -i -e 's/unsigned char/const char/' $dst | ||
sed -i -e 's/unsigned int/const unsigned int/' $dst | ||
fi | ||
|
||
# xxd already converts dots in underscores | ||
name=`echo $name | sed 's/\./_/g'` | ||
|
||
# generate embeddings in source for extract_embeddings(char *tmpdir) | ||
echo "extern char *${name};" >> src/embedded.h | ||
echo "extern unsigned int ${name}_len;" >> src/embedded.h | ||
|
||
cat <<EOF >> src/embedded.c | ||
if(muntargz_to_path(tmpdir,(char*)&${name},${name}_len)) | ||
return(false); | ||
{ | ||
if(!CJIT) return(false); | ||
if(!CJIT->tmpdir) return(false); | ||
char incpath[512]; | ||
snprintf(incpath,511,"%s/%s",CJIT->tmpdir,"${name}"); | ||
tcc_add_include_path(CJIT->TCC, incpath); | ||
} | ||
EOF | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
head=src/embedded.h | ||
code=src/embedded.c | ||
rm -f ${head} ${code} | ||
cat <<EOF > ${head} | ||
// Generated by cjit/build/init-embeddings.sh | ||
// `date` | ||
#ifndef __EMBEDDED_H__ | ||
#define __EMBEDDED_H__ | ||
EOF | ||
|
||
cat <<EOF > ${code} | ||
// Generated by cjit/build/init-embeddings.sh | ||
// `date` | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <inttypes.h> | ||
#include <embedded.h> | ||
#include <cjit.h> | ||
// from file.c | ||
extern int muntar_to_path(const char *path, const uint8_t *buf, const unsigned int len); | ||
extern int muntargz_to_path(const char *path, const uint8_t *buf, const unsigned int len); | ||
// main function | ||
bool extract_embeddings(CJITState *CJIT, char *tmpdir) { | ||
EOF | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.