Encode/decode AST into metadata, re-instantiate inlined items
This commit is contained in:
parent
be9914625b
commit
f3ca50c9ca
33 changed files with 10751 additions and 1019 deletions
57
src/etc/gen-astencode
Executable file
57
src/etc/gen-astencode
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
#!/bin/sh
|
||||
|
||||
M=src/comp/metadata
|
||||
GEN_TYPES="syntax::ast::item syntax::ast::def middle::typeck::method_origin \
|
||||
middle::freevars::freevar_entry syntax::ast::def_id"
|
||||
|
||||
# Find serializer tool:
|
||||
for S in build/*/stage2/bin/serializer; do
|
||||
|
||||
# Find rustc:
|
||||
D=$(dirname "$S")
|
||||
R="${D}/rustc"
|
||||
if [ ! -x "$R" ]; then
|
||||
echo "rustc not found or not executable at path '$R'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Generating src/comp/metadata/astencode_gen.rs"
|
||||
|
||||
# First, generate dummy fns so that the compiler can type
|
||||
# everything.
|
||||
echo "// TEMPORARY DEFINITIONS: re-run gen-astencode" \
|
||||
> $M/astencode_gen.rs
|
||||
for T in $GEN_TYPES; do
|
||||
echo "fn serialize_${T//::/_}<S>(_s: S, _v: $T) {}" \
|
||||
>> $M/astencode_gen.rs
|
||||
echo "fn deserialize_${T//::/_}<S>(_s: S) -> $T { fail; }" \
|
||||
>> $M/astencode_gen.rs
|
||||
done
|
||||
|
||||
# Generate the real code into a temporary file.
|
||||
if ! "$S" src/comp/rustc.rc $GEN_TYPES > tmp.$$.rs
|
||||
then
|
||||
echo ""
|
||||
echo ""
|
||||
echo "****************************************"
|
||||
echo "* Compilation errors encountered *"
|
||||
echo "* *"
|
||||
echo "* Dummy versions of the AST encoder *"
|
||||
echo "* have been left in astencode_gen.rs. *"
|
||||
echo "* Fix the compilation errors and rerun *"
|
||||
echo "* this script to generate the real *"
|
||||
echo "* versions. *"
|
||||
echo "****************************************"
|
||||
rm tmp.$$.rs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy over into the final destination and clean up.
|
||||
"$R" --pretty normal tmp.$$.rs > $M/astencode_gen.rs
|
||||
# rm -f tmp.$$.rs
|
||||
exit 0
|
||||
done
|
||||
|
||||
# If we made it this far, must not have found any
|
||||
# serializer:
|
||||
echo "serializer tool not found."
|
||||
|
|
@ -18,8 +18,11 @@ def report_err(s):
|
|||
print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s))
|
||||
err=1
|
||||
|
||||
file_names = [s for s in sys.argv[1:] if not s.endswith("_gen.rs")]
|
||||
|
||||
try:
|
||||
for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")):
|
||||
for line in fileinput.input(file_names,
|
||||
openhook=fileinput.hook_encoded("utf-8")):
|
||||
if (line.find('\t') != -1 and
|
||||
fileinput.filename().find("Makefile") == -1):
|
||||
report_err("tab character")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue