diff options
author | Josh Haberman <haberman@google.com> | 2013-02-15 16:27:18 -0800 |
---|---|---|
committer | Josh Haberman <haberman@google.com> | 2013-02-15 16:27:18 -0800 |
commit | 7d3e2bd2c4cfd1296d1d6f996d7548de26540d41 (patch) | |
tree | b4b35967b3322c65cfb1a32220e8718de09d85fc /tools/upbc.lua | |
parent | ea198bdcf947ba4bd51474bdd4f7b82b5e4cf41d (diff) |
Sync with 8 months of Google-internal development.
Many things have changed and been simplified.
The memory-management story for upb_def and upb_handlers
is much more robust; upb_def and upb_handlers should be
fairly stable interfaces now. There is still much work
to do for the runtime component (upb_sink).
Diffstat (limited to 'tools/upbc.lua')
-rw-r--r-- | tools/upbc.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/upbc.lua b/tools/upbc.lua new file mode 100644 index 0000000..f68d25f --- /dev/null +++ b/tools/upbc.lua @@ -0,0 +1,50 @@ +--[[ + + upb - a minimalist implementation of protocol buffers. + + Copyright (c) 2012 Google Inc. See LICENSE for details. + Author: Josh Haberman <jhaberman@gmail.com> + + The upb compiler. Unlike the proto2 compiler, this does + not output any parsing code or generated classes or anything + specific to the protobuf binary format at all. At the moment + it only dumps C initializers for upb_defs, so that a .proto + file can be represented in a .o file. + +--]] + +local dump_cinit = require "dump_cinit" +local upb = require "upb" + +local src = arg[1] +local outbase = arg[2] +local basename = arg[3] +local hfilename = outbase .. ".upb.h" +local cfilename = outbase .. ".upb.c" + +if os.getenv("UPBC_VERBOSE") then + print("upbc:") + print(string.format(" source file=%s", src)) + print(string.format(" output file base=%s", outbase)) + print(string.format(" hfilename=%s", hfilename)) + print(string.format(" cfilename=%s", cfilename)) +end + +-- Open input/output files. +local f = assert(io.open(src, "r"), "couldn't open input file " .. src) +local descriptor = f:read("*all") +local symtab = upb.SymbolTable() +symtab:load_descriptor(descriptor) + +os.execute(string.format("mkdir -p `dirname %s`", outbase)) +local hfile = assert(io.open(hfilename, "w"), "couldn't open " .. hfilename) +local cfile = assert(io.open(cfilename, "w"), "couldn't open " .. cfilename) + +local happend = dump_cinit.file_appender(hfile) +local cappend = dump_cinit.file_appender(cfile) + +-- Dump defs +dump_cinit.dump_defs(symtab, basename, happend, cappend) + +hfile:close() +cfile:close() |