Skip to content

Commit

Permalink
EnvironmentLoader, clean merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dmiller423 committed Apr 24, 2020
1 parent b9002bb commit 75ee8f0
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 17 deletions.
34 changes: 17 additions & 17 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"variables": [
{
"name": "WSL",
"type": "BOOL",
"value": "TRUE"
"value": "TRUE",
"type": "BOOL"
}
]
},
Expand All @@ -46,8 +46,8 @@
"variables": [
{
"name": "WSL",
"type": "BOOL",
"value": "TRUE"
"value": "TRUE",
"type": "BOOL"
}
]
},
Expand All @@ -64,18 +64,18 @@
"variables": [
{
"name": "CMAKE_C_COMPILER",
"type": "STRING",
"value": "${env.cc}"
"value": "${env.cc}",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER",
"type": "STRING",
"value": "${env.cxx}"
"value": "${env.cxx}",
"type": "STRING"
},
{
"name": "CMAKE_SYSROOT",
"type": "STRING",
"value": "${env.fexsysroot}"
"value": "${env.fexsysroot}",
"type": "STRING"
}
]
},
Expand All @@ -92,18 +92,18 @@
"variables": [
{
"name": "CMAKE_C_COMPILER",
"type": "STRING",
"value": "${env.cc}"
"value": "${env.cc}",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER",
"type": "STRING",
"value": "${env.cxx}"
"value": "${env.cxx}",
"type": "STRING"
},
{
"name": "CMAKE_SYSROOT",
"type": "STRING",
"value": "${env.fexsysroot}"
"value": "${env.fexsysroot}",
"type": "STRING"
}
]
},
Expand All @@ -117,7 +117,7 @@
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_clang_x64" ],
"remoteMachineName": "${env.fexremote}", // string "-662331587;z.port0.org (username=ubuntu, port=22, authentication=PrivateKey)",
"remoteMachineName": "${env.fexremote}",
"remoteCMakeListsRoot": "$HOME/projects/.vs/${projectDirName}/src",
"remoteBuildRoot": "$HOME/projects/.vs/${projectDirName}/build/${name}",
"remoteInstallRoot": "$HOME/projects/.vs/${projectDirName}/install/${name}",
Expand Down
1 change: 1 addition & 0 deletions Source/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(NAME Common)
set(SRCS
ArgumentLoader.cpp
EnvironmentLoader.cpp
Config.cpp
StringUtil.cpp)

Expand Down
111 changes: 111 additions & 0 deletions Source/Common/EnvironmentLoader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <functional>
#include <filesystem>
#include <string_view>
#include <unordered_map>
#include "Common/Config.h"
#include "LogManager.h"

namespace FEX::EnvLoader {

using string = std::string;
using string_view = std::string_view;

void Load(char *const envp[])
{
std::unordered_map<string_view,string_view> EnvMap;

for(const char *const *pvar=envp; pvar && *pvar; pvar++) {
string_view Var(*pvar);
size_t pos = Var.rfind('=');
if (string::npos==pos)
continue;

string_view Ident = Var.substr(0,pos);
string_view Value = Var.substr(pos+1);
EnvMap[Ident]=Value;
}

std::function GetVar = [=](const string_view id) -> const string_view {
if (EnvMap.find(id) != EnvMap.end())
return EnvMap.at(id);

// If envp[] was empty, search using std::getenv()
const char* vs = std::getenv(id.data());
string_view sv(vs?vs:"");
return sv;
};

string_view Value;
{
if ((Value = GetVar("FEX_CORE")).size()) {
// Accept Numeric or name //
if (isdigit(Value[0])) Config::Add("Core", Value);
else {
uint32_t CoreVal = 0;
if (Value == string_view("irint")) CoreVal = 0; // default
else if (Value == string_view("irjit")) CoreVal = 1;
else if (Value == string_view("llvm")) CoreVal = 2;
else if (Value == string_view("host")) CoreVal = 3;
else if (Value == string_view("vm")) CoreVal = 4;
else { LogMan::Msg::D("FEX_CORE has invalid identifier"); }
Config::Add("Core", std::to_string(CoreVal));
}
}

if ((Value = GetVar("FEX_BREAK")).size()) {
if (isdigit(Value[0])) Config::Add("Break", Value);
}

if ((Value = GetVar("FEX_SINGLE_STEP")).size()) {
if (isdigit(Value[0])) {
Config::Add("SingleStep", Value);
Config::Add("MaxInst", std::to_string(1u));
}
}
else if ((Value = GetVar("FEX_MAX_INST")).size()) {
if (isdigit(Value[0])) Config::Add("MaxInst", Value);
}

if ((Value = GetVar("FEX_MULTIBLOCK")).size()) {
if (isdigit(Value[0])) Config::Add("Multiblock", Value);
}

if ((Value = GetVar("FEX_GDB_SERVER")).size()) {
if (isdigit(Value[0])) Config::Add("GdbServer", Value);
}
}

{
if ((Value = GetVar("FEX_ROOTFS")).size()) {
Config::Add("RootFS", Value);
if (!std::filesystem::exists(Value)) {
LogMan::Msg::D("FEX_ROOTFS '%s' doesn't exist", Value.data());
Config::Add("RootFS", "");
}
}

if ((Value = GetVar("FEX_UNIFIED_MEM")).size()) {
if (isdigit(Value[0])) Config::Add("UnifiedMemory", Value);
}
}

{
if ((Value = GetVar("FEX_DUMP_GPRS")).size()) {
if (isdigit(Value[0])) Config::Add("DumpGPRs", Value);
}

if ((Value = GetVar("FEX_IPC_CLIENT")).size()) {
if (isdigit(Value[0])) Config::Add("IPCClient", Value);
}

if ((Value = GetVar("FEX_ELF_TYPE")).size()) {
if (isdigit(Value[0])) Config::Add("ELFType", Value);
}

if ((Value = GetVar("FEX_IPCID")).size()) {
Config::Add("IPCID", Value);
}
}
}

}
7 changes: 7 additions & 0 deletions Source/Common/EnvironmentLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace FEX::EnvLoader {

void Load(char *const envp[]);

}

0 comments on commit 75ee8f0

Please sign in to comment.