aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/src/chlists.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-02-21 17:53:04 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-02-21 17:53:04 +0000
commit108f7c4e1a50669853deb4429bb61f60604e156d (patch)
treebc9aa290f85e9ea6833cfdc25ff63cf8c73a78a4 /os/kernel/src/chlists.c
parentdb7b60f402fda8ffb708e73feea7ed566eea0386 (diff)
downloadChibiOS-108f7c4e1a50669853deb4429bb61f60604e156d.tar.gz
ChibiOS-108f7c4e1a50669853deb4429bb61f60604e156d.tar.bz2
ChibiOS-108f7c4e1a50669853deb4429bb61f60604e156d.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2754 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel/src/chlists.c')
0 files changed, 0 insertions, 0 deletions
>126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
/*
 *  nextpnr -- Next Generation Place and Route
 *
 *  Copyright (C) 2021  Symbiflow Authors
 *
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "design_utils.h"
#include "log.h"
#include "nextpnr.h"
#include "util.h"

NEXTPNR_NAMESPACE_BEGIN

static const MacroPOD *lookup_macro(const ChipInfoPOD *chip, IdString cell_type)
{
    for (const auto &macro : chip->macros) {
        if (IdString(macro.name) == cell_type)
            return &macro;
    }
    return nullptr;
}

static const MacroExpansionPOD *lookup_macro_rules(const ChipInfoPOD *chip, IdString cell_type)
{
    for (const auto &rule : chip->macro_rules) {
        if (IdString(rule.prim_name) == cell_type)
            return &rule;
    }
    return nullptr;
}

static IdString derived_name(Context *ctx, IdString base_name, IdString suffix)
{
    return ctx->id(stringf("%s/%s", base_name.c_str(ctx), suffix.c_str(ctx)));
}

void Arch::expand_macros()
{
    // Make up a list of cells, so we don't have modify-while-iterating issues
    Context *ctx = getCtx();
    std::vector<CellInfo *> cells;
    for (auto &cell : ctx->cells)
        cells.push_back(cell.second.get());

    std::vector<CellInfo *> next_cells;

    bool first_iter = false;
    do {
        // Expand cells
        for (auto cell : cells) {
            // TODO: consult exception map
            const MacroExpansionPOD *exp = lookup_macro_rules(chip_info, cell->type);

            // Block infinite expansion loop due to a macro being expanded in the same primitive.
            // E.g.: OBUFTDS expands into the following cells, with an infinite loop being generated:
            //          - 2 OBUFTDS
            //          - 1 INV
            if (exp && first_iter)
                continue;

            const MacroPOD *macro = lookup_macro(chip_info, exp ? IdString(exp->macro_name) : cell->type);
            if (macro == nullptr)
                continue;

            // Get the ultimate root of this macro expansion
            IdString parent = (cell->macro_parent == IdString()) ? cell->name : cell->macro_parent;
            // Create child instances
            for (const auto &inst : macro->cell_insts) {
                CellInfo *inst_cell =
                        ctx->createCell(derived_name(ctx, cell->name, IdString(inst.name)), IdString(inst.type));