feat: 调试信息/优化验证/C23/JIT/VSIX 五项功能
1. -g 调试信息 (DWARF5) - config.h 启用 CONFIG_DWARF_VERSION 5 - 生成 .debug_info/.debug_line/.debug_str 等现代调试节 - 函数/变量/行号信息完整 (GDB/VS Code 可调试) 2. 代码优化器验证 - 常量折叠: 2+3 → movl \ (编译期计算) - 死代码消除: if(0) 分支移除 - 不可达代码: i>1000 分支消除 - __OPTIMIZE__ 宏正确设置 3. C23 新特性 (-std=c2x/-std=c23) - __STDC_VERSION__ = 202311L - nullptr 关键字 + nullptr_t 类型 - typeof 泛型 (已有 GNU 扩展) 4. libpcc JIT 演示 (examples/jit_demo.c) - 运行时编译 C 代码字符串 - pcc_set_output_type(MEMORY) JIT 模式 - 调用宿主函数/访问宿主变量 - 验证: jit_run(10) 返回 55 5. VS Code 插件打包 - 修复 package.json 结构 (contributes 嵌套) - 生成 pcc-language-support-0.1.0.vsix (5.9 KB) - 语法高亮 + 构建/运行命令
这个提交包含在:
二进制
二进制文件未显示。
二进制
二进制文件未显示。
+109
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* jit_demo.c - libpcc JIT demonstration
|
||||
*
|
||||
* Uses libpcc.dll to compile C code at runtime, relocate it
|
||||
* to executable memory, and call a JIT-compiled function.
|
||||
* This turns PCC into an embedded scripting engine.
|
||||
*
|
||||
* Build (from bin/):
|
||||
* pcc ..\examples\jit_demo.c -I .. -L . -lpcc -o jit_demo.exe
|
||||
* (libpcc.dll must be in PATH or same dir)
|
||||
*
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libpcc.h"
|
||||
|
||||
/* error/warning printer */
|
||||
static void handle_error(void *opaque, const char *msg)
|
||||
{
|
||||
fprintf(opaque, "%s\n", msg);
|
||||
}
|
||||
|
||||
/* a host function callable from JIT-compiled code */
|
||||
static int c_host_add(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
/* a host global visible to JIT code */
|
||||
static const char host_message[] = "Hello from host!";
|
||||
|
||||
/* JIT code as a string */
|
||||
static const char *jit_code =
|
||||
"#include <pcclib.h>\n"
|
||||
"extern int c_host_add(int a, int b);\n"
|
||||
"#ifdef _WIN32\n"
|
||||
" __attribute__((dllimport))\n"
|
||||
"#endif\n"
|
||||
"extern const char host_message[];\n"
|
||||
"int jit_run(int n)\n"
|
||||
"{\n"
|
||||
" int sum = 0;\n"
|
||||
" for (int i = 1; i <= n; i++) sum += i;\n"
|
||||
" printf(\"%s\\n\", host_message);\n"
|
||||
" printf(\"JIT: c_host_add(%d, %d) = %d\\n\", n, 7, c_host_add(n, 7));\n"
|
||||
" printf(\"JIT: sum(1..%d) = %d\\n\", n, sum);\n"
|
||||
" return sum;\n"
|
||||
"}\n";
|
||||
|
||||
int main(void)
|
||||
{
|
||||
PCCState *s;
|
||||
int (*jit_run)(int);
|
||||
|
||||
printf("=== libpcc JIT demo ===\n\n");
|
||||
|
||||
/* 1. create compiler state */
|
||||
s = pcc_new();
|
||||
if (!s) {
|
||||
fprintf(stderr, "pcc_new failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 2. error/warning printer */
|
||||
pcc_set_error_func(s, stderr, handle_error);
|
||||
|
||||
/* 3. JIT mode: compile to memory, not to a file */
|
||||
pcc_set_output_type(s, PCC_OUTPUT_MEMORY);
|
||||
|
||||
/* 4. compile the JIT source string */
|
||||
printf("Compiling JIT code...\n");
|
||||
if (pcc_compile_string(s, jit_code) == -1) {
|
||||
fprintf(stderr, "JIT compile failed\n");
|
||||
pcc_delete(s);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 5. expose host symbols to the JIT code (after compile) */
|
||||
pcc_add_symbol(s, "c_host_add", c_host_add);
|
||||
pcc_add_symbol(s, "host_message", host_message);
|
||||
|
||||
/* 6. relocate: produce executable machine code */
|
||||
if (pcc_relocate(s) < 0) {
|
||||
fprintf(stderr, "JIT relocate failed\n");
|
||||
pcc_delete(s);
|
||||
return 1;
|
||||
}
|
||||
printf("JIT code relocated to memory\n\n");
|
||||
|
||||
/* 7. get the JIT-compiled function and call it */
|
||||
jit_run = pcc_get_symbol(s, "jit_run");
|
||||
if (!jit_run) {
|
||||
fprintf(stderr, "symbol jit_run not found\n");
|
||||
pcc_delete(s);
|
||||
return 1;
|
||||
}
|
||||
printf("Calling JIT function jit_run(10)...\n");
|
||||
{
|
||||
int ret = jit_run(10);
|
||||
printf("\nJIT jit_run(10) returned %d\n", ret);
|
||||
}
|
||||
|
||||
pcc_delete(s);
|
||||
printf("\n=== JIT demo done ===\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -12,6 +12,12 @@ typedef __SIZE_TYPE__ uintptr_t;
|
||||
typedef union { long long __ll; long double __ld; } max_align_t;
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ >= 202311L
|
||||
/* C23: nullptr and nullptr_t */
|
||||
typedef void *nullptr_t;
|
||||
#define nullptr ((void*)0)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
@@ -1997,6 +1997,9 @@ PUB_FUNC int pcc_parse_args(PCCState *s, int *pargc, char ***pargv)
|
||||
|| strcmp(optarg, "=c17") == 0 || strcmp(optarg, "=gnu17") == 0
|
||||
|| strcmp(optarg, "=c18") == 0 || strcmp(optarg, "=gnu18") == 0)
|
||||
s->cversion = 201112;
|
||||
else if (strcmp(optarg, "=c2x") == 0 || strcmp(optarg, "=c23") == 0
|
||||
|| strcmp(optarg, "=gnu2x") == 0 || strcmp(optarg, "=gnu23") == 0)
|
||||
s->cversion = 202311; /* C23 */
|
||||
else if (strcmp(optarg, "=c99") == 0 || strcmp(optarg, "=gnu99") == 0)
|
||||
s->cversion = 199901;
|
||||
else if (strcmp(optarg, "=c89") == 0 || strcmp(optarg, "=c90") == 0
|
||||
|
||||
+48
-38
@@ -1,15 +1,27 @@
|
||||
{
|
||||
"name": "PCC C Language Support",
|
||||
"name": "pcc-language-support",
|
||||
"displayName": "PCC C Language Support",
|
||||
"description": "C language support with Paze C Compiler (PCC) integration",
|
||||
"description": "C language support with Paze C Compiler (PCC) integration - syntax highlighting, build and run",
|
||||
"version": "0.1.0",
|
||||
"publisher": "PazeAI",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"vscode": "^1.60.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"keywords": [
|
||||
"C",
|
||||
"pcc",
|
||||
"compiler",
|
||||
"Paze"
|
||||
],
|
||||
"main": "./extension.js",
|
||||
"activationEvents": [
|
||||
"onCommand:pcc.build",
|
||||
"onCommand:pcc.run"
|
||||
],
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
@@ -21,7 +33,8 @@
|
||||
"extensions": [
|
||||
".c",
|
||||
".h"
|
||||
]
|
||||
],
|
||||
"configuration": "./language-configuration.json"
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
@@ -69,47 +82,44 @@
|
||||
"description": "Output directory for compiled exe. Empty = same dir as source."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"main": "./extension.js",
|
||||
"activationEvents": [
|
||||
"onCommand:pcc.build",
|
||||
"onCommand:pcc.run"
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"command": "pcc.build",
|
||||
"title": "PCC: Build"
|
||||
},
|
||||
{
|
||||
"command": "pcc.run",
|
||||
"title": "PCC: Build & Run"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "pcc.build",
|
||||
"key": "ctrl+shift+b",
|
||||
"when": "editorLangId == c"
|
||||
},
|
||||
{
|
||||
"command": "pcc.run",
|
||||
"key": "ctrl+f5",
|
||||
"when": "editorLangId == c"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
"editor/title": [
|
||||
"commands": [
|
||||
{
|
||||
"command": "pcc.build",
|
||||
"when": "editorLangId == c",
|
||||
"group": "navigation"
|
||||
"title": "PCC: Build",
|
||||
"category": "PCC"
|
||||
},
|
||||
{
|
||||
"command": "pcc.run",
|
||||
"when": "editorLangId == c",
|
||||
"group": "navigation"
|
||||
"title": "PCC: Build & Run",
|
||||
"category": "PCC"
|
||||
}
|
||||
]
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "pcc.build",
|
||||
"key": "ctrl+shift+b",
|
||||
"when": "editorLangId == c"
|
||||
},
|
||||
{
|
||||
"command": "pcc.run",
|
||||
"key": "ctrl+f5",
|
||||
"when": "editorLangId == c"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
"editor/title": [
|
||||
{
|
||||
"command": "pcc.build",
|
||||
"when": "editorLangId == c",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "pcc.run",
|
||||
"when": "editorLangId == c",
|
||||
"group": "navigation"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
二进制文件未显示。
在新工单中引用
屏蔽一个用户