Пример #1
0
  public FunctionContext(
      TranslationContext translationContext,
      GimpleFunction gimpleFunction,
      JimpleMethodBuilder builder) {
    this.gimpleFunction = gimpleFunction;
    this.translationContext = translationContext;
    this.builder = builder;

    VarUsageInspector varUsage = new VarUsageInspector(gimpleFunction);

    for (GimpleVarDecl decl : gimpleFunction.getVariableDeclarations()) {
      Variable localVariable =
          translationContext
              .resolveType(decl.getType())
              .createLocalVariable(this, decl.getName(), varUsage.getUsage(decl.getId()));

      symbolTable.put(decl.getId(), localVariable);
    }

    for (GimpleParameter param : gimpleFunction.getParameters()) {
      ImType type = translationContext.resolveType(param.getType());
      builder.addParameter(type.paramType(), "p_" + param.getName());
      ImExpr paramExpr =
          JvmExprs.toExpr(this, new JimpleExpr("p_" + param.getName()), type.paramType(), true);

      Variable variable =
          type.createLocalVariable(this, param.getName(), varUsage.getUsage(param.getId()));
      variable.writeAssignment(this, paramExpr);

      symbolTable.put(param.getId(), variable);
    }
  }
  @Override
  public RecordValue variable(GimpleVarDecl decl, VarAllocator allocator) {

    JLValue instance =
        allocator.reserve(decl.getName(), layout.getType(), new RecordConstructor(this));

    if (isUnitPointer()) {
      // If we are using the RecordUnitPtr strategy, then the record value is also it's address
      return new RecordValue(instance, new RecordUnitPtr(instance));

    } else if (decl.isAddressable()) {
      JLValue unitArray =
          allocator.reserveUnitArray(
              decl.getName(), layout.getType(), Optional.of((JExpr) instance));
      FatPtrPair address = new FatPtrPair(new RecordClassValueFunction(this), unitArray);
      JExpr value = Expressions.elementAt(address.getArray(), 0);
      return new RecordValue(value, address);

    } else {

      return new RecordValue(instance);
    }
  }