diff --git a/.gitignore b/.gitignore index ae5b56dd..ead2de09 100644 --- a/.gitignore +++ b/.gitignore @@ -42,9 +42,10 @@ cbqn-jit.bqn /local/ perf.data* -# clangd +# clangd / compile commands compile_commands.json .cache/ +.singeli_compile_commands.json # things not used anymore, but still may be present in existing clones /SingeliClone/ diff --git a/build/src/build.bqn b/build/src/build.bqn index 898ab733..ae25e97f 100644 --- a/build/src/build.bqn +++ b/build/src/build.bqn @@ -689,10 +689,10 @@ AddRule ← { 𝕊 cache‿cacheKey‿dst‿GetCMD‿disp‿deps: res } -clangd ← {¬po.clangd? {_add⇐{𝕨𝔽_𝕣𝕩:@} ⋄ Files⇐⊣}; ⟨AtRoot⟩ •Import "clangd.bqn"} +clangd ← {¬po.clangd? {_addC⇐{𝕨𝔽_𝕣𝕩:@} ⋄ AddSingeli⇐{𝕊:@} ⋄ SingeliInit⇐⊢ ⋄ CFiles⇐⊣}; ⟨AtRoot⟩ •Import "clangd.bqn"} MakeCCInv ← { 𝕊 GetArgs‿Init‿cache‿id‿src‿customDeps: # src should be CBQN-base-dir-relative, so that cache doesn't store full paths - GetArgs clangd._add src + GetArgs clangd._addC src dst ← cache.File id∾".o" GetCMD ← { 𝕊: Init @ @@ -703,6 +703,7 @@ MakeCCInv ← { 𝕊 GetArgs‿Init‿cache‿id‿src‿customDeps: # src shoul } MakeSingeliInv ← { 𝕊 args‿Init‿cache‿id‿src‿customDeps: # src should be CBQN-base-dir-relative, so that cache doesn't store full paths + args clangd.AddSingeli src dst ← cache.File id∾".c" GetCMD ← { 𝕊: Init @ @@ -733,7 +734,7 @@ cachedBin‿linkerCache ← { ⟨"src/jit/", "nvm.c"⟩ ⟨"src/utils/", "ryu.c", "utf.c", "hash.c", "file.c", "mut.c", "each.c", "bits.c"⟩ ⟩ - cbqnSrc ↩ cbqnSrc clangd.Files "src" + cbqnSrc ↩ cbqnSrc clangd.CFiles "src" singeliMap ← 1↓¨ ({⊑ ({"X86_64":'x'; "AARCH64":'a'; "RV64":'g'; "NONE":'g'} po.arch) ∊ 𝕩}¨ ⊑¨)⊸/ ⟨ "xa."‿"src/builtins/arithm.c"‿"monarith", "xa."‿"src/builtins/compare.c"‿"equal", "xa."‿"src/builtins/arithd.c"‿"dyarith", "xa."‿"src/builtins/cmp.c"‿"cmp", @@ -781,6 +782,7 @@ cachedBin‿linkerCache ← { (⊑"slow-pdep"<⊸∊ po.has) / ⟨"-c", "SLOW_PDEP=1"⟩ {po.native? ⟨⟩; "-a" ⋈ 1↓∾ ','⊸∾¨ po.singeliArch} ⟩ + clangd.SingeliInit ⟨po.singeliDir, po.arch⟩ {𝕊: "Singeli args: "∾•Repr singeliArgs} _verboseLog @ {𝕊: "Singeli-determined C arch: "∾•Repr po.singeliCFlags; @} _verboseLog @ singeliObjs ↩ {MakeSingeliInv ⟨singeliArgs, {𝕊:UpdateSubmodule po.singeliDir}, singeliCache, 𝕩, "src/singeli/src/"•file.At 𝕩∾".singeli", (𝕩≡"dyarith")/⟨gaRule⟩⟩}¨ 1⊑¨singeliMap diff --git a/build/src/clangd.bqn b/build/src/clangd.bqn index 8e1ef76a..3a5339a4 100644 --- a/build/src/clangd.bqn +++ b/build/src/clangd.bqn @@ -6,21 +6,39 @@ Esc←{ 𝕩 ↩ i ⊏⟜out⌾((i<≠out)⊸/) 𝕩 # Replace ∾(i<≠in) /⟜"\"⊸∾¨ 𝕩 # Insert \ } -n←@+10 +lf←@+10 JStr ← {∾⟨"""",Esc 𝕩,""""⟩} -JArr ← {'['∾']'∾˜2↓∾𝕨⊸∾¨ 𝕩} -JObj ← {∾⟨'{',n,¯2↓∾(JStr¨𝕨) {∾⟨" ",𝕨,": ",𝕩,',',n⟩}¨ 𝕩, n,'}'⟩} +JArr ← {'['∾']'∾˜ (≠𝕨) ↓ ∾ 𝕨⊸∾¨ 𝕩} +JObj ← {∾⟨'{',lf,¯2↓∾(JStr¨𝕨) {∾⟨" ",𝕨,": ",𝕩,',',lf⟩}¨ 𝕩, lf,'}'⟩} precompFiles ← ⥊"bytecodeLocal"‿"bytecodeSubmodule" {∾⟨"../build/",𝕨,"/gen/",𝕩⟩}⌜ "compiles"‿"explain"‿"formatter"‿"runtime0"‿"runtime1"‿"runtime1x" -Files ⇐ { +RecursiveFiles ⇐ { res ← ⟨⟩ {'d'=•file.Type AtRoot 𝕩? 𝕊¨ 𝕩⊸•file.At¨ •file.List AtRoot 𝕩; res∾↩ <𝕩} 𝕩 - {⊑(<¯2↑𝕩)∊".c"‿".h"}¨⊸/ res + res +} + +CFiles ⇐ { + res ← RecursiveFiles 𝕩 + res {⊑(<¯2↑𝕩)∊".c"‿".h"}¨⊸/↩ res ∾ 𝕩⊸•file.At¨ precompFiles } +cObjects ← ⟨⟩ +_addC ⇐ {cObjects∾↩ <⟨𝕩, (𝔽@)∾<𝕩⟩} + +singeliState ← @ +singeliObjects ← ⟨⟩ +AddSingeli ⇐ { + singeliObjects∾↩ <𝕨‿𝕩 +} +SingeliInit ⇐ { + singeliState ↩ 𝕩 +} + + ModifyCBQNFlags ← { filenames ← 4↓¨ ⊑¨ 𝕩 flagK←⟨⟩ @@ -87,24 +105,35 @@ ModifyCBQNFlags ← { 𝕩 {n‿f 𝕊 f2: ⟨n, f∾⟨"-Wno-undefined-internal", "-DCLANGD"⟩∾f2⟩}¨ (gfk⊐•file.At¨ filenames)⊏gfv ∾ <⟨⟩ } -objects ← ⟨⟩ Finish ⇐ { 𝕊 write: - objects ModifyCBQNFlags⌾(({"src/"≡4↑⊑𝕩}¨ objects)⊸/)↩ - FileObj ← { name‿flags: - "file"‿"directory"‿"arguments" JObj ⟨JStr name, JStr AtRoot "", ", " JArr JStr¨ flags⟩ + _doWrite ← { + 𝕩 •FChars⍟write 𝕗 + •Out ∾⟨{write? "Wrote "; "Would write "}, 𝕨, " to ", •file.At 𝕩⟩ } - res ← (","∾n) JArr FileObj¨ objects + TLArr ← (","∾lf)⊸JArr + { - •Out {write? "Removing"; "Would remove"} ∾ " old "∾𝕩 - •file.Remove⍟write 𝕩 - }⍟•file.Exists AtRoot "compile_commands.json" - resPath ← AtRoot "build/compile_commands.json" - { - write? - resPath •FChars res - •Out "Wrote clangd compile commands to "∾•file.At resPath - ; - •Out "Would write clangd compile commands to "∾•file.At resPath + cObjects ModifyCBQNFlags⌾(({"src/"≡4↑⊑𝕩}¨ cObjects)⊸/)↩ + FileObj ← { name‿flags: + "file"‿"directory"‿"arguments" JObj ⟨JStr name, JStr AtRoot "", ", " JArr JStr¨ flags⟩ + } + res ← TLArr FileObj¨ cObjects + { + •Out {write? "Removing"; "Would remove"} ∾ " old "∾𝕩 + •file.Remove⍟write 𝕩 + }⍟•file.Exists AtRoot "compile_commands.json" + + + "clangd compile commands" res _doWrite AtRoot "build/compile_commands.json" } -} -_add ⇐ {objects∾↩ <⟨𝕩, (𝔽@)∾<𝕩⟩} \ No newline at end of file + + { + singeliState≡@? @; + dir‿arch ← singeliState + cmd0 ← ⟨"-a", arch, "-l", "="∾AtRoot dir •file.At "include"⟩ + res ← TLArr { cmd‿name: + "file"‿"arguments" JObj ⟨JStr AtRoot name, ", " JArr JStr¨ cmd0 ∾ cmd⟩ + }¨ singeliObjects + "Singeli compile commands" res _doWrite AtRoot "build/.singeli_compile_commands.json" + } +} \ No newline at end of file