Skip to content

Latest commit

 

History

History
410 lines (320 loc) · 13.9 KB

File metadata and controls

410 lines (320 loc) · 13.9 KB

SWFRecomp: Differences Between wasm-support and master Branches

Overview

The wasm-support branch contains significant enhancements to the SWFRecomp project, adding WebAssembly build support, improved documentation, better build automation, and enhanced ActionScript variable handling. This document comprehensively lists all differences between the two branches.

Note: This document was updated on 2025-11-02 to reflect the current state of the branches. The wasm-hello-world example files and docs/ directory (GitHub Pages) were moved to SWFRecompDocs and are no longer part of this diff.

Statistics:

  • 24 files changed
  • 1,848 insertions (+)
  • 72 deletions (-)
  • 18 commits ahead of master

Commit History

The wasm-support branch includes 18 commits beyond master:

  1. 7dc144c - cleanup documentation and build artifacts
  2. 9ba9419 - variable optimization
  3. 961031e - updated next steps doc
  4. 21ee82e - added two more docs
  5. f624fb6 - Implement StringAdd variable storage with Copy-on-Store
  6. 00b9801 - added STRING_VARIABLE_STORAGE_PLAN.md
  7. ecbce76 - corrected several details in the documents
  8. e285712 - added 2 font planning docs
  9. 2ade8d6 - minor document updates
  10. 03905a5 - added AS3_TEST_SWF_GENERATION_GUIDE.md
  11. 15edc43 - added ABC_PARSER_RESEARCH.md and ABC_IMPLEMENTATION_INFO.md
  12. bf32dfe - added ABC_PARSER_GUIDE.md
  13. f51802a - added 2 more planning docs, deprecated most of the old docs
  14. abaa0e5 - added 3 more planning docs
  15. 41e103f - added 5 more planning docs
  16. cf3892a - added AS3_IMPLEMENTATION_PLAN.md
  17. 8fef768 - initial commit for this fork

Major Changes by Category

1. Documentation (README.md)

Complete rewrite of the main README - transformed from a casual/experimental tone to professional project documentation.

Key Changes:

  • Project Description: Changed from "This is a stupid idea" to a proper technical description explaining it's a static recompiler for Flash SWF files
  • Added Live Demo Link: https://swfrecomp.github.io/SWFRecompDocs/
  • Added Comprehensive Sections:
    • What is This? (explains static recompilation concept)
    • Documentation (links to all guides)
    • Quick Start (prerequisites, build instructions, examples)
    • Project Structure (directory layout)
    • How It Works (detailed workflow diagram)
    • Current Features (feature status table)
    • Related Projects (links to SWFModernRuntime, N64Recomp)
    • Legal Note (Adobe Open Screen Project info)

New Features Documented:

  • Improved build system with automated builds
  • Better project structure with clean separation
  • Enhanced documentation with complete guides
  • WebAssembly examples that run in browser

Documentation Improvements:

  • Added step-by-step build instructions for both native and WASM
  • Added complete example workflow (from SWF to WASM)
  • Added visual workflow diagram showing compilation pipeline
  • Added feature status table
  • Added links to related projects

Tone Change:

  • From: Casual, self-deprecating ("This is a stupid idea. Let's do it anyway")
  • To: Professional, technical, comprehensive project documentation

Size: README grew from ~100 lines to ~266 lines

Note: The README references live demos at https://swfrecomp.github.io/SWFRecompDocs/ - these demo files are hosted in the SWFRecompDocs repository, not in SWFRecomp.

2. Core ActionScript Implementation Changes (src/action/action.cpp)

Major Enhancements to Variable Handling:

2.1 String Deduplication System

Added:

  • std::map<std::string, size_t> string_to_id - Tracks declared strings to prevent duplicates
  • getStringId() method - Retrieves ID for previously declared strings
  • Deduplication logic in declareString():
    auto it = string_to_id.find(str);
    if (it != string_to_id.end()) {
        // String already exists - don't create duplicate
        return;
    }

Benefits:

  • Eliminates duplicate string constants in generated C code
  • Reduces memory footprint
  • More efficient code generation

2.2 Simplified Variable Operations

Changed GetVariable implementation:

// OLD:
temp_val = getVariable((char*) STACK_TOP_VALUE, STACK_TOP_N);
POP();
PUSH_VAR(temp_val);

// NEW:
actionGetVariable(stack, sp);

Changed SetVariable implementation:

// OLD:
temp_val = getVariable((char*) STACK_SECOND_TOP_VALUE, STACK_SECOND_TOP_N);
SET_VAR(temp_val, STACK_TOP_TYPE, STACK_TOP_N, STACK_TOP_VALUE);
POP_2();

// NEW:
actionSetVariable(stack, sp);

Benefits:

  • Cleaner generated code
  • Better encapsulation of variable operations
  • Easier to maintain and extend

2.3 Enhanced String Push with ID Tracking

Changed:

// OLD:
PUSH_STR(str_X, length);

// NEW:
PUSH_STR_ID(str_X, length, string_id);

Benefits:

  • Runtime can track string IDs for variable storage
  • Enables more efficient string variable handling
  • Supports Copy-on-Store optimization

2.4 MAX_STRING_ID Constant Generation

Added:

// Generate MAX_STRING_ID constant for runtime initialization
context.out_script_defs << endl << endl
    << "// Maximum string ID for variable array allocation" << endl
    << "#define MAX_STRING_ID " << next_str_i << endl;
context.out_script_decls << endl
    << "#define MAX_STRING_ID " << next_str_i << endl;

Benefits:

  • Runtime knows how many string variables to allocate
  • Enables static array allocation instead of dynamic
  • Better performance and memory management

3. Header Changes (include/action/action.hpp)

Added:

#include <map>  // For string deduplication

// In SWFAction class:
std::map<std::string, size_t> string_to_id;  // Track declared strings
size_t getStringId(const char* str);         // Get ID for previously declared string

4. New Test Cases

4.1 trace_swf_4 Test (Complete WASM Example)

NEW: Complete working example with automated builds

Added files:

  • tests/trace_swf_4/config.toml (4 lines) - Recompiler configuration
  • tests/trace_swf_4/Makefile (62 lines) - Automated native build
  • tests/trace_swf_4/build_wasm.sh (71 lines) - Automated WASM build
  • tests/trace_swf_4/README.md (186 lines) - Complete documentation

Native Runtime:

  • tests/trace_swf_4/runtime/native/include/recomp.h (105 lines)
  • tests/trace_swf_4/runtime/native/include/stackvalue.h (4 lines)
  • tests/trace_swf_4/runtime/native/main.c (6 lines)
  • tests/trace_swf_4/runtime/native/runtime.c (305 lines)

WASM Runtime:

  • tests/trace_swf_4/runtime/wasm/main.c (27 lines)
  • tests/trace_swf_4/runtime/wasm/recomp.h (62 lines)
  • tests/trace_swf_4/runtime/wasm/runtime.c (76 lines)
  • tests/trace_swf_4/runtime/wasm/stackvalue.h (4 lines)
  • tests/trace_swf_4/runtime/wasm/index.html (199 lines)

Features:

  • Complete build automation (no manual file copying)
  • Separate native and WASM runtime implementations
  • Comprehensive documentation
  • Working live demo

4.2 dyna_string_vars_swf_4 Test (Variable Storage)

NEW: Test case for dynamic string variable storage

Added files:

  • tests/dyna_string_vars_swf_4/config.toml (4 lines)
  • tests/dyna_string_vars_swf_4/test_main.c (12 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/include/recomp.h (105 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/include/stackvalue.h (4 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/main.c (6 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/runtime.c (305 lines)

Purpose:

  • Tests dynamic string variable storage
  • Tests Copy-on-Store optimization
  • Validates variable handling improvements

4.3 string_add_to_var_test

NEW: Documentation for string concatenation tests

Added files:

  • tests/string_add_to_var_test/README.md (35 lines)

Purpose:

  • Documents string concatenation behavior
  • Explains variable storage patterns

5. Build System Improvements

5.1 .gitignore Enhancements

Added entries:

NewDocs/
docs/specs/

# Temporary files
COMMIT_MESSAGE.txt

# Test executables
test_vars

Purpose:

  • Ignore documentation drafts
  • Ignore downloaded specifications
  • Ignore build artifacts
  • Ignore temporary files

5.2 Automated Build Scripts

trace_swf_4/Makefile Features:

  • Clean separation of source and build directories
  • Automatic directory creation
  • Native compilation with gcc
  • Proper dependency tracking
  • Clean target for rebuild

trace_swf_4/build_wasm.sh Features:

  • Emscripten environment setup
  • WASM compilation with emcc
  • Automatic file organization
  • HTML/JS generation
  • Output bundling for deployment

Benefits:

  • No manual file copying required
  • Reproducible builds
  • Clear build process
  • Easy deployment to GitHub Pages

File-by-File Summary

Modified Files (4 files)

  1. README.md

    • Complete rewrite: casual � professional
    • Added: Quick start, documentation, examples, diagrams
    • Size: ~100 lines � 266 lines
    • +204 lines, -20 lines
  2. .gitignore

    • Added: NewDocs/, docs/specs/, COMMIT_MESSAGE.txt, test_vars
    • +8 lines
  3. include/action/action.hpp

    • Added: std::map for string deduplication
    • Added: getStringId() method
    • +7 lines, -1 line
  4. src/action/action.cpp

    • Added: String deduplication system
    • Changed: GetVariable/SetVariable to use action functions
    • Changed: PUSH_STR � PUSH_STR_ID with ID tracking
    • Added: MAX_STRING_ID constant generation
    • +62 lines, -38 lines

New Files (20 files)

trace_swf_4 Test (13 files):

  • tests/trace_swf_4/config.toml (4 lines)
  • tests/trace_swf_4/Makefile (62 lines)
  • tests/trace_swf_4/build_wasm.sh (71 lines)
  • tests/trace_swf_4/README.md (186 lines)
  • tests/trace_swf_4/runtime/native/include/recomp.h (105 lines)
  • tests/trace_swf_4/runtime/native/include/stackvalue.h (4 lines)
  • tests/trace_swf_4/runtime/native/main.c (6 lines)
  • tests/trace_swf_4/runtime/native/runtime.c (305 lines)
  • tests/trace_swf_4/runtime/wasm/main.c (27 lines)
  • tests/trace_swf_4/runtime/wasm/recomp.h (62 lines)
  • tests/trace_swf_4/runtime/wasm/runtime.c (76 lines)
  • tests/trace_swf_4/runtime/wasm/stackvalue.h (4 lines)
  • tests/trace_swf_4/runtime/wasm/index.html (199 lines)

dyna_string_vars_swf_4 Test (6 files):

  • tests/dyna_string_vars_swf_4/config.toml (4 lines)
  • tests/dyna_string_vars_swf_4/test_main.c (12 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/include/recomp.h (105 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/include/stackvalue.h (4 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/main.c (6 lines)
  • tests/dyna_string_vars_swf_4/runtime/native/runtime.c (305 lines)

string_add_to_var_test (1 file):

  • tests/string_add_to_var_test/README.md (35 lines)

Technical Improvements Summary

1. Code Quality

  • String Deduplication: Eliminates duplicate string constants
  • Cleaner Generated Code: Simplified variable operations
  • Better Encapsulation: Action functions instead of inline operations

2. Build System

  • Automated Builds: Makefile + build scripts
  • No Manual Steps: All file copying automated
  • Reproducible: Same results every time
  • Multi-Target: Native + WASM from same source

3. Documentation

  • Professional README: Complete project overview
  • Live Demos: Working examples in browser
  • Comprehensive Guides: Step-by-step instructions
  • Better Structure: Clear organization

4. WASM Support

  • Complete Pipeline: SWF � C � WASM
  • Working Examples: trace_swf_4 demo
  • Browser Integration: HTML + JavaScript interface
  • Deployment Ready: GitHub Pages compatible

5. Testing Infrastructure

  • Multiple Test Cases: trace_swf_4, dyna_string_vars_swf_4, string_add_to_var_test
  • Dual Runtimes: Native and WASM variants
  • Comprehensive Tests: Console output, variable storage, string operations

6. Variable Storage Optimization

  • Copy-on-Store: Efficient string variable handling
  • ID Tracking: Runtime can identify string literals
  • Static Allocation: MAX_STRING_ID enables fixed-size arrays
  • Memory Efficiency: Reduced allocations and copying

Impact Assessment

Compatibility

  • Backward Compatible: No breaking changes to master functionality
  • Additive Only: All changes are additions or improvements
  • Optional WASM: Native builds still work exactly as before

Performance

  • String Deduplication: Reduces code size and memory usage
  • Optimized Variables: Copy-on-Store reduces string copying
  • Static Allocation: MAX_STRING_ID enables compile-time sizing

Maintainability

  • Better Organization: Clear project structure
  • Comprehensive Docs: Easy for new contributors
  • Automated Testing: Build scripts make testing easier
  • Cleaner Code: Better encapsulation and separation

Usability

  • GitHub Pages: Live demos attract users
  • Quick Start: Easy to try out the project
  • Examples: Multiple working examples to learn from
  • Documentation: Complete guides for all workflows

Summary

The wasm-support branch represents a significant maturation of the SWFRecomp project:

  1. Professional Documentation: Transformed from experimental project to production-ready
  2. WebAssembly Support: Complete pipeline from SWF to browser-runnable WASM
  3. Build Automation: No manual steps, reproducible builds
  4. Code Quality: String deduplication, cleaner variable handling, better encapsulation
  5. Live Demos: Working examples accessible via GitHub Pages
  6. Testing Infrastructure: Multiple test cases with dual runtime support
  7. Developer Experience: Comprehensive guides, clear structure, easy to contribute

Total Changes:

  • 24 files changed (4 modified, 20 added)
  • 1,848 additions
  • 72 deletions
  • 18 commits

Key Achievement: Successfully demonstrates SWF → C → WASM pipeline with live demo at https://swfrecomp.github.io/SWFRecompDocs/ (demos hosted in SWFRecompDocs repository)

This branch is ready for merging into master and represents the project's evolution from proof-of-concept to a viable tool for Flash preservation through static recompilation.