Exemplo n.º 1
0
void CmdPin::printConfig(Gpio *gpio, unsigned int pin)
{
    Gpio::Index i = static_cast<Gpio::Index>(pin);
    Gpio::Mode m = gpio->mode(i);
    printf("%s", mode(m));
    if (m == Gpio::Mode::Output)
    {
        printf(": Type = %s, Speed = %s, Pull = %s", outputType(gpio->outputType(i)), speed(gpio->speed(i)), pull(gpio->pull(i)));
    }
    else if (m == Gpio::Mode::Input)
    {
        printf(": Pull = %s", pull(gpio->pull(i)));
    }
    else if (m == Gpio::Mode::Alternate)
    {
        printf(": Function = %i, Type = %s, Speed = %s, Pull = %s", static_cast<int>(gpio->alternate(i)), outputType(gpio->outputType(i)), speed(gpio->speed(i)), pull(gpio->pull(i)));
    }
}
Exemplo n.º 2
0
void reflowTypes(Block* const changed, const BlockList& blocks) {
  assert(isRPOSorted(blocks));

  auto retypeDst = [&] (IRInstruction* inst, int num) {
    auto ssa = inst->dst(num);

    /*
     * The type of a tmp defined by DefLabel is the union of the
     * types of the tmps at each incoming Jmp.
     */
    if (inst->op() == DefLabel) {
      Type type = Type::Bottom;
      inst->block()->forEachSrc(num, [&](IRInstruction*, SSATmp* tmp) {
        type = Type::unionOf(type, tmp->type());
      });
      ssa->setType(type);
      return;
    }

    ssa->setType(outputType(inst, num));
  };

  auto visit = [&] (IRInstruction* inst) {
    for (int i = 0; i < inst->numDsts(); ++i) {
      auto const ssa = inst->dst(i);
      auto const oldType = ssa->type();
      retypeDst(inst, i);
      if (!ssa->type().equals(oldType)) {
        FTRACE(5, "reflowTypes: retyped {} in {}\n", oldType.toString(),
               inst->toString());
      }
    }
  };

  auto it = rpoIteratorTo(blocks, changed);
  assert(it != blocks.end());
  for (; it != blocks.end(); ++it) {
    FTRACE(5, "reflowTypes: visiting block {}\n", (*it)->id());
    for (auto& inst : **it) visit(&inst);
  }
}
Exemplo n.º 3
0
void Options::parseCommandLine()
{
    QCommandLineParser parser;
    parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addPositionalArgument("files", "Files to compile.", "[files...]");

    QCommandLineOption include(QStringList() << "i" << "include", "Include directories.", "include", "");
    parser.addOption(include);

    QCommandLineOption errorLimit("error-limit", "Stop after N errors. [Default: 20]", "N", "20");
    parser.addOption(errorLimit);

    QCommandLineOption outputFile(QStringList() << "o" << "out",
                                  "Output to file or stdout if empty.", "file", "");
    parser.addOption(outputFile);

    QCommandLineOption outputType(QStringList() << "e" << "emit",
                                  "Specify the type of output. [Default: obj]\n   type=obj|llvm|ast", "type", "obj");
    parser.addOption(outputType);

    QCommandLineOption readFromStdin("stdin", "Read from stdin.");
    parser.addOption(readFromStdin);

    parser.process(*QCoreApplication::instance());

    m_files = parser.positionalArguments();
    m_includeDirs = parser.values(include);
    m_errorLimit = parser.value(errorLimit).toInt();
    m_outputFile = parser.value(outputFile);
    m_outputType = parser.value(outputType);
    if (m_outputType != "obj" && m_outputType != "llvm" && m_outputType != "ast")
        m_outputType = "obj";
    m_readFromStdin = parser.isSet(readFromStdin);

    if (m_files.isEmpty() && !m_readFromStdin)
        parser.showHelp();
}
Exemplo n.º 4
0
void SSATmp::setInstruction(IRInstruction* inst, int dstId) {
  m_inst = inst;
  m_type = outputType(inst, dstId);
}
Exemplo n.º 5
0
void outputField ( FudgeField * field, unsigned int indent )
{
    /* Output the field's type, name (if present) and ordinal (if present) */
    outputIndent ( indent );
    outputType ( field->type );
    printf ( " " );
    if ( field->flags & FUDGE_FIELD_HAS_NAME )
    {   
        outputString ( field->name );

        if ( field->flags & FUDGE_FIELD_HAS_ORDINAL )
            printf ( "/" );
    }
    if ( field->flags & FUDGE_FIELD_HAS_ORDINAL )
        printf ( "ord(%d)", field->ordinal );
    printf ( ": " );

    /* Output the field contents */
    switch ( field->type )
    {
        case FUDGE_TYPE_INDICATOR:      break;
        case FUDGE_TYPE_BOOLEAN:        printf ( field->data.boolean ? "true" : "false" ); break;
        case FUDGE_TYPE_BYTE:           printf ( "%d", field->data.byte ); break;
        case FUDGE_TYPE_SHORT:          printf ( "%d", field->data.i16 ); break;
        case FUDGE_TYPE_INT:            printf ( "%d", field->data.i32 ); break;
        case FUDGE_TYPE_LONG:           printf ( "%ld", ( long int ) field->data.i64 ); break;
        case FUDGE_TYPE_FLOAT:          printf ( "%f", field->data.f32 ); break;
        case FUDGE_TYPE_DOUBLE:         printf ( "%f", field->data.f64 ); break;
        case FUDGE_TYPE_SHORT_ARRAY:    outputArray ( field->data.bytes, field->numbytes, "%d", 2, 8 ); break;
        case FUDGE_TYPE_INT_ARRAY:      outputArray ( field->data.bytes, field->numbytes, "%d", 4, 8 ); break;
        case FUDGE_TYPE_LONG_ARRAY:     outputArray ( field->data.bytes, field->numbytes, "%lu", 8, 4 ); break;
        case FUDGE_TYPE_FLOAT_ARRAY:    outputArray ( field->data.bytes, field->numbytes, "%f", 4, 4 ); break;
        case FUDGE_TYPE_DOUBLE_ARRAY:   outputArray ( field->data.bytes, field->numbytes, "%f", 8, 4 ); break;
        case FUDGE_TYPE_STRING:         outputString ( field->data.string ); break;
        case FUDGE_TYPE_BYTE_ARRAY: 
        case FUDGE_TYPE_BYTE_ARRAY_4:
        case FUDGE_TYPE_BYTE_ARRAY_8:
        case FUDGE_TYPE_BYTE_ARRAY_16:
        case FUDGE_TYPE_BYTE_ARRAY_20:
        case FUDGE_TYPE_BYTE_ARRAY_32:
        case FUDGE_TYPE_BYTE_ARRAY_64:
        case FUDGE_TYPE_BYTE_ARRAY_128:
        case FUDGE_TYPE_BYTE_ARRAY_256:
        case FUDGE_TYPE_BYTE_ARRAY_512:
            outputArray ( field->data.bytes, field->numbytes, "%d", 1, 10 ); 
            break;
        case FUDGE_TYPE_FUDGE_MSG:
            printf ( "\n" );
            outputIndent ( indent );
            printf ( "{\n" );
            outputMessage ( field->data.message, indent + 1 );
            outputIndent ( indent );
            printf ( "}" );
            break;
        default:
            printf ( "%d bytes ", field->numbytes );
            outputArray ( field->data.bytes, field->numbytes, "%d", 1, 8 ); 
            break;
    }

    printf ( "\n" );
}
Exemplo n.º 6
0
SSATmp::SSATmp(uint32_t opndId, IRInstruction* i, int dstId /* = 0 */)
  : m_inst(i)
  , m_type(outputType(i, dstId))
  , m_id(opndId)
{
}
Exemplo n.º 7
0
int JSampleObj::inputType(int n) {
  if ((n-=IN_LAST) < 0) return JIntegerData::id;
  return outputType(n);
}
Exemplo n.º 8
0
void LinearScan::rematerializeAux(Trace* trace,
                                  SSATmp* curSp,
                                  SSATmp* curFp,
                                  std::vector<SSATmp*> localValues) {
  IRInstruction::List& instList = trace->getInstructionList();
  for (IRInstruction::Iterator it = instList.begin();
       it != instList.end();
       ++it) {
    IRInstruction* inst = *it;
    Opcode opc = inst->getOpcode();
    SSATmp* dst = inst->getDst();
    if (opc == DefFP || opc == FreeActRec) {
      curFp = dst;
      assert(dst && dst->getReg() == rVmFp);
    }
    if (opc == Reload) {
      // s = Spill t0
      // t = Reload s
      SSATmp* spilledTmp = getSpilledTmp(dst);
      IRInstruction* spilledInst = spilledTmp->getInstruction();
      IRInstruction* newInst = NULL;
      if (spilledInst->isRematerializable() ||
          (spilledInst->getOpcode() == LdStack &&
           spilledInst->getSrc(0) == curSp)) {
        // XXX: could change <newInst> to the non-check version.
        // Rematerialize those rematerializable instructions (i.e.,
        // isRematerializable returns true) and LdStack.
        newInst = spilledInst->clone(m_irFactory);
        // The new instruction needn't have an exit label, because it is always
        // dominated by the original instruction.
        newInst->setLabel(NULL);
      } else {
        // Rematerialize LdLoc.
        std::vector<SSATmp*>::iterator pos =
          std::find(localValues.begin(),
                    localValues.end(),
                    canonicalize(spilledTmp));
        // Search for a local that stores the value of <spilledTmp>.
        if (pos != localValues.end()) {
          size_t locId = pos - localValues.begin();
          assert(curFp != NULL);
          ConstInstruction constInst(curFp, Local(locId));
          IRInstruction* ldHomeInst =
            m_irFactory->cloneInstruction(&constInst);
          newInst = m_irFactory->gen(LdLoc,
                                     dst->getType(),
                                     m_irFactory->getSSATmp(ldHomeInst));
        }
      }
      if (newInst) {
        UNUSED Type::Tag oldType = dst->getType();
        newInst->setDst(dst);
        dst->setInstruction(newInst);
        assert(outputType(newInst) == oldType);
        *it = newInst;
        newInst->setParent(trace);
      }
    }

    // Updating <curSp> and <localValues>.
    if (dst && dst->getReg() == rVmSp) {
      // <inst> modifies the stack pointer.
      curSp = dst;
    }
    if (opc == LdLoc || opc == StLoc || opc == StLocNT) {
      // dst = LdLoc home
      // StLoc/StLocNT home, src
      int locId = getLocalIdFromHomeOpnd(inst->getSrc(0));
      // Note that when we implement inlining, we will need to deal
      // with the new local id space of the inlined function.
      SSATmp* localValue = (opc == LdLoc ? dst : inst->getSrc(1));
      if (int(localValues.size()) < locId + 1) {
        localValues.resize(locId + 1);
      }
      localValues[locId] = canonicalize(localValue);
    }
    // Other instructions that may have side effects on locals must
    // kill the local variable values.
    else if (opc == IterInit) {
      int valLocId = inst->getSrc(3)->getConstValAsInt();
      localValues[valLocId] = NULL;
      if (inst->getNumSrcs() == 5) {
        int keyLocId = inst->getSrc(4)->getConstValAsInt();
        localValues[keyLocId] = NULL;
      }
    } else if (opc == IterNext) {
      int valLocId = inst->getSrc(2)->getConstValAsInt();
      localValues[valLocId] = NULL;
      if (inst->getNumSrcs() == 4) {
        int keyLocId = inst->getSrc(3)->getConstValAsInt();
        localValues[keyLocId] = NULL;
      }
    }

    if (inst->isControlFlowInstruction()) {
      LabelInstruction* label = inst->getLabel();
      if (label != NULL && label->getId() == inst->getId() + 1) {
        rematerializeAux(label->getParent(), curSp, curFp, localValues);
      }
    }
  }
}