Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/epiqc/ScaffCC
08 July 2025, 20:07:17 UTC
  • Code
  • Branches (10)
  • Releases (1)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/ScaffCC_OSX
    • refs/heads/master
    • refs/tags/2.2
    • refs/tags/5.0
    • refs/tags/v1.0
    • refs/tags/v1.0-beta.2
    • refs/tags/v2.0
    • refs/tags/v2.1
    • refs/tags/v3.0
    • refs/tags/v4.0
    • v3.1
  • 2238ff7
  • /
  • scaffold
  • /
  • Scaffold.makefile
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:b6477053c86d9517544117806145690402e91c8e
origin badgedirectory badge Iframe embedding
swh:1:dir:88a06140015e6c13b1b7981d596996c392fc2dae
origin badgerevision badge
swh:1:rev:9d2cca71cf54ddfebda26e247d82ae7b71d9e03c
origin badgesnapshot badge
swh:1:snp:7eb50f12cf990a0030724453139e994df238639f
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 9d2cca71cf54ddfebda26e247d82ae7b71d9e03c authored by Pranav Gokhale on 30 June 2018, 18:56:21 UTC
Fix OpenQASM output formatting of Rx and Ry
Tip revision: 9d2cca7
Scaffold.makefile
SHELL=/bin/bash
PERL=/usr/bin/perl
PYTHON=/usr/bin/python

ROOT=".."
DIRNAME=""
FILENAME=""
FILE=""
CFILE=""
TOFF=0
CTQG=0
ROTATIONS=0

BUILD=$(ROOT)/build/Release+Asserts

SQCTPATH=$(ROOT)/Rotations/sqct/rotZ
GRIDSYNTHPATH=$(ROOT)/Rotations/gridsynth/gridsynth
ROTATIONPATH=$(GRIDSYNTHPATH) # select rotation decomposition tool
SCRIPTSPATH=$(ROOT)/scripts/ # select path to scripts
PRECISION=""
OPTIMIZE=0

CC=$(BUILD)/bin/clang
OPT=$(BUILD)/bin/opt

CC_FLAGS=-c -emit-llvm -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include -I$(DIRNAME)

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
SCAFFOLD_LIB=$(ROOT)/build/Release+Asserts/lib/Scaffold.so
endif
ifeq ($(UNAME_S),Darwin)
SCAFFOLD_LIB=$(ROOT)/build/Release+Asserts/lib/Scaffold.dylib
endif


################################
# Resource Count Estimation
################################
resources: $(FILE).resources

################################
# Flat QASM generation
################################
flat: $(FILE).qasmf

################################
# OpenQASM generation
################################
openqasm: $(FILE).qasm

################################
# QASM generation
################################
qasm: $(FILE).qasmh

################################
# QASM optimization
################################
optimize: $(FILE)_optimized.qasmf

################################
# QX Simulator Generation
################################
qc: $(FILE).qc


.PHONY: res_count qasm flat optimize qc

################################
# Intermediate targets
################################
# Pre-process CTQG
$(FILE)_merged.scaffold: $(FILENAME)
	@if [ $(CTQG) -eq 1 ]; then \
		echo "[Scaffold.makefile] Extracting CTQG from Scaffold ..."; \
		$(PERL) $(ROOT)/ctqg/trans/pre_process.pl $(FILENAME); \
		echo "[Scaffold.makefile] Compiling CTQG ..."; \
		$(ROOT)/ctqg/CTQG/ctqg $(CFILE).ctqg; \
		echo "[Scaffold.makefile] Merging CTQG output back into Scaffold ..."; \
    $(PERL) $(ROOT)/ctqg/trans/trans.pl $(CFILE).qasm > trans.qasm; \
    mv trans.qasm $(CFILE).qasm; \
		$(PERL) $(ROOT)/ctqg/trans/merge.pl $(CFILE).qasm; \
	else \
		cp $(FILENAME) $(FILE)_merged.scaffold; \
	fi

# Compile Scaffold to LLVM bytecode
$(FILE).ll: $(FILE)_merged.scaffold
	@echo "[Scaffold.makefile] Compiling $(FILE)_merged.scaffold ..."
	@$(CC) $(FILE)_merged.scaffold $(CC_FLAGS) -o $(FILE).ll

$(FILE)1.ll: $(FILE).ll
	@echo "[Scaffold.makefile] Transforming cbits ..."
	@$(OPT) -S -load $(SCAFFOLD_LIB) -xform-cbit-stores $(FILE).ll -o $(FILE)1.ll > /dev/null

# Perform normal C++ optimization routines
$(FILE)4.ll: $(FILE)1.ll
	@echo "[Scaffold.makefile] O1 optimizations ..."
	@$(OPT) -S $(FILE)1.ll -no-aa -tbaa -targetlibinfo -basicaa -o $(FILE)1a.ll > /dev/null
	@$(OPT) -S $(FILE)1a.ll -simplifycfg -domtree -o $(FILE)1b.ll > /dev/null
	@$(OPT) -S $(FILE)1b.ll -early-cse -lower-expect -o $(FILE)2.ll > /dev/null
	@$(OPT) -S $(FILE)2.ll -targetlibinfo -no-aa -tbaa -basicaa -globalopt -ipsccp -o $(FILE)3.ll > /dev/null
	@$(OPT) -S $(FILE)3.ll -instcombine -simplifycfg -basiccg -prune-eh -always-inline -functionattrs -domtree -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -iv-users -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -memcpyopt -sccp -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -adce -simplifycfg -instcombine -strip-dead-prototypes -preverify -domtree -verify -o $(FILE)4.ll > /dev/null

# Perform loop unrolling until completely unrolled, then remove dead code
#
# Gory details:
# Unroll until the 'diff' of *4 and *6tmp is NULL (i.e., no differences)
# *4 is used to create *6tmp; *6tmp is copied over *4 for each iteration to retry 'diff'
# As a weird consquence, we need to first rename *4 to *6tmp and create an empty *4 to diff
# This screws with the intermediate results, but they are mostly for debugging anyway
$(FILE)6.ll: $(FILE)4.ll
	@UCNT=0; \
	mv $(FILE)4.ll $(FILE)6tmp.ll; \
	touch $(FILE)4.ll; \
	while [ -n "$$(diff -q $(FILE)4.ll $(FILE)6tmp.ll)" ]; do \
		UCNT=$$(expr $$UCNT + 1); \
		echo "[Scaffold.makefile] Unrolling Loops ($$UCNT) ..."; \
		cp $(FILE)6tmp.ll $(FILE)4.ll; \
		$(OPT) -S $(FILE)4.ll -mem2reg -loops -loop-simplify -loop-rotate -lcssa -loop-unroll -unroll-threshold=100000000 -sccp -simplifycfg -o $(FILE)5.ll > /dev/null && \
		echo "[Scaffold.makefile] Cloning Functions ($$UCNT) ..." && \
		$(OPT) -S -load $(SCAFFOLD_LIB) -FunctionClone -sccp $(FILE)5.ll -o $(FILE)5a.ll > /dev/null && \
		echo "[Scaffold.makefile] Dead Argument Elimination ($$UCNT) ..." && \
		$(OPT) -S -deadargelim $(FILE)5a.ll -o $(FILE)6tmp.ll > /dev/null; \
	done && \
	$(OPT) -S $(FILE)6tmp.ll -internalize -globaldce -adce -o $(FILE)6.ll > /dev/null  
	

# Perform Rotation decomposition if requested and rotation decomp tool is built
$(FILE)7.ll: $(FILE)6.ll
	@if [ ! -e $(ROTATIONPATH) ]; then \
		echo "[Scaffold.makefile] Rotation tool not built, skipping rotation decomposition ..."; \
		cp $(FILE)6.ll $(FILE)7.ll; \
	elif [ $(ROTATIONS) -eq 1 ]; then \
		echo "[Scaffold.makefile] Decomposing Rotations ..." && \
		export ROTATIONPATH=$(ROTATIONPATH) && \
    export PRECISION=$(PRECISION); \
		$(OPT) -S -load $(SCAFFOLD_LIB) -Rotations $(FILE)6.ll -o $(FILE)7.ll > /dev/null; \
	else \
		cp $(FILE)6.ll $(FILE)7.ll; \
	fi

# Remove any code that is useless after optimizations
$(FILE)8.ll: $(FILE)7.ll
	@echo "[Scaffold.makefile] Internalizing and Removing Unused Functions ..."
	@$(OPT) -S $(FILE)7.ll -internalize -globaldce -deadargelim -o $(FILE)8.ll > /dev/null

# Compile RKQC 
$(FILE)9.ll: $(FILE)8.ll
	@if [ $(RKQC) -eq 1 ]; then \
        echo "[Scaffold.makefile] Compiling RKQC Functions ..."; \
        $(OPT) -S -load $(SCAFFOLD_LIB) -GenRKQC $(FILE)8.ll -o $(FILE)9.ll > /dev/null 2> $(FILE).errs; \
	else \
		mv $(FILE)8.ll $(FILE)9.ll; \
    fi

# Perform Toffoli decomposition if TOFF is 1
$(FILE)11.ll: $(FILE)9.ll
	@if [ $(TOFF) -eq 1 ]; then \
    echo "[Scaffold.makefile] Toffoli Decomposition ..."; \
		$(OPT) -S -load $(SCAFFOLD_LIB) -ToffoliReplace $(FILE)9.ll -o $(FILE)11.ll > /dev/null; \
	else \
		cp $(FILE)9.ll $(FILE)11.ll; \
	fi

# Insert reverse functions if REVERSE is 1
$(FILE)12.ll: $(FILE)11.ll
	@echo "[Scaffold.makefile] Inserting Reverse Functions..."
	@$(OPT) -S -load $(SCAFFOLD_LIB) -FunctionReverse $(FILE)11.ll -o $(FILE)12.ll > /dev/null

# Generate resource counts from final LLVM output
$(FILE).resources: $(FILE)12.ll
	@echo "[Scaffold.makefile] Generating resource count ..."    
	@$(OPT) -load $(SCAFFOLD_LIB) -ResourceCount $(FILE)12.ll 2> $(FILE).resources > /dev/null
	@echo "[Scaffold.makefile] Resources written to $(FILE).resources ..."  

# Generate hierarchical QASM
$(FILE).qasmh: $(FILE)12.ll
	@echo "[Scaffold.makefile] Generating hierarchical QASM ..."  
	@$(OPT) -load $(SCAFFOLD_LIB) -gen-qasm $(FILE)12.ll 2> $(FILE).qasmh > /dev/null
	@echo "[Scaffold.makefile] Hierarchical QASM written to $(FILE).qasmh ..."  

# Translate hierarchical QASM back to C++ for flattening
$(FILE)_qasm.scaffold: $(FILE).qasmh
	@echo "[Scaffold.makefile] Generating flattened QASM ..."
	@$(PYTHON) $(ROOT)/scaffold/flatten-qasm.py $(FILE).qasmh

# Compile C++
$(FILE)_qasm: $(FILE)_qasm.scaffold
	@$(CC) $(FILE)_qasm.scaffold -o $(FILE)_qasm

# Generate flattened QASM 
$(FILE).qasmf: $(FILE)12.ll
	@echo "[Scaffold.makefile] Flattening modules ..." 
	@$(OPT) -S -load $(SCAFFOLD_LIB) -FlattenModule -all 1 $(FILE)12.ll -o $(FILE)12.inlined.ll 2> /dev/null
	@$(OPT) -load $(SCAFFOLD_LIB) -gen-qasm $(FILE)12.inlined.ll 2> $(FILE).qasmh > /dev/null
	@$(PYTHON) $(ROOT)/scaffold/flatten-qasm.py $(FILE).qasmh
	@$(CC) $(FILE)_qasm.scaffold -o $(FILE)_qasm
	@./$(FILE)_qasm > $(FILE).tmp
	@cat fdecl.out $(FILE).tmp > $(FILE).qasmf
	@echo "[Scaffold.makefile] Flat QASM written to $(FILE).qasmf ..."    

# Generate OpenQASM
$(FILE).qasm: $(FILE)12.ll
	@echo "[Scaffold.makefile] Flattening modules ..."
	@$(OPT) -S -load $(SCAFFOLD_LIB) -FlattenModule -all 1 $(FILE)12.ll -o $(FILE)12.inlined.ll 2> /dev/null
	@echo "[Scaffold.makefile] Generating OpenQASM ..."
	@$(OPT) -load $(SCAFFOLD_LIB) -gen-openqasm $(FILE)12.inlined.ll 2> $(FILE).qasm > /dev/null
	@echo "[Scaffold.makefile] OpenQASM written to $(FILE).qasm ..."

# Generate optimized QASM
$(FILE)_optimized.qasmf: $(FILE)12.ll
	@if [ $(OPTIMIZE) -eq 1 ]; then \
		echo "[Scaffold.makefile] Optimizing circuit ..."; \
		$(OPT) -S -load $(SCAFFOLD_LIB) -FlattenModule -all 1 $(FILE)12.ll -o $(FILE)12.inlined.ll 2> /dev/null; \
		$(OPT) -load $(SCAFFOLD_LIB) -Optimize $(FILE)12.inlined.ll 2> $(FILE)_optimized.qasmf > /dev/null; \
		echo "[Scaffold.makefile] Optimized circuit written to $(FILE)_optimized.qasmf ..."; \
	fi

# Generate simulation input
$(FILE).qc: $(FILE).qasmf
	@echo "[Scaffold.makefile] Transforming flat QASM to QX Simulator input ..."
	@$(SHELL) $(ROOT)/scripts/qasmf2qc.sh $(FILE).qasmf
	@echo "[Scaffold.makefile] QX Simulator input written to $(FILE).qc ..." 

# purge cleans temp files
purge:
	@rm -f $(FILE)_merged.scaffold $(FILE)_no.scaffold $(FILE).ll $(FILE)1.ll $(FILE)1a.ll $(FILE)1b.ll $(FILE)2.ll $(FILE)3.ll $(FILE)4.ll $(FILE)5.ll $(FILE)5a.ll $(FILE)6.ll $(FILE)6tmp.ll $(FILE)7.ll $(FILE)8.ll $(FILE)9.ll $(FILE)10.ll $(FILE)11.ll $(FILE)12.ll $(FILE)12.inlined.ll $(FILE)tmp.ll $(FILE)_qasm $(FILE)_qasm.scaffold fdecl.out $(CFILE).ctqg $(CFILE).c $(CFILE).signals $(FILE).tmp sim_$(CFILE) $(FILE).*.qasm

# clean removes all completed files
clean: purge
	@rm -f $(FILE).resources $(FILE).qasmh $(FILE).qasmf $(FILE).qasm $(FILE)_optimized.qasmf $(FILE).qc

.PHONY: clean purge

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API