drgn/libdrgn/build-aux/gen_drgn_h.awk
Omar Sandoval 8b264f8823 Update copyright headers to Facebook and add missing headers
drgn was originally my side project, but for awhile now it's also been
my work project. Update the copyright headers to reflect this, and add a
copyright header to various files that were missing it.
2020-05-15 15:13:02 -07:00

40 lines
1.2 KiB
Awk

# Copyright (c) Facebook, Inc. and its affiliates.
# SPDX-License-Identifier: GPL-3.0+
# This script generates "drgn.h" from "drgn.h.in" and all of the
# "arch_foo.c.in" files. It replaces @DRGN_VERSION_*@ based on the "version"
# variable given on the command line and @ENUM_DRGN_REGISTER_NUMBER@ with the
# definition generated from the "arch_foo.c.in" files.
BEGIN {
if (!match(version, /^([0-9]+)\.([0-9]+)\.([0-9]+)/, version_arr)) {
print "could not parse version" > "/dev/stderr"
exit 1
}
enum = "enum drgn_register_number {\n"
}
ARGIND == ARGC - 1 {
gsub(/@DRGN_VERSION_MAJOR@/, version_arr[1])
gsub(/@DRGN_VERSION_MINOR@/, version_arr[2])
gsub(/@DRGN_VERSION_PATCH@/, version_arr[3])
gsub(/@ENUM_DRGN_REGISTER_NUMBER@/, enum)
print
next
}
ENDFILE {
if (ARGIND == ARGC - 1)
exit
if (!match(FILENAME, /^([^\/]*\/)*arch_([^\/]*)\.c\.in$/, group)) {
print FILENAME ": error: could not parse architecture name" > "/dev/stderr"
exit 1
}
prefix = "DRGN_REGISTER_" toupper(sanitize(arch_name)) "_"
PROCINFO["sorted_in"] = "@val_num_asc"
for (reg in registers)
enum = enum "\t" prefix sanitize(reg) " = " registers[reg] ",\n"
if (ARGIND == ARGC - 2)
enum = enum "};"
}