compiler/backend/cgen

    Dark Mode
Search:
  Source   Edit

This module implements the C code generator.This include file contains the logic to produce constant string and seq literals. The code here is responsible that const x = ["a", "b"] works without hidden runtime creation code. The price is that seqs and strings are not purely a library implementation.Thread var support for architectures that lack native support for thread local storage.included from cgen.nim

Consts

NonMagics = {mNewString, mNewStringOfCap, mNewSeq, mSetLengthSeq,
             mAppendSeqElem, mEnumToStr, mExit, mParseBiggestFloat, mAbsI,
             mDotDot, mEqCString, mIsolate}
magics that are treated like normal procedures by the code generator.   Source   Edit
sfTopLevel = sfMainModule
the procedure contains top-level code, which currently affects how emit, asm, and error handling works   Source   Edit

Procs

proc cgenWriteModules(backend: RootRef; config: ConfigRef) {....raises: [OSError,
    IOError, KeyError, Exception, ERecoverableError, ValueError], tags: [
    ReadEnvEffect, ReadIOEffect, WriteDirEffect, ReadDirEffect, RootEffect,
    WriteIOEffect].}
  Source   Edit
proc declareThreadVar(m: BModule; id: GlobalId; isExtern: bool) {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc defineGlobalVar(m: BModule; id: GlobalId) {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc emulatedThreadVars(conf: ConfigRef): bool {.inline, ...raises: [], tags: [].}
  Source   Edit
proc fillGlobalLoc(m: BModule; id: GlobalId) {....raises: [], tags: [].}
  Source   Edit
proc fillProcLoc(m: BModule; id: ProcedureId) {....raises: [], tags: [].}
  Source   Edit
proc finalizeMainModule(m: BModule) {....raises: [], tags: [].}
  Source   Edit
proc finalizeModule(m: BModule) {....raises: [], tags: [].}
  Source   Edit
proc finishProc(p: BProc; id: ProcedureId): string {.
    ...raises: [KeyError, Exception, ERecoverableError],
    tags: [ReadDirEffect, RootEffect].}
  Source   Edit
proc genConstDefinition(q: BModule; id: ConstId) {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc genDatInitCode(m: BModule): bool {....raises: [KeyError, Exception,
    ERecoverableError], tags: [ReadDirEffect, RootEffect].}
this function is called after all modules are closed, it means raising dependency on the symbols is too late as it will not propagate into other modules, only simple rope manipulations are allowed   Source   Edit
proc genMainProc(m: BModule; body: Rope) {....raises: [], tags: [].}
this function is called in cgenWriteModules after all modules are closed, it means raising dependency on the symbols is too late as it will not propagate into other modules, only simple rope manipulations are allowed   Source   Edit
proc genPartial(p: BProc; n: CgNode) {....raises: [Exception, ERecoverableError],
                                       tags: [RootEffect].}
Generates the C code for n and appends the result to p. This is intended for CG IR that wasn't already available when calling startProc.   Source   Edit
proc genProc(m: BModule; id: ProcedureId; procBody: sink Body): Rope {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
Generates the code for the procedure id, where procBody is the code of the body with all applicable lowerings and transformation applied.   Source   Edit
proc genProcPrototype(m: BModule; id: ProcedureId) {.
    ...raises: [ERecoverableError, Exception, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc genStmts(p: BProc; n: CgNode) {....raises: [Exception, ERecoverableError],
                                     tags: [RootEffect].}
Generates and emits the C code for the statement list node n, which makes up the full body of the procedure. This is the external entry point into the C code generator.   Source   Edit
proc genTypeInfo(config: ConfigRef; m: BModule; t: PType; info: TLineInfo): Rope {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc genVarPrototype(m: BModule; id: GlobalId) {.
    ...raises: [ERecoverableError, Exception, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc getDatInitName(m: BModule): Rope {....raises: [], tags: [].}
  Source   Edit
proc getInitName(m: BModule): Rope {....raises: [], tags: [].}
  Source   Edit
proc newModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule {.
    ...raises: [OSError, IOError],
    tags: [ReadEnvEffect, ReadIOEffect, WriteDirEffect, ReadDirEffect].}
  Source   Edit
proc rawNewModule(g: BModuleList; module: PSym; filename: AbsoluteFile): BModule {.
    ...raises: [OSError, IOError],
    tags: [ReadEnvEffect, ReadIOEffect, WriteDirEffect, ReadDirEffect].}
  Source   Edit
proc startProc(m: BModule; id: ProcedureId; procBody: sink Body): BProc {.
    ...raises: [Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc symInDynamicLib(m: BModule; id: ProcedureId) {.
    ...raises: [ValueError, Exception, ERecoverableError, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit
proc useConst(m: BModule; id: ConstId) {.
    ...raises: [ERecoverableError, Exception, KeyError],
    tags: [RootEffect, ReadDirEffect].}
  Source   Edit