package emit import ( "git.smesh.lol/moxie/pkg/syntax" "git.smesh.lol/moxie/pkg/ssa" "git.smesh.lol/moxie/pkg/types" ) var parseErrors []string var compileErrors []string var genericFuncDecls map[string]*syntax.FuncDecl var genericPkgScopes map[string]*types.Scope type irEmitter struct { buf []byte triple string ptrBits int32 pkg *ssa.SSAPackage valName map[ssa.SSAValue]string nextReg int32 extDecls map[string]string extGlobals map[string]string strConst []string strMap map[string]int32 curFunc *ssa.SSAFunction typeIDs map[string]int32 typeIDNext int32 extTypeIDs map[string]bool localTypeIDs map[string]bool allocTypes map[ssa.SSAValue]string regTypes map[string]string hoisted map[ssa.SSAValue]bool blockExitLabel map[int32]string nameUsed map[string]bool missingStores map[ssa.SSAValue]ssa.SSAValue globalTypes map[string]string globalDeclTypes map[string]string sortedMembers []ssa.SSAMember loadToGlobal map[string]*ssa.SSAGlobal allocBlock map[ssa.SSAValue]int32 storedTo map[string]bool usedAs map[string]bool deferList []*ssa.SSADefer deferID int32 deallocActive bool deallocAllocs map[ssa.SSAValue]int32 deallocCount int32 scopeAllocs map[int32][]string instrScope map[ssa.SSAInstruction]int32 scopeActive bool } func sortedKeys(m map[string]bool) []string { var keys []string for k := range m { keys = append(keys, k) } for i := 1; i < len(keys); i++ { for j := i; j > 0 && keys[j] < keys[j-1]; j-- { keys[j], keys[j-1] = keys[j-1], keys[j] } } return keys } func newIREmitter(pkg *ssa.SSAPackage, triple string) *irEmitter { ptrBits := 64 if len(triple) >= 4 && triple[:4] == "wasm" { ptrBits = 32 } return &irEmitter{ buf: []byte{:0:4096}, triple: triple, ptrBits: ptrBits, pkg: pkg, valName: map[ssa.SSAValue]string{}, extDecls: map[string]string{}, extGlobals: map[string]string{}, strMap: map[string]int32{}, allocTypes: map[ssa.SSAValue]string{}, regTypes: map[string]string{}, blockExitLabel: map[int32]string{}, nameUsed: map[string]bool{}, } } func (e *irEmitter) dataLayout() string { if len(e.triple) >= 6 && e.triple[:6] == "x86_64" { return "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" } if len(e.triple) >= 7 && e.triple[:7] == "aarch64" { return "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" } if len(e.triple) >= 6 && e.triple[:6] == "wasm32" { return "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" } if len(e.triple) >= 3 && e.triple[:3] == "arm" { return "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" } return "" } func (e *irEmitter) w(s string) { e.buf = append(e.buf, s...) }