原型,原型链2023.2.11

本文探讨了JavaScript中的闭包及其优缺点,Ajax的不同请求方式,JavaScript继承策略(包括extends、原型链和call等),Promise的使用与限制,原型和原型链的特点,Vue组件生命周期,对象创建方法,冒泡排序算法,以及jQuery中事件处理函数的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.闭包 优缺点 注意什么

闭包:当函数可以记住并访问外部作用域,就产生了闭包,那个外部作用域就叫做闭包

优点:避免全局变量被污染

缺点:使用不当会造成内存泄漏

形成的原因:外层函数的作用域对象无法释放。

2.Ajax 有几种方式

Ajax的全称是异步js与XML技术,通过它与后台服务器进行数据交换,可以使网页实现异步更新

//与XML结合的数据,异步请求后台数据

除了常见的Get和Post,还有update、delete和put等

3.js继承有几种方式

//类继承:extends

//原型链

//call(this)

1.extends

2.原型链:new

3.call(this)

4.组合式继承:call+new

4.promise常用的方法

pending进行中

fuilled成功 pending–》resolve

reject失败 pending–>reject

缺点:书写麻烦,不能实现异步代码,同步执行的需求(配合async函数使用即可)

5.原型,原型链,有什么特点

原型:每一个对象都与另一个对象相关联,那个关联的对象就称为原型。

原型链:就是把原型串联起来,原型链的顶端是null

6.vue的生命周期 vue组件的参数传递方式

beforecreate created

beforemount mounted

beforeupdate updated

beforedestroy destroyed

父子通信 (自定义属性 props)

子父通信(自定义事件 this.$emit)

兄弟之间传参(通过eventBus

7.js创建对象

一、通过字面量创建对象

二、通过new Object来创建对象

三、通过构造函数创建对象

new一个实例对象

create

8.冒泡排序

<script>
    //升序
    function maopao() {
        var arr = [9, 2, 33, 66, 55, 34, 1, 91, 88];//定义一个数组;
        for (var i = 1; i < arr.length; i++) {
            for (var j = 0; j < arr.length - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    var temp = arr[j];      //定义一个临时变量temp
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
 
            }
        }
        return arr; //返回数组
    }
 
    document.write("升序:" + maopao());
</script>

9.手写一个通用的事件侦听函数

答案

10.jQuery中bing(),live(),on()的区别

答案

Starting C simulation ... D:/vitis202302/Vitis_HLS/2023.2/bin/vitis_hls.bat G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray/solution2/csim.tcl INFO: [HLS 200-10] Running 'D:/vitis202302/Vitis_HLS/2023.2/bin/unwrapped/win64.o/vitis_hls.exe' INFO: [HLS 200-10] For user 'HP' on host 'desktop-qjs3vb7' (Windows NT_amd64 version 6.2) on Tue Jul 22 15:29:28 +0800 2025 INFO: [HLS 200-10] In directory 'G:/vitis2023_project' INFO: [HLS 200-2053] The vitis_hls executable is being deprecated. Consider using vitis-run --mode hls --tcl Sourcing Tcl script 'G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray/solution2/csim.tcl' INFO: [HLS 200-1510] Running: source G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray/solution2/csim.tcl INFO: [HLS 200-1510] Running: open_project SmoothProfileOnXAxisMean_NoGray INFO: [HLS 200-10] Opening project 'G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray'. INFO: [HLS 200-1510] Running: set_top SmoothProfileOnXAxisMean INFO: [HLS 200-1510] Running: add_files SmoothProfileOnXAxisMean.cpp WARNING: [HLS 200-40] Cannot find design file 'SmoothProfileOnXAxisMean.cpp' INFO: [HLS 200-1510] Running: add_files SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.h INFO: [HLS 200-10] Adding design file 'SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.h' to the project INFO: [HLS 200-1510] Running: add_files -tb SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean_test.cpp -cflags -Wno-unknown-pragmas INFO: [HLS 200-10] Adding test bench file 'SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean_test.cpp' to the project INFO: [HLS 200-1510] Running: open_solution solution2 -flow_target vivado INFO: [HLS 200-10] Opening solution 'G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray/solution2'. INFO: [SYN 201-201] Setting up clock 'default' with a period of 5ns. INFO: [SYN 201-201] Setting up clock 'default' with an uncertainty of 0.35ns. INFO: [HLS 200-1611] Setting target device to 'xcku060-ffva1156-2-e' INFO: [HLS 200-1505] Using flow_target 'vivado' Resolution: For help on HLS 200-1505 see docs.xilinx.com/access/sources/dita/topic?Doc_Version=2023.2%20English&url=ug1448-hls-guidance&resourceid=200-1505.html INFO: [HLS 200-1464] Running solution command: config_export -display_name=SmoothProfileOnXAxisMean INFO: [HLS 200-1464] Running solution command: config_export -format=ip_catalog INFO: [HLS 200-1464] Running solution command: config_export -library=KU060_200M_II1_NoGray_WIN33_250721 INFO: [HLS 200-1464] Running solution command: config_export -output=D:/HLS/SmoothProfileOnXAxisMean INFO: [HLS 200-1464] Running solution command: config_export -rtl=verilog INFO: [HLS 200-1464] Running solution command: config_export -vendor=WEIGUO INFO: [HLS 200-1464] Running solution command: config_export -version=2.5 INFO: [HLS 200-1464] Running solution command: config_cosim -tool=xsim INFO: [HLS 200-1510] Running: set_part xcku060-ffva1156-2-e INFO: [HLS 200-1510] Running: create_clock -period 5 -name default INFO: [HLS 200-1510] Running: config_export -display_name SmoothProfileOnXAxisMean -format ip_catalog -library KU060_200M_II1_NoGray_WIN33_250721 -output D:/HLS/SmoothProfileOnXAxisMean -rtl verilog -vendor WEIGUO -version 2.5 INFO: [HLS 200-1510] Running: config_cosim -tool xsim INFO: [HLS 200-1510] Running: set_clock_uncertainty 0.35 INFO: [HLS 200-1510] Running: source ./SmoothProfileOnXAxisMean_NoGray/solution2/directives.tcl INFO: [HLS 200-1510] Running: set_directive_top -name SmoothProfileOnXAxisMean SmoothProfileOnXAxisMean INFO: [HLS 200-1510] Running: csim_design -quiet INFO: [SIM 211-2] *************** CSIM start *************** INFO: [SIM 211-4] CSIM will launch GCC as the compiler. INFO: [HLS 200-2036] Building debug C Simulation binaries Compiling ../../../src/SmoothProfileOnXAxisMean_test.cpp in debug mode Generating csim.exe Makefile.rules:317: recipe for target 'csim.exe' failed In file included from D:/vitis202302/Vitis_HLS/2023.2/include/floating_point_v7_1_bitacc_cmodel.h:150:0, from D:/vitis202302/Vitis_HLS/2023.2/include/hls_fpo.h:140, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/hls_half_fpo.h:19, from D:/vitis202302/Vitis_HLS/2023.2/include/hls_half.h:26, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_private.h:52, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_common.h:666, from D:/vitis202302/Vitis_HLS/2023.2/include/ap_int.h:10, from ../../../src/SmoothProfileOnXAxisMean.h:3, from ../../../src/SmoothProfileOnXAxisMean_test.cpp:3: D:/vitis202302/Vitis_HLS/2023.2/include/gmp.h:58:0: warning: "__GMP_LIBGMP_DLL" redefined #define __GMP_LIBGMP_DLL 0 In file included from D:/vitis202302/Vitis_HLS/2023.2/include/hls_fpo.h:140:0, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/hls_half_fpo.h:19, from D:/vitis202302/Vitis_HLS/2023.2/include/hls_half.h:26, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_private.h:52, from D:/vitis202302/Vitis_HLS/2023.2/include/etc/ap_common.h:666, from D:/vitis202302/Vitis_HLS/2023.2/include/ap_int.h:10, from ../../../src/SmoothProfileOnXAxisMean.h:3, from ../../../src/SmoothProfileOnXAxisMean_test.cpp:3: D:/vitis202302/Vitis_HLS/2023.2/include/floating_point_v7_1_bitacc_cmodel.h:142:0: note: this is the location of the previous definition #define __GMP_LIBGMP_DLL 1 obj/SmoothProfileOnXAxisMean_test.o: In function `main': G:\vitis2023_project\SmoothProfileOnXAxisMean_NoGray\solution2\csim\build/../../../src/SmoothProfileOnXAxisMean_test.cpp:59: undefined reference to `SmoothProfileOnXAxisMean(hls::stream<float, 0>&, hls::stream<float, 0>&, ap_uint<6>, float)' collect2.exe: error: ld returned 1 exit status make: *** [csim.exe] Error 1 ERROR: [SIM 211-100] 'csim_design' failed: compilation error(s). INFO: [SIM 211-3] *************** CSIM finish *************** INFO: [HLS 200-111] Finished Command csim_design CPU user time: 0 seconds. CPU system time: 0 seconds. Elapsed time: 2.536 seconds; current allocated memory: 0.371 MB. 4 while executing "source G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray/solution2/csim.tcl" invoked from within "hls::main G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray/solution2/csim.tcl" ("uplevel" body line 1) invoked from within "uplevel 1 hls::main {*}$newargs" (procedure "hls_proc" line 16) invoked from within "hls_proc [info nameofexecutable] $argv" INFO: [HLS 200-112] Total CPU user time: 1 seconds. Total CPU system time: 0 seconds. Total elapsed time: 4.239 seconds; peak allocated memory: 199.672 MB. Finished C simulation.
07-23
<think>我们遇到了一个HLS C仿真失败的问题。错误信息显示在链接阶段出现了未定义的引用: `undefined reference to 'SmoothProfileOnXAxisMean(hls::stream<float, 0>&, hls::stream<float, 0>&, ap_uint<6>, float)'` 这个错误通常发生在函数的声明和定义不一致,或者没有将定义文件加入到测试中。 观察错误信息: - 测试文件 `SmoothProfileOnXAxisMean_test.cpp` 中调用了函数 `SmoothProfileOnXAxisMean`,但是链接器找不到其定义。 查看项目设置: - 我们添加了头文件 `SmoothProfileOnXAxisMean.h`,但是并没有添加包含函数定义的源文件(如.cpp文件)。 - 在之前的命令中,有一个警告:`WARNING: [HLS 200-40] Cannot find design file 'SmoothProfileOnXAxisMean.cpp'`,说明设计文件(.cpp)没有找到。 因此,问题在于:我们只添加了头文件,而没有添加实现文件(.cpp)。在HLS项目中,设计文件(即函数的实现)必须被添加到项目中。 解决方案: 1. 确保 `SmoothProfileOnXAxisMean.cpp` 文件存在于项目中,并且路径正确。 2. 使用 `add_files` 命令将 `.cpp` 文件添加到设计文件中。 修改步骤: 在 `csim.tcl` 脚本中,应该添加设计源文件(.cpp)而不仅仅是头文件。例如: ``` add_files SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.cpp ``` 但是,从错误信息中我们看到,在添加设计文件时出现了警告,提示找不到 `SmoothProfileOnXAxisMean.cpp`。所以我们需要检查文件路径是否正确。 项目结构假设: - 项目位于 `G:/vitis2023_project/SmoothProfileOnXAxisMean_NoGray/` - 源文件可能在 `src` 子目录下:`SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.cpp` 因此,在Tcl脚本中,应该使用正确的路径添加设计文件。 另外,在测试文件中,我们包含了头文件,但是测试文件本身不会包含函数实现,所以必须将实现文件编译并链接。 重新检查Tcl脚本中的命令: - 我们添加了头文件(这通常是不必要的,因为头文件会被源文件包含),但没有添加源文件。 所以,我们需要将 `add_files SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.h` 改为添加源文件(.cpp),或者同时添加源文件和头文件(但头文件不是必须添加的,除非它被用于测试)。 但是,请注意,HLS的 `add_files` 命令用于添加设计文件(即要综合的源文件),而测试文件用 `add_files -tb` 添加。 因此,正确的步骤应该是: - 使用 `add_files` 添加设计源文件(.cpp) - 使用 `add_files -tb` 添加测试文件(.cpp) 修改后的Tcl命令可能如下: ``` add_files SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.cpp add_files -tb SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean_test.cpp ``` 但是,请注意,我们之前已经添加了一个头文件,这可能导致问题?实际上,头文件不需要通过`add_files`添加,它会被源文件包含。所以我们可以移除添加头文件的命令。 总结: 1. 移除添加头文件的命令(因为头文件会被源文件包含,不需要单独添加)。 2. 添加设计源文件(.cpp)。 3. 确保测试文件被正确添加为测试文件(使用`-tb`选项)。 因此,Tcl脚本中应该有以下命令: ``` # 添加设计文件(综合的源文件) add_files SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.cpp # 添加测试文件 add_files -tb SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean_test.cpp ``` 另外,在测试文件中,确保包含了正确的头文件,并且函数声明与定义一致。 如果路径不正确,请根据实际路径调整。 注意:在HLS中,设计文件(如.cpp)和测试文件(如_test.cpp)是分开的。设计文件会被综合,测试文件用于验证。 修改后重新运行C仿真。 如果问题仍然存在,请检查: - 函数在头文件中的声明与在源文件中的定义是否一致(包括命名空间、参数列表等)。 - 源文件中是否包含了对应的头文件(例如,在.cpp文件中:`#include "SmoothProfileOnXAxisMean.h"`)。 示例头文件内容(SmoothProfileOnXAxisMean.h)可能如下: ```cpp #ifndef SMOOTHPROFILEONXAXISMEAN_H #define SMOOTHPROFILEONXAXISMEAN_H #include <ap_int.h> #include <hls_stream.h> void SmoothProfileOnXAxisMean(hls::stream<float>& points_in_z, hls::stream<float>& smoothed_z, ap_uint<6> mean_win_size, float invalid_z); #endif ``` 源文件(SmoothProfileOnXAxisMean.cpp)应该包含这个头文件,并实现函数。 如果头文件中使用了`hls::stream`,注意在测试文件中也要包含相同的头文件,并且使用相同的流类型。 另外,注意测试文件中调用的函数参数类型必须与定义一致。错误信息中显示的函数参数类型为`hls::stream<float, 0>&`,而在头文件中声明的是`hls::stream<float>&`。实际上,`hls::stream<float>`是模板别名,可能定义为`hls::stream<float, 0>`,所以应该一致。但为了安全,最好在声明和定义中都使用相同的方式。 通常,我们这样声明流:`hls::stream<float>`,它等价于`hls::stream<float, 0>`(默认深度0表示使用默认深度)。 因此,如果头文件声明和源文件定义一致,那么测试文件中也应该包含相同的头文件,这样函数原型就一致了。 所以,请确保测试文件中包含了头文件`SmoothProfileOnXAxisMean.h`,这样测试文件中的函数调用就会使用正确的声明。 总结步骤: 1. 在Tcl脚本中正确添加设计源文件(.cpp)和测试文件(_test.cpp)。 2. 确保头文件中的函数声明和源文件中的定义一致。 3. 确保测试文件包含了头文件。 修改后重新运行C仿真。</think># HLS C仿真失败问题分析与解决方案 从您提供的HLS C仿真日志来看,主要问题是在链接阶段出现了未定义引用错误。让我们详细分析问题原因并提供解决方案: ## 错误分析 ### 核心错误信息 ```log undefined reference to `SmoothProfileOnXAxisMean(hls::stream<float, 0>&, hls::stream<float, 0>&, ap_uint<6>, float)' collect2.exe: error: ld returned 1 exit status make: *** [csim.exe] Error 1 ERROR: [SIM 211-100] 'csim_design' failed: compilation error(s). ``` ### 问题原因 1. **函数实现缺失**: - 测试文件 `SmoothProfileOnXAxisMean_test.cpp` 引用了 `SmoothProfileOnXAxisMean` 函数 - 但项目中只添加了头文件(`.h`),没有添加实现文件(`.cpp`) - 导致链接器找不到函数实现 2. **文件路径问题**: ```log WARNING: [HLS 200-40] Cannot find design file 'SmoothProfileOnXAxisMean.cpp' ``` - HLS找不到指定的实现文件 - 可能是路径错误或文件不存在 3. **项目配置问题**: - 只添加了头文件,没有添加实现文件 - 测试文件没有正确链接到函数实现 ## 解决方案 ### 1. 添加实现文件到项目 修改Tcl脚本,确保添加了头文件和实现文件: ```tcl # 修改后的csim.tcl open_project SmoothProfileOnXAxisMean_NoGray set_top SmoothProfileOnXAxisMean # 添加头文件和实现文件 add_files SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.h add_files SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean.cpp # 添加测试文件 add_files -tb SmoothProfileOnXAxisMean_NoGray/src/SmoothProfileOnXAxisMean_test.cpp -cflags -Wno-unknown-pragmas # 其余配置保持不变 open_solution solution2 -flow_target vivado set_part xcku060-ffva1156-2-e create_clock -period 5 -name default # ... 其他配置 csim_design -clean ``` ### 2. 检查文件路径和命名 确保文件结构和命名正确: ``` 项目根目录/ ├── SmoothProfileOnXAxisMean_NoGray/ │ ├── src/ │ │ ├── SmoothProfileOnXAxisMean.h # 头文件 │ │ ├── SmoothProfileOnXAxisMean.cpp # 实现文件 │ │ └── SmoothProfileOnXAxisMean_test.cpp # 测试文件 │ └── solution2/ │ └── csim.tcl # Tcl脚本 ``` ### 3. 实现文件示例 确保 `SmoothProfileOnXAxisMean.cpp` 包含函数实现: ```cpp #include "SmoothProfileOnXAxisMean.h" void SmoothProfileOnXAxisMean(hls::stream<float>& points_in_z, hls::stream<float>& smoothed_z, ap_uint<6> mean_win_size, float invalid_z) { // 函数实现代码 // ... } ``` ### 4. 测试文件修改 在测试文件中包含正确的头文件: ```cpp // SmoothProfileOnXAxisMean_test.cpp #include <iostream> #include <hls_stream.h> #include "SmoothProfileOnXAxisMean.h" // 确保包含正确的头文件 int main() { hls::stream<float> input; hls::stream<float> output; ap_uint<6> win_size = 5; float invalid = -1.0f; // 填充测试数据 for (int i = 0; i < 3200; i++) { input.write(i % 100 * 1.0f); // 示例数据 } // 调用设计函数 SmoothProfileOnXAxisMean(input, output, win_size, invalid); // 验证输出 // ... return 0; } ``` ## HLS项目配置最佳实践 ### 1. 标准项目结构 ``` project/ ├── src/ │ ├── design.h │ ├── design.cpp │ └── testbench.cpp ├── solution1/ │ └── directives.tcl └── csim.tcl ``` ### 2. 完整Tcl脚本示例 ```tcl # csim.tcl open_project my_project set_top my_top_function # 添加设计文件 add_files src/design.cpp add_files src/design.h # 添加测试文件 add_files -tb src/testbench.cpp # 解决方案配置 open_solution solution1 set_part {xcku060-ffva1156-2-e} create_clock -period 5 -name default # 综合和仿真配置 config_export -format ip_catalog -rtl verilog config_cosim -tool xsim # 运行C仿真 csim_design -clean ``` ### 3. 常见错误处理 | 错误类型 | 原因 | 解决方案 | |---------|------|---------| | 未定义引用 | 函数实现缺失 | 添加.cpp文件到项目 | | 文件未找到 | 路径错误 | 使用相对路径或完整路径 | | 类型不匹配 | 头文件不一致 | 确保声明和定义一致 | | 链接错误 | 缺少库 | 添加`-l`链接选项 | ## 验证步骤 1. 确保所有文件存在且路径正确 2. 运行修改后的Tcl脚本: ``` vitis_hls -f csim.tcl ``` 3. 检查输出日志,确认没有错误: ```log INFO: [SIM 211-1] CSim done with 0 errors. INFO: [SIM 211-3] *************** CSIM finish *************** ``` ## 总结 您遇到的HLS C仿真失败问题主要是由于: 1. 实现文件(`.cpp`)未添加到项目中 2. 文件路径配置不正确 3. 测试文件与设计文件链接失败 通过以下步骤解决: 1. 将实现文件添加到Tcl脚本 2. 验证文件路径和命名 3. 确保头文件和实现文件中的函数签名一致 4. 使用正确的测试文件配置
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值