Ejemplo n.º 1
0
 /**
  * Assembles the source code.
  *
  * @param var the variable to assign the value to
  */
 @Override
 public void assemble(Register var) throws IOException {
   Expression varOrString = AssembleExpression.getRegisterOrExpression(this.string);
   if (this.maxLen != null) {
     Expression varOrMaxLen = AssembleExpression.getRegisterOrExpression(this.maxLen);
     if (this.startOffset != null) {
       Expression varOrStartOffset = AssembleExpression.getRegisterOrExpression(this.startOffset);
       ScriptParser.writeLine(
           name + " " + var + " " + varOrString + " " + varOrMaxLen + " " + varOrStartOffset);
       varOrStartOffset.setInUse(false);
     } else {
       ScriptParser.writeLine(name + " " + var + " " + varOrString + " " + varOrMaxLen);
     }
     varOrMaxLen.setInUse(false);
   } else {
     ScriptParser.writeLine(name + " " + var + " " + varOrString);
   }
   varOrString.setInUse(false);
 }
 /** Assembles the source code. */
 @Override
 public void assemble() throws IOException {
   Expression varOrIniFile = AssembleExpression.getRegisterOrExpression(this.iniFile);
   ScriptParser.writeLine(name + " " + varOrIniFile);
   varOrIniFile.setInUse(false);
 }
Ejemplo n.º 3
0
  /**
   * Assembles the source code.
   *
   * @throws IOException
   */
  @Override
  public void assemble() throws IOException {
    // Do not assemble anything if there are no cases!
    if (this.casesList.isEmpty()) return;

    // Give each case a label.
    for (SwitchCaseStatement statement : this.casesList)
      statement.setLabel(LabelList.getCurrent().getNext());
    if (this.defaultCase != null) this.defaultCase.setLabel(LabelList.getCurrent().getNext());

    Label gotoEnd = LabelList.getCurrent().getNext();
    Label gotoStart = LabelList.getCurrent().getNext();

    // Go to the jump table which is assembled after the switch case labels and
    // statements.
    ScriptParser.writeLine("Goto " + gotoStart);

    // Using "break;" inside a switch jumps to the end.
    Label parentBreak = CodeInfo.getCurrent().setBreakLabel(gotoEnd);

    // Assemble all the statements inside the switch { }. This includes the
    // case labels.
    for (Statement statement : this.statementList) statement.assemble();

    // Restore the parent break label.
    CodeInfo.getCurrent().setBreakLabel(parentBreak);

    // Label at the top of the jump table.
    gotoStart.write();

    // Jump instructions can jump directly to the case labels.
    if (this.switchExpression instanceof JumpExpression) {
      ((JumpExpression) this.switchExpression).assemble(this.casesList);
    }
    // Other expressions we just assemble them if required and compare their
    // result.
    else {
      Expression varOrSwitchExpression =
          AssembleExpression.getRegisterOrExpression(this.switchExpression);
      for (SwitchCaseStatement caseStatement : this.casesList) {
        // Type is an integer; use IntCmp.
        if (caseStatement.getMatch().getType().equals(ExpressionType.Integer)) {
          ScriptParser.writeLine(
              String.format(
                  "IntCmp %s %s %s",
                  varOrSwitchExpression, caseStatement.getMatch(), caseStatement.getLabel()));
        }
        // Type is a string; use StrCmp or StrCmpS (if special `` quotes were
        // used).
        else {
          ScriptParser.writeLine(
              String.format(
                  "StrCmp%s %s %s %s",
                  caseStatement.getMatch().getType().equals(ExpressionType.StringSpecial)
                      ? "S"
                      : "",
                  varOrSwitchExpression,
                  caseStatement.getMatch(),
                  caseStatement.getLabel()));
        }
      }
      varOrSwitchExpression.setInUse(false);
    }

    // Default case jump.
    if (this.defaultCase != null) ScriptParser.writeLine("Goto " + this.defaultCase.getLabel());

    gotoEnd.write();
  }