blob: f6729fa20ec93de09c1c6646af412d8f681d0887 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package main
import (
"flag"
"log"
"os"
"fidl/compiler/backend/types"
"fidlgen_hlcpp/codegen"
)
// TODO(fxb/45483): Until all SDK consumers are moved off to using dedicated
// flags to invoke HLCPP fidlgen, we must preserve this legacy flags.
var jsonPath = flag.String("json", "",
"relative path to the FIDL intermediate representation.")
var outputBase = flag.String("output-base", "",
"the base file name for files generated by this generator.")
var includeBase = flag.String("include-base", "",
"the directory to which C and C++ includes should be relative.")
var generatorsUnused = flag.String("generators", "",
"unused")
var clangFormatPath = flag.String("clang-format-path", "",
"path to the clang-format tool.")
func flagsValid() bool {
return *jsonPath != "" && *outputBase != "" && *includeBase != ""
}
func main() {
flag.Parse()
if !flag.Parsed() || !flagsValid() {
flag.PrintDefaults()
os.Exit(1)
}
fidl, err := types.ReadJSONIr(*jsonPath)
if err != nil {
log.Fatal(err)
}
config := types.Config{
OutputBase: *outputBase,
IncludeBase: *includeBase,
}
if err := codegen.NewFidlGenerator().GenerateFidl(fidl, &config, *clangFormatPath); err != nil {
log.Fatalf("Error running generator: %v", err)
}
}