<commit_before>package compiler

import (
	"fmt"
	"io"
	"strconv"

	"github.com/PuerkitoBio/agora/bytecode"
)

var (
	maj, min      = bytecode.Version()
	disasmComment = fmt.Sprintf("// Generated from the disassembler, v%d.%d", maj, min)
)

// A Disasm translates a bytecode representation into assembly source code.
type Disasm struct {
	w   io.Writer
	err error
}

// ToAsm takes the in-memory bytecode File structure and translates it to
// assembly source code, writing the results to the provided writer. If an
// error is encountered, it is returned, otherwise it returns nil.
func (d *Disasm) ToAsm(f *bytecode.File, w io.Writer) error {
	d.w = w
	d.err = nil
	// 1- Write the standard comment
	d.write(disasmComment, true)
	// 2- Write every function
	for _, fn := range f.Fns {
		d.write("[f]", true)
		d.write(fn.Header.Name, true)
		d.write(fn.Header.StackSz, true)
		d.write(fn.Header.ExpArgs, true)
		d.write(fn.Header.ExpVars, true)
		d.write(fn.Header.LineStart, true)
		d.write(fn.Header.LineEnd, true)

		// 3- Write the function's K section
		d.write("[k]", true)
		for _, k := range fn.Ks {<commit_msg>if func name is empty, save it to asm as <anon><commit_after>package compiler

import (
	"fmt"
	"io"
	"strconv"

	"github.com/PuerkitoBio/agora/bytecode"
)

var (
	maj, min      = bytecode.Version()
	disasmComment = fmt.Sprintf("// Generated from the disassembler, v%d.%d", maj, min)
)

// A Disasm translates a bytecode representation into assembly source code.
type Disasm struct {
	w   io.Writer
	err error
}

// ToAsm takes the in-memory bytecode File structure and translates it to
// assembly source code, writing the results to the provided writer. If an
// error is encountered, it is returned, otherwise it returns nil.
func (d *Disasm) ToAsm(f *bytecode.File, w io.Writer) error {
	d.w = w
	d.err = nil
	// 1- Write the standard comment
	d.write(disasmComment, true)
	// 2- Write every function
	for _, fn := range f.Fns {
		d.write("[f]", true)
		// If the func name is empty, set it to <anon>
		if fn.Header.Name == "" {
			d.write("<anon>", true)
		} else {
			d.write(fn.Header.Name, true)
		}
		d.write(fn.Header.StackSz, true)
		d.write(fn.Header.ExpArgs, true)
		d.write(fn.Header.ExpVars, true)
		d.write(fn.Header.LineStart, true)
		d.write(fn.Header.LineEnd, true)

		// 3- Write the function's K section
		d.write("[k]", true)
		for _, k := range fn.Ks {
{'fraction_non_alphanumeric': 0.1327212020033389, 'fraction_numerical': 0.0025041736227045075, 'mean_word_length': 3.342391304347826, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5856179', 'n_tokens_mistral': 902, 'n_tokens_neox': 854, 'n_words': 271}