mirror of
https://github.com/github/codeql.git
synced 2025-12-22 03:36:30 +01:00
This checks in the trapgen script generating trap entries in C++. The codegen suite has been slightly reorganized, moving the templates directory up one level and chopping everything into smaller bazel packages. Running tests is now done via ``` bazel run //swift/codegen/test ``` With respect to the PoC, the nested `codeql::trap` namespace has been dropped in favour of a `Trap` prefix (or suffix in case of entries) within the `codeql` namespace. Also, generated C++ code is not checked in in git any more, and generated during build. Finally, labels get printed in hex in the trap file. `TrapLabel` is for the moment only default-constructible, so only one single label is possible. `TrapArena`, that is responsible for creating disjoint labels will come in a later commit.
29 lines
741 B
Python
29 lines
741 B
Python
""" generator script scaffolding """
|
|
|
|
import argparse
|
|
import logging
|
|
import sys
|
|
|
|
from . import options, render
|
|
|
|
|
|
def _parse(tags):
|
|
parser = argparse.ArgumentParser()
|
|
for opt in options.get(tags):
|
|
opt.add_to(parser)
|
|
ret = parser.parse_args()
|
|
log_level = logging.DEBUG if ret.verbose else logging.INFO
|
|
logging.basicConfig(format="{levelname} {message}", style='{', level=log_level)
|
|
return ret
|
|
|
|
|
|
def run(*modules):
|
|
""" run generation functions in specified in `modules`, or in current module by default
|
|
"""
|
|
if modules:
|
|
opts = _parse({t for m in modules for t in m.tags})
|
|
for m in modules:
|
|
m.generate(opts, render.Renderer())
|
|
else:
|
|
run(sys.modules["__main__"])
|