Esempio n. 1
0
def _generate_prim_subtype_col(prim_type, prim_name):
  ''' Returns code for the given primitive's array subtype column. '''
  subtype_column_label = CodeGenManager.get_label(
      'array_subtype_column_{0}'.format(prim_name))
  CodeGenManager.add_global_label('__primitives', subtype_column_label)
  subtype_column = CodeGenManager.prim_array_subtype_cols[prim_type]
  subtype_column_asm = ast_class.ASTClass.c_gen_code_subtype_column_helper(
      subtype_column_label, subtype_column)

  return (subtype_column_label, subtype_column_asm)
Esempio n. 2
0
def _generate_prim_array_create(prim_name, array_cit_label):
  create_fn_label = CodeGenManager.get_label(
      'create_array_{0}'.format(prim_name))
  CodeGenManager.add_global_label('__primitives', create_fn_label)
  CodeGenManager.primitive_array_create_labels[prim_name] = create_fn_label
  create_fn_asm = [
    'global {0}'.format(create_fn_label),
    '{0}:'.format(create_fn_label),
    array.create_array(True, array_cit_label)
  ]
  return (create_fn_label, create_fn_asm)
Esempio n. 3
0
def _generate_prim_cit(prim_type, prim_name, subtype_label):
  ''' Returns code for the given primitive's CIT '''
  sit_col_label = 'sit_column_{0}'.format(
      CodeGenManager.java_lang_object_defn.canonical_name)
  sit_col_label = CodeGenManager.memoize_label(
      CodeGenManager.java_lang_object_defn, sit_col_label)
  CodeGenManager.add_global_label(
    CodeGenManager.java_lang_object_defn.canonical_name, sit_col_label)

  array_cit_label = CodeGenManager.get_label('array_cit_{0}'.format(prim_name))
  CodeGenManager.add_global_label('__primitives', array_cit_label)
  array_cit_asm = cit.generate_array_cit(prim_name, array_cit_label,
    sit_col_label, subtype_label)

  return (array_cit_label, array_cit_asm)
Esempio n. 4
0
def set_global_labels(asts):
  '''Sets all the global labels an ASTRoot defines'''
  for ast in asts:
    if ast.class_or_interface:
      t = ast.class_or_interface

      canonical_name = t.canonical_name

      # Add the array related labels to the externs list.
      CodeGenManager.add_global_label(
          canonical_name, t.c_array_cit_label)

      # Add the array creation label.
      CodeGenManager.add_global_label(
          canonical_name, t.c_create_array_function_label)

      # Add all the methods defined in this class to the CodeGenManager
      for m in t.methods:
        CodeGenManager.add_global_label(canonical_name, m.c_defn_label)

      if isinstance(t, ast_interface.ASTInterface):
        # Interfaces don't define any method bodies.
        continue

      # Add static field labels to the CodeGenManager.
      for f in t.fields:
        if f.is_static:
          CodeGenManager.add_global_label(canonical_name, f.c_defn_label)

      # Add the CIT label to the list to be externed.
      CodeGenManager.add_global_label(
          canonical_name, t.c_cit_label)

      # Add the SIT column label to the list to be externed.
      CodeGenManager.add_global_label(canonical_name, t.c_sit_column_label)

      # Add the code instance creation label to the externs list.
      CodeGenManager.add_global_label(
          canonical_name, t.c_create_object_function_label)