/*
 *  ======== package/cfg/static_p674.cfg ========
 *  This generated configuration script runs the user's configuration script
 *  the context of a specific target and platform in order to generate
 *  all the files necessary to create an executable; e.g., linker command
 *  files, static C/C++ data structures, etc.
 */

/*
 *  ======== _runescape ========
 *  Recursive unescape to decode serialized strings
 */
function _runescape(obj) {
    for (var i in obj) {
	if (obj[i] != null) {
	    if (typeof obj[i] == 'string') {
		obj[i] = unescape(obj[i]);
	    }
	    else if (typeof obj[i] == 'object') {
		_runescape(obj[i]);
	    }
	}
    }
}

/*
 *  ======== _getPlatCfg ========
 */
function _getPlatCfg() {
    var tmp = {};
    _runescape(tmp);
    return (tmp);
}
/*
 *  ======== _cfginit ========
 */
function _cfginit() {
    xdc.loadPackage('xdc.services.intern.cmd');
    var prog = xdc.om['xdc.cfg.Program'];

    /* initialize prog attrs from build model */
    var build = {
        releases: {
            0: {
                name: "configPkg",
                attrs: {
                    prefix: "",
                    label: "default"
                },
                otherFiles: {},
                excludeDirs: {}
            }
        },
        target: {
            $name:"ti.targets.C674",
            name: "C674",
            suffix: "674",
            compatibleSuffixes: {
                $name:"ti.targets.C674/compatibleSuffixes",
                0: "64P",
                1: "64",
                2: "62"
            },
            isa: "674",
            model: {
                $name:"ti.targets.C674/model",
                endian: "little"
            },
            rts: "ti.targets.rts6000",
            base: {
                $name:"ti.targets.C62",
                name: "C62",
                suffix: "62",
                compatibleSuffixes: {
                    $name:"ti.targets.C62/compatibleSuffixes",
                },
                isa: "62",
                model: {
                    $name:"ti.targets.C62/model",
                    endian: "little"
                },
                rts: "ti.targets.rts6000",
                platform: "ti.platforms.sim6xxx%3ATMS320C6211",
                platforms: {
                    $name:"ti.targets.C62/platforms",
                },
                binaryParser: "ti.targets.omf.cof.Coff",
                debugGen: {
                    $name:"ti.targets.C62/debugGen",
                    execTemplate: "ti/targets/ccs_exec.xdt",
                    execPattern: "%24%28cfgDir%29%24%28cfgName%29.pjt",
                    packageTemplate: "ti/targets/ccs_package.xdt",
                    packagePattern: "package/%24%28pkgName%29.pjt"
                },
                extensions: {
                    $name:"ti.targets.C62/extensions",
                    ".s62": {
                        $name:"ti.targets.C62/extensions/'.s62'",
                        suf: ".s62",
                        typ: "asm"
                    },
                    ".asm": {
                        $name:"ti.targets.C62/extensions/'.asm'",
                        suf: ".asm",
                        typ: "asm"
                    },
                    ".c": {
                        $name:"ti.targets.C62/extensions/'.c'",
                        suf: ".c",
                        typ: "c"
                    },
                    ".cpp": {
                        $name:"ti.targets.C62/extensions/'.cpp'",
                        suf: ".cpp",
                        typ: "cpp"
                    },
                    ".cxx": {
                        $name:"ti.targets.C62/extensions/'.cxx'",
                        suf: ".cxx",
                        typ: "cpp"
                    },
                    ".C": {
                        $name:"ti.targets.C62/extensions/'.C'",
                        suf: ".C",
                        typ: "cpp"
                    },
                    ".cc": {
                        $name:"ti.targets.C62/extensions/'.cc'",
                        suf: ".cc",
                        typ: "cpp"
                    }
                },
                versionMap: {
                    $name:"ti.targets.C62/versionMap",
                    "TMS320C6x_4.32": "1%2C0%2C4.32%2C0",
                    "TMS320C55x_2.56": "1%2C0%2C2.56%2C0",
                    "TMS320C54x_3.83": "1%2C0%2C3.83%2C0",
                    "TMS320C2000_3.07": "1%2C0%2C3.07%2C0"
                },
                alignDirectiveSupported: true,
                profiles: {
                    $name:"ti.targets.C62/profiles",
                    debug: {
                        $name:"ti.targets.C62/profiles/'debug'",
                        compileOpts: {
                            $name:"ti.targets.C62/profiles/'debug'/compileOpts",
                            copts: "-g",
                            defs: "-D_DEBUG_%3D1"
                        },
                        filters: {
                            $name:"ti.targets.C62/profiles/'debug'/filters",
                        }
                    },
                    release: {
                        $name:"ti.targets.C62/profiles/'release'",
                        compileOpts: {
                            $name:"ti.targets.C62/profiles/'release'/compileOpts",
                            copts: "-O2"
                        },
                        filters: {
                            $name:"ti.targets.C62/profiles/'release'/filters",
                        }
                    },
                    profile: {
                        $name:"ti.targets.C62/profiles/'profile'",
                        compileOpts: {
                            $name:"ti.targets.C62/profiles/'profile'/compileOpts",
                            copts: "-gp"
                        },
                        filters: {
                            $name:"ti.targets.C62/profiles/'profile'/filters",
                        }
                    },
                    coverage: {
                        $name:"ti.targets.C62/profiles/'coverage'",
                        compileOpts: {
                            $name:"ti.targets.C62/profiles/'coverage'/compileOpts",
                            copts: "-gp"
                        },
                        filters: {
                            $name:"ti.targets.C62/profiles/'coverage'/filters",
                        }
                    },
                    whole_program: {
                        $name:"ti.targets.C62/profiles/'whole_program'",
                        compileOpts: {
                            $name:"ti.targets.C62/profiles/'whole_program'/compileOpts",
                            copts: "-oe%20-O2%20-mo"
                        },
                        filters: {
                            $name:"ti.targets.C62/profiles/'whole_program'/filters",
                        }
                    },
                    whole_program_debug: {
                        $name:"ti.targets.C62/profiles/'whole_program_debug'",
                        compileOpts: {
                            $name:"ti.targets.C62/profiles/'whole_program_debug'/compileOpts",
                            copts: "-oe%20--symdebug%3Adwarf%20-mo"
                        },
                        filters: {
                            $name:"ti.targets.C62/profiles/'whole_program_debug'/filters",
                        }
                    }
                },
                sectMap: {
                    $name:"ti.targets.C62/sectMap",
                    ".text": "code",
                    ".stack": "stack",
                    ".bss": "data",
                    ".cinit": "data",
                    ".pinit": "data",
                    ".const": "data",
                    ".data": "data",
                    ".switch": "data",
                    ".sysmem": "data",
                    ".far": "data",
                    ".args": "data",
                    ".cio": "data"
                },
                stdInclude: "ti/targets/std.h",
                stdTypes: {
                    $name:"ti.targets.C62/stdTypes",
                    t_IArg: {
                        $name:"ti.targets.C62/stdTypes/t_IArg",
                        size: 4,
                        align: 4
                    },
                    t_Char: {
                        $name:"ti.targets.C62/stdTypes/t_Char",
                        size: 1,
                        align: 1
                    },
                    t_Double: {
                        $name:"ti.targets.C62/stdTypes/t_Double",
                        size: 8,
                        align: 8
                    },
                    t_Float: {
                        $name:"ti.targets.C62/stdTypes/t_Float",
                        size: 4,
                        align: 4
                    },
                    t_Fxn: {
                        $name:"ti.targets.C62/stdTypes/t_Fxn",
                        size: 4,
                        align: 4
                    },
                    t_Int: {
                        $name:"ti.targets.C62/stdTypes/t_Int",
                        size: 4,
                        align: 4
                    },
                    t_Int8: {
                        $name:"ti.targets.C62/stdTypes/t_Int8",
                        size: 1,
                        align: 1
                    },
                    t_Int16: {
                        $name:"ti.targets.C62/stdTypes/t_Int16",
                        size: 2,
                        align: 2
                    },
                    t_Int32: {
                        $name:"ti.targets.C62/stdTypes/t_Int32",
                        size: 4,
                        align: 4
                    },
                    t_Int40: {
                        $name:"ti.targets.C62/stdTypes/t_Int40",
                        size: 8,
                        align: 8
                    },
                    t_Int64: {
                        $name:"ti.targets.C62/stdTypes/t_Int64",
                        size: 8,
                        align: 8
                    },
                    t_Long: {
                        $name:"ti.targets.C62/stdTypes/t_Long",
                        size: 8,
                        align: 8
                    },
                    t_LDouble: {
                        $name:"ti.targets.C62/stdTypes/t_LDouble",
                        size: 8,
                        align: 8
                    },
                    t_LLong: {
                        $name:"ti.targets.C62/stdTypes/t_LLong",
                        size: 8,
                        align: 8
                    },
                    t_Ptr: {
                        $name:"ti.targets.C62/stdTypes/t_Ptr",
                        size: 4,
                        align: 4
                    },
                    t_Short: {
                        $name:"ti.targets.C62/stdTypes/t_Short",
                        size: 2,
                        align: 2
                    },
                    t_Size: {
                        $name:"ti.targets.C62/stdTypes/t_Size",
                        size: 4,
                        align: 4
                    }
                },
                bitsPerChar: 8
            },
            platform: "ti.platforms.evmDA830",
            platforms: {
                $name:"ti.targets.C674/platforms",
                0: "ti.platforms.evmDA830"
            },
            binaryParser: "ti.targets.omf.cof.Coff",
            version: "ti.targets.C674%7B1%2C0%2C7.2%2C1",
            debugGen: {
                $name:"ti.targets.C674/debugGen",
                execTemplate: "ti/targets/ccs_exec.xdt",
                execPattern: "%24%28cfgDir%29%24%28cfgName%29.pjt",
                packageTemplate: "ti/targets/ccs_package.xdt",
                packagePattern: "package/%24%28pkgName%29.pjt"
            },
            extensions: {
                $name:"ti.targets.C674/extensions",
                ".s674": {
                    $name:"ti.targets.C674/extensions/'.s674'",
                    suf: ".s674",
                    typ: "asm"
                },
                ".s64P": {
                    $name:"ti.targets.C674/extensions/'.s64P'",
                    suf: ".s64P",
                    typ: "asm"
                },
                ".s64": {
                    $name:"ti.targets.C674/extensions/'.s64'",
                    suf: ".s64",
                    typ: "asm"
                },
                ".s62": {
                    $name:"ti.targets.C674/extensions/'.s62'",
                    suf: ".s62",
                    typ: "asm"
                },
                ".asm": {
                    $name:"ti.targets.C674/extensions/'.asm'",
                    suf: ".asm",
                    typ: "asm"
                },
                ".c": {
                    $name:"ti.targets.C674/extensions/'.c'",
                    suf: ".c",
                    typ: "c"
                },
                ".cpp": {
                    $name:"ti.targets.C674/extensions/'.cpp'",
                    suf: ".cpp",
                    typ: "cpp"
                },
                ".cxx": {
                    $name:"ti.targets.C674/extensions/'.cxx'",
                    suf: ".cxx",
                    typ: "cpp"
                },
                ".C": {
                    $name:"ti.targets.C674/extensions/'.C'",
                    suf: ".C",
                    typ: "cpp"
                },
                ".cc": {
                    $name:"ti.targets.C674/extensions/'.cc'",
                    suf: ".cc",
                    typ: "cpp"
                }
            },
            versionMap: {
                $name:"ti.targets.C674/versionMap",
                "TMS320C6x_4.32": "1%2C0%2C4.32%2C0",
                "TMS320C55x_2.56": "1%2C0%2C2.56%2C0",
                "TMS320C54x_3.83": "1%2C0%2C3.83%2C0",
                "TMS320C2000_3.07": "1%2C0%2C3.07%2C0"
            },
            alignDirectiveSupported: true,
            rootDir: "C%3A/CCStudio_v5.1/ccsv5/tools/compiler/c6000",
            profiles: {
                $name:"ti.targets.C674/profiles",
                debug: {
                    $name:"ti.targets.C674/profiles/'debug'",
                    compileOpts: {
                        $name:"ti.targets.C674/profiles/'debug'/compileOpts",
                        copts: "--symdebug%3Adwarf",
                        defs: "-D_DEBUG_%3D1"
                    },
                    filters: {
                        $name:"ti.targets.C674/profiles/'debug'/filters",
                    }
                },
                release: {
                    $name:"ti.targets.C674/profiles/'release'",
                    compileOpts: {
                        $name:"ti.targets.C674/profiles/'release'/compileOpts",
                        copts: "-O2"
                    },
                    filters: {
                        $name:"ti.targets.C674/profiles/'release'/filters",
                    }
                },
                profile: {
                    $name:"ti.targets.C674/profiles/'profile'",
                    compileOpts: {
                        $name:"ti.targets.C674/profiles/'profile'/compileOpts",
                        copts: "--gen_profile_info"
                    },
                    filters: {
                        $name:"ti.targets.C674/profiles/'profile'/filters",
                    }
                },
                coverage: {
                    $name:"ti.targets.C674/profiles/'coverage'",
                    compileOpts: {
                        $name:"ti.targets.C674/profiles/'coverage'/compileOpts",
                        copts: "--gen_profile_info"
                    },
                    filters: {
                        $name:"ti.targets.C674/profiles/'coverage'/filters",
                    }
                },
                whole_program: {
                    $name:"ti.targets.C674/profiles/'whole_program'",
                    compileOpts: {
                        $name:"ti.targets.C674/profiles/'whole_program'/compileOpts",
                        copts: "-oe%20-O2%20-mo"
                    },
                    filters: {
                        $name:"ti.targets.C674/profiles/'whole_program'/filters",
                    }
                },
                whole_program_debug: {
                    $name:"ti.targets.C674/profiles/'whole_program_debug'",
                    compileOpts: {
                        $name:"ti.targets.C674/profiles/'whole_program_debug'/compileOpts",
                        copts: "-oe%20--symdebug%3Adwarf%20-mo"
                    },
                    filters: {
                        $name:"ti.targets.C674/profiles/'whole_program_debug'/filters",
                    }
                }
            },
            sectMap: {
                $name:"ti.targets.C674/sectMap",
                ".text": "code",
                ".stack": "stack",
                ".bss": "data",
                ".cinit": "data",
                ".pinit": "data",
                ".const": "data",
                ".data": "data",
                ".switch": "data",
                ".sysmem": "data",
                ".far": "data",
                ".args": "data",
                ".cio": "data"
            },
            stdInclude: "ti/targets/std.h",
            stdTypes: {
                $name:"ti.targets.C674/stdTypes",
                t_IArg: {
                    $name:"ti.targets.C674/stdTypes/t_IArg",
                    size: 4,
                    align: 4
                },
                t_Char: {
                    $name:"ti.targets.C674/stdTypes/t_Char",
                    size: 1,
                    align: 1
                },
                t_Double: {
                    $name:"ti.targets.C674/stdTypes/t_Double",
                    size: 8,
                    align: 8
                },
                t_Float: {
                    $name:"ti.targets.C674/stdTypes/t_Float",
                    size: 4,
                    align: 4
                },
                t_Fxn: {
                    $name:"ti.targets.C674/stdTypes/t_Fxn",
                    size: 4,
                    align: 4
                },
                t_Int: {
                    $name:"ti.targets.C674/stdTypes/t_Int",
                    size: 4,
                    align: 4
                },
                t_Int8: {
                    $name:"ti.targets.C674/stdTypes/t_Int8",
                    size: 1,
                    align: 1
                },
                t_Int16: {
                    $name:"ti.targets.C674/stdTypes/t_Int16",
                    size: 2,
                    align: 2
                },
                t_Int32: {
                    $name:"ti.targets.C674/stdTypes/t_Int32",
                    size: 4,
                    align: 4
                },
                t_Int40: {
                    $name:"ti.targets.C674/stdTypes/t_Int40",
                    size: 8,
                    align: 8
                },
                t_Int64: {
                    $name:"ti.targets.C674/stdTypes/t_Int64",
                    size: 8,
                    align: 8
                },
                t_Long: {
                    $name:"ti.targets.C674/stdTypes/t_Long",
                    size: 8,
                    align: 8
                },
                t_LDouble: {
                    $name:"ti.targets.C674/stdTypes/t_LDouble",
                    size: 8,
                    align: 8
                },
                t_LLong: {
                    $name:"ti.targets.C674/stdTypes/t_LLong",
                    size: 8,
                    align: 8
                },
                t_Ptr: {
                    $name:"ti.targets.C674/stdTypes/t_Ptr",
                    size: 4,
                    align: 4
                },
                t_Short: {
                    $name:"ti.targets.C674/stdTypes/t_Short",
                    size: 2,
                    align: 2
                },
                t_Size: {
                    $name:"ti.targets.C674/stdTypes/t_Size",
                    size: 4,
                    align: 4
                }
            },
            bitsPerChar: 8,
            ar: {
                $name:"ti.targets.C674/ar",
                cmd: "ar6x",
                opts: "rq"
            },
            arOpts: {
                $name:"ti.targets.C674/arOpts",
                prefix: "",
                suffix: ""
            },
            lnk: {
                $name:"ti.targets.C674/lnk",
                cmd: "lnk6x",
                opts: ""
            },
            lnkOpts: {
                $name:"ti.targets.C674/lnkOpts",
                prefix: "-w%20-q%20-u%20_c_int00",
                suffix: "-c%20-m%20%24%28XDCCFGDIR%29/%24@.map%20-l%20%24%28rootDir%29/lib/rts6740.lib"
            },
            cc: {
                $name:"ti.targets.C674/cc",
                cmd: "cl6x%20-c",
                opts: "-mv6740"
            },
            ccOpts: {
                $name:"ti.targets.C674/ccOpts",
                prefix: "-qq%20-pdsw225",
                suffix: ""
            },
            ccConfigOpts: {
                $name:"ti.targets.C674/ccConfigOpts",
                prefix: "%24%28ccOpts.prefix%29%20-mo%20--no_compress",
                suffix: "%24%28ccOpts.suffix%29"
            },
            asm: {
                $name:"ti.targets.C674/asm",
                cmd: "cl6x%20-c",
                opts: "-mv6740"
            },
            asmOpts: {
                $name:"ti.targets.C674/asmOpts",
                prefix: "-qq",
                suffix: ""
            },
            includeOpts: "-I%24%28rootDir%29/include",
            binDir: "%24%28rootDir%29/bin/",
            pathPrefix: "",
            vers: {
                $name:"ti.targets.C674/vers",
                cmd: "cl6x",
                opts: "--compiler_revision"
            }
        },
        test: {},
        cfgArgsEncoded: true,
        cfgArgs: "null",
        cfgScript: "C%3A/tmp_C6A8168/DSP_sysbios_Static_example/static.cfg",
        cfgHome: "configPkg",
        profile: "whole_program"
    };
    build.target.findSuffix = function findSuffix(pkg) {
        if (arguments.length < 1) {
            throw new Error("The function ITarget.findSuffix() requires an " + "argument");
        }
        var suffixMap = {};
        if ("build" in pkg) {
            var build = pkg.build;
            if (build.libraries.length != 0) {
                if (build.libDesc[0].suffix != undefined) {
                    for (var i = 0; i < build.libDesc.length; i++) {
                        suffixMap[build.libDesc[i].suffix] = "";
                    }
                } else {
                    for (var i = 0; i < build.libDesc.length; i++) {
                        if (build.libDesc[i].target == prog.build.target.$name) {
                            suffixMap[prog.build.target.suffix] = "";
                            break;
                        }
                    }
                }
            }
        } else {
            if ("length" in pkg) {
                for (var i = 0; i < pkg.length; i++) {
                    suffixMap[pkg[i]] = "";
                }
            } else {
                throw new Error("An invalid argument type supplied to " + "ITarget.findSuffix()");
            }
        }
        var compTargs = [];
        for (var prop in this.compatibleSuffixes) {
            compTargs[prop] = this.compatibleSuffixes[prop];
        }
        if (this.suffix in suffixMap) {
            return (this.suffix);
        }
        if (compTargs.length < 1) {
            return (null);
        }
        for (var i = 0; i < compTargs.length; i++) {
            if (compTargs[i] in suffixMap) {
                return (compTargs[i]);
            }
        }
        return (null);
    };

    build.target.selectSuffix = function selectSuffix(list) {
        var suffixMap = {};
        for (var i = 0; i < list.length; i++) {
            suffixMap[list[i]] = "";
        }
        var compTargs = [];
        for (var prop in this.compatibleSuffixes) {
            compTargs[prop] = this.compatibleSuffixes[prop];
        }
        if (this.suffix in suffixMap) {
            return (this.suffix);
        }
        if (compTargs.length < 1) {
            return (null);
        }
        for (var i = 0; i < compTargs.length; i++) {
            if (compTargs[i] in suffixMap) {
                return (compTargs[i]);
            }
        }
        return (null);
    };

    build.target.asmName = function asmName(cname) {
        return ("_" + cname);
    };

    _runescape(build);
    build.cfgArgs = null;
    prog.build = build;
    
    prog.name = "static.p674";

    prog.endian = prog.build.target.model.endian;

    /* use the platform package's Platform module */
    var Platform = xdc.useModule("ti.platforms.evmC6A8168.Platform");
    var platParams = _getPlatCfg();
    for (var prop in platParams) {
        if (!(prop in Platform.PARAMS)) {
            delete platParams[prop];
        }
    }
    prog.platformName = "ti.platforms.evmC6A8168";
    prog.platform = Platform.create("", _getPlatCfg(), platParams);
    /* record the executable's package name */
    prog.buildPackage = "configPkg";

    /* record build-model information required during config generation */
    prog.$$bind("$$isasm", 1);
    prog.$$bind("$$isrom", 0);
    prog.$$bind("$$gentab", [
    ]);
    
    /* bind prog to an appropriate execution context */
    prog.cpu = prog.platform.getExeContext(prog);

    /* import the target's run-time support pkg */
    xdc.loadPackage("ti.targets.rts6000");
}
    
/* function to import the cfg script's package */
function _userscript($$legacy, script) {
    var home;
    var spath;
    home = xdc.loadPackage("configPkg");
    
    xdc.om.$$bind('$homepkg', home);

    var platParams = _getPlatCfg();

    /* load & run program cfg script and monitor all loaded files */
    _runCfg("C:/tmp_C6A8168/DSP_sysbios_Static_example/static.cfg", spath, "package/cfg/static_p674",  
             false, 
             false,
             platParams, script);

    /*
     *  ======== _loadOrEval ========
     *  Either load the user configuration script from disk, or else
     *  execute the supplied source text directly. In either case,
     *  provide the same execution environment.
     */
    function _loadOrEval(cfgScript, noTrack, path, script) {
        if (!script) {
            utils.loadCapsule(cfgScript, noTrack, path);
        }
        else {
            /* set up the same environment that loadCapsule would */ 
            var $saveCsd = utils.csd;
            var $cfgFile = utils.findFile(cfgScript, path);
            if ($cfgFile) {
                $cfgFile = java.io.File($cfgFile);
            }
            if ($cfgFile && $cfgFile.exists()) {
                utils.csd = $cfgFile.getParentFile().getCanonicalPath();
            }
            utils.evaluateScript(script);
            utils.csd = $saveCsd;
        }
    }

    /*
     *  ======== _runCfg ========
     *  Run a user supplied configuration script and prevent user's script from
     *  overwriting the global variable prog.
     */
    function _runCfg(cfgScript, path, programName, legacyTcf, legacyCfg,
        platParams, script)
    {
        if (legacyTcf) {
            /* save current global variables */
            var $save = {prog: utils.global.prog, Program: Program};
    
            /* initialize global variables for legacy config scripts */
            environment["config.programName"] = programName;
            environment["config.platform"] = Program.platformName;
            utils.seedPath = environment["config.importPath"];
            utils.loadPlatform.params = platParams;
            Program = $$legacy.Program;     /* defined in cfg.tci */
            
            /* run legacy config script with prog == to RTSC Program; this
             * allows legacy script to read build atributes from RTSC model
             * before re-creating the prog object
             */
            utils.loadCapsule(cfgScript, false, path);  
    
            /* restore global variables; now prog == TCOM prog because
             * utils.loadPlatform() creates the TCOM prog object.
             */
            $$legacy.prog = utils.global.prog;  /* in case XDC wants it */
            utils.global.prog = $save.prog;
            Program = $save.Program;
    
            /* run XDC configuration script, if it exists */
            if (legacyCfg) {
                utils.importFile(cfgScript.replace(/\.tcf/, ".cfg"), path);
            }
        }
        else {
            _loadOrEval(cfgScript, false, path, script);
        }
    }
}
    
function _postinit() {

    var cout = null;


    utils.genDep("package/cfg/static_p674", "configPkg", utils.loadedFiles, cout, null);
}
