コード例 #1
0
ファイル: ucode.c プロジェクト: wan2land/mini-c
void processFunction(SymbolTable *table, Node *ptr)
{
    int stIndex, i;
    char *functionName;
    Node *p;
    int width = 0;

    functionName = ptr->son->son->next->token.tokenValue;
    flag_returned = 0;

    stIndex = lookup(table, functionName);

    SymbolTable *nextTable = table->rows[stIndex].table;

    // parameters
    if (ptr->son->son->next->next->son) {
        for (p = ptr->son->son->next->next->son; p; p = p->next) {
            if (p->token.tokenNumber == PARAM_DCL) {
                processDeclaration(nextTable, p->son); // todo
            } else {
                icg_error(9);
            }
        }
    }
    for (p = ptr->son->next->son->son; p; p = p->next) {
        if (p->token.tokenNumber == DCL) {
            processDeclaration(nextTable, p->son); // todo
        } else {
            icg_error(3);
        }
    }

    emitProc(functionName, nextTable->offset - 1, nextTable->base, 2);

    // 지역변수
    for (i = 0; i < nextTable->count; i++) {
        emitSym("sym", nextTable->base, nextTable->rows[i].offset, nextTable->rows[i].width);
    }

    // Run Statement
    for (p = ptr->son; p; p = p->next) {
        if (p->token.tokenNumber == COMPOUND_ST) {
            processStatement(nextTable, p);
        }
    }

    if (!flag_returned) {
        emit0("ret");
    }
    emit0("end");
}
コード例 #2
0
void UnprocessedStatement::process(Ruleset &r) {
  Extension extension;
  Mixin mixin;
  Declaration* declaration;

#ifdef WITH_LIBGLOG
  VLOG(2) << "Statement: " << getTokens()->toString();
#endif
  
  // process extends statement
  if (getExtension(extension.getTarget())) {
    extension.setExtension(r.getSelector());
    getLessRuleset()->getContext()->addExtension(extension);
    return;
  }
  
  mixin.setStylesheet(getLessRuleset()->getLessStylesheet());
  
  // process mixin
  if (mixin.parse(*getTokens()) &&
      mixin.insert(*r.getStylesheet(), *getLessRuleset()->getContext(),
                   &r, getLessRuleset())) {

  } else {
    declaration = r.createDeclaration();
    
    if (processDeclaration(declaration)) {
    
#ifdef WITH_LIBGLOG
      VLOG(2) << "Declaration: " <<
        declaration->getProperty() << ": " << declaration->getValue().toString();
#endif
    
      getLessRuleset()->getContext()->processValue(declaration->getValue());

#ifdef WITH_LIBGLOG
      VLOG(2) << "Processed declaration: " <<
        declaration->getProperty() << ": " << declaration->getValue().toString();
#endif
    
    } else {
      r.deleteDeclaration(*declaration);
      throw new ParseException(getTokens()->toString(),
                               "variable, mixin or declaration.",
                               getTokens()->front().line,
                               getTokens()->front().column,
                               getTokens()->front().source);
    }
  }

#ifdef WITH_LIBGLOG
  VLOG(3) << "Statement done";
#endif
}
コード例 #3
0
ファイル: ucode.c プロジェクト: wan2land/mini-c
void codeGen(Node *root, FILE *ucoFile)
{
    Node *p;            // pointer for Node
    int globalSize;        // the size of global variables

    file = ucoFile; //

    rootTable = initSymbolTable();

    // step 1: process the declaration part
    for (p = root->son; p; p = p->next) {
        if (p->token.tokenNumber == DCL) {
            processDeclaration(rootTable, p->son);
        } else if (p->token.tokenNumber == FUNC_DEF) {
            processFuncHeader(rootTable, p->son);
        } else {
            icg_error(3);
        }
    }

    globalSize = rootTable->offset - 1;

    // step 2: process the function part
    for (p = root->son; p; p = p->next) {
        if (p->token.tokenNumber == FUNC_DEF) {
            processFunction(rootTable, p);
        }
    }

    display(rootTable, 0);

    // step 3: generate codes for starting routine
    //                bgn        globalSize
    //                ldp
    //                call    main
    //                end
    emit1("bgn", globalSize);
    emit0("ldp");
    emitJump("call", "main");
    emit0("end");
}