Exemplo n.º 1
0
void Assembler::assemblyFunction(Core::FunType::PtrType fun,
    Core::Environment* env) {
  if (fun->body == NULL) return;

  std::ostringstream ss;

  Core::AbstractScope::PtrType global_scope(new Core::GlobalScope(env));

  Core::BlockScope::PtrType function_scope(new Core::BlockScope(global_scope));
  for (int i = 0; i < fun->args.size(); i++) {
    function_scope->define(fun->idents[i], fun->args[i]->toLValue());
  }

  Core::BlockScope::PtrType body_scope(new Core::BlockScope(function_scope));



  std::cout << "; " << fun->name << std::endl;
  std::cout << ".method public static " << functionSignature(fun) << std::endl;

  StmtAssembler ass(body_scope, env, ss);
  fun->body->sblock_->accept(&ass);

  std::cout << ".limit stack " << ass.stackLimit << std::endl;
  std::cout << ".limit locals " << global_scope->maxIx() << std::endl;
  std::cout << ss.str();

  if (fun->ret_type->getType() == Core::VOID)
    std::cout << "  return" << std::endl;

  std::cout << ".end method" << std::endl << std::endl;
};
Exemplo n.º 2
0
static void my_make_nmb_name( struct nmb_name *n, const char *name, int type)
{
	fstring unix_name;
	memset( (char *)n, '\0', sizeof(struct nmb_name) );
	fstrcpy(unix_name, name);
	strupper_m(unix_name);
	push_ascii(n->name, unix_name, sizeof(n->name), STR_TERMINATE);
	n->name_type = (unsigned int)type & 0xFF;
	push_ascii(n->scope,  global_scope(), 64, STR_TERMINATE);
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
    stekin::initEnv(argc, argv);
    yyparse();
    if (error::hasError()) {
        return 1;
    }
    semantic::Block global_flow(grammar::builder.buildAndClear());
    if (error::hasError()) {
        return 1;
    }
    util::sptr<output::Statement const> global_scope(global_flow.compile(globalSpace()));
    if (error::hasError()) {
        return 1;
    }
    std::stringstream os;
    output::wrapGlobal(os, *global_scope);
    if (error::hasError()) {
        return 1;
    }
    std::cout << os.str();
    return 0;
}