Esempio n. 1
0
def generate_actuals_base_h(decoder, decoder_name, filename, out, cl_args):
    """Generates actual decoder C++ declarations in the given file.

    Args:
        decoder: The decoder tables.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
        """

    num_blocks = dgen_output.GetNumberCodeBlocks(cl_args['auto-actual-sep'])

    assert filename.endswith('actuals.h')

    values = {
        'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
        'IFDEF_NAME': dgen_output.ifdef_name(filename),
        'FILEBASE': filename[:-len('.h')],
        'decoder_name': decoder_name,
    }
    out.write(ACTUAL_BASE_H_HEADER % values)
    for block in range(1, num_blocks + 1):
        values['filename_index'] = block
        out.write(ACTUAL_BASE_INCLUDE % values)
    out.write(ACTUAL_BASE_H_FOOTER % values)
Esempio n. 2
0
def generate_actuals_h(decoder, decoder_name, filename, out, cl_args):
    """Generates actual decoder C++ declarations in the given file.

    Args:
        decoder: The decoder tables.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
        """

    separators = cl_args['auto-actual-sep']
    num_blocks = dgen_output.GetNumberCodeBlocks(separators)

    # Find block to print
    block = dgen_output.FindBlockIndex(filename, 'actuals_%s.h', num_blocks)

    values = {
        'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
        'IFDEF_NAME': dgen_output.ifdef_name(filename),
        'decoder_name': decoder_name,
    }
    out.write(ACTUAL_H_HEADER % values)
    _print_actual_headers(GetActualDecodersBlock(decoder, block, separators),
                          out)
    out.write(ACTUAL_H_FOOTER % values)
Esempio n. 3
0
def generate_actuals_base_h(decoder, decoder_name,
                               filename, out, cl_args):
  """Generates actual decoder C++ declarations in the given file.

    Args:
        decoder: The decoder tables.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
        """

  num_blocks = dgen_output.GetNumberCodeBlocks(cl_args['auto-actual-sep'])

  assert filename.endswith('actuals.h')

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'FILEBASE'   : filename[:-len('.h')],
      'decoder_name': decoder_name,
      }
  out.write(ACTUAL_BASE_H_HEADER % values)
  for block in range(1, num_blocks+1):
    values['filename_index'] = block
    out.write(ACTUAL_BASE_INCLUDE % values)
  out.write(ACTUAL_BASE_H_FOOTER % values)
Esempio n. 4
0
def generate_actuals_h(decoder, decoder_name, filename, out, cl_args):
  """Generates actual decoder C++ declarations in the given file.

    Args:
        decoder: The decoder tables.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
        """

  separators = cl_args['auto-actual-sep']
  num_blocks = dgen_output.GetNumberCodeBlocks(separators)

  # Find block to print
  block = dgen_output.FindBlockIndex(filename, 'actuals_%s.h', num_blocks)

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'decoder_name': decoder_name,
      }
  out.write(ACTUAL_H_HEADER % values)
  _print_actual_headers(
    GetActualDecodersBlock(decoder, block, separators), out)
  out.write(ACTUAL_H_FOOTER % values)
Esempio n. 5
0
def generate_named_decoder_h(decoder, decoder_name, filename, out, cl_args):
    """Generates the named decoder for testing.

    Args:
        tables: list of Table objects to process.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
    """
    global _cl_args
    if not decoder.primary: raise Exception('No tables provided.')
    assert filename.endswith('_decoder.h')
    _cl_args = cl_args

    values = {
        'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
        'NOT_TCB_MESSAGE' : dgen_output.NOT_TCB_BOILERPLATE,
        'IFDEF_NAME' : dgen_output.ifdef_name(filename),
        'FILENAME_BASE': filename[:-len('_decoder.h')],
        'decoder_name': decoder_name,
        }
    out.write(NAMED_DECODER_H_HEADER % values)
    _generate_baseline_and_actual(DECODER_STATE_FIELD, DECODER_STATE_FIELD_NAME,
                                  decoder, values, out)
    out.write(DECODER_STATE_DECODER_COMMENTS)
    for table in decoder.tables():
      values['table'] = table.name
      out.write(DECODER_STATE_DECODER % values)
    out.write(NAMED_DECODER_H_FOOTER % values)
Esempio n. 6
0
def generate_named_decoder_h(decoder, decoder_name, filename, out, cl_args):
  """Generates the named decoder for testing.

    Args:
        tables: list of Table objects to process.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
    """
  global _cl_args
  assert filename.endswith('_named_decoder.h')
  _cl_args = cl_args

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'NOT_TCB_MESSAGE': dgen_output.NOT_TCB_BOILERPLATE,
      'IFDEF_NAME': dgen_output.ifdef_name(filename),
      'FILENAME_BASE': filename[:-len('_named_decoder.h')],
      'decoder_name': decoder_name,
  }
  out.write(NAMED_DECODER_H_HEADER % values)
  _generate_baseline_and_actual(DECODER_STATE_FIELD, DECODER_STATE_FIELD_NAME,
                                decoder, values, out)
  out.write(DECODER_STATE_DECODER_COMMENTS)
  for table in decoder.tables():
    values['table'] = table.name
    out.write(DECODER_STATE_DECODER % values)
  out.write(NAMED_DECODER_H_FOOTER % values)
Esempio n. 7
0
def generate_named_classes_h(decoder, decoder_name, filename, out, cl_args):
  """Defines named classes needed for decoder testing.

  Args:
    tables: list of Table objects to process.
    decoder_name: The name of the decoder state to build.
    filename: The (localized) name for the .h file.
    out: a COutput object to write to.
    cl_args: A dictionary of additional command line arguments.
  """
  global _cl_args
  if not decoder.primary: raise Exception('No tables provided.')
  _cl_args = cl_args

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'NOT_TCB_MESSAGE' : dgen_output.NOT_TCB_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'decoder_name': decoder_name,
      }
  out.write(NAMED_CLASSES_H_HEADER % values)
  out.write(RULE_CLASSES_HEADER)
  _generate_baseline_and_actual(RULE_CLASS, RULE_CLASS_SYM,
                                decoder, values, out)
  out.write(NAMED_DECODERS_HEADER)
  _generate_baseline_and_actual(NAMED_CLASS_DECLARE, NAMED_CLASS_DECLARE_SYM,
                                decoder, values, out)
  out.write(NAMED_CLASSES_H_FOOTER % values)
def generate_named_bases_h(decoder, decoder_name, filename, out, cl_args):
  """Defines named classes needed for testing generated baselines.

  Args:
    tables: list of Table objects to process.
    decoder_name: The name of the decoder state to build.
    filename: The (localized) name for the .h file.
    out: a COutput object to write to.
    cl_args: A dictionary of additional command line arguments.
  """
  global _cl_args
  if not decoder.primary: raise Exception('No tables provided.')
  assert filename.endswith(NAMED_BASES_H_SUFFIX)
  _cl_args = cl_args

  decoder = dgen_baselines.AddBaselinesToDecoder(decoder)

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'NOT_TCB_MESSAGE' : dgen_output.NOT_TCB_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'FILENAME_BASE': filename[:-len(NAMED_BASES_H_SUFFIX)],
      'decoder_name': decoder_name,
      }
  out.write(NAMED_BASES_H_HEADER % values)
  _generate_generated_baseline(decoder, out)
  out.write(NAMED_BASES_H_FOOTER % values)
Esempio n. 9
0
def generate_named_classes_h(decoder, decoder_name, filename, out, cl_args):
  """Defines named classes needed for decoder testing.

  Args:
    tables: list of Table objects to process.
    decoder_name: The name of the decoder state to build.
    filename: The (localized) name for the .h file.
    out: a COutput object to write to.
    cl_args: A dictionary of additional command line arguments.
  """
  global _cl_args
  assert filename.endswith('_named_classes.h')
  _cl_args = cl_args

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'NOT_TCB_MESSAGE' : dgen_output.NOT_TCB_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'FILENAME_BASE': filename[:-len('_named_classes.h')],
      'decoder_name': decoder_name,
      }
  out.write(NAMED_CLASSES_H_HEADER % values)
  out.write(RULE_CLASSES_HEADER)
  _generate_baseline_and_actual(RULE_CLASS, RULE_CLASS_SYM,
                                decoder, values, out)
  out.write(NAMED_DECODERS_HEADER)
  _generate_baseline_and_actual(NAMED_CLASS_DECLARE, NAMED_CLASS_DECLARE_SYM,
                                decoder, values, out)
  out.write(NAMED_CLASSES_H_FOOTER % values)
def generate_baselines_h(decoder, decoder_name,
                         filename, out, cl_args):
  """Generates baseline decoder C++ declarations in the given file.

    Args:
        decoder: The decoder tables.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
        """
  if not decoder.primary: raise Exception('No tables provided.')

  separators = cl_args['auto-baseline-sep']
  num_blocks = dgen_output.GetNumberCodeBlocks(separators)

  # Find block to print
  block = dgen_output.FindBlockIndex(filename, 'baselines_%s.h', num_blocks)

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'decoder_name': decoder_name,
      }
  out.write(BASELINE_H_HEADER % values)
  _print_baseline_headers(
      GetBaselineDecodersBlock(decoder, block, separators), out)
  out.write(BASELINE_H_FOOTER % values)
def generate_baselines_base_h(decoder, decoder_name,
                               filename, out, cl_args):
  """Generates baseline decoder C++ declarations in the given file.

    Args:
        decoder: The decoder tables.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
        """
  if not decoder.primary: raise Exception('No tables provided.')

  separators = cl_args['auto-baseline-sep']
  num_blocks = dgen_output.GetNumberCodeBlocks(separators)

  assert filename.endswith('baselines.h')

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'FILEBASE'   : filename[:-len('.h')],
      'decoder_name': decoder_name,
      }
  out.write(BASELINE_BASE_H_HEADER % values)
  for block in range(1, num_blocks+1):
    values['filename_index'] = block
    out.write(BASELINE_BASE_INCLUDE % values)
  out.write(BASELINE_BASE_H_FOOTER % values)
Esempio n. 12
0
def generate_h(decoder, decoder_name, filename, out, cl_args):
    """Entry point to the decoder for .h file.

    Args:
        decoder: The decoder defined by the list of Table objects to process.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        named_decoders: If true, generate a decoder state with named instances.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
    """
    global _cl_args
    if not decoder.primary: raise Exception('No tables provided.')
    _cl_args = cl_args

    # Before starting, remove all testing information from the parsed tables.
    decoder = decoder.action_filter(['actual'])

    values = {
        'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
        'IFDEF_NAME': dgen_output.ifdef_name(filename),
        'decoder_name': decoder_name,
        }
    out.write(H_HEADER % values)
    out.write(DECODER_DECLARE_HEADER % values)
    out.write(DECODER_DECLARE_METHOD_COMMENTS)
    for table in decoder.tables():
      values['table_name'] = table.name
      out.write(DECODER_DECLARE_METHOD % values)
    out.write(DECODER_DECLARE_FIELD_COMMENTS)
    for action in decoder.action_filter(['actual']).decoders():
      values['decoder'] = action.actual()
      out.write(DECODER_DECLARE_FIELD % values)
    out.write(DECODER_DECLARE_FOOTER % values)
    out.write(H_FOOTER % values)
def generate_h(decoder, decoder_name, filename, out, cl_args):
    """Entry point to the decoder for .h file.

    Args:
        decoder: The decoder defined by the list of Table objects to
                 process.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        named_decoders: If true, generate a decoder state with named
                 instances.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
    """
    global _cl_args
    if not decoder.primary: raise Exception('No tables provided.')
    assert filename.endswith('.h')
    _cl_args = cl_args

    # Generate actuals from descriptions in tables, for each of the
    # tables that should automatically generate the corresponding
    # needed actual class decoders.
    actuals = cl_args.get('auto-actual')
    if actuals:
      decoder = dgen_actuals.AddAutoActualsToDecoder(decoder, actuals)

    # Before starting, remove all testing information from the parsed tables.
    decoder = decoder.action_filter(['actual'])

    values = {
        'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
        'IFDEF_NAME': dgen_output.ifdef_name(filename),
        'FILENAME_BASE': filename[:-len('.h')],
        'decoder_name': decoder_name,
        }
    out.write(H_HEADER % values)
    out.write(DECODER_DECLARE_HEADER % values)
    out.write(DECODER_DECLARE_METHOD_COMMENTS)
    for table in decoder.tables():
      values['table_name'] = table.name
      out.write(DECODER_DECLARE_METHOD % values)
    out.write(DECODER_DECLARE_FIELD_COMMENTS)
    for action in decoder.action_filter(['actual']).decoders():
      values['decoder'] = action.actual()
      out.write(DECODER_DECLARE_FIELD % values)
    out.write(DECODER_DECLARE_FOOTER % values)
    out.write(H_FOOTER % values)
Esempio n. 14
0
def generate_h(decoder, decoder_name, filename, out, cl_args):
    """Entry point to the decoder for .h file.

    Args:
        decoder: The decoder defined by the list of Table objects to
                 process.
        decoder_name: The name of the decoder state to build.
        filename: The (localized) name for the .h file.
        named_decoders: If true, generate a decoder state with named
                 instances.
        out: a COutput object to write to.
        cl_args: A dictionary of additional command line arguments.
    """
    global _cl_args
    assert filename.endswith('.h')
    _cl_args = cl_args

    # Before starting, remove all testing information from the parsed tables.
    decoder = decoder.action_filter(['actual'])

    values = {
        'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
        'IFDEF_NAME': dgen_output.ifdef_name(filename),
        'FILENAME_BASE': filename[:-len('.h')],
        'decoder_name': decoder_name,
    }
    out.write(H_HEADER % values)
    values['fictitious_decoder'] = (
        decoder.get_value('FictitiousFirst').actual())
    out.write(DECODER_DECLARE_HEADER % values)
    out.write(DECODER_DECLARE_METHOD_COMMENTS)
    for table in decoder.tables():
        values['table_name'] = table.name
        out.write(DECODER_DECLARE_METHOD % values)
    out.write(DECODER_DECLARE_FIELD_COMMENTS)
    for action in decoder.action_filter(['actual']).decoders():
        values['decoder'] = action.actual()
        out.write(DECODER_DECLARE_FIELD % values)
    out.write(DECODER_DECLARE_FOOTER % values)
    out.write(H_FOOTER % values)
def generate_named_classes_h(decoder, decoder_name, filename, out, cl_args):
  """Defines named classes needed for decoder testing.

  Args:
    tables: list of Table objects to process.
    decoder_name: The name of the decoder state to build.
    filename: The (localized) name for the .h file.
    out: a COutput object to write to.
    cl_args: A dictionary of additional command line arguments.
  """
  global _cl_args
  if not decoder.primary: raise Exception('No tables provided.')
  assert filename.endswith('_named_classes.h')
  _cl_args = cl_args

  # Generate actuals from descriptions in tables, for each of the
  # tables that should automatically generate the corresponding
  # needed actual class decoders.
  actuals = cl_args.get('auto-actual')
  if actuals:
    decoder = dgen_actuals.AddAutoActualsToDecoder(decoder, actuals)

  values = {
      'FILE_HEADER': dgen_output.HEADER_BOILERPLATE,
      'NOT_TCB_MESSAGE' : dgen_output.NOT_TCB_BOILERPLATE,
      'IFDEF_NAME' : dgen_output.ifdef_name(filename),
      'FILENAME_BASE': filename[:-len('_named_classes.h')],
      'decoder_name': decoder_name,
      }
  out.write(NAMED_CLASSES_H_HEADER % values)
  out.write(RULE_CLASSES_HEADER)
  _generate_baseline_and_actual(RULE_CLASS, RULE_CLASS_SYM,
                                decoder, values, out)
  out.write(NAMED_DECODERS_HEADER)
  _generate_baseline_and_actual(NAMED_CLASS_DECLARE, NAMED_CLASS_DECLARE_SYM,
                                decoder, values, out)
  out.write(NAMED_CLASSES_H_FOOTER % values)