Skip to content

Commit f8cc0c1

Browse files
committed
Stuff
1 parent 4cb0f46 commit f8cc0c1

3 files changed

Lines changed: 82 additions & 43 deletions

File tree

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ void compileRecursive(std::filesystem::path inputDir) {
3636
if (i->path().filename().extension() == ".sqf"sv) {
3737
if (i->path().filename() == "fnc_zeusAttributes.sqf") continue; //Hard ignore for missing include file
3838
//if (i->path().filename() != "test.sqf") continue; //Hard ignore for missing include file
39-
if (i->path().string().find("keybinding") == std::string::npos) continue; //CBA trying to format a code piece
40-
if (i->path().filename().string().find("XEH_preStart") == std::string::npos) continue; //Hard ignore unit tests
39+
//if (i->path().string().find("keybinding") == std::string::npos) continue; //CBA trying to format a code piece
40+
//if (i->path().filename().string().find("XEH_preStart") == std::string::npos) continue; //Hard ignore unit tests
4141
tasks.emplace(i->path());
4242
}
4343
}

src/optimizer/optimizerModuleConstantFold.cpp

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "optimizerModuleConstantFold.hpp"
22
#include <algorithm>
33
#include <sstream>
4+
#include <unordered_set>
45

56
class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldActionMap> {
67
public:
@@ -46,25 +47,55 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
4647
//math
4748

4849

49-
binaryActions["+"] = [](OptimizerModuleBase::Node & node) -> void {
50-
float leftArg = std::get<float>(node.children[0].value);
51-
float rightArg = std::get<float>(node.children[1].value);
52-
53-
node.type = InstructionType::push;
54-
node.children.clear();
55-
node.constant = true;
56-
node.value = leftArg + rightArg;
57-
};
58-
59-
binaryActions["-"] = [](OptimizerModuleBase::Node & node) -> void {
60-
float leftArg = std::get<float>(node.children[0].value);
61-
float rightArg = std::get<float>(node.children[1].value);
62-
63-
node.type = InstructionType::push;
64-
node.children.clear();
65-
node.constant = true;
66-
node.value = leftArg - rightArg;
67-
};
50+
//binaryActions["+"] = [](OptimizerModuleBase::Node & node) -> void {
51+
// if (node.children[0].value.index() == 1) { //string
52+
// auto leftArg = std::get<STRINGTYPE>(node.children[0].value);
53+
// auto rightArg = std::get<STRINGTYPE>(node.children[1].value);
54+
// node.value = leftArg + rightArg;
55+
// } else {//float
56+
// float leftArg = std::get<float>(node.children[0].value);
57+
// float rightArg = std::get<float>(node.children[1].value);
58+
// node.value = leftArg + rightArg;
59+
// }
60+
//
61+
//
62+
//
63+
// node.type = InstructionType::push;
64+
// node.children.clear();
65+
// node.constant = true;
66+
//
67+
//};
68+
69+
//binaryActions["-"] = [](OptimizerModuleBase::Node & node) -> void {
70+
// if (node.children[0].value.index() == 4) { //array
71+
// //std::unordered_set<STRINGTYPE> vals;
72+
// //
73+
// //for (auto& i : node.children[1].children) { //#TODO number support
74+
// // if (i.value.index() != 1)
75+
// // return; //not string, don't optimize
76+
// // vals.emplace(std::get<STRINGTYPE>(i.value));
77+
// //}
78+
// //std::vector<OptimizerModuleBase::Node> newNodes;
79+
// //for (auto& it : node.children[0].children) {
80+
// // if (it.value.index() != 1)
81+
// // return; //not string, don't optimize
82+
// // auto & sval = std::get<STRINGTYPE>(it.value);
83+
// //
84+
// // auto found = vals.find(sval);
85+
// // if (found == vals.end())
86+
// // newNodes.emplace_back(std::move(it));
87+
// //}
88+
// //node.children[0].children = std::move(newNodes);
89+
// return;
90+
// } else {//float
91+
// float leftArg = std::get<float>(node.children[0].value);
92+
// float rightArg = std::get<float>(node.children[1].value);
93+
// node.value = leftArg - rightArg;
94+
// }
95+
// node.type = InstructionType::push;
96+
// node.children.clear();
97+
// node.constant = true;
98+
//};
6899

69100
binaryActions["/"] = [](OptimizerModuleBase::Node & node) -> void {
70101
float leftArg = std::get<float>(node.children[0].value);
@@ -118,19 +149,26 @@ class OptimizerConstantFoldActionMap : public Singleton<OptimizerConstantFoldAct
118149
}
119150

120151
void setupNulary() {
121-
nularyActions["true"] = [](OptimizerModuleBase::Node & node) -> void {
122-
node.type = InstructionType::push;
123-
node.children.clear();
124-
node.constant = true;
125-
node.value = true;
126-
};
127-
128-
nularyActions["false"] = [](OptimizerModuleBase::Node & node) -> void {
129-
node.type = InstructionType::push;
130-
node.children.clear();
131-
node.constant = true;
132-
node.value = false;
133-
};
152+
//nularyActions["true"] = [](OptimizerModuleBase::Node & node) -> void {
153+
// node.type = InstructionType::push;
154+
// node.children.clear();
155+
// node.constant = true;
156+
// node.value = true;
157+
//};
158+
//
159+
//nularyActions["false"] = [](OptimizerModuleBase::Node & node) -> void {
160+
// node.type = InstructionType::push;
161+
// node.children.clear();
162+
// node.constant = true;
163+
// node.value = false;
164+
//};
165+
166+
//nularyActions["nil"] = [](OptimizerModuleBase::Node & node) -> void {
167+
// node.type = InstructionType::push;
168+
// node.children.clear();
169+
// node.constant = true;
170+
// node.value = false;//#TODO
171+
//};
134172
}
135173

136174
std::unordered_map<std::string, std::function<void(OptimizerModuleBase::Node&)>> binaryActions;
@@ -181,6 +219,7 @@ void OptimizerModuleConstantFold::processNode(Node& node) {
181219
case InstructionType::assignToLocal: break;
182220
case InstructionType::getVariable: break;
183221
case InstructionType::makeArray: {
222+
return;
184223
if (node.areChildrenConstant()) {//#TODO when converting to ASM check again if all elements are push
185224
bool allPush = std::all_of(node.children.begin(), node.children.end(), [](const Node & it)
186225
{

src/scriptCompiler.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path file) {
7272
{
7373
auto node = OptimizerModuleBase::nodeFromAST(ast);
7474

75-
std::ofstream nodeo("P:\\node.txt");
76-
node.dumpTree(nodeo, 0);
77-
nodeo.close();
75+
//std::ofstream nodeo("P:\\node.txt");
76+
//node.dumpTree(nodeo, 0);
77+
//nodeo.close();
7878

7979
auto res = node.bottomUpFlatten();
8080

8181
Optimizer opt;
8282

8383
opt.optimize(node);
8484

85-
std::ofstream nodeop("P:\\nodeOpt.txt");
86-
node.dumpTree(nodeop, 0);
87-
nodeop.close();
85+
//std::ofstream nodeop("P:\\nodeOpt.txt");
86+
//node.dumpTree(nodeop, 0);
87+
//nodeop.close();
8888

8989
CompiledCodeData stuff;
9090
CompileTempData temp;
@@ -98,9 +98,9 @@ CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path file) {
9898
stuff.constants.emplace_back(std::move(mainCode));
9999

100100

101-
std::ofstream output2("P:\\outOpt.sqfa", std::ofstream::binary);
102-
ScriptSerializer::compiledToHumanReadable(stuff, output2);
103-
output2.flush();
101+
//std::ofstream output2("P:\\outOpt.sqfa", std::ofstream::binary);
102+
//ScriptSerializer::compiledToHumanReadable(stuff, output2);
103+
//output2.flush();
104104
}
105105

106106

0 commit comments

Comments
 (0)