summaryrefslogtreecommitdiff
path: root/src/optimizer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/optimizer.h')
-rw-r--r--src/optimizer.h62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/optimizer.h b/src/optimizer.h
index 04ee7dddf..5edcaad87 100644
--- a/src/optimizer.h
+++ b/src/optimizer.h
@@ -1,21 +1,27 @@
+
+#ifndef __optimizer_h__
+#define __optimizer_h__
+
+#include "simple_ast.h"
+
extern bool preciseF32,
receiveJSON,
emitJSON,
minifyWhitespace,
last;
-extern Ref extraInfo;
+extern cashew::Ref extraInfo;
-void eliminateDeadFuncs(Ref ast);
-void eliminate(Ref ast, bool memSafe=false);
-void eliminateMemSafe(Ref ast);
-void simplifyExpressions(Ref ast);
-void optimizeFrounds(Ref ast);
-void simplifyIfs(Ref ast);
-void registerize(Ref ast);
-void registerizeHarder(Ref ast);
-void minifyLocals(Ref ast);
-void asmLastOpts(Ref ast);
+void eliminateDeadFuncs(cashew::Ref ast);
+void eliminate(cashew::Ref ast, bool memSafe=false);
+void eliminateMemSafe(cashew::Ref ast);
+void simplifyExpressions(cashew::Ref ast);
+void optimizeFrounds(cashew::Ref ast);
+void simplifyIfs(cashew::Ref ast);
+void registerize(cashew::Ref ast);
+void registerizeHarder(cashew::Ref ast);
+void minifyLocals(cashew::Ref ast);
+void asmLastOpts(cashew::Ref ast);
//
@@ -33,7 +39,7 @@ enum AsmType {
struct AsmData;
-AsmType detectType(Ref node, AsmData *asmData=nullptr, bool inVarDef=false);
+AsmType detectType(cashew::Ref node, AsmData *asmData=nullptr, bool inVarDef=false);
struct AsmData {
struct Local {
@@ -42,49 +48,49 @@ struct AsmData {
AsmType type;
bool param; // false if a var
};
- typedef std::unordered_map<IString, Local> Locals;
+ typedef std::unordered_map<cashew::IString, Local> Locals;
Locals locals;
- std::vector<IString> params; // in order
- std::vector<IString> vars; // in order
+ std::vector<cashew::IString> params; // in order
+ std::vector<cashew::IString> vars; // in order
AsmType ret;
- Ref func;
+ cashew::Ref func;
- AsmType getType(const IString& name) {
+ AsmType getType(const cashew::IString& name) {
auto ret = locals.find(name);
if (ret != locals.end()) return ret->second.type;
return ASM_NONE;
}
- void setType(const IString& name, AsmType type) {
+ void setType(const cashew::IString& name, AsmType type) {
locals[name].type = type;
}
- bool isLocal(const IString& name) {
+ bool isLocal(const cashew::IString& name) {
return locals.count(name) > 0;
}
- bool isParam(const IString& name) {
+ bool isParam(const cashew::IString& name) {
return isLocal(name) && locals[name].param;
}
- bool isVar(const IString& name) {
+ bool isVar(const cashew::IString& name) {
return isLocal(name) && !locals[name].param;
}
AsmData() {} // if you want to fill in the data yourself
- AsmData(Ref f); // if you want to read data from f, and modify it as you go (parallel to denormalize)
+ AsmData(cashew::Ref f); // if you want to read data from f, and modify it as you go (parallel to denormalize)
void denormalize();
- void addParam(IString name, AsmType type) {
+ void addParam(cashew::IString name, AsmType type) {
locals[name] = Local(type, true);
params.push_back(name);
}
- void addVar(IString name, AsmType type) {
+ void addVar(cashew::IString name, AsmType type) {
locals[name] = Local(type, false);
vars.push_back(name);
}
- void deleteVar(IString name) {
+ void deleteVar(cashew::IString name) {
locals.erase(name);
for (size_t i = 0; i < vars.size(); i++) {
if (vars[i] == name) {
@@ -99,9 +105,9 @@ bool isInteger(double x);
bool isInteger32(double x);
-extern IString ASM_FLOAT_ZERO;
+extern cashew::IString ASM_FLOAT_ZERO;
-extern IString SIMD_INT8X16_CHECK,
+extern cashew::IString SIMD_INT8X16_CHECK,
SIMD_INT16X8_CHECK,
SIMD_INT32X4_CHECK,
SIMD_FLOAT32X4_CHECK,
@@ -117,3 +123,5 @@ struct HeapInfo {
HeapInfo parseHeap(const char *name);
+#endif // __optimizer_h__
+