Files
Alessandro Di Federico 777adcbd45 model::Binary: add segments and imported libraries
Now, `scripts/revng` uses the model and we no longer need to emit
.li.csv and .need.csv.
2021-12-22 17:47:54 +01:00

54 lines
1.2 KiB
Python

#
# This file is distributed under the MIT License. See LICENSE.md for details.
#
import argparse
import json
import sys
import yaml
from .dump_model import fetch_text_model, parse_model, remap_metaaddress
def log(message):
sys.stderr.write(message + "\n")
def main():
parser = argparse.ArgumentParser(description="Extract and process rev.ng model.")
parser.add_argument("--json",
action="store_true",
help="Dump as JSON.")
parser.add_argument("--remap",
action="store_true",
help="Remap MetaAddresses. Implies --json.")
args = parser.parse_args()
if args.remap:
args.json = True
text_model = fetch_text_model(sys.stdin)
# Consume all remaining input
sys.stdin.read()
if text_model is None:
log("Couldn't load model")
return 1
if not args.json:
print(text_model)
return 0
# Decode YAML
model = parse_model(text_model)
# Remap MetaAddress
if args.remap:
model = remap_metaaddress(model)
# Dump as JSON
print(json.dumps(model,
indent=2,
sort_keys=True,
check_circular=False))
return 0