lp-type-lookup.c 992 Bytes
Newer Older
1
/*
Philip Carns's avatar
Philip Carns committed
2
 * Copyright (C) 2013 University of Chicago.
3
 * See COPYRIGHT notice in top-level directory.
Philip Carns's avatar
Philip Carns committed
4
 *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 */

#include <string.h>
#include <assert.h>

#include "ross.h"
#include "codes/lp-type-lookup.h"

#define MAX_LP_TYPES 64

struct lp_name_mapping
{
    const char* name;
    const tw_lptype* type;
};

static struct lp_name_mapping map_array[MAX_LP_TYPES];
static int map_array_size = 0;

void lp_type_register(const char* name, const tw_lptype* type)
{
    map_array[map_array_size].name = strdup(name);
    assert(map_array[map_array_size].name);
    map_array[map_array_size].type = type;
    map_array_size++;

    return;
}

const tw_lptype* lp_type_lookup(const char* name)
{
    int i;

    for(i=0; i<map_array_size; i++)
    {
        if(strcmp(name, map_array[i].name) == 0)
        {
            return(map_array[i].type);
        }
    }

    return(NULL);
}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */