Skip to content

Commit d919e29

Browse files
author
Philip Herron
committed
This will now compile a void function declaration to gimple
-fdump-tree-gimple should provide output of the skeleton function Addresses #19
1 parent 5311533 commit d919e29

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

gcc/rust/backend/rust-compile.cc

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,11 @@ Compilation::visit (AST::Function &function)
341341
scope.Push ();
342342
printf ("INSIDE FUNCTION: %s\n", function.function_name.c_str ());
343343

344-
if (!function.has_function_return_type ())
345-
{
346-
// TODO
347-
// auto fntype = backend->function_type ();
344+
Backend::Btyped_identifier receiver;
345+
std::vector<Backend::Btyped_identifier> parameters;
346+
std::vector<Backend::Btyped_identifier> results;
348347

349-
auto mangled_asm_name = ""; // TODO
350-
currentFndecl
351-
= backend->function (backend->void_type (), function.function_name,
352-
mangled_asm_name, 0, function.locus);
353-
}
354-
else
348+
if (function.has_function_return_type ())
355349
{
356350
translatedType = NULL;
357351
function.return_type->accept_vis (*this);
@@ -360,40 +354,42 @@ Compilation::visit (AST::Function &function)
360354
rust_error_at (function.locus, "Unable to compile type");
361355
return;
362356
}
363-
364-
auto mangled_asm_name = ""; // TODO
365-
currentFndecl = backend->function (translatedType, function.function_name,
366-
mangled_asm_name, 0, function.locus);
367357
}
368358

369-
std::vector< ::Bvariable *> params;
370359
for (auto &param : function.function_params)
371360
{
372361
printf ("FUNC PARAM: %s\n", param.as_string ().c_str ());
373362
// TODO
374363
}
375364

376-
if (params.size () == 0 && function.function_params.size () > 0)
365+
if (parameters.size () != function.function_params.size ())
377366
{
378-
rust_error_at (function.locus, "Unable to compile parameters");
367+
rust_error_at (function.locus,
368+
"Unable to compile all function parameters");
379369
return;
380370
}
381-
else if (params.size () > 0)
371+
372+
auto fntype = backend->function_type (receiver, parameters, results, NULL,
373+
function.locus);
374+
375+
auto mangled_asm_name = ""; // TODO
376+
auto fndecl = backend->function (fntype, function.function_name,
377+
mangled_asm_name, 0, function.locus);
378+
379+
// walk the expression body
380+
std::vector<Bvariable *> vars;
381+
auto code_block
382+
= backend->block (fndecl, NULL, vars, function.locus, Location ());
383+
for (auto &stmt : function.function_body->statements)
382384
{
383-
backend->function_set_parameters (currentFndecl, params);
385+
stmt->accept_vis (*this);
384386
}
385387

386-
/*
387-
// walk the expression body
388-
Bstatement *body;
389-
for (auto &stmt : function.function_body->statements)
390-
{
391-
stmt->accept_vis (*this);
392-
}
393-
394-
backend->function_set_body (fndecl, body);*/
388+
auto body = backend->block_statement (code_block);
389+
if (!backend->function_set_body (fndecl, body))
390+
rust_error_at (function.locus, "failed to set body to function");
395391

396-
func_decls.push_back (currentFndecl);
392+
func_decls.push_back (fndecl);
397393
currentFndecl = NULL;
398394

399395
scope.Pop ();

0 commit comments

Comments
 (0)