/**
 * (c) 2014-2016 Alexandro Sanchez Bach. All rights reserved.
 * Released under GPL v2 license. Read LICENSE for more details.
 */

#pragma once

#include "nucleus/common.h"
#include "nucleus/graphics/hir/hir.h"

#include <memory>
#include <string>
#include <vector>

namespace gfx {
namespace hir {

// Forward declarations
class Block;
class Instruction;
class Module;

class Function {
    Module& parent;

public:
    Instruction* function;
    std::vector<Instruction*> parameters;
    std::vector<Block*> blocks;

    // Constructor
    Function(Module& parent, Literal type);
    Function(Module& parent, Literal type, Literal id);
    ~Function();

    /**
     * Get the ID of this function generated by the starting Function instruction
     * @return  Function ID
     */
    Literal getId() const;

    /**
     * Get the parent module of this function
     * @return  Parent module
     */
    Module& getParent() const;

    /**
     * Add a local variable to the scope of this function
     * @param[in]  instr  Pointer to the Instruction defining the variable
     */
    void addLocalVariable(Instruction* instr);

    /**
     * Save a human-readable version of this HIR function
     * @return  String containing the readable version of this HIR function
     */
    std::string dump();
};

}  // namespace hir
}  // namespace gfx
