feat: 搭建基础框架

This commit is contained in:
msojocs 2023-06-07 20:24:14 +08:00
parent 5b5acb5355
commit 787b1cec2f
15 changed files with 192001 additions and 35 deletions

View File

@ -9,7 +9,9 @@ add_executable(wcc
src/wcc/usage.cpp src/wcc/usage.cpp
src/utils/file.cpp src/utils/file.cpp
) )
add_executable(wcsc src/wcsc.cpp) add_executable(wcsc
src/wcsc.cpp
)
set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

9
src/include/define.h Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
#ifndef __USAGE_H__ #ifndef __USAGE_H__
#define __USAGE_H__ #define __USAGE_H__
int usage(); int usage(int a1, const char **a2);
#endif #endif

72
src/include/wxml.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef __WXML_H_
#define __WXML_H_
#include <iostream>
namespace WXML{
class Compiler
{
private:
/* data */
public:
Compiler(/* args */);
~Compiler();
static void CompileLazy();
static void DealWxsTag();
static void GetFuncId();
static void GetVersionInfo(int a1, int *a2);
static void ParseSource();
static void RenderDefine();
static void WXMLHelperCode(std::string &result);
};
Compiler::Compiler(/* args */)
{
}
Compiler::~Compiler()
{
}
class DOMLib
{
private:
/* data */
const char *szWXIFControlAttrs[4] = { "wx-if", "wx:if", "wx:elif", "wx:else" }; // weak
public:
DOMLib(/* args */);
~DOMLib();
};
DOMLib::DOMLib(/* args */)
{
}
DOMLib::~DOMLib()
{
}
namespace EXPRLib
{
class Tokenizer
{
private:
/* data */
public:
Tokenizer(/* args */);
~Tokenizer();
};
Tokenizer::Tokenizer(/* args */)
{
}
Tokenizer::~Tokenizer()
{
}
} // namespace EXPRLib
}
#endif

View File

@ -1,5 +1,6 @@
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include "../include/file.h"
/** /**
* *

View File

@ -10,8 +10,8 @@ int main(int argc, char **argv) {
string gwxMark = "$gwx"; string gwxMark = "$gwx";
string blankStr = " "; string blankStr = " ";
bool hasConfigParam = false; bool hasConfigParam = false;
string configPathData; string configPathLocation;
vector<string> fileList; vector<string> paramList;
string configData; string configData;
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
@ -23,23 +23,139 @@ int main(int argc, char **argv) {
if (hasConfigParam) { if (hasConfigParam) {
// 有--config-path参数下一个参数是路径跳过 // 有--config-path参数下一个参数是路径跳过
i++; i++;
configPathData = argv[i]; configPathLocation = argv[i];
}else { }else {
fileList.emplace_back(argv[i]); paramList.emplace_back(argv[i]);
} }
} }
// 有配置文件,从配置文件解析 // 有配置文件,从配置文件解析
if (hasConfigParam) { if (hasConfigParam) {
int ret = readFile(configPathData, configData); int ret = readFile(configPathLocation, configData);
string line; string line;
if (0 == ret) { if (0 == ret) {
getNextArg(line, configData, '\n'); getNextArg(line, configData, '\n');
fileList.emplace_back(line); paramList.emplace_back(line);
}
}
int mark = 0;
bool end = false;
bool version = false;
bool hasXCParam = false;
string xcParam;
bool hasCallbackParam = false;
string callbackParam;
string outputFileName;
vector<char> temp;
for (int i = 0; i < paramList.size(); i++)
{
string param = paramList[i];
if (param[0] != '-') {
// 不是参数名,跳过
temp.push_back(param[0]);
continue;
}
// 是参数名-xxx
switch (param[1])
{
case 'd':
// output code for debug
/* code */
if(!param[2]){
mark |= 2u;
continue;
}
if(param[2] == 's') {
mark |= 4u;
continue;
}
break;
case 's':
// read from stdin
/* code */
if(param[2] == 't') {
mark |= 8u;
continue;
}
if (i + 1 < paramList.size()) {
temp.push_back(param[2]);
end = true;
}
break;
case 'v':
// 版本信息
/* code */
if (param[2] == 'b')
mark |= 0x10u;
else
version = true;
break;
case 'x':
// -xc output simplified code for custom component
/* code */
if(param[2] == 'c' && i < paramList.size()) {
hasXCParam = true;
if(paramList[i + 1][0] != '-') {
xcParam.assign(paramList[i + 1]);
i++;
}
continue;
}
break;
case 'c':
// -cc: output compelete code for custom component
// -cb [callback.js...]
/* code */
if(param[2] == 'c' && i + 1 < paramList.size()) {
hasCallbackParam = true;
if(paramList[i + 1][0] != '-') {
callbackParam.assign(paramList[i + 1]);
i++;
}
continue;
}
break;
case 'o':
// -o: output destination (default stdout)
// -om XComponentDefine
/* code */
if (i + 1 < paramList.size()) {
outputFileName = paramList[i + 1];
i++;
}
break;
case 'g':
// -gn gwxMark
/* code */
if (param[2] == 'n' && i + 1 < paramList.size()) {
gwxMark.assign(paramList[i + 1]);
i++;
}
break;
case 'p':
/* code */
mark |= 0x20u;
break;
case 't':
/* code */
mark |= 1u;
break;
case 'i':
/* code */
mark |= 0x40u;
break;
default:
break;
} }
} }
return 0; return 0;
} }

View File

@ -1,13 +1,13 @@
#include <iostream> #include <iostream>
//----- (00401726) -------------------------------------------------------- //----- (00401726) --------------------------------------------------------
int usage() int usage(int argc, const char **argv)
{ {
printf("Wechat WXML Compiler, version %s\n", "v0.5vv_20200413_syb_scopedata"); printf("Wechat WXML Compiler, version %s\n", "v0.5vv_20200413_syb_scopedata");
printf( printf(
"Usage: %s [-d] [-o OUTPUT] [-xc XComponentDefine] [-om XComponentDefine] [-cb [callback.js...]] [-llcommon] [-llw/-l" "Usage: %s [-d] [-o OUTPUT] [-xc XComponentDefine] [-om XComponentDefine] [-cb [callback.js...]] [-llcommon] [-llw/-l"
"la XCPath] <FILES... | -s <SINGLE_FILE>\n", "la XCPath] <FILES... | -s <SINGLE_FILE>\n",
*a2); *argv);
printf(" Options:\n"); printf(" Options:\n");
printf(" -d: output code for debug\n"); printf(" -d: output code for debug\n");
printf(" -o: output destination (default stdout)\n"); printf(" -o: output destination (default stdout)\n");

21
src/wxml/compiler.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "../include/wxml.h"
#include "../include/define.h"
namespace WXML{
void Compiler::GetVersionInfo(int a1, int *a2) {
std::ostream& result = std::cout;
result << "/*";
result << "v0.5vv_20200413_syb_scopedata";
result << "*/";
result << a2;
result << ".__wcc_version__='";
result << "v0.5vv_20200413_syb_scopedata";
result << "';";
result << a2;
result << ".__wcc_version_info__={\"customComponents\":true,\"fixZeroRpx\":true,\"propValueDeepCopy\":false};";
}
void Compiler::WXMLHelperCode(std::string &result) {
result.assign(aIfThisThisGUnd);
}
}

0
src/wxml/dom_lib.cpp Normal file
View File

View File

View File

@ -0,0 +1,4 @@
#include "../include/wxml.h"
namespace WXML {
}

BIN
test/vector Executable file

Binary file not shown.

12
test/vector.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
vector<string> t;
t.push_back("123456");
t.push_back("7890");
cout << t.at(0) << endl;
return 0;
}

View File

@ -61,7 +61,7 @@ int main(int argc, const char **argv, const char **envp)
std::ostream::sentry *v57; // [esp+18h] [ebp-374h] std::ostream::sentry *v57; // [esp+18h] [ebp-374h]
_DWORD *Block; // [esp+1Ch] [ebp-370h] _DWORD *Block; // [esp+1Ch] [ebp-370h]
bool hasConfigParam; // [esp+20h] [ebp-36Ch] bool hasConfigParam; // [esp+20h] [ebp-36Ch]
int v60; // [esp+20h] [ebp-36Ch] int mark; // [esp+20h] [ebp-36Ch]
std::ostream::sentry *v61; // [esp+20h] [ebp-36Ch] std::ostream::sentry *v61; // [esp+20h] [ebp-36Ch]
std::ostream::sentry *v62; // [esp+20h] [ebp-36Ch] std::ostream::sentry *v62; // [esp+20h] [ebp-36Ch]
int *k; // [esp+20h] [ebp-36Ch] int *k; // [esp+20h] [ebp-36Ch]
@ -206,6 +206,8 @@ int main(int argc, const char **argv, const char **envp)
std::string::_M_dispose((void **)&configPathParamName); std::string::_M_dispose((void **)&configPathParamName);
} }
} }
// 读 --config-path 文件的配置内容
if ( v99 ) if ( v99 )
{ {
v138 = 0; v138 = 0;
@ -222,10 +224,12 @@ int main(int argc, const char **argv, const char **envp)
} }
std::string::_M_dispose((void **)&v137); std::string::_M_dispose((void **)&v137);
} }
// 20230606
Streama = 0; Streama = 0;
v43 = 0; v43 = 0;
v44 = 0; v44 = 0;
v60 = 0; mark = 0;
v53 = 0; v53 = 0;
v55 = -1431655765 * ((v90 - (int)fileList) >> 3); v55 = -1431655765 * ((v90 - (int)fileList) >> 3);
v45 = 0; v45 = 0;
@ -235,31 +239,37 @@ int main(int argc, const char **argv, const char **envp)
v67 = 6 * (_DWORD)Streama; v67 = 6 * (_DWORD)Streama;
v4 = &fileList[6 * (_DWORD)Streama]; v4 = &fileList[6 * (_DWORD)Streama];
v5 = (_BYTE *)*v4; v5 = (_BYTE *)*v4;
if ( *(_BYTE *)*v4 != 45 ) // ASCII 45 => '-'
if ( *(_BYTE *)*v4 != '-' /*45*/ )
{ {
std::vector<std::string>::push_back((int)&v86, (int)v4); std::vector<std::string>::push_back((int)&v86, (int)v4);
goto LABEL_84; goto LABEL_84;
} }
// v4 是 '-'
// v6 = '-'的下一个字符
v6 = v5[1]; v6 = v5[1];
switch ( v6 ) switch ( v6 )
{ {
case 'd': case 'd':
// output code for debug
v7 = v5[2]; v7 = v5[2];
if ( !v7 ) if ( !v7 )
{ {
v60 |= 2u; mark |= 2u;
goto LABEL_84; goto LABEL_84;
} }
if ( v7 == 115 ) if ( v7 == 's' /*115*/ )
{ {
v60 |= 4u; mark |= 4u;
goto LABEL_84; goto LABEL_84;
} }
break; break;
case 's': case 's':
if ( v5[2] == 116 ) // read from stdin
if ( v5[2] == 't' /*116*/ )
{ {
v60 |= 8u; mark |= 8u;
goto LABEL_84; goto LABEL_84;
} }
if ( (int)&Streama->_ptr + 1 < v55 ) if ( (int)&Streama->_ptr + 1 < v55 )
@ -270,16 +280,20 @@ int main(int argc, const char **argv, const char **envp)
} }
break; break;
case 'v': case 'v':
if ( v5[2] == 98 ) // 版本信息
v60 |= 0x10u; // 输出:
// /*v0.5vv_20200413_syb_scopedata*/global.__wcc_version__='v0.5vv_20200413_syb_scopedata';global.__wcc_version_info__={"customComponents":true,"fixZeroRpx":true,"propValueDeepCopy":false};
if ( v5[2] == 'b'/*98*/ )
mark |= 0x10u;
else else
v44 = 1; v44 = 1;
goto LABEL_84; goto LABEL_84;
case 'x': case 'x':
if ( v5[2] == 99 && (int)&Streama->_ptr + 1 < v55 ) // -xc output simplified code for custom component
if ( v5[2] == 'c'/*99*/ && (int)&Streama->_ptr + 1 < v55 )
{ {
v53 = 1; v53 = 1;
if ( *(_BYTE *)v89[v67 + 6] != 45 ) if ( *(_BYTE *)v89[v67 + 6] != '-'/*45*/ )
{ {
std::string::_M_assign((int)&v95, (int)&fileList[v67 + 6]); std::string::_M_assign((int)&v95, (int)&fileList[v67 + 6]);
v53 = 1; v53 = 1;
@ -289,10 +303,12 @@ int main(int argc, const char **argv, const char **envp)
} }
break; break;
case 'c': case 'c':
if ( v5[2] == 99 && (int)&Streama->_ptr + 1 < v55 ) // -cc: output compelete code for custom component
// -cb [callback.js...]
if ( v5[2] == 'c'/*99*/ && (int)&Streama->_ptr + 1 < v55 )
{ {
v53 = 0; v53 = 0;
if ( *(_BYTE *)v89[v67 + 6] != 45 ) if ( *(_BYTE *)v89[v67 + 6] != '-'/*45*/ )
{ {
std::string::_M_assign((int)&v95, (int)&fileList[v67 + 6]); std::string::_M_assign((int)&v95, (int)&fileList[v67 + 6]);
v53 = 0; v53 = 0;
@ -302,6 +318,8 @@ int main(int argc, const char **argv, const char **envp)
} }
break; break;
case 'o': case 'o':
// -o: output destination (default stdout)
// -om XComponentDefine
v8 = (FILE *)((char *)&Streama->_ptr + 1); v8 = (FILE *)((char *)&Streama->_ptr + 1);
if ( (int)&Streama->_ptr + 1 < v55 ) if ( (int)&Streama->_ptr + 1 < v55 )
{ {
@ -312,7 +330,8 @@ LABEL_72:
} }
break; break;
case 'g': case 'g':
if ( v5[2] == 110 && (int)&Streama->_ptr + 1 < v55 ) // gwxMark
if ( v5[2] == 'n'/*110*/ && (int)&Streama->_ptr + 1 < v55 )
{ {
std::string::_M_assign((int)gwxMark, (int)&fileList[v67 + 6]); std::string::_M_assign((int)gwxMark, (int)&fileList[v67 + 6]);
v8 = (FILE *)((char *)&Streama->_ptr + 1); v8 = (FILE *)((char *)&Streama->_ptr + 1);
@ -320,17 +339,18 @@ LABEL_72:
} }
break; break;
case 'p': case 'p':
v60 |= 0x20u; mark |= 0x20u;
goto LABEL_84; goto LABEL_84;
case 't': case 't':
v60 |= 1u; mark |= 1u;
goto LABEL_84; goto LABEL_84;
case 'i': case 'i':
v60 |= 0x40u; mark |= 0x40u;
goto LABEL_84; goto LABEL_84;
} }
std::string::basic_string((void **)&configPathParamName, "--split"); std::string::basic_string((void **)&configPathParamName, "--split");
v51 = std::operator==<char>((int)&fileList[v67], (int)&configPathParamName); v51 = std::operator==<char>((int)&fileList[v67], (int)&configPathParamName);
// 相等
if ( v51 ) if ( v51 )
v51 = (int)&Streama->_ptr + 1 < v55; v51 = (int)&Streama->_ptr + 1 < v55;
std::string::_M_dispose((void **)&configPathParamName); std::string::_M_dispose((void **)&configPathParamName);
@ -341,13 +361,13 @@ LABEL_72:
goto LABEL_84; goto LABEL_84;
} }
v9 = fileList[6 * (_DWORD)Streama]; v9 = fileList[6 * (_DWORD)Streama];
if ( *(_BYTE *)(v9 + 1) == 99 && *(_BYTE *)(v9 + 2) == 98 ) if ( *(_BYTE *)(v9 + 1) == 'c'/*99*/ && *(_BYTE *)(v9 + 2) == 'b'/*98*/ )
{ {
LOBYTE(v142[0]) = 0; LOBYTE(v142[0]) = 0;
v140 = (char *)v142; v140 = (char *)v142;
v10 = (char *)fileList[v67 + 6]; v10 = (char *)fileList[v67 + 6];
Streama = (FILE *)((char *)Streama + 1); Streama = (FILE *)((char *)Streama + 1);
v60 |= 0x80u; mark |= 0x80u;
v141 = 0; v141 = 0;
ReadFile(v10, (unsigned int *)&v140); ReadFile(v10, (unsigned int *)&v140);
if ( v141 ) if ( v141 )
@ -376,12 +396,12 @@ LABEL_72:
} }
} }
v49 = fileList[6 * (_DWORD)Streama]; v49 = fileList[6 * (_DWORD)Streama];
if ( *(_BYTE *)(v49 + 1) == 108 && *(_BYTE *)(v49 + 2) == 108 ) if ( *(_BYTE *)(v49 + 1) == 'l'/*108*/ && *(_BYTE *)(v49 + 2) == 'l'/*108*/ )
{ {
v13 = *(_BYTE *)(v49 + 3); v13 = *(_BYTE *)(v49 + 3);
if ( v13 != 119 ) if ( v13 != 'w'/*119*/ )
{ {
if ( v13 != 97 ) if ( v13 != 'a'/*97*/ )
{ {
v14 = ___acrt_iob_func(2u); v14 = ___acrt_iob_func(2u);
fprintf(v14, "Error: expected -llw or -lla, but got %s", (const char *)v49); fprintf(v14, "Error: expected -llw or -lla, but got %s", (const char *)v49);
@ -601,7 +621,7 @@ LABEL_84:
&v105, &v105,
v53, v53,
(int)gwxMark, (int)gwxMark,
v60, mark,
10, 10,
(int *)v127, (int *)v127,
(int *)v128, (int *)v128,
@ -776,7 +796,7 @@ LABEL_84:
&v105, &v105,
v53, v53,
(int *)gwxMark, (int *)gwxMark,
v60, mark,
10, 10,
(int *)v127, (int *)v127,
(int *)v128, (int *)v128,

191709
test/wcc.disassembly.cpp Normal file

File diff suppressed because one or more lines are too long